diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index d5e1d2c..96c9681 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -19,6 +19,32 @@ type ChangeCoinReq struct { Coin int64 `json:"coin"` } +type AddAdCountReq struct { + Count int `json:"count"` +} + +type AddAdCountData struct { +} + +type AddAdCountResp struct { + Code int `json:"code"` + Data AddAdCountData `json:"data"` + Message string `json:"message"` +} + +type AddFlopReq struct { + Count int `json:"count"` +} + +type AddFlopData struct { +} + +type AddFlopResp struct { + Code int `json:"code"` + Data AddFlopData `json:"data"` + Message string `json:"message"` +} + type ChangeCoinData struct { Coin DoBuyCatCoin `json:"coin"` } diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 99e8fa2..39a512e 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -26,6 +26,7 @@ func StartHttpTicker() { go func() { for range ticker.C { if time.Now().Hour() == 0 && time.Now().Minute() < 1 { + rand.Seed(time.Now().UnixNano()) randint := rand.Intn(100) floatval := float32(randint) / 100 G_randVal = 180 + floatval @@ -111,6 +112,8 @@ func startServerHttpServe() { //test http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫 http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫 + http.HandleFunc("/api/test/addAdCount", AddAdCount) //增加广告次数 + http.HandleFunc("/api/test/addFlop", AddFlop) //增加翻牌 //real http.HandleFunc("/api/account/login", UserLogin) //登录 @@ -1292,6 +1295,42 @@ func Getrandredbag(w http.ResponseWriter, r *http.Request) { HandlerGetrandredbag(w, s, Uuid) } +func AddFlop(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("AddFlop , body:%v,uuid=%v", s, Uuid) + + HandlerAddFlop(w, s, Uuid) +} + +func AddAdCount(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("AddAdCount , body:%v,uuid=%v", s, Uuid) + + HandlerAddAdCount(w, s, Uuid) +} + func ChangeCoin(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index eb340cf..91e7a4b 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -41,6 +41,82 @@ func SetHeader(w http.ResponseWriter) { } +func HandlerAddFlop(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp AddFlopResp + resp.Code = 0 + resp.Message = "success" + var rdata AddFlopReq + err := json.Unmarshal([]byte(data), &rdata) + if err != nil { + logger.Info("json decode HandlerAddFlop data failed:%v,for:%v", err, data) + resp.Message = "json unmarshal failed" + resp.Code = 1 + respstr, _ := json.Marshal(&resp) + logger.Info("###HandlerLogin###rdata:%v", string(respstr)) + fmt.Fprint(w, string(respstr)) + return + } + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerTestaddCat getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + uinfo.FlopCardLefCnt += rdata.Count + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerAddAdCount(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp AddAdCountResp + resp.Code = 0 + resp.Message = "success" + var rdata AddAdCountReq + err := json.Unmarshal([]byte(data), &rdata) + if err != nil { + logger.Info("json decode HandlerChangeCoin data failed:%v,for:%v", err, data) + resp.Message = "json unmarshal failed" + resp.Code = 1 + respstr, _ := json.Marshal(&resp) + logger.Info("###HandlerLogin###rdata:%v", string(respstr)) + fmt.Fprint(w, string(respstr)) + return + } + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerTestaddCat getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + uinfo.GetWatchAdsGoldTime += rdata.Count + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp ChangeCoinResp @@ -87,7 +163,6 @@ func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) { respstr, _ := json.Marshal(&resp) fmt.Fprint(w, string(respstr)) - logger.Info("###HandlerLogin###rdata:%v", string(respstr)) } func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) { @@ -135,7 +210,7 @@ func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) { respstr, _ := json.Marshal(&resp) fmt.Fprint(w, string(respstr)) - logger.Info("###HandlerLogin###rdata:%v", string(respstr)) + //logger.Info("###HandlerLogin###rdata:%v", string(respstr)) } func HandlerLogin(w http.ResponseWriter, data string, uuid int, token string) { -- libgit2 0.21.0