Commit a63e6df922012e4433cc03a6a91f976ea8c56b91

Authored by 陆恒
1 parent 4f87991c
Exists in master

提交接口

src/HttpServer/logic/constdef.go
... ... @@ -50,6 +50,9 @@ const (
50 50 )
51 51  
52 52 const (
53   - WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制
54   - ACCGOLDRATELIMIT = 3 //玩家每天看视频加速金币次数
  53 + WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制
  54 + ACCGOLDRATELIMIT = 3 //玩家每天看视频加速金币次数
  55 + WATCHADSGOLDLIMIT = 15 //玩家每天看广告领金币限制次数
  56 + WATCHADSGOLDLRATE = 10800 //看广告领取金币的秒数
  57 + ZHENGHOURMULT = 3600 //整点领取金币的秒数
55 58 )
... ...
src/HttpServer/logic/datadef.go
... ... @@ -111,6 +111,84 @@ type AcclecteResp struct {
111 111 Data AcclectData `json:"data"`
112 112 }
113 113  
  114 +type WatchAdsGetGoldData struct {
  115 + Reward string `json:"reward"`
  116 + LeftTimes int `json:"leftTimes"`
  117 + Coin DoBuyCatCoin `json:"coin"`
  118 +}
  119 +type WatchAdsGetGoldResp struct {
  120 + Code int `json:"code"`
  121 + Message string `json:"message"`
  122 + Data WatchAdsGetGoldData `json:"data"`
  123 +}
  124 +
  125 +type RecvTimingRewardData struct {
  126 + Reward string `json:"reward"`
  127 +}
  128 +
  129 +type RecvTimingRewardResp struct {
  130 + Code int `json:"code"`
  131 + Message string `json:"message"`
  132 + Data RecvTimingRewardData `json:"data"`
  133 +}
  134 +
  135 +type RecoveryReq struct {
  136 + Position int `json:"position"`
  137 +}
  138 +
  139 +type RecoveryData struct {
  140 + Coin DoBuyCatCoin `json:"coin"`
  141 +}
  142 +
  143 +type RecoveryResp struct {
  144 + Code int `json:"code"`
  145 + Message string `json:"message"`
  146 + Data RecoveryData `json:"data"`
  147 +}
  148 +
  149 +type ComposeReq struct {
  150 + PositionList []int `json:"positionList"`
  151 +}
  152 +
  153 +type ComposeData struct {
  154 + CatList []CatPosInfo `json:"catList"`
  155 + Coin DoBuyCatCoin `json:"coin"`
  156 +}
  157 +
  158 +type ComposeResp struct {
  159 + Code int `json:"code"`
  160 + Message string `json:"message"`
  161 + Data ComposeData `json:"data"`
  162 +}
  163 +
  164 +type RecvRedCatReq struct {
  165 + Rtype int `json:"type"`
  166 + RedCatId int `json:"redCatId"`
  167 +}
  168 +
  169 +type RecvRedCatData struct {
  170 + Num float32 `json:"num"`
  171 +}
  172 +
  173 +type RecvRedCatResp struct {
  174 + Code int `json:"code"`
  175 + Message string `json:"message"`
  176 + Data RecvRedCatData `json:"data"`
  177 +}
  178 +
  179 +type LimitCatListData struct {
  180 + CatId int `json:"catId"`
  181 + Cash float32 `json:"cash"`
  182 + Status int `json:"status"`
  183 + Date string `json:"date"`
  184 +}
  185 +
  186 +type LimitCatListResp struct {
  187 + Code int `json:"code"`
  188 + Message string `json:"message"`
  189 + Data []LimitCatListData `json:"data"`
  190 +}
  191 +
114 192 type AcclecteBoxResp struct {
115 193 Code int `json:"code"`
116 194 Message string `json:"message"`
... ... @@ -469,38 +547,40 @@ type AchieveMentData struct {
469 547  
470 548 //玩家数据
471 549 type UserData struct {
472   - UserId int //玩家id
473   - RegTime int //注册时间
474   - Gold int64 //金币
475   - GoldSum int64 //玩家累计金币
476   - Love int64 //爱心值
477   - Goldrate int64 //金币生成速率
478   - Loverate int64 //爱心生产速率
479   - Highestlv int //当前最高猫等级
480   - InviteId int //邀请者uid
481   - CurBoxLv int //当前猫箱子等级
482   - IsDouble int //当前加速标签 1表示3倍收益 0表示正常
483   - StartDoubleTime int //开始双倍时间
484   - DoubleLeftTimes int //开始双倍时间
485   - IsAuto int //当前是否自动合成
486   - IsBoxAcc int //是否处于加速生成箱子状态
487   - RandGiftNum int //当前剩余空投猫粮次数
488   - RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum
489   - RandGiftTime int //记录上一次空投猫粮时间
490   - Redbag float32 //红包值 单位为分
491   - Head string //头像地址
492   - NickName string //昵称
493   - RealName string //实名
494   - IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是
495   - OfflineGold int64 //离线金币
496   - OfflineLove int64 //离线爱心
497   - LastLoginTime int //上次登陆时间
498   - CatShopInfo CatShopData //猫咖门店数据
499   - Taskinfo TaskData //任务数据
500   - AchieveMent AchieveMentData //成就数据
501   - PosInfo []CatPosInfo //位置信息 从0开始
502   - BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推
503   - CatRoomInfo []CatRoomData //猫咖店数据
  550 + UserId int //玩家id
  551 + RegTime int //注册时间
  552 + Gold int64 //金币
  553 + GoldSum int64 //玩家累计金币
  554 + Love int64 //爱心值
  555 + Goldrate int64 //金币生成速率
  556 + Loverate int64 //爱心生产速率
  557 + Highestlv int //当前最高猫等级
  558 + InviteId int //邀请者uid
  559 + CurBoxLv int //当前猫箱子等级
  560 + IsDouble int //当前加速标签 1表示3倍收益 0表示正常
  561 + StartDoubleTime int //开始双倍时间
  562 + DoubleLeftTimes int //剩余加速金币次数
  563 + GetWatchAdsGoldTime int //看广告领金币次数
  564 + IsAuto int //当前是否自动合成
  565 + IsBoxAcc int //是否处于加速生成箱子状态
  566 + RandGiftNum int //当前剩余空投猫粮次数
  567 + RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum
  568 + RandGiftTime int //记录上一次空投猫粮时间
  569 + Redbag float32 //红包值 单位为分
  570 + Head string //头像地址
  571 + NickName string //昵称
  572 + RealName string //实名
  573 + IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是
  574 + OfflineGold int64 //离线金币
  575 + OfflineLove int64 //离线爱心
  576 + LastLoginTime int //上次登陆时间
  577 + LastTimingRewardHour int //上次领取整点奖励的时刻
  578 + CatShopInfo CatShopData //猫咖门店数据
  579 + Taskinfo TaskData //任务数据
  580 + AchieveMent AchieveMentData //成就数据
  581 + PosInfo []CatPosInfo //位置信息 从0开始
  582 + BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推
  583 + CatRoomInfo []CatRoomData //猫咖店数据
504 584  
505 585 }
506 586  
... ...
src/HttpServer/logic/function.go
... ... @@ -12,6 +12,67 @@ import (
12 12 "time"
13 13 )
14 14  
  15 +//加红包接口
  16 +func (u *UserData) AddRedPackect(num float32) {
  17 + //todo 接后台
  18 + u.Redbag += num
  19 +}
  20 +
  21 +//清空一个位置的猫
  22 +func (u *UserData) CleadPos(pos int) {
  23 + if pos < 0 || pos >= len(u.PosInfo) {
  24 + logger.Error("CleadPos failed pos=%v,posinfo=%v", pos, u.PosInfo)
  25 + return
  26 + }
  27 +
  28 + u.PosInfo[pos].Cat = 0
  29 + u.PosInfo[pos].Position = pos
  30 + u.PosInfo[pos].StartTime = 0
  31 + u.PosInfo[pos].RedPacket = 0
  32 + u.PosInfo[pos].Time = 0
  33 +}
  34 +
  35 +//设置一个位置的猫
  36 +func (u *UserData) SetCatPos(pos int, catlv, time int, redpack float32, starttime int) {
  37 + if pos < 0 || pos >= len(u.PosInfo) {
  38 + logger.Error("CleadPos failed pos=%v,posinfo=%v", pos, u.PosInfo)
  39 + return
  40 + }
  41 +
  42 + u.PosInfo[pos].Cat = catlv
  43 + u.PosInfo[pos].Position = pos
  44 + u.PosInfo[pos].StartTime = starttime
  45 + u.PosInfo[pos].RedPacket = redpack
  46 + u.PosInfo[pos].Time = time
  47 +}
  48 +
  49 +//获取所有分红猫列表的位置
  50 +func (u *UserData) GetLimitCatList() []int {
  51 + var rtlist []int
  52 + for k, v := range u.PosInfo {
  53 + if v.Cat > 36 {
  54 + rtlist = append(rtlist, k)
  55 + }
  56 + }
  57 +
  58 + return rtlist
  59 +}
  60 +
  61 +//根据猫等级获得位置
  62 +func (u *UserData) GetCatPos(catlv int) int {
  63 + pos := -1
  64 + for _, v := range u.PosInfo {
  65 + if v.Cat == catlv {
  66 + pos = v.Position
  67 + }
  68 + }
  69 +
  70 + if pos < 0 || pos >= len(u.PosInfo) {
  71 + pos = -1
  72 + }
  73 + return pos
  74 +}
  75 +
15 76 func (u *UserData) HandlePassDay() {
16 77 isdiffday := false
17 78 nowtime := time.Now()
... ... @@ -45,6 +106,7 @@ func (u *UserData) HandlePassDay() {
45 106 if isdiffday {
46 107 //跨天了
47 108 u.DoubleLeftTimes = ACCGOLDRATELIMIT
  109 + u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT
48 110 }
49 111  
50 112 u.LastLoginTime = int(nowtime.Unix())
... ... @@ -97,6 +159,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
97 159 udata.Redbag = 0
98 160 udata.IsFirstRedBgCat = 0
99 161 udata.DoubleLeftTimes = ACCGOLDRATELIMIT
  162 + udata.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT
100 163 udata.RegTime = int(time.Now().Unix())
101 164 udata.LastLoginTime = int(time.Now().Unix())
102 165  
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -33,6 +33,14 @@ func startServerHttpServe() {
33 33 http.HandleFunc("/api/home/shop", QueryBuyCat) //商店
34 34 http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数
35 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) //分红猫列表
36 44  
37 45 /////---------------------------------------------------------------------old
38 46 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置
... ... @@ -447,6 +455,24 @@ func DoBuyCat(w http.ResponseWriter, r *http.Request) {
447 455 HandlerDoBuyCat(w, s, Uuid)
448 456 }
449 457  
  458 +func LeftTimes(w http.ResponseWriter, r *http.Request) {
  459 + Uuid := 0
  460 + if len(r.Header) > 0 {
  461 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  462 + }
  463 + if Uuid == 0 {
  464 + SetHeader(w)
  465 + return
  466 + }
  467 + result, _ := ioutil.ReadAll(r.Body)
  468 + r.Body.Close()
  469 +
  470 + s := string(result)
  471 + logger.Info("LeftTimes , body:%v,uuid=%v", s, Uuid)
  472 +
  473 + HandlerLeftTimes(w, s, Uuid)
  474 +}
  475 +
450 476 func LeftRateTimes(w http.ResponseWriter, r *http.Request) {
451 477 Uuid := 0
452 478 if len(r.Header) > 0 {
... ... @@ -591,6 +617,132 @@ func AcclecteBoxRate(w http.ResponseWriter, r *http.Request) {
591 617 // HandlerAcclecteBoxRate(w, s, Uuid)
592 618 }
593 619  
  620 +func RedCatList(w http.ResponseWriter, r *http.Request) {
  621 + Uuid := 0
  622 + if len(r.Header) > 0 {
  623 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  624 + }
  625 + if Uuid == 0 {
  626 + SetHeader(w)
  627 + return
  628 + }
  629 + result, _ := ioutil.ReadAll(r.Body)
  630 + r.Body.Close()
  631 +
  632 + s := string(result)
  633 + logger.Info("RedCatList , body:%v,uuid=%v", s, Uuid)
  634 +
  635 + //HandlerRecvTimingReward(w, s, Uuid)
  636 +}
  637 +
  638 +func LimitCatList(w http.ResponseWriter, r *http.Request) {
  639 + Uuid := 0
  640 + if len(r.Header) > 0 {
  641 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  642 + }
  643 + if Uuid == 0 {
  644 + SetHeader(w)
  645 + return
  646 + }
  647 + result, _ := ioutil.ReadAll(r.Body)
  648 + r.Body.Close()
  649 +
  650 + s := string(result)
  651 + logger.Info("LimitCatList , body:%v,uuid=%v", s, Uuid)
  652 +
  653 + HandlerLimitCatList(w, s, Uuid)
  654 +}
  655 +
  656 +func RecvRedCat(w http.ResponseWriter, r *http.Request) {
  657 + Uuid := 0
  658 + if len(r.Header) > 0 {
  659 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  660 + }
  661 + if Uuid == 0 {
  662 + SetHeader(w)
  663 + return
  664 + }
  665 + result, _ := ioutil.ReadAll(r.Body)
  666 + r.Body.Close()
  667 +
  668 + s := string(result)
  669 + logger.Info("RecvRedCat , body:%v,uuid=%v", s, Uuid)
  670 +
  671 + HandlerRecvRedCat(w, s, Uuid)
  672 +}
  673 +
  674 +func Compose(w http.ResponseWriter, r *http.Request) {
  675 + Uuid := 0
  676 + if len(r.Header) > 0 {
  677 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  678 + }
  679 + if Uuid == 0 {
  680 + SetHeader(w)
  681 + return
  682 + }
  683 + result, _ := ioutil.ReadAll(r.Body)
  684 + r.Body.Close()
  685 +
  686 + s := string(result)
  687 + logger.Info("Compose , body:%v,uuid=%v", s, Uuid)
  688 +
  689 + HandlerCompose(w, s, Uuid)
  690 +}
  691 +
  692 +func Recovery(w http.ResponseWriter, r *http.Request) {
  693 + Uuid := 0
  694 + if len(r.Header) > 0 {
  695 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  696 + }
  697 + if Uuid == 0 {
  698 + SetHeader(w)
  699 + return
  700 + }
  701 + result, _ := ioutil.ReadAll(r.Body)
  702 + r.Body.Close()
  703 +
  704 + s := string(result)
  705 + logger.Info("Recovery , body:%v,uuid=%v", s, Uuid)
  706 +
  707 + HandlerRecovery(w, s, Uuid)
  708 +}
  709 +
  710 +func RecvTimingReward(w http.ResponseWriter, r *http.Request) {
  711 + Uuid := 0
  712 + if len(r.Header) > 0 {
  713 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  714 + }
  715 + if Uuid == 0 {
  716 + SetHeader(w)
  717 + return
  718 + }
  719 + result, _ := ioutil.ReadAll(r.Body)
  720 + r.Body.Close()
  721 +
  722 + s := string(result)
  723 + logger.Info("RecvTimingReward , body:%v,uuid=%v", s, Uuid)
  724 +
  725 + HandlerRecvTimingReward(w, s, Uuid)
  726 +}
  727 +
  728 +func WatchAdsGetGold(w http.ResponseWriter, r *http.Request) {
  729 + Uuid := 0
  730 + if len(r.Header) > 0 {
  731 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  732 + }
  733 + if Uuid == 0 {
  734 + SetHeader(w)
  735 + return
  736 + }
  737 + result, _ := ioutil.ReadAll(r.Body)
  738 + r.Body.Close()
  739 +
  740 + s := string(result)
  741 + logger.Info("WatchAdsGetGold , body:%v,uuid=%v", s, Uuid)
  742 +
  743 + HandlerWatchAdsGetGold(w, s, Uuid)
  744 +}
  745 +
594 746 func AcclecteGold(w http.ResponseWriter, r *http.Request) {
595 747 Uuid := 0
596 748 if len(r.Header) > 0 {
... ...
src/HttpServer/logic/logic.go
... ... @@ -403,6 +403,398 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) {
403 403 fmt.Fprint(w, string(respstr))
404 404 }
405 405  
  406 +func HandlerLimitCatList(w http.ResponseWriter, data string, uuid int) {
  407 + SetHeader(w)
  408 + var resp LimitCatListResp
  409 + resp.Code = 0
  410 + resp.Message = "success"
  411 +
  412 + for {
  413 +
  414 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  415 + if err != nil || uinfo == nil {
  416 + logger.Error("HandlerRecvRedCat getuserinfo failed=%v", err)
  417 + resp.Code = 1
  418 + resp.Message = "get userinfo failed"
  419 + break
  420 + }
  421 +
  422 + poslist := uinfo.GetLimitCatList()
  423 +
  424 + for _, pos := range poslist {
  425 + if pos > 0 && pos < len(uinfo.PosInfo) {
  426 + var tmp LimitCatListData
  427 + tmp.CatId = uinfo.PosInfo[pos].Cat
  428 + tmp.Status = 0
  429 + tmp.Cash = uinfo.PosInfo[pos].RedPacket
  430 + tmp.Date = time.Now().Format("2006-01-02T 15:04:05")
  431 + resp.Data = append(resp.Data, tmp)
  432 + }
  433 + }
  434 +
  435 + resp.Code = 0
  436 + break
  437 + }
  438 +
  439 + //回包
  440 + respstr, _ := json.Marshal(&resp)
  441 + fmt.Fprint(w, string(respstr))
  442 +
  443 +}
  444 +
  445 +func HandlerRecvRedCat(w http.ResponseWriter, data string, uuid int) {
  446 + SetHeader(w)
  447 + var resp RecvRedCatResp
  448 + resp.Code = 0
  449 + resp.Message = "success"
  450 + var rdata RecvRedCatReq
  451 + err := json.Unmarshal([]byte(data), &rdata)
  452 +
  453 + for {
  454 + if err != nil {
  455 + logger.Info("json decode HandlerRecvRedCat data failed:%v", err, " for:%v", data)
  456 + resp.Message = "json unmarshal failed"
  457 + resp.Code = 1
  458 + break
  459 + }
  460 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  461 + if err != nil || uinfo == nil {
  462 + logger.Error("HandlerRecvRedCat getuserinfo failed=%v", err)
  463 + resp.Code = 1
  464 + resp.Message = "get userinfo failed"
  465 + break
  466 + }
  467 +
  468 + //先判断位置
  469 + cpos := uinfo.GetCatPos(rdata.RedCatId)
  470 + if cpos == -1 {
  471 + logger.Error("HandlerRecvRedCat nothave cat failed=%v", rdata.RedCatId)
  472 + resp.Code = 1
  473 + resp.Message = "nothave cat failed"
  474 + break
  475 + }
  476 +
  477 + //判读下计时的时间是否结束
  478 + nowtime := int(time.Now().Unix())
  479 + v := uinfo.PosInfo[cpos]
  480 + if v.Time != 0 {
  481 + if nowtime < v.StartTime+v.Time {
  482 + //时间还未结束无法领取
  483 + logger.Error("HandlerRecvRedCat timenotenough failed=%v", rdata.RedCatId)
  484 + resp.Code = 1
  485 + resp.Message = "timenotenough failed"
  486 + break
  487 + }
  488 + }
  489 +
  490 + //领取红包
  491 + addredpack := v.RedPacket
  492 + if rdata.Rtype == 1 {
  493 + addredpack = addredpack * 2
  494 + }
  495 +
  496 + uinfo.AddRedPackect(addredpack)
  497 + uinfo.CleadPos(cpos)
  498 +
  499 + uinfo.CalcGoldRate()
  500 +
  501 + resp.Data.Num = addredpack
  502 + resp.Code = 0
  503 + break
  504 + }
  505 +
  506 + //回包
  507 + respstr, _ := json.Marshal(&resp)
  508 + fmt.Fprint(w, string(respstr))
  509 +
  510 +}
  511 +
  512 +func HandlerCompose(w http.ResponseWriter, data string, uuid int) {
  513 + SetHeader(w)
  514 + var resp ComposeResp
  515 + resp.Code = 0
  516 + resp.Message = "success"
  517 + var rdata ComposeReq
  518 + err := json.Unmarshal([]byte(data), &rdata)
  519 +
  520 + for {
  521 + if err != nil {
  522 + logger.Info("json decode HandlerCompose data failed:%v", err, " for:%v", data)
  523 + resp.Message = "json unmarshal failed"
  524 + resp.Code = 1
  525 + break
  526 + }
  527 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  528 + if err != nil || uinfo == nil {
  529 + logger.Error("HandlerCompose getuserinfo failed=%v", err)
  530 + resp.Code = 1
  531 + resp.Message = "get userinfo failed"
  532 + break
  533 + }
  534 +
  535 + //先需要判断五个位置是否准确
  536 + eastsum := 0
  537 + westsum := 0
  538 + southsum := 0
  539 + northsum := 0
  540 + middlesum := 0
  541 + for _, val := range rdata.PositionList {
  542 + if val < 0 || val >= len(uinfo.PosInfo) {
  543 + logger.Error("HandlerCompose Position failed=%v", err)
  544 +
  545 + break
  546 + }
  547 + v := uinfo.PosInfo[val]
  548 + if v.Cat == 103 {
  549 + eastsum++
  550 + }
  551 + if v.Cat == 104 {
  552 + westsum++
  553 + }
  554 + if v.Cat == 105 {
  555 + southsum++
  556 + }
  557 + if v.Cat == 106 {
  558 + northsum++
  559 + }
  560 + if v.Cat == 107 {
  561 + middlesum++
  562 + }
  563 + }
  564 + if !(eastsum > 0 && westsum > 0 && northsum > 0 && southsum > 0 && middlesum > 0) {
  565 + logger.Error("HandlerCompose notfivecat failed=%v", err)
  566 + resp.Code = 1
  567 + resp.Message = "notfivecat failed"
  568 + break
  569 + }
  570 +
  571 + //合成了五方猫
  572 + //获取一天招财猫配置
  573 + cfg := jsonconf.GetRedCatConfig(100 + 2)
  574 + if cfg == nil {
  575 + logger.Error("HandlerCompose getcfg failed=%v", err)
  576 + resp.Code = 1
  577 + resp.Message = "getcfg failed"
  578 + break
  579 + }
  580 + nowtime := int(time.Now().Unix())
  581 + uinfo.SetCatPos(rdata.PositionList[0], 2+100, 24*3600, cfg.Money, nowtime)
  582 + //清空其他位置的猫
  583 + for k, v := range rdata.PositionList {
  584 + if k > 0 {
  585 + uinfo.CleadPos(v)
  586 + }
  587 + }
  588 +
  589 + //重新计算一下速度
  590 + uinfo.CalcGoldRate()
  591 +
  592 + resp.Data.CatList = append(resp.Data.CatList, uinfo.PosInfo...)
  593 + resp.Data.Coin.UserId = uuid
  594 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  595 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  596 + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10)
  597 + resp.Code = 0
  598 + break
  599 + }
  600 +
  601 + //回包
  602 + respstr, _ := json.Marshal(&resp)
  603 + fmt.Fprint(w, string(respstr))
  604 +
  605 +}
  606 +
  607 +func HandlerRecovery(w http.ResponseWriter, data string, uuid int) {
  608 + SetHeader(w)
  609 + var resp RecoveryResp
  610 + resp.Code = 0
  611 + resp.Message = "success"
  612 + var rdata RecoveryReq
  613 + err := json.Unmarshal([]byte(data), &rdata)
  614 +
  615 + for {
  616 + if err != nil {
  617 + logger.Info("json decode HandlerRecovery data failed:%v", err, " for:%v", data)
  618 + resp.Message = "json unmarshal failed"
  619 + resp.Code = 1
  620 + break
  621 + }
  622 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  623 + if err != nil || uinfo == nil {
  624 + logger.Error("HandlerRecovery getuserinfo failed=%v", err)
  625 + resp.Code = 1
  626 + resp.Message = "get userinfo failed"
  627 + break
  628 + }
  629 +
  630 + if rdata.Position < 0 || rdata.Position >= len(uinfo.PosInfo) {
  631 + logger.Error("HandlerRecovery Position failed=%v", err)
  632 + resp.Code = 1
  633 + resp.Message = "Position failed"
  634 + break
  635 + }
  636 +
  637 + if uinfo.PosInfo[rdata.Position].Cat > 36 || uinfo.PosInfo[rdata.Position].Cat == 0 {
  638 + //高级猫或者没有猫无法卖
  639 + logger.Error("HandlerRecovery CatLV failed=%v", err)
  640 + resp.Code = 1
  641 + resp.Message = "CatLV failed"
  642 + break
  643 + }
  644 +
  645 + cfg := jsonconf.GetCatConfig(uinfo.PosInfo[rdata.Position].Cat)
  646 + if cfg == nil {
  647 + logger.Error("HandlerRecovery CatLVCFG failed=%v", uinfo.PosInfo[rdata.Position].Cat)
  648 + resp.Code = 1
  649 + resp.Message = "CatLVCFG failed"
  650 + break
  651 + }
  652 + uinfo.CleadPos(rdata.Position)
  653 +
  654 + //重新计算速度
  655 + uinfo.CalcGoldRate()
  656 + //加金币
  657 + price, _ := strconv.ParseInt(cfg.Price, 10, 64)
  658 + uinfo.Gold += price / 10
  659 +
  660 + resp.Data.Coin.UserId = uuid
  661 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  662 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  663 + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10)
  664 + resp.Code = 0
  665 + break
  666 + }
  667 +
  668 + //回包
  669 + respstr, _ := json.Marshal(&resp)
  670 + fmt.Fprint(w, string(respstr))
  671 +}
  672 +
  673 +func HandlerRecvTimingReward(w http.ResponseWriter, data string, uuid int) {
  674 + SetHeader(w)
  675 + var resp RecvTimingRewardResp
  676 + resp.Code = 0
  677 + resp.Message = "success"
  678 +
  679 + for {
  680 +
  681 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  682 + if err != nil || uinfo == nil {
  683 + logger.Error("HandlerRecvTimingReward getuserinfo failed=%v", err)
  684 + resp.Code = 1
  685 + resp.Message = "get userinfo failed"
  686 + break
  687 + }
  688 +
  689 + //判断一下领取的时间点是否正确
  690 + nowt := time.Now()
  691 + if nowt.Minute() < 50 && nowt.Minute() > 10 {
  692 + logger.Error("HandlerRecvTimingReward time failed=%v", err)
  693 + resp.Code = 1
  694 + resp.Message = "time failed"
  695 + break
  696 + }
  697 +
  698 + nowh := 0
  699 + if nowt.Minute() >= 50 {
  700 + //领取的是笑一个小时
  701 + if nowt.Hour() < 23 {
  702 + if uinfo.LastTimingRewardHour >= nowt.Hour()+1 {
  703 + //已经领取过了 无法在零
  704 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err)
  705 + resp.Code = 1
  706 + resp.Message = "alreadyfetched failed"
  707 + break
  708 + }
  709 + nowh = nowt.Hour()
  710 + } else {
  711 + if uinfo.LastTimingRewardHour == 0 {
  712 + //已经领取过了 无法在零
  713 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err)
  714 + resp.Code = 1
  715 + resp.Message = "alreadyfetched failed"
  716 + break
  717 + }
  718 + nowh = 0
  719 + }
  720 +
  721 + }
  722 +
  723 + if nowt.Minute() <= 10 {
  724 + //领取的是本时段的
  725 + if uinfo.LastTimingRewardHour >= nowt.Hour() {
  726 + //已经领取过了 无法在零
  727 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err)
  728 + resp.Code = 1
  729 + resp.Message = "alreadyfetched failed"
  730 + break
  731 + }
  732 + nowh = nowt.Hour()
  733 + }
  734 +
  735 + addgold := uinfo.Goldrate * ZHENGHOURMULT
  736 + uinfo.Gold += addgold
  737 + uinfo.LastTimingRewardHour = nowh
  738 +
  739 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  740 +
  741 + resp.Data.Reward = strconv.FormatInt(addgold, 10)
  742 + resp.Code = 0
  743 + break
  744 + }
  745 +
  746 + //回包
  747 + respstr, _ := json.Marshal(&resp)
  748 + fmt.Fprint(w, string(respstr))
  749 +}
  750 +
  751 +func HandlerWatchAdsGetGold(w http.ResponseWriter, data string, uuid int) {
  752 + SetHeader(w)
  753 + var resp WatchAdsGetGoldResp
  754 + resp.Code = 0
  755 + resp.Message = "success"
  756 +
  757 + for {
  758 +
  759 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  760 + if err != nil || uinfo == nil {
  761 + logger.Error("HandlerWatchAdsGetGold getuserinfo failed=%v", err)
  762 + resp.Code = 1
  763 + resp.Message = "get userinfo failed"
  764 + break
  765 + }
  766 +
  767 + if uinfo.GetWatchAdsGoldTime <= 0 {
  768 + //不够次数了
  769 + logger.Error("HandlerWatchAdsGetGold not enoughtimes failed=%v", err)
  770 + resp.Code = 1
  771 + resp.Message = "enoughtimes"
  772 + break
  773 + }
  774 +
  775 + uinfo.GetWatchAdsGoldTime--
  776 + addgold := uinfo.Goldrate * WATCHADSGOLDLRATE
  777 + uinfo.Gold += addgold
  778 +
  779 + resp.Data.Reward = strconv.FormatInt(addgold, 10)
  780 + resp.Data.LeftTimes = uinfo.GetWatchAdsGoldTime
  781 +
  782 + resp.Data.Coin.UserId = uuid
  783 + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10)
  784 + accrate := uinfo.Goldrate * 3
  785 + resp.Data.Coin.IcomeRate = strconv.FormatInt(accrate, 10)
  786 + resp.Data.Coin.UpdateTime = int(time.Now().Unix())
  787 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  788 +
  789 + resp.Code = 0
  790 + break
  791 + }
  792 +
  793 + //回包
  794 + respstr, _ := json.Marshal(&resp)
  795 + fmt.Fprint(w, string(respstr))
  796 +}
  797 +
406 798 func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) {
407 799 SetHeader(w)
408 800 var resp AcclecteResp
... ... @@ -455,6 +847,33 @@ func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) {
455 847 fmt.Fprint(w, string(respstr))
456 848 }
457 849  
  850 +func HandlerLeftTimes(w http.ResponseWriter, data string, uuid int) {
  851 + SetHeader(w)
  852 + var resp LeftRateTimesResp
  853 + resp.Code = 0
  854 + resp.Message = "success"
  855 +
  856 + for {
  857 +
  858 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  859 + if err != nil || uinfo == nil {
  860 + logger.Error("HandlerLeftTimes getuserinfo failed=%v", err)
  861 + resp.Code = 1
  862 + resp.Message = "get userinfo failed"
  863 + break
  864 + }
  865 +
  866 + resp.Data.LeftTimes = uinfo.GetWatchAdsGoldTime
  867 + resp.Data.LimitTimes = WATCHADSGOLDLIMIT
  868 +
  869 + resp.Code = 0
  870 + break
  871 + }
  872 + //回包
  873 + respstr, _ := json.Marshal(&resp)
  874 + fmt.Fprint(w, string(respstr))
  875 +}
  876 +
458 877 func HandlerLeftRateTimes(w http.ResponseWriter, data string, uuid int) {
459 878 SetHeader(w)
460 879 var resp LeftRateTimesResp
... ...