diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index de8ddf1..94faed2 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -14,6 +14,21 @@ type TestAddCatResp struct { Message string `json:"message"` } +type ChangeCoinReq struct { + Type int `json:"type"` + Coin string `json:"coin"` +} + +type ChangeCoinData struct { + Coin DoBuyCatCoin `json:"coin"` +} + +type ChangeCoinResp struct { + Code int `json:"code"` + Data ChangeCoinData `json:"data"` + Message string `json:"message"` +} + type UserLoginReq struct { Lype int `json:"type"` UserId int `json:"userId"` diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 6c78791..92257c4 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -573,8 +573,8 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { d1.Cat = 0 //d1.Cat = 18 - if i < 4 { - d1.Cat = 36 + if i < 2 { + d1.Cat = 1 } udata.PosInfo = append(udata.PosInfo, d1) diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 325654a..99e8fa2 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -109,7 +109,8 @@ func CheckErr(err error) { func startServerHttpServe() { //test - http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫 + http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫 + http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫 //real http.HandleFunc("/api/account/login", UserLogin) //登录 @@ -1291,6 +1292,24 @@ func Getrandredbag(w http.ResponseWriter, r *http.Request) { HandlerGetrandredbag(w, s, Uuid) } +func ChangeCoin(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("ChangeCoin , body:%v,uuid=%v", s, Uuid) + + HandlerChangeCoin(w, s, Uuid) +} + func TestaddCat(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 24954b1..6ccd9ca 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -41,6 +41,55 @@ func SetHeader(w http.ResponseWriter) { } +func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp ChangeCoinResp + resp.Code = 0 + resp.Message = "success" + var rdata ChangeCoinReq + 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 + } + + addgold, _ := strconv.ParseInt(rdata.Coin, 10, 64) + if rdata.Type == 0 { + uinfo.Gold += addgold + } else { + uinfo.Gold -= addgold + } + + resp.Data.Coin.UserId = uuid + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10) + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10) + resp.Data.Coin.UpdateTime = int(time.Now().Unix()) + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + break + } + + //回包 + 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) { SetHeader(w) var resp TestAddCatResp @@ -77,6 +126,7 @@ func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) { catid, _ := strconv.Atoi(rdata.CatId) uinfo.PosInfo[rdata.Position].Cat = catid + uinfo.CalcGoldRate() SaveUserInfo(uinfo, strconv.Itoa(uuid)) break } -- libgit2 0.21.0