From 3e479fb8173994b3b014bfbc72b7389ee83d6b4d Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Thu, 11 Jun 2020 14:41:07 +0800 Subject: [PATCH] 提交接口 --- src/HttpServer/logic/constdef.go | 3 +++ src/HttpServer/logic/datadef.go | 23 +++++++++++++++++++++++ src/HttpServer/logic/function.go | 4 ++++ src/HttpServer/logic/httpserver.go | 38 ++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+), 0 deletions(-) diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index 0ce7c7d..d457f42 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -55,4 +55,7 @@ const ( WATCHADSGOLDLIMIT = 15 //玩家每天看广告领金币限制次数 WATCHADSGOLDLRATE = 10800 //看广告领取金币的秒数 ZHENGHOURMULT = 3600 //整点领取金币的秒数 + DRAWTICKETNUM = 5 //每日送的抽奖券次数 + DRAWTICKETGETLIMIT = 5 //每日抽奖券获得次数 + DRAWTICKETNUMLIMIT = 10 //抽奖券上限 ) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 46b8a97..bf2e016 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -189,6 +189,27 @@ type LimitCatListResp struct { Data []LimitCatListData `json:"data"` } +type QueryTurntableData struct { + TicketCount int `json:"ticketCount"` + LeftTime int `json:"leftTime"` + LimitTicket int `json:"limitTicket"` +} + +type QueryTurntableResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data QueryTurntableData `json:"data"` +} + +type AddTicketData struct { +} + +type AddTicketResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data AddTicketData `json:"data"` +} + type AcclecteBoxResp struct { Code int `json:"code"` Message string `json:"message"` @@ -561,6 +582,8 @@ type UserData struct { StartDoubleTime int //开始双倍时间 DoubleLeftTimes int //剩余加速金币次数 GetWatchAdsGoldTime int //看广告领金币次数 + DrawTicket int //抽奖券次数 + DrawTicketTimes int //剩余增加抽奖券次数 IsAuto int //当前是否自动合成 IsBoxAcc int //是否处于加速生成箱子状态 RandGiftNum int //当前剩余空投猫粮次数 diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 438a39b..659594d 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -107,6 +107,8 @@ func (u *UserData) HandlePassDay() { //跨天了 u.DoubleLeftTimes = ACCGOLDRATELIMIT u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT + u.DrawTicket = DRAWTICKETNUM + u.DoubleLeftTimes = DRAWTICKETGETLIMIT } u.LastLoginTime = int(nowtime.Unix()) @@ -163,6 +165,8 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { udata.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT udata.RegTime = int(time.Now().Unix()) udata.LastLoginTime = int(time.Now().Unix()) + udata.DrawTicket = DRAWTICKETNUM + udata.DoubleLeftTimes = DRAWTICKETGETLIMIT //初始化16个猫爬架 for i := 0; i < 16; i++ { diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index e41c198..2e36bc9 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -41,6 +41,8 @@ func startServerHttpServe() { http.HandleFunc("/api/home/compose", Compose) //五猫合成 http.HandleFunc("/api/home/recvRedCat", RecvRedCat) //红包猫领取 http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表 + http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页 + http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券 /////---------------------------------------------------------------------old http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 @@ -635,6 +637,42 @@ func RedCatList(w http.ResponseWriter, r *http.Request) { //HandlerRecvTimingReward(w, s, Uuid) } +func AddTicket(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("AddTicket , body:%v,uuid=%v", s, Uuid) + + HandlerAddTicket(w, s, Uuid) +} + +func QueryTurntable(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("QueryTurntable , body:%v,uuid=%v", s, Uuid) + + HandlerQueryTurntable(w, s, Uuid) +} + func LimitCatList(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 01021c3..fb62775 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -403,6 +403,75 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerAddTicket(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp AddTicketResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerQueryTurntable getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + if uinfo.DoubleLeftTimes == 0 { + logger.Error("HandlerQueryTurntable DoubleLeftTimes failed=%v", err) + resp.Code = 1 + resp.Message = "DoubleLeftTimes not enough" + break + } + + uinfo.DoubleLeftTimes-- + uinfo.DrawTicket += 5 + if uinfo.DrawTicket > DRAWTICKETNUMLIMIT { + uinfo.DrawTicket = DRAWTICKETNUMLIMIT + } + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerQueryTurntable(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QueryTurntableResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerQueryTurntable getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + resp.Data.TicketCount = uinfo.DrawTicket + resp.Data.LeftTime = uinfo.DoubleLeftTimes + resp.Data.LimitTicket = DRAWTICKETNUMLIMIT + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerLimitCatList(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp LimitCatListResp -- libgit2 0.21.0