Commit 3e2f8b162a4b05d8d3bfada4a5bd412183f4ff6b

Authored by 陆恒
1 parent 3e014017
Exists in master

提交

src/HttpServer/logic/datadef.go
... ... @@ -14,6 +14,21 @@ type TestAddCatResp struct {
14 14 Message string `json:"message"`
15 15 }
16 16  
  17 +type ChangeCoinReq struct {
  18 + Type int `json:"type"`
  19 + Coin string `json:"coin"`
  20 +}
  21 +
  22 +type ChangeCoinData struct {
  23 + Coin DoBuyCatCoin `json:"coin"`
  24 +}
  25 +
  26 +type ChangeCoinResp struct {
  27 + Code int `json:"code"`
  28 + Data ChangeCoinData `json:"data"`
  29 + Message string `json:"message"`
  30 +}
  31 +
17 32 type UserLoginReq struct {
18 33 Lype int `json:"type"`
19 34 UserId int `json:"userId"`
... ...
src/HttpServer/logic/function.go
... ... @@ -573,8 +573,8 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
573 573  
574 574 d1.Cat = 0
575 575 //d1.Cat = 18
576   - if i < 4 {
577   - d1.Cat = 36
  576 + if i < 2 {
  577 + d1.Cat = 1
578 578 }
579 579 udata.PosInfo = append(udata.PosInfo, d1)
580 580  
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -109,7 +109,8 @@ func CheckErr(err error) {
109 109  
110 110 func startServerHttpServe() {
111 111 //test
112   - http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫
  112 + http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫
  113 + http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫
113 114  
114 115 //real
115 116 http.HandleFunc("/api/account/login", UserLogin) //登录
... ... @@ -1291,6 +1292,24 @@ func Getrandredbag(w http.ResponseWriter, r *http.Request) {
1291 1292 HandlerGetrandredbag(w, s, Uuid)
1292 1293 }
1293 1294  
  1295 +func ChangeCoin(w http.ResponseWriter, r *http.Request) {
  1296 + Uuid := 0
  1297 + if len(r.Header) > 0 {
  1298 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1299 + }
  1300 + if Uuid == 0 {
  1301 + SetHeader(w)
  1302 + return
  1303 + }
  1304 + result, _ := ioutil.ReadAll(r.Body)
  1305 + r.Body.Close()
  1306 +
  1307 + s := string(result)
  1308 + logger.Info("ChangeCoin , body:%v,uuid=%v", s, Uuid)
  1309 +
  1310 + HandlerChangeCoin(w, s, Uuid)
  1311 +}
  1312 +
1294 1313 func TestaddCat(w http.ResponseWriter, r *http.Request) {
1295 1314 Uuid := 0
1296 1315 if len(r.Header) > 0 {
... ...
src/HttpServer/logic/logic.go
... ... @@ -41,6 +41,55 @@ func SetHeader(w http.ResponseWriter) {
41 41  
42 42 }
43 43  
  44 +func HandlerChangeCoin(w http.ResponseWriter, data string, uuid int) {
  45 + SetHeader(w)
  46 + var resp ChangeCoinResp
  47 + resp.Code = 0
  48 + resp.Message = "success"
  49 + var rdata ChangeCoinReq
  50 + err := json.Unmarshal([]byte(data), &rdata)
  51 + if err != nil {
  52 + logger.Info("json decode HandlerChangeCoin 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 + addgold, _ := strconv.ParseInt(rdata.Coin, 10, 64)
  72 + if rdata.Type == 0 {
  73 + uinfo.Gold += addgold
  74 + } else {
  75 + uinfo.Gold -= addgold
  76 + }
  77 +
  78 + resp.Data.Coin.UserId = uuid
  79 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  80 + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10)
  81 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  82 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  83 + break
  84 + }
  85 +
  86 + //回包
  87 + respstr, _ := json.Marshal(&resp)
  88 + fmt.Fprint(w, string(respstr))
  89 +
  90 + logger.Info("###HandlerLogin###rdata:%v", string(respstr))
  91 +}
  92 +
44 93 func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) {
45 94 SetHeader(w)
46 95 var resp TestAddCatResp
... ... @@ -77,6 +126,7 @@ func HandlerTestaddCat(w http.ResponseWriter, data string, uuid int) {
77 126  
78 127 catid, _ := strconv.Atoi(rdata.CatId)
79 128 uinfo.PosInfo[rdata.Position].Cat = catid
  129 + uinfo.CalcGoldRate()
80 130 SaveUserInfo(uinfo, strconv.Itoa(uuid))
81 131 break
82 132 }
... ...