From 8f499beed8525b0bd193104cfa5b19f25373186d Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Wed, 13 May 2020 17:58:55 +0800 Subject: [PATCH] 任务相关接口 --- src/HttpServer/logic/constdef.go | 9 +++++++++ src/HttpServer/logic/datadef.go | 28 ++++++++++++++++++++++++++-- src/HttpServer/logic/function.go | 11 +++++++++++ src/HttpServer/logic/httpserver.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 2 deletions(-) diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index 4de33d7..95b073e 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -1,5 +1,14 @@ package logic +//任务成就类型枚举 +var ( + TASKTYPE_PASSLEVEL = 1 //表示通过x关卡 + TASKTYPE_GETREDBAG = 2 //领取x次红包 + TASKTYPE_WATCHADS = 3 //3表示观看x次广告 + TASKTYPE_KILLSTAR = 4 //4表示消除x颗星星 + TASKTYPE_USEITEM = 5 //5表示使用x次道具 +) + var ( WETCHATAPPID="wx572a2a5ec4538f33" WETCHATSERCRT = "b31e2e7406af88fe7395cd178bdb64fc" diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index febd970..3ee0df7 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -107,14 +107,38 @@ type GetcashrecordResp struct { Data WithDrawList `json:"data"` } +type OnlinentfResp struct { + Code int `json:"code"` + Message string `json:"message"` +} + +type UpdatetaskReq struct { + Tasktype int `json:"tasktype"` + Value int `json:"value"` +} + +type UpdatetaskResp struct { + Code int `json:"code"` + Message string `json:"message"` +} + //********************************************************************************************************** +//其中提取次数和当日登陆在userdata中记录 type TaskInfo struct { - + OnlineMin int //在线分钟数 + PassLevel int //通过关卡数 + UseItemCnt int //使用道具次数 + GetRedbagCnt int //领取红包次数 + GetGuanGold int //收集金币数 } +// type AchieveMentInfo struct { - + WatchAdsCnt int //观看广告数 + KillStar int //消除星星数 + SumGetGuan int //存钱罐累计提取 + SumUseItemCnt int //使用道具次数累计 } diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 2a45bbb..915c7b4 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -138,6 +138,12 @@ func (u *UserData) HandlePassDay() { u.WatchAddsTime = WATCH_ADD_DAY_LIMIT //todo 重置任务相关的数据 u.GetFromGuanCnt = 0 + + u.Task.GetGuanGold = 0 + u.Task.GetRedbagCnt = 0 + u.Task.OnlineMin = 0 + u.Task.PassLevel = 0 + u.Task.UseItemCnt = 0 } u.LastLoginTime = int(nowtime.Unix()) @@ -156,6 +162,11 @@ func GetUserData(uuid int, resp *UserLoginResp) error{ //此处要处理一下跨天逻辑 data.HandlePassDay() + //此处处理一下从sdk拉取钱包金币数量 + //todo + + SaveUserInfo(data) + resp.Data.Walletgold = data.RealGold resp.Data.Leftads = data.WatchAddsTime resp.Data.Guangold = data.GuanGold diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index e90e95a..8448115 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -46,10 +46,57 @@ func startServerHttpServe() { http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 + http.HandleFunc("/eliminatestar/onlinentf", Onlinentf) //在线通知 + http.HandleFunc("/eliminatestar/updatetaskandachieve", Updatetaskandachieve) //在线通知 + + err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) CheckErr(err) } +func Updatetaskandachieve(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid) + + HandlerUpdatetaskandachieve(w, s, Uuid) +} + + +func Onlinentf(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid) + + HandlerOnlinentf(w, s, Uuid) +} + func Getcashrecord(w http.ResponseWriter, r *http.Request) { Uuid := 0 diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index d21d20d..ac681dd 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -158,7 +158,80 @@ func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { } +func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp UpdatetaskResp + resp.Code = 0 + var rdata UpdatetaskReq + err := json.Unmarshal([]byte(data), &rdata) + for { + + if err != nil { + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = ERROR_JSONUNMASH_ERROR + break + } + uinfo,err := GetUserInfo(uuid) + if err != nil || uinfo == nil{ + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + switch rdata.Tasktype { + case TASKTYPE_PASSLEVEL: + uinfo.Task.PassLevel += rdata.Value + case TASKTYPE_GETREDBAG: + uinfo.Task.GetRedbagCnt += rdata.Value + case TASKTYPE_WATCHADS: + uinfo.Achieve.WatchAdsCnt += rdata.Value + case TASKTYPE_KILLSTAR: + uinfo.Achieve.KillStar += rdata.Value + case TASKTYPE_USEITEM: + uinfo.Task.UseItemCnt += rdata.Value + uinfo.Achieve.SumUseItemCnt += rdata.Value + } + + SaveUserInfo(uinfo) + resp.Code = ERROR_OK + break + } + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerOnlinentf(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp OnlinentfResp + resp.Code = 0 + for { + + uinfo,err := GetUserInfo(uuid) + if err != nil || uinfo == nil{ + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + uinfo.Task.OnlineMin ++ + + SaveUserInfo(uinfo) + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) { SetHeader(w) -- libgit2 0.21.0