Commit f5ecc2c09b9062ee56d4294bc1fa413071905617

Authored by 陆恒
1 parent 0d8ea0a7
Exists in master

提交

src/HttpServer/logic/datadef.go
... ... @@ -19,6 +19,32 @@ type ChangeCoinReq struct {
19 19 Coin int64 `json:"coin"`
20 20 }
21 21  
  22 +type AddAdCountReq struct {
  23 + Count int `json:"count"`
  24 +}
  25 +
  26 +type AddAdCountData struct {
  27 +}
  28 +
  29 +type AddAdCountResp struct {
  30 + Code int `json:"code"`
  31 + Data AddAdCountData `json:"data"`
  32 + Message string `json:"message"`
  33 +}
  34 +
  35 +type AddFlopReq struct {
  36 + Count int `json:"count"`
  37 +}
  38 +
  39 +type AddFlopData struct {
  40 +}
  41 +
  42 +type AddFlopResp struct {
  43 + Code int `json:"code"`
  44 + Data AddFlopData `json:"data"`
  45 + Message string `json:"message"`
  46 +}
  47 +
22 48 type ChangeCoinData struct {
23 49 Coin DoBuyCatCoin `json:"coin"`
24 50 }
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -26,6 +26,7 @@ func StartHttpTicker() {
26 26 go func() {
27 27 for range ticker.C {
28 28 if time.Now().Hour() == 0 && time.Now().Minute() < 1 {
  29 + rand.Seed(time.Now().UnixNano())
29 30 randint := rand.Intn(100)
30 31 floatval := float32(randint) / 100
31 32 G_randVal = 180 + floatval
... ... @@ -111,6 +112,8 @@ func startServerHttpServe() {
111 112 //test
112 113 http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫
113 114 http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫
  115 + http.HandleFunc("/api/test/addAdCount", AddAdCount) //增加广告次数
  116 + http.HandleFunc("/api/test/addFlop", AddFlop) //增加翻牌
114 117  
115 118 //real
116 119 http.HandleFunc("/api/account/login", UserLogin) //登录
... ... @@ -1292,6 +1295,42 @@ func Getrandredbag(w http.ResponseWriter, r *http.Request) {
1292 1295 HandlerGetrandredbag(w, s, Uuid)
1293 1296 }
1294 1297  
  1298 +func AddFlop(w http.ResponseWriter, r *http.Request) {
  1299 + Uuid := 0
  1300 + if len(r.Header) > 0 {
  1301 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1302 + }
  1303 + if Uuid == 0 {
  1304 + SetHeader(w)
  1305 + return
  1306 + }
  1307 + result, _ := ioutil.ReadAll(r.Body)
  1308 + r.Body.Close()
  1309 +
  1310 + s := string(result)
  1311 + logger.Info("AddFlop , body:%v,uuid=%v", s, Uuid)
  1312 +
  1313 + HandlerAddFlop(w, s, Uuid)
  1314 +}
  1315 +
  1316 +func AddAdCount(w http.ResponseWriter, r *http.Request) {
  1317 + Uuid := 0
  1318 + if len(r.Header) > 0 {
  1319 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1320 + }
  1321 + if Uuid == 0 {
  1322 + SetHeader(w)
  1323 + return
  1324 + }
  1325 + result, _ := ioutil.ReadAll(r.Body)
  1326 + r.Body.Close()
  1327 +
  1328 + s := string(result)
  1329 + logger.Info("AddAdCount , body:%v,uuid=%v", s, Uuid)
  1330 +
  1331 + HandlerAddAdCount(w, s, Uuid)
  1332 +}
  1333 +
1295 1334 func ChangeCoin(w http.ResponseWriter, r *http.Request) {
1296 1335 Uuid := 0
1297 1336 if len(r.Header) > 0 {
... ...
src/HttpServer/logic/logic.go
... ... @@ -41,6 +41,82 @@ func SetHeader(w http.ResponseWriter) {
41 41  
42 42 }
43 43  
  44 +func HandlerAddFlop(w http.ResponseWriter, data string, uuid int) {
  45 + SetHeader(w)
  46 + var resp AddFlopResp
  47 + resp.Code = 0
  48 + resp.Message = "success"
  49 + var rdata AddFlopReq
  50 + err := json.Unmarshal([]byte(data), &rdata)
  51 + if err != nil {
  52 + logger.Info("json decode HandlerAddFlop data failed:%v,for:%v", err, data)
  53 + resp.Message = "json unmarshal failed"
  54 + resp.Code = 1
  55 + respstr, _ := json.Marshal(&resp)
  56 + logger.Info("###HandlerLogin###rdata:%v", string(respstr))
  57 + fmt.Fprint(w, string(respstr))
  58 + return
  59 + }
  60 +
  61 + for {
  62 +
  63 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  64 + if err != nil || uinfo == nil {
  65 + logger.Error("HandlerTestaddCat getuserinfo failed=%v", err)
  66 + resp.Code = 1
  67 + resp.Message = "get userinfo failed"
  68 + break
  69 + }
  70 +
  71 + uinfo.FlopCardLefCnt += rdata.Count
  72 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  73 + break
  74 + }
  75 +
  76 + //回包
  77 + respstr, _ := json.Marshal(&resp)
  78 + fmt.Fprint(w, string(respstr))
  79 +
  80 +}
  81 +
  82 +func HandlerAddAdCount(w http.ResponseWriter, data string, uuid int) {
  83 + SetHeader(w)
  84 + var resp AddAdCountResp
  85 + resp.Code = 0
  86 + resp.Message = "success"
  87 + var rdata AddAdCountReq
  88 + err := json.Unmarshal([]byte(data), &rdata)
  89 + if err != nil {
  90 + logger.Info("json decode HandlerChangeCoin data failed:%v,for:%v", err, data)
  91 + resp.Message = "json unmarshal failed"
  92 + resp.Code = 1
  93 + respstr, _ := json.Marshal(&resp)
  94 + logger.Info("###HandlerLogin###rdata:%v", string(respstr))
  95 + fmt.Fprint(w, string(respstr))
  96 + return
  97 + }
  98 +
  99 + for {
  100 +
  101 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  102 + if err != nil || uinfo == nil {
  103 + logger.Error("HandlerTestaddCat getuserinfo failed=%v", err)
  104 + resp.Code = 1
  105 + resp.Message = "get userinfo failed"
  106 + break
  107 + }
  108 +
  109 + uinfo.GetWatchAdsGoldTime += rdata.Count
  110 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  111 + break
  112 + }
  113 +
  114 + //回包
  115 + respstr, _ := json.Marshal(&resp)
  116 + fmt.Fprint(w, string(respstr))
  117 +
  118 +}
  119 +
44 120 func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) {
45 121 SetHeader(w)
46 122 var resp ChangeCoinResp
... ... @@ -87,7 +163,6 @@ func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) {
87 163 respstr, _ := json.Marshal(&resp)
88 164 fmt.Fprint(w, string(respstr))
89 165  
90   - logger.Info("###HandlerLogin###rdata:%v", string(respstr))
91 166 }
92 167  
93 168 func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) {
... ... @@ -135,7 +210,7 @@ func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) {
135 210 respstr, _ := json.Marshal(&resp)
136 211 fmt.Fprint(w, string(respstr))
137 212  
138   - logger.Info("###HandlerLogin###rdata:%v", string(respstr))
  213 + //logger.Info("###HandlerLogin###rdata:%v", string(respstr))
139 214 }
140 215  
141 216 func HandlerLogin(w http.ResponseWriter, data string, uuid int, token string) {
... ...