Commit b8745176833ba520df0842f98802097bcac11e0f

Authored by 陆恒
1 parent 81b07025
Exists in master

提交

src/HttpServer/logic/constdef.go
... ... @@ -58,4 +58,5 @@ const (
58 58 DRAWTICKETNUM = 5 //每日送的抽奖券次数
59 59 DRAWTICKETGETLIMIT = 5 //每日抽奖券获得次数
60 60 DRAWTICKETNUMLIMIT = 10 //抽奖券上限
  61 + WAREHOUSELIMIT = 15 //仓库容量上限
61 62 )
... ...
src/HttpServer/logic/datadef.go
... ... @@ -331,10 +331,15 @@ type DoBuyCatResp struct {
331 331 Data DoBuyCatData `json:"data"`
332 332 }
333 333  
  334 +type QueryWareHouseData struct {
  335 + CatList []int `json:"catList"`
  336 + CatCapacity int `json:"catCapacity"`
  337 +}
  338 +
334 339 type QueryWareHouseResp struct {
335   - Code int `json:"code"`
336   - Message string `json:"message"`
337   - Data []DataDesc `json:"data"`
  340 + Code int `json:"code"`
  341 + Message string `json:"message"`
  342 + Data QueryWareHouseData `json:"data"`
338 343 }
339 344  
340 345 type QueryAutomergeResp struct {
... ... @@ -347,21 +352,24 @@ type QueryAutomergeResp struct {
347 352 }
348 353  
349 354 type PutWareHouseReq struct {
350   - Pos int `json:"pos"`
  355 + Position int `json:"position"`
  356 +}
  357 +type PutWareHouseData struct {
  358 + Coin DoBuyCatCoin `json:"coin"`
351 359 }
352 360 type PutWareHouseResp struct {
353   - Code int `json:"code"`
354   - Message string `json:"message"`
355   - Warepos int `json:"warepos"`
  361 + Code int `json:"code"`
  362 + Message string `json:"message"`
  363 + Data PutWareHouseData `json:"data"`
356 364 }
357 365  
358 366 type TakeWareHouseReq struct {
359   - Warepos int `json:"warepos"`
  367 + CatId int `json:"catId"`
360 368 }
361 369 type TakeWareHouseResp struct {
362   - Code int `json:"code"`
363   - Message string `json:"message"`
364   - Pos int `json:"pos"`
  370 + Code int `json:"code"`
  371 + Message string `json:"message"`
  372 + Data PutWareHouseData `json:"data"`
365 373 }
366 374  
367 375 type CatRoomDesc struct {
... ... @@ -665,7 +673,10 @@ type UserData struct {
665 673  
666 674 //仓库数据详情
667 675 type WareHouseDesc struct {
668   - Warelv int //红包猫等级 对应表id
  676 + Warelv int //红包猫等级 对应表id
  677 + RedPacket float32
  678 + Time int
  679 + StartTime int
669 680 }
670 681  
671 682 //玩家仓库数据
... ...
src/HttpServer/logic/function.go
... ... @@ -494,7 +494,7 @@ func MergeRedBagCat(uinfo *UserData, pos int) int {
494 494 tmprate += int(v.Rate * 100 / sumrate)
495 495 if tmprate >= randnum {
496 496 uinfo.PosInfo[pos].Position = pos
497   - uinfo.PosInfo[pos].Cat = 100 + v.Id
  497 + uinfo.PosInfo[pos].Cat = REDCATIDEXTRA + v.Id
498 498 if v.Id == 13 {
499 499 uinfo.PosInfo[pos].Time = 10 * 60
500 500 uinfo.PosInfo[pos].StartTime = int(time.Now().Unix())
... ... @@ -544,7 +544,7 @@ func (udata *UserData) CalcGoldRate() int64 {
544 544 return 0
545 545 }
546 546 for _, v := range udata.PosInfo {
547   - if v.Cat > 0 && v.Cat < 100 {
  547 + if v.Cat > 0 && v.Cat < REDCATIDEXTRA {
548 548 //有猫存在的要计算一下
549 549 //非红包猫
550 550 for _, vv := range jsonconf.GetJsonConf().CatConfig {
... ... @@ -556,7 +556,7 @@ func (udata *UserData) CalcGoldRate() int64 {
556 556 }
557 557 }
558 558  
559   - if v.Cat > 100 {
  559 + if v.Cat > REDCATIDEXTRA {
560 560 //红包猫 需要判断是否产金币
561 561 rcfg := jsonconf.GetRedCatConfig(v.Cat)
562 562 if rcfg != nil {
... ... @@ -585,14 +585,14 @@ func (udata *UserData) CalcGoldRate() int64 {
585 585 if v.Warelv == 0 {
586 586 continue
587 587 }
588   - rcfg := jsonconf.GetRedCatConfig(v.Warelv + 100)
  588 + rcfg := jsonconf.GetRedCatConfig(v.Warelv + REDCATIDEXTRA)
589 589 if rcfg != nil {
590 590 if rcfg.Is_37 != 0 {
591 591 onerate, _ := strconv.ParseInt(cfg37.Gold_get, 10, 64)
592 592 sumrate += onerate
593 593 }
594 594 } else {
595   - logger.Error("GetRedCatConfig failed lv=%v", v.Warelv+100)
  595 + logger.Error("GetRedCatConfig failed lv=%v", v.Warelv+REDCATIDEXTRA)
596 596 }
597 597 }
598 598  
... ... @@ -631,7 +631,7 @@ func (u *UserData) CalcHigestCatName() string {
631 631 return ""
632 632 }
633 633 for _, val := range wdata.Info {
634   - reallv := val.Warelv + 100
  634 + reallv := val.Warelv + REDCATIDEXTRA
635 635 if higestlv < reallv {
636 636 higestlv = reallv
637 637 }
... ... @@ -688,3 +688,30 @@ func (u *UserData) GetRedCatIdList() []int {
688 688 }
689 689  
690 690 }
  691 +
  692 +//尝试将合成界面的猫放入仓库 返回位置索引 -1表示仓库已满放入失败
  693 +func (u *UserData) tryPutToWareHouse(info *UserWareHouseData, pos int, uuid int) int {
  694 + rtval := -1
  695 + for k, v := range info.Info {
  696 + if v.Warelv == 0 {
  697 + rtval = k
  698 + info.Info[k].Warelv = u.PosInfo[pos].Cat
  699 + info.Info[k].Time = u.PosInfo[pos].Time
  700 + info.Info[k].RedPacket = u.PosInfo[pos].RedPacket
  701 + info.Info[k].StartTime = u.PosInfo[pos].StartTime
  702 + //v.Warelv = lv
  703 +
  704 + break
  705 + }
  706 + }
  707 + if rtval != -1 {
  708 + wares, _ := json.Marshal(info)
  709 + redishandler.GetRedisClient().HSet(redis.USER_WAREHOUSE_INFO, strconv.Itoa(uuid), string(wares))
  710 + }
  711 + return rtval
  712 +}
  713 +
  714 +//根据id获得仓位位置
  715 +func (w *UserWareHouseData) GetWarePosById(cid int) int {
  716 + return -1
  717 +}
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -23,30 +23,33 @@ func CheckErr(err error) {
23 23 }
24 24  
25 25 func startServerHttpServe() {
26   - http.HandleFunc("/api/account/login", UserLogin) //登录
27   - http.HandleFunc("/api/home/buy", DoBuyCat) //购买猫
28   - http.HandleFunc("/api/home/synResource", GetUserData) //同步资源
29   - http.HandleFunc("/api/home/recvOfflineReward", GetOfflineReward) //领取离线奖励
30   - http.HandleFunc("/api/ranking/list", QueryPlayerRank) //排行榜
31   - http.HandleFunc("/api/home/index", GetMainPageInfo) //主页面
32   - http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速
33   - http.HandleFunc("/api/home/shop", QueryBuyCat) //商店
34   - http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数
35   - http.HandleFunc("/api/home/change", ExchangePos) //合成
36   - http.HandleFunc("/api/home/leftTimes", LeftTimes) //剩余看广告领取金币次数
37   - http.HandleFunc("/api/home/adCoin", WatchAdsGetGold) //看广告领取金币
38   - http.HandleFunc("/api/home/recvTimingReward", RecvTimingReward) //整点领取金币
39   - http.HandleFunc("/api/home/redCatList", RedCatList) //红包猫列表 此接口目前没有用到 暂时不实线
40   - http.HandleFunc("/api/home/recovery", Recovery) //回收猫
41   - http.HandleFunc("/api/home/compose", Compose) //五猫合成
42   - http.HandleFunc("/api/home/recvRedCat", RecvRedCat) //红包猫领取
43   - http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表
44   - http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页
45   - http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券
46   - http.HandleFunc("/api/turntable/multiple", Multiple) //增加倍数
47   - http.HandleFunc("/api/turntable/draw", DrawTable) //抽奖
48   - http.HandleFunc("/api/flop/leftTimes", QueryFlop) //剩余翻牌次数
49   - http.HandleFunc("/api/flop/flop", DoFlop) //进行翻牌
  26 + http.HandleFunc("/api/account/login", UserLogin) //登录
  27 + http.HandleFunc("/api/home/buy", DoBuyCat) //购买猫
  28 + http.HandleFunc("/api/home/synResource", GetUserData) //同步资源
  29 + http.HandleFunc("/api/home/recvOfflineReward", GetOfflineReward) //领取离线奖励
  30 + http.HandleFunc("/api/ranking/list", QueryPlayerRank) //排行榜
  31 + http.HandleFunc("/api/home/index", GetMainPageInfo) //主页面
  32 + http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速
  33 + http.HandleFunc("/api/home/shop", QueryBuyCat) //商店
  34 + http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数
  35 + http.HandleFunc("/api/home/change", ExchangePos) //合成
  36 + http.HandleFunc("/api/home/leftTimes", LeftTimes) //剩余看广告领取金币次数
  37 + http.HandleFunc("/api/home/adCoin", WatchAdsGetGold) //看广告领取金币
  38 + http.HandleFunc("/api/home/recvTimingReward", RecvTimingReward) //整点领取金币
  39 + http.HandleFunc("/api/home/redCatList", RedCatList) //红包猫列表 此接口目前没有用到 暂时不实线
  40 + http.HandleFunc("/api/home/recovery", Recovery) //回收猫
  41 + http.HandleFunc("/api/home/compose", Compose) //五猫合成
  42 + http.HandleFunc("/api/home/recvRedCat", RecvRedCat) //红包猫领取
  43 + http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表
  44 + http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页
  45 + http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券
  46 + http.HandleFunc("/api/turntable/multiple", Multiple) //增加倍数
  47 + http.HandleFunc("/api/turntable/draw", DrawTable) //抽奖
  48 + http.HandleFunc("/api/flop/leftTimes", QueryFlop) //剩余翻牌次数
  49 + http.HandleFunc("/api/flop/flop", DoFlop) //进行翻牌
  50 + http.HandleFunc("/api/package/catList", QueryWareHouse) //背包列表
  51 + http.HandleFunc("/api/package/putToPackage", PutCattoWareHouse) //加入背包
  52 + http.HandleFunc("/api/package/getFromPackage", TakeCatoutfromWareHouse) //背包中取出
50 53  
51 54 /////---------------------------------------------------------------------old
52 55 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置
... ... @@ -58,19 +61,19 @@ func startServerHttpServe() {
58 61 http.HandleFunc("/happycat/clickrandgift", ClickRandGift) //请求点击猫箱子
59 62 //http.HandleFunc("/happycat/querybuycat", QueryBuyCat) //请求商店购买信息
60 63  
61   - http.HandleFunc("/happycat/querwarehouse", QueryWareHouse) //请求仓库信息
62   - http.HandleFunc("/happycat/putcattowarehouse", PutCattoWareHouse) //将合成界面的猫放入仓库
63   - http.HandleFunc("/happycat/takecatoutfromwarehouse", TakeCatoutfromWareHouse) //将仓库的猫取出
64   - http.HandleFunc("/happycat/acclecteboxrate ", AcclecteBoxRate) //请求点击猫箱子
65   - http.HandleFunc("/happycat/queryautomergeinfo ", QueryAutomergeInfo) //请求点击猫箱子
66   - http.HandleFunc("/happycat/querycatroominfo ", QueryCatRoomInfo) //请求点击猫箱子
67   - http.HandleFunc("/happycat/buycatroom ", BuyCatRoom) //请求点击猫箱子
68   - http.HandleFunc("/happycat/upcattoroom ", UpCattoRoom) //请求点击猫箱子
69   - http.HandleFunc("/happycat/querycatshopinfo ", QueryCatShopInfo) //请求点击猫箱子
70   - http.HandleFunc("/happycat/catshoplay ", CatShoPlay) //请求点击猫箱子
71   - http.HandleFunc("/happycat/getcatshopreward ", GetCatShopReward) //请求点击猫箱子
72   - http.HandleFunc("/happycat/acclectecatstory ", AcclecteCatStory) //请求点击猫箱子
73   - http.HandleFunc("/chappycatat/updateuserinfo ", UpdateUserInfo) //请求点击猫箱子
  64 + //http.HandleFunc("/happycat/querwarehouse", QueryWareHouse) //请求仓库信息
  65 + //http.HandleFunc("/happycat/putcattowarehouse", PutCattoWareHouse) //将合成界面的猫放入仓库
  66 + // http.HandleFunc("/happycat/takecatoutfromwarehouse", TakeCatoutfromWareHouse) //将仓库的猫取出
  67 + http.HandleFunc("/happycat/acclecteboxrate ", AcclecteBoxRate) //请求点击猫箱子
  68 + http.HandleFunc("/happycat/queryautomergeinfo ", QueryAutomergeInfo) //请求点击猫箱子
  69 + http.HandleFunc("/happycat/querycatroominfo ", QueryCatRoomInfo) //请求点击猫箱子
  70 + http.HandleFunc("/happycat/buycatroom ", BuyCatRoom) //请求点击猫箱子
  71 + http.HandleFunc("/happycat/upcattoroom ", UpCattoRoom) //请求点击猫箱子
  72 + http.HandleFunc("/happycat/querycatshopinfo ", QueryCatShopInfo) //请求点击猫箱子
  73 + http.HandleFunc("/happycat/catshoplay ", CatShoPlay) //请求点击猫箱子
  74 + http.HandleFunc("/happycat/getcatshopreward ", GetCatShopReward) //请求点击猫箱子
  75 + http.HandleFunc("/happycat/acclectecatstory ", AcclecteCatStory) //请求点击猫箱子
  76 + http.HandleFunc("/chappycatat/updateuserinfo ", UpdateUserInfo) //请求点击猫箱子
74 77 //http.HandleFunc("/happycat/queryplayerrank ", QueryPlayerRank) //请求点击猫箱子
75 78 http.HandleFunc("/happycat/querycompletetask ", QueryCompleteTask) //请求点击猫箱子
76 79 http.HandleFunc("/happycat/querycompleteachievement ", QueryCompleteAchievement) //请求点击猫箱子
... ... @@ -392,7 +395,7 @@ func QueryAutomergeInfo(w http.ResponseWriter, r *http.Request) {
392 395 func QueryWareHouse(w http.ResponseWriter, r *http.Request) {
393 396 Uuid := 0
394 397 if len(r.Header) > 0 {
395   - Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  398 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
396 399 }
397 400 if Uuid == 0 {
398 401 SetHeader(w)
... ... @@ -404,13 +407,13 @@ func QueryWareHouse(w http.ResponseWriter, r *http.Request) {
404 407 s := string(result)
405 408 logger.Info("QueryWareHouse , body:%v,uuid=%v", s, Uuid)
406 409  
407   - //HandlerQueryWareHouse(w, s, Uuid)
  410 + HandlerQueryWareHouse(w, s, Uuid)
408 411 }
409 412  
410 413 func PutCattoWareHouse(w http.ResponseWriter, r *http.Request) {
411 414 Uuid := 0
412 415 if len(r.Header) > 0 {
413   - Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  416 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
414 417 }
415 418 if Uuid == 0 {
416 419 SetHeader(w)
... ... @@ -422,13 +425,13 @@ func PutCattoWareHouse(w http.ResponseWriter, r *http.Request) {
422 425 s := string(result)
423 426 logger.Info("PutCattoWareHouse , body:%v,uuid=%v", s, Uuid)
424 427  
425   - //HandlerPutCattoWareHouse(w, s, Uuid)
  428 + HandlerPutCattoWareHouse(w, s, Uuid)
426 429 }
427 430  
428 431 func TakeCatoutfromWareHouse(w http.ResponseWriter, r *http.Request) {
429 432 Uuid := 0
430 433 if len(r.Header) > 0 {
431   - Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  434 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
432 435 }
433 436 if Uuid == 0 {
434 437 SetHeader(w)
... ... @@ -440,7 +443,7 @@ func TakeCatoutfromWareHouse(w http.ResponseWriter, r *http.Request) {
440 443 s := string(result)
441 444 logger.Info("TakeCatoutfromWareHouse , body:%v,uuid=%v", s, Uuid)
442 445  
443   - ///HandlerTakeCatoutfromWareHouse(w, s, Uuid)
  446 + HandlerTakeCatoutfromWareHouse(w, s, Uuid)
444 447 }
445 448  
446 449 func DoBuyCat(w http.ResponseWriter, r *http.Request) {
... ...
src/HttpServer/logic/logic.go
... ... @@ -784,19 +784,19 @@ func HandlerCompose(w http.ResponseWriter, data string, uuid int) {
784 784 break
785 785 }
786 786 v := uinfo.PosInfo[val]
787   - if v.Cat == 103 {
  787 + if v.Cat == 3+REDCATIDEXTRA {
788 788 eastsum++
789 789 }
790   - if v.Cat == 104 {
  790 + if v.Cat == 4+REDCATIDEXTRA {
791 791 westsum++
792 792 }
793   - if v.Cat == 105 {
  793 + if v.Cat == 5+REDCATIDEXTRA {
794 794 southsum++
795 795 }
796   - if v.Cat == 106 {
  796 + if v.Cat == 6+REDCATIDEXTRA {
797 797 northsum++
798 798 }
799   - if v.Cat == 107 {
  799 + if v.Cat == 7+REDCATIDEXTRA {
800 800 middlesum++
801 801 }
802 802 }
... ... @@ -809,7 +809,7 @@ func HandlerCompose(w http.ResponseWriter, data string, uuid int) {
809 809  
810 810 //合成了五方猫
811 811 //获取一天招财猫配置
812   - cfg := jsonconf.GetRedCatConfig(100 + 2)
  812 + cfg := jsonconf.GetRedCatConfig(REDCATIDEXTRA + 2)
813 813 if cfg == nil {
814 814 logger.Error("HandlerCompose getcfg failed=%v", err)
815 815 resp.Code = 1
... ... @@ -817,7 +817,7 @@ func HandlerCompose(w http.ResponseWriter, data string, uuid int) {
817 817 break
818 818 }
819 819 nowtime := int(time.Now().Unix())
820   - uinfo.SetCatPos(rdata.PositionList[0], 2+100, 24*3600, cfg.Money, nowtime)
  820 + uinfo.SetCatPos(rdata.PositionList[0], 2+REDCATIDEXTRA, 24*3600, cfg.Money, nowtime)
821 821 //清空其他位置的猫
822 822 for k, v := range rdata.PositionList {
823 823 if k > 0 {
... ... @@ -1266,3 +1266,180 @@ func HandlerExchangePos(w http.ResponseWriter, data string, uuid int) {
1266 1266 fmt.Fprint(w, string(respstr))
1267 1267  
1268 1268 }
  1269 +
  1270 +func HandlerQueryWareHouse(w http.ResponseWriter, data string, uuid int) {
  1271 + SetHeader(w)
  1272 + var resp QueryWareHouseResp
  1273 + resp.Code = 0
  1274 + for {
  1275 + udatastr, err := redishandler.GetRedisClient().HGet(redis.USER_WAREHOUSE_INFO, strconv.Itoa(uuid))
  1276 + if err != nil {
  1277 + logger.Info("HandlerQueryWareHouse failed err=%v", err)
  1278 + resp.Code = 1
  1279 + resp.Message = "get redis failed"
  1280 + break
  1281 + }
  1282 + udata := new(UserWareHouseData)
  1283 + err = json.Unmarshal([]byte(udatastr), udata)
  1284 + if err != nil {
  1285 + logger.Error("HandlerQueryWareHouse Unmarshal redis failed ")
  1286 + resp.Code = 1
  1287 + resp.Message = "Unmarshal redis failed"
  1288 + break
  1289 + }
  1290 +
  1291 + for _, v := range udata.Info {
  1292 + catlv := v.Warelv + REDCATIDEXTRA
  1293 + resp.Data.CatList = append(resp.Data.CatList, catlv)
  1294 + }
  1295 +
  1296 + resp.Data.CatCapacity = WAREHOUSELIMIT
  1297 +
  1298 + resp.Code = 0
  1299 + break
  1300 + }
  1301 + //回包
  1302 + respstr, _ := json.Marshal(&resp)
  1303 + fmt.Fprint(w, string(respstr))
  1304 +}
  1305 +
  1306 +func HandlerPutCattoWareHouse(w http.ResponseWriter, data string, uuid int) {
  1307 + SetHeader(w)
  1308 + var resp PutWareHouseResp
  1309 +
  1310 + resp.Code = 0
  1311 + var rdata PutWareHouseReq
  1312 + err := json.Unmarshal([]byte(data), &rdata)
  1313 + for {
  1314 + if err != nil {
  1315 + logger.Error("HandlerPutCattoWareHouse json unmarshal failed=%v", err)
  1316 + resp.Code = 1
  1317 + resp.Message = "json failed"
  1318 + break
  1319 + }
  1320 + udatastr, err := redishandler.GetRedisClient().HGet(redis.USER_WAREHOUSE_INFO, strconv.Itoa(uuid))
  1321 + if err != nil {
  1322 + logger.Info("HandlerPutCattoWareHouse failed err=%v", err)
  1323 + resp.Code = 1
  1324 + resp.Message = "get redis failed"
  1325 + break
  1326 + }
  1327 + udata := new(UserWareHouseData)
  1328 + err = json.Unmarshal([]byte(udatastr), udata)
  1329 + if err != nil {
  1330 + logger.Error("HandlerPutCattoWareHouse Unmarshal redis failed ")
  1331 + resp.Code = 1
  1332 + resp.Message = "Unmarshal redis failed"
  1333 + break
  1334 + }
  1335 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  1336 + if err != nil || uinfo == nil {
  1337 + logger.Error("HandlerPutCattoWareHouse getuserinfo failed=%v", err)
  1338 + resp.Code = 1
  1339 + resp.Message = "get userinfo failed"
  1340 + break
  1341 + }
  1342 +
  1343 + if rdata.Position < 0 || rdata.Position >= len(uinfo.PosInfo) {
  1344 + logger.Error("HandlerPutCattoWareHouse posnotvalid failed=%v", err)
  1345 + resp.Code = 1
  1346 + resp.Message = "posnotvalid"
  1347 + break
  1348 + }
  1349 +
  1350 + //合成界面红包猫的等级采用id+37的形式
  1351 + rtval := uinfo.tryPutToWareHouse(udata, rdata.Position, uuid)
  1352 + if rtval == -1 {
  1353 + logger.Error("HandlerPutCattoWareHouse warehouse full failed=%v", err)
  1354 + resp.Code = 1
  1355 + resp.Message = "warehouse full"
  1356 + break
  1357 + }
  1358 +
  1359 + uinfo.CleadPos(rdata.Position)
  1360 + uinfo.CalcGoldRate()
  1361 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  1362 +
  1363 + resp.Data.Coin.UserId = uuid
  1364 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  1365 + //accrate := uinfo.Goldrate * 3
  1366 + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10)
  1367 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  1368 + resp.Code = 0
  1369 +
  1370 + break
  1371 + }
  1372 + respstr, _ := json.Marshal(&resp)
  1373 + fmt.Fprint(w, string(respstr))
  1374 +}
  1375 +
  1376 +func HandlerTakeCatoutfromWareHouse(w http.ResponseWriter, data string, uuid int) {
  1377 + SetHeader(w)
  1378 + var resp TakeWareHouseResp
  1379 +
  1380 + resp.Code = 0
  1381 + var rdata TakeWareHouseReq
  1382 + err := json.Unmarshal([]byte(data), &rdata)
  1383 + for {
  1384 + if err != nil {
  1385 + logger.Error("HandlerTakeCatoutfromWareHouse json unmarshal failed=%v", err)
  1386 + resp.Code = 1
  1387 + resp.Message = "json failed"
  1388 + break
  1389 + }
  1390 + udatastr, err := redishandler.GetRedisClient().HGet(redis.USER_WAREHOUSE_INFO, strconv.Itoa(uuid))
  1391 + if err != nil {
  1392 + logger.Info("HandlerTakeCatoutfromWareHouse failed err=%v", err)
  1393 + resp.Code = 1
  1394 + resp.Message = "get redis failed"
  1395 + break
  1396 + }
  1397 + udata := new(UserWareHouseData)
  1398 + err = json.Unmarshal([]byte(udatastr), udata)
  1399 + if err != nil {
  1400 + logger.Error("HandlerTakeCatoutfromWareHouse Unmarshal redis failed ")
  1401 + resp.Code = 1
  1402 + resp.Message = "Unmarshal redis failed"
  1403 + break
  1404 + }
  1405 +
  1406 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  1407 + if err != nil || uinfo == nil {
  1408 + logger.Error("HandlerPutCattoWareHouse getuserinfo failed=%v", err)
  1409 + resp.Code = 1
  1410 + resp.Message = "get userinfo failed"
  1411 + break
  1412 + }
  1413 + wpos := udata.GetWarePosById(rdata.CatId)
  1414 + if wpos == -1 {
  1415 + logger.Error("HandlerTakeCatoutfromWareHouse wpos failed=%v", err)
  1416 + resp.Code = 1
  1417 + resp.Message = "wpos"
  1418 + break
  1419 + }
  1420 + winfo := udata.Info[wpos]
  1421 +
  1422 + uinfo.SetRedCatPos(winfo.Warelv+REDCATIDEXTRA, winfo.Time, winfo.RedPacket, winfo.StartTime)
  1423 +
  1424 + udata.Info[wpos].Warelv = 0
  1425 + udata.Info[wpos].StartTime = 0
  1426 + udata.Info[wpos].RedPacket = 0
  1427 + udata.Info[wpos].Time = 0
  1428 +
  1429 + wares, _ := json.Marshal(udata)
  1430 + redishandler.GetRedisClient().HSet(redis.USER_WAREHOUSE_INFO, strconv.Itoa(uuid), string(wares))
  1431 +
  1432 + uinfo.CalcGoldRate()
  1433 +
  1434 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  1435 + resp.Data.Coin.UserId = uuid
  1436 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  1437 + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10)
  1438 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  1439 + resp.Code = 0
  1440 +
  1441 + break
  1442 + }
  1443 + respstr, _ := json.Marshal(&resp)
  1444 + fmt.Fprint(w, string(respstr))
  1445 +}
... ...