From a63e6df922012e4433cc03a6a91f976ea8c56b91 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Thu, 11 Jun 2020 11:49:29 +0800 Subject: [PATCH] 提交接口 --- src/HttpServer/logic/constdef.go | 7 +++++-- src/HttpServer/logic/datadef.go | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- src/HttpServer/logic/function.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/httpserver.go | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 751 insertions(+), 34 deletions(-) diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index 43c2bf3..0ce7c7d 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -50,6 +50,9 @@ const ( ) const ( - WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制 - ACCGOLDRATELIMIT = 3 //玩家每天看视频加速金币次数 + WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制 + ACCGOLDRATELIMIT = 3 //玩家每天看视频加速金币次数 + WATCHADSGOLDLIMIT = 15 //玩家每天看广告领金币限制次数 + WATCHADSGOLDLRATE = 10800 //看广告领取金币的秒数 + ZHENGHOURMULT = 3600 //整点领取金币的秒数 ) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index c37631c..46b8a97 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -111,6 +111,84 @@ type AcclecteResp struct { Data AcclectData `json:"data"` } +type WatchAdsGetGoldData struct { + Reward string `json:"reward"` + LeftTimes int `json:"leftTimes"` + Coin DoBuyCatCoin `json:"coin"` +} +type WatchAdsGetGoldResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data WatchAdsGetGoldData `json:"data"` +} + +type RecvTimingRewardData struct { + Reward string `json:"reward"` +} + +type RecvTimingRewardResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data RecvTimingRewardData `json:"data"` +} + +type RecoveryReq struct { + Position int `json:"position"` +} + +type RecoveryData struct { + Coin DoBuyCatCoin `json:"coin"` +} + +type RecoveryResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data RecoveryData `json:"data"` +} + +type ComposeReq struct { + PositionList []int `json:"positionList"` +} + +type ComposeData struct { + CatList []CatPosInfo `json:"catList"` + Coin DoBuyCatCoin `json:"coin"` +} + +type ComposeResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data ComposeData `json:"data"` +} + +type RecvRedCatReq struct { + Rtype int `json:"type"` + RedCatId int `json:"redCatId"` +} + +type RecvRedCatData struct { + Num float32 `json:"num"` +} + +type RecvRedCatResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data RecvRedCatData `json:"data"` +} + +type LimitCatListData struct { + CatId int `json:"catId"` + Cash float32 `json:"cash"` + Status int `json:"status"` + Date string `json:"date"` +} + +type LimitCatListResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data []LimitCatListData `json:"data"` +} + type AcclecteBoxResp struct { Code int `json:"code"` Message string `json:"message"` @@ -469,38 +547,40 @@ type AchieveMentData struct { //玩家数据 type UserData struct { - UserId int //玩家id - RegTime int //注册时间 - Gold int64 //金币 - GoldSum int64 //玩家累计金币 - Love int64 //爱心值 - Goldrate int64 //金币生成速率 - Loverate int64 //爱心生产速率 - Highestlv int //当前最高猫等级 - InviteId int //邀请者uid - CurBoxLv int //当前猫箱子等级 - IsDouble int //当前加速标签 1表示3倍收益 0表示正常 - StartDoubleTime int //开始双倍时间 - DoubleLeftTimes int //开始双倍时间 - IsAuto int //当前是否自动合成 - IsBoxAcc int //是否处于加速生成箱子状态 - RandGiftNum int //当前剩余空投猫粮次数 - RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum - RandGiftTime int //记录上一次空投猫粮时间 - Redbag float32 //红包值 单位为分 - Head string //头像地址 - NickName string //昵称 - RealName string //实名 - IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是 - OfflineGold int64 //离线金币 - OfflineLove int64 //离线爱心 - LastLoginTime int //上次登陆时间 - CatShopInfo CatShopData //猫咖门店数据 - Taskinfo TaskData //任务数据 - AchieveMent AchieveMentData //成就数据 - PosInfo []CatPosInfo //位置信息 从0开始 - BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推 - CatRoomInfo []CatRoomData //猫咖店数据 + UserId int //玩家id + RegTime int //注册时间 + Gold int64 //金币 + GoldSum int64 //玩家累计金币 + Love int64 //爱心值 + Goldrate int64 //金币生成速率 + Loverate int64 //爱心生产速率 + Highestlv int //当前最高猫等级 + InviteId int //邀请者uid + CurBoxLv int //当前猫箱子等级 + IsDouble int //当前加速标签 1表示3倍收益 0表示正常 + StartDoubleTime int //开始双倍时间 + DoubleLeftTimes int //剩余加速金币次数 + GetWatchAdsGoldTime int //看广告领金币次数 + IsAuto int //当前是否自动合成 + IsBoxAcc int //是否处于加速生成箱子状态 + RandGiftNum int //当前剩余空投猫粮次数 + RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum + RandGiftTime int //记录上一次空投猫粮时间 + Redbag float32 //红包值 单位为分 + Head string //头像地址 + NickName string //昵称 + RealName string //实名 + IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是 + OfflineGold int64 //离线金币 + OfflineLove int64 //离线爱心 + LastLoginTime int //上次登陆时间 + LastTimingRewardHour int //上次领取整点奖励的时刻 + CatShopInfo CatShopData //猫咖门店数据 + Taskinfo TaskData //任务数据 + AchieveMent AchieveMentData //成就数据 + PosInfo []CatPosInfo //位置信息 从0开始 + BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推 + CatRoomInfo []CatRoomData //猫咖店数据 } diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index e335744..53b4c91 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -12,6 +12,67 @@ import ( "time" ) +//加红包接口 +func (u *UserData) AddRedPackect(num float32) { + //todo 接后台 + u.Redbag += num +} + +//清空一个位置的猫 +func (u *UserData) CleadPos(pos int) { + if pos < 0 || pos >= len(u.PosInfo) { + logger.Error("CleadPos failed pos=%v,posinfo=%v", pos, u.PosInfo) + return + } + + u.PosInfo[pos].Cat = 0 + u.PosInfo[pos].Position = pos + u.PosInfo[pos].StartTime = 0 + u.PosInfo[pos].RedPacket = 0 + u.PosInfo[pos].Time = 0 +} + +//设置一个位置的猫 +func (u *UserData) SetCatPos(pos int, catlv, time int, redpack float32, starttime int) { + if pos < 0 || pos >= len(u.PosInfo) { + logger.Error("CleadPos failed pos=%v,posinfo=%v", pos, u.PosInfo) + return + } + + u.PosInfo[pos].Cat = catlv + u.PosInfo[pos].Position = pos + u.PosInfo[pos].StartTime = starttime + u.PosInfo[pos].RedPacket = redpack + u.PosInfo[pos].Time = time +} + +//获取所有分红猫列表的位置 +func (u *UserData) GetLimitCatList() []int { + var rtlist []int + for k, v := range u.PosInfo { + if v.Cat > 36 { + rtlist = append(rtlist, k) + } + } + + return rtlist +} + +//根据猫等级获得位置 +func (u *UserData) GetCatPos(catlv int) int { + pos := -1 + for _, v := range u.PosInfo { + if v.Cat == catlv { + pos = v.Position + } + } + + if pos < 0 || pos >= len(u.PosInfo) { + pos = -1 + } + return pos +} + func (u *UserData) HandlePassDay() { isdiffday := false nowtime := time.Now() @@ -45,6 +106,7 @@ func (u *UserData) HandlePassDay() { if isdiffday { //跨天了 u.DoubleLeftTimes = ACCGOLDRATELIMIT + u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT } u.LastLoginTime = int(nowtime.Unix()) @@ -97,6 +159,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { udata.Redbag = 0 udata.IsFirstRedBgCat = 0 udata.DoubleLeftTimes = ACCGOLDRATELIMIT + udata.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT udata.RegTime = int(time.Now().Unix()) udata.LastLoginTime = int(time.Now().Unix()) diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index ee89f6b..e41c198 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -33,6 +33,14 @@ func startServerHttpServe() { http.HandleFunc("/api/home/shop", QueryBuyCat) //商店 http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数 http.HandleFunc("/api/home/change", ExchangePos) //合成 + http.HandleFunc("/api/home/leftTimes", LeftTimes) //剩余看广告领取金币次数 + http.HandleFunc("/api/home/adCoin", WatchAdsGetGold) //看广告领取金币 + http.HandleFunc("/api/home/recvTimingReward", RecvTimingReward) //整点领取金币 + http.HandleFunc("/api/home/redCatList", RedCatList) //红包猫列表 此接口目前没有用到 暂时不实线 + http.HandleFunc("/api/home/recovery", Recovery) //回收猫 + http.HandleFunc("/api/home/compose", Compose) //五猫合成 + http.HandleFunc("/api/home/recvRedCat", RecvRedCat) //红包猫领取 + http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表 /////---------------------------------------------------------------------old http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 @@ -447,6 +455,24 @@ func DoBuyCat(w http.ResponseWriter, r *http.Request) { HandlerDoBuyCat(w, s, Uuid) } +func LeftTimes(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("LeftTimes , body:%v,uuid=%v", s, Uuid) + + HandlerLeftTimes(w, s, Uuid) +} + func LeftRateTimes(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { @@ -591,6 +617,132 @@ func AcclecteBoxRate(w http.ResponseWriter, r *http.Request) { // HandlerAcclecteBoxRate(w, s, Uuid) } +func RedCatList(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("RedCatList , body:%v,uuid=%v", s, Uuid) + + //HandlerRecvTimingReward(w, s, Uuid) +} + +func LimitCatList(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("LimitCatList , body:%v,uuid=%v", s, Uuid) + + HandlerLimitCatList(w, s, Uuid) +} + +func RecvRedCat(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("RecvRedCat , body:%v,uuid=%v", s, Uuid) + + HandlerRecvRedCat(w, s, Uuid) +} + +func Compose(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("Compose , body:%v,uuid=%v", s, Uuid) + + HandlerCompose(w, s, Uuid) +} + +func Recovery(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("Recovery , body:%v,uuid=%v", s, Uuid) + + HandlerRecovery(w, s, Uuid) +} + +func RecvTimingReward(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("RecvTimingReward , body:%v,uuid=%v", s, Uuid) + + HandlerRecvTimingReward(w, s, Uuid) +} + +func WatchAdsGetGold(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("WatchAdsGetGold , body:%v,uuid=%v", s, Uuid) + + HandlerWatchAdsGetGold(w, s, Uuid) +} + func AcclecteGold(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 4ba07ee..cd5d65c 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -403,6 +403,398 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerLimitCatList(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp LimitCatListResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerRecvRedCat getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + poslist := uinfo.GetLimitCatList() + + for _, pos := range poslist { + if pos > 0 && pos < len(uinfo.PosInfo) { + var tmp LimitCatListData + tmp.CatId = uinfo.PosInfo[pos].Cat + tmp.Status = 0 + tmp.Cash = uinfo.PosInfo[pos].RedPacket + tmp.Date = time.Now().Format("2006-01-02T 15:04:05") + resp.Data = append(resp.Data, tmp) + } + } + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerRecvRedCat(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp RecvRedCatResp + resp.Code = 0 + resp.Message = "success" + var rdata RecvRedCatReq + err := json.Unmarshal([]byte(data), &rdata) + + for { + if err != nil { + logger.Info("json decode HandlerRecvRedCat data failed:%v", err, " for:%v", data) + resp.Message = "json unmarshal failed" + resp.Code = 1 + break + } + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerRecvRedCat getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //先判断位置 + cpos := uinfo.GetCatPos(rdata.RedCatId) + if cpos == -1 { + logger.Error("HandlerRecvRedCat nothave cat failed=%v", rdata.RedCatId) + resp.Code = 1 + resp.Message = "nothave cat failed" + break + } + + //判读下计时的时间是否结束 + nowtime := int(time.Now().Unix()) + v := uinfo.PosInfo[cpos] + if v.Time != 0 { + if nowtime < v.StartTime+v.Time { + //时间还未结束无法领取 + logger.Error("HandlerRecvRedCat timenotenough failed=%v", rdata.RedCatId) + resp.Code = 1 + resp.Message = "timenotenough failed" + break + } + } + + //领取红包 + addredpack := v.RedPacket + if rdata.Rtype == 1 { + addredpack = addredpack * 2 + } + + uinfo.AddRedPackect(addredpack) + uinfo.CleadPos(cpos) + + uinfo.CalcGoldRate() + + resp.Data.Num = addredpack + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerCompose(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp ComposeResp + resp.Code = 0 + resp.Message = "success" + var rdata ComposeReq + err := json.Unmarshal([]byte(data), &rdata) + + for { + if err != nil { + logger.Info("json decode HandlerCompose data failed:%v", err, " for:%v", data) + resp.Message = "json unmarshal failed" + resp.Code = 1 + break + } + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerCompose getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //先需要判断五个位置是否准确 + eastsum := 0 + westsum := 0 + southsum := 0 + northsum := 0 + middlesum := 0 + for _, val := range rdata.PositionList { + if val < 0 || val >= len(uinfo.PosInfo) { + logger.Error("HandlerCompose Position failed=%v", err) + + break + } + v := uinfo.PosInfo[val] + if v.Cat == 103 { + eastsum++ + } + if v.Cat == 104 { + westsum++ + } + if v.Cat == 105 { + southsum++ + } + if v.Cat == 106 { + northsum++ + } + if v.Cat == 107 { + middlesum++ + } + } + if !(eastsum > 0 && westsum > 0 && northsum > 0 && southsum > 0 && middlesum > 0) { + logger.Error("HandlerCompose notfivecat failed=%v", err) + resp.Code = 1 + resp.Message = "notfivecat failed" + break + } + + //合成了五方猫 + //获取一天招财猫配置 + cfg := jsonconf.GetRedCatConfig(100 + 2) + if cfg == nil { + logger.Error("HandlerCompose getcfg failed=%v", err) + resp.Code = 1 + resp.Message = "getcfg failed" + break + } + nowtime := int(time.Now().Unix()) + uinfo.SetCatPos(rdata.PositionList[0], 2+100, 24*3600, cfg.Money, nowtime) + //清空其他位置的猫 + for k, v := range rdata.PositionList { + if k > 0 { + uinfo.CleadPos(v) + } + } + + //重新计算一下速度 + uinfo.CalcGoldRate() + + resp.Data.CatList = append(resp.Data.CatList, uinfo.PosInfo...) + resp.Data.Coin.UserId = uuid + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10) + resp.Data.Coin.UpdateTime = int(time.Now().Unix()) + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10) + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerRecovery(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp RecoveryResp + resp.Code = 0 + resp.Message = "success" + var rdata RecoveryReq + err := json.Unmarshal([]byte(data), &rdata) + + for { + if err != nil { + logger.Info("json decode HandlerRecovery data failed:%v", err, " for:%v", data) + resp.Message = "json unmarshal failed" + resp.Code = 1 + break + } + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerRecovery getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + if rdata.Position < 0 || rdata.Position >= len(uinfo.PosInfo) { + logger.Error("HandlerRecovery Position failed=%v", err) + resp.Code = 1 + resp.Message = "Position failed" + break + } + + if uinfo.PosInfo[rdata.Position].Cat > 36 || uinfo.PosInfo[rdata.Position].Cat == 0 { + //高级猫或者没有猫无法卖 + logger.Error("HandlerRecovery CatLV failed=%v", err) + resp.Code = 1 + resp.Message = "CatLV failed" + break + } + + cfg := jsonconf.GetCatConfig(uinfo.PosInfo[rdata.Position].Cat) + if cfg == nil { + logger.Error("HandlerRecovery CatLVCFG failed=%v", uinfo.PosInfo[rdata.Position].Cat) + resp.Code = 1 + resp.Message = "CatLVCFG failed" + break + } + uinfo.CleadPos(rdata.Position) + + //重新计算速度 + uinfo.CalcGoldRate() + //加金币 + price, _ := strconv.ParseInt(cfg.Price, 10, 64) + uinfo.Gold += price / 10 + + resp.Data.Coin.UserId = uuid + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10) + resp.Data.Coin.UpdateTime = int(time.Now().Unix()) + resp.Data.Coin.IcomeRate = strconv.FormatInt(uinfo.Goldrate, 10) + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerRecvTimingReward(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp RecvTimingRewardResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerRecvTimingReward getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //判断一下领取的时间点是否正确 + nowt := time.Now() + if nowt.Minute() < 50 && nowt.Minute() > 10 { + logger.Error("HandlerRecvTimingReward time failed=%v", err) + resp.Code = 1 + resp.Message = "time failed" + break + } + + nowh := 0 + if nowt.Minute() >= 50 { + //领取的是笑一个小时 + if nowt.Hour() < 23 { + if uinfo.LastTimingRewardHour >= nowt.Hour()+1 { + //已经领取过了 无法在零 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err) + resp.Code = 1 + resp.Message = "alreadyfetched failed" + break + } + nowh = nowt.Hour() + } else { + if uinfo.LastTimingRewardHour == 0 { + //已经领取过了 无法在零 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err) + resp.Code = 1 + resp.Message = "alreadyfetched failed" + break + } + nowh = 0 + } + + } + + if nowt.Minute() <= 10 { + //领取的是本时段的 + if uinfo.LastTimingRewardHour >= nowt.Hour() { + //已经领取过了 无法在零 + logger.Error("HandlerRecvTimingReward alreadyfetched failed=%v", err) + resp.Code = 1 + resp.Message = "alreadyfetched failed" + break + } + nowh = nowt.Hour() + } + + addgold := uinfo.Goldrate * ZHENGHOURMULT + uinfo.Gold += addgold + uinfo.LastTimingRewardHour = nowh + + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + resp.Data.Reward = strconv.FormatInt(addgold, 10) + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerWatchAdsGetGold(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp WatchAdsGetGoldResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerWatchAdsGetGold getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + if uinfo.GetWatchAdsGoldTime <= 0 { + //不够次数了 + logger.Error("HandlerWatchAdsGetGold not enoughtimes failed=%v", err) + resp.Code = 1 + resp.Message = "enoughtimes" + break + } + + uinfo.GetWatchAdsGoldTime-- + addgold := uinfo.Goldrate * WATCHADSGOLDLRATE + uinfo.Gold += addgold + + resp.Data.Reward = strconv.FormatInt(addgold, 10) + resp.Data.LeftTimes = uinfo.GetWatchAdsGoldTime + + resp.Data.Coin.UserId = uuid + resp.Data.Coin.Coin = strconv.FormatInt(uinfo.Gold, 10) + accrate := uinfo.Goldrate * 3 + resp.Data.Coin.IcomeRate = strconv.FormatInt(accrate, 10) + resp.Data.Coin.UpdateTime = int(time.Now().Unix()) + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp AcclecteResp @@ -455,6 +847,33 @@ func HandlerAcclecteGold(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerLeftTimes(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp LeftRateTimesResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerLeftTimes getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + resp.Data.LeftTimes = uinfo.GetWatchAdsGoldTime + resp.Data.LimitTimes = WATCHADSGOLDLIMIT + + resp.Code = 0 + break + } + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerLeftRateTimes(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp LeftRateTimesResp -- libgit2 0.21.0