Commit 8f499beed8525b0bd193104cfa5b19f25373186d

Authored by 陆恒
1 parent f39958c2

任务相关接口

src/HttpServer/logic/constdef.go
1 1 package logic
2 2  
  3 +//任务成就类型枚举
  4 +var (
  5 + TASKTYPE_PASSLEVEL = 1 //表示通过x关卡
  6 + TASKTYPE_GETREDBAG = 2 //领取x次红包
  7 + TASKTYPE_WATCHADS = 3 //3表示观看x次广告
  8 + TASKTYPE_KILLSTAR = 4 //4表示消除x颗星星
  9 + TASKTYPE_USEITEM = 5 //5表示使用x次道具
  10 +)
  11 +
3 12 var (
4 13 WETCHATAPPID="wx572a2a5ec4538f33"
5 14 WETCHATSERCRT = "b31e2e7406af88fe7395cd178bdb64fc"
... ...
src/HttpServer/logic/datadef.go
... ... @@ -107,14 +107,38 @@ type GetcashrecordResp struct {
107 107 Data WithDrawList `json:"data"`
108 108 }
109 109  
  110 +type OnlinentfResp struct {
  111 + Code int `json:"code"`
  112 + Message string `json:"message"`
  113 +}
  114 +
  115 +type UpdatetaskReq struct {
  116 + Tasktype int `json:"tasktype"`
  117 + Value int `json:"value"`
  118 +}
  119 +
  120 +type UpdatetaskResp struct {
  121 + Code int `json:"code"`
  122 + Message string `json:"message"`
  123 +}
  124 +
110 125 //**********************************************************************************************************
111 126  
  127 +//其中提取次数和当日登陆在userdata中记录
112 128 type TaskInfo struct {
113   -
  129 + OnlineMin int //在线分钟数
  130 + PassLevel int //通过关卡数
  131 + UseItemCnt int //使用道具次数
  132 + GetRedbagCnt int //领取红包次数
  133 + GetGuanGold int //收集金币数
114 134 }
115 135  
  136 +//
116 137 type AchieveMentInfo struct {
117   -
  138 + WatchAdsCnt int //观看广告数
  139 + KillStar int //消除星星数
  140 + SumGetGuan int //存钱罐累计提取
  141 + SumUseItemCnt int //使用道具次数累计
118 142 }
119 143  
120 144  
... ...
src/HttpServer/logic/function.go
... ... @@ -138,6 +138,12 @@ func (u *UserData) HandlePassDay() {
138 138 u.WatchAddsTime = WATCH_ADD_DAY_LIMIT
139 139 //todo 重置任务相关的数据
140 140 u.GetFromGuanCnt = 0
  141 +
  142 + u.Task.GetGuanGold = 0
  143 + u.Task.GetRedbagCnt = 0
  144 + u.Task.OnlineMin = 0
  145 + u.Task.PassLevel = 0
  146 + u.Task.UseItemCnt = 0
141 147 }
142 148  
143 149 u.LastLoginTime = int(nowtime.Unix())
... ... @@ -156,6 +162,11 @@ func GetUserData(uuid int, resp *UserLoginResp) error{
156 162 //此处要处理一下跨天逻辑
157 163 data.HandlePassDay()
158 164  
  165 + //此处处理一下从sdk拉取钱包金币数量
  166 + //todo
  167 +
  168 + SaveUserInfo(data)
  169 +
159 170 resp.Data.Walletgold = data.RealGold
160 171 resp.Data.Leftads = data.WatchAddsTime
161 172 resp.Data.Guangold = data.GuanGold
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -46,10 +46,57 @@ func startServerHttpServe() {
46 46 http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口
47 47 http.HandleFunc("/eliminatestar/getcash", Getcash) //提现
48 48 http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表
  49 + http.HandleFunc("/eliminatestar/onlinentf", Onlinentf) //在线通知
  50 + http.HandleFunc("/eliminatestar/updatetaskandachieve", Updatetaskandachieve) //在线通知
  51 +
  52 +
49 53 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil)
50 54 CheckErr(err)
51 55 }
52 56  
  57 +func Updatetaskandachieve(w http.ResponseWriter, r *http.Request) {
  58 +
  59 + Uuid := 0
  60 + if len(r.Header) > 0 {
  61 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  62 + }
  63 +
  64 + if Uuid == 0 {
  65 + SetHeader(w)
  66 + //logger.Error("Uuid is nil!")
  67 + return
  68 + }
  69 + result, _ := ioutil.ReadAll(r.Body)
  70 + r.Body.Close()
  71 +
  72 + s := string(result)
  73 + logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid)
  74 +
  75 + HandlerUpdatetaskandachieve(w, s, Uuid)
  76 +}
  77 +
  78 +
  79 +func Onlinentf(w http.ResponseWriter, r *http.Request) {
  80 +
  81 + Uuid := 0
  82 + if len(r.Header) > 0 {
  83 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  84 + }
  85 +
  86 + if Uuid == 0 {
  87 + SetHeader(w)
  88 + //logger.Error("Uuid is nil!")
  89 + return
  90 + }
  91 + result, _ := ioutil.ReadAll(r.Body)
  92 + r.Body.Close()
  93 +
  94 + s := string(result)
  95 + logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid)
  96 +
  97 + HandlerOnlinentf(w, s, Uuid)
  98 +}
  99 +
53 100 func Getcashrecord(w http.ResponseWriter, r *http.Request) {
54 101  
55 102 Uuid := 0
... ...
src/HttpServer/logic/logic.go
... ... @@ -158,7 +158,80 @@ func HandlerGetcash(w http.ResponseWriter, data string, uuid int) {
158 158  
159 159 }
160 160  
  161 +func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) {
  162 + SetHeader(w)
  163 + var resp UpdatetaskResp
  164 + resp.Code = 0
  165 + var rdata UpdatetaskReq
  166 + err := json.Unmarshal([]byte(data), &rdata)
  167 + for {
  168 +
  169 + if err != nil {
  170 + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data)
  171 + resp.Message = "json解析错误"
  172 + resp.Code = ERROR_JSONUNMASH_ERROR
  173 + break
  174 + }
  175 + uinfo,err := GetUserInfo(uuid)
  176 + if err != nil || uinfo == nil{
  177 + logger.Error("redis failed err=%v", err)
  178 + resp.Message = "服务器错误"
  179 + resp.Code = ERROR_SRV_ERROR
  180 + break
  181 + }
  182 +
  183 + switch rdata.Tasktype {
  184 + case TASKTYPE_PASSLEVEL:
  185 + uinfo.Task.PassLevel += rdata.Value
  186 + case TASKTYPE_GETREDBAG:
  187 + uinfo.Task.GetRedbagCnt += rdata.Value
  188 + case TASKTYPE_WATCHADS:
  189 + uinfo.Achieve.WatchAdsCnt += rdata.Value
  190 + case TASKTYPE_KILLSTAR:
  191 + uinfo.Achieve.KillStar += rdata.Value
  192 + case TASKTYPE_USEITEM:
  193 + uinfo.Task.UseItemCnt += rdata.Value
  194 + uinfo.Achieve.SumUseItemCnt += rdata.Value
  195 + }
  196 +
  197 + SaveUserInfo(uinfo)
  198 + resp.Code = ERROR_OK
  199 + break
  200 + }
161 201  
  202 + //回包
  203 + respstr, _ := json.Marshal(&resp)
  204 + fmt.Fprint(w, string(respstr))
  205 +
  206 +}
  207 +
  208 +func HandlerOnlinentf(w http.ResponseWriter, data string, uuid int) {
  209 + SetHeader(w)
  210 + var resp OnlinentfResp
  211 + resp.Code = 0
  212 + for {
  213 +
  214 + uinfo,err := GetUserInfo(uuid)
  215 + if err != nil || uinfo == nil{
  216 + logger.Error("redis failed err=%v", err)
  217 + resp.Message = "服务器错误"
  218 + resp.Code = ERROR_SRV_ERROR
  219 + break
  220 + }
  221 +
  222 + uinfo.Task.OnlineMin ++
  223 +
  224 + SaveUserInfo(uinfo)
  225 +
  226 + resp.Code = ERROR_OK
  227 + break
  228 + }
  229 +
  230 + //回包
  231 + respstr, _ := json.Marshal(&resp)
  232 + fmt.Fprint(w, string(respstr))
  233 +
  234 +}
162 235  
163 236 func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) {
164 237 SetHeader(w)
... ...