Commit 3258476fda116dc40ffc7c3360736202f7512fd4
1 parent
ae4fcef9
Exists in
master
and in
4 other branches
提交签到接口
Showing
6 changed files
with
282 additions
and
48 deletions
Show diff stats
src/HttpServer/jsonconf/jsonconf.go
... | ... | @@ -80,6 +80,27 @@ func GetJsonConf() *GameConfig { |
80 | 80 | return g_jsonconf |
81 | 81 | } |
82 | 82 | |
83 | +func GetSignConfig(round, daynum int) *SignRewardDetail { | |
84 | + if round > g_jsonconf.SignConfig.Round { | |
85 | + //取reward2 | |
86 | + if daynum > len(g_jsonconf.SignConfig.Reward.Reward2) { | |
87 | + logger.Error("GetSignConfig failed") | |
88 | + return nil | |
89 | + } | |
90 | + | |
91 | + return &g_jsonconf.SignConfig.Reward.Reward2[daynum-1] | |
92 | + | |
93 | + } else { | |
94 | + //取reward1 | |
95 | + if daynum > len(g_jsonconf.SignConfig.Reward.Reward1) { | |
96 | + logger.Error("GetSignConfig failed") | |
97 | + return nil | |
98 | + } | |
99 | + | |
100 | + return &g_jsonconf.SignConfig.Reward.Reward1[daynum-1] | |
101 | + } | |
102 | +} | |
103 | + | |
83 | 104 | func GetMoneyBoxCfg(lv int) *MoneyBoxLevelDesc { |
84 | 105 | rt := new(MoneyBoxLevelDesc) |
85 | 106 | rt = nil | ... | ... |
src/HttpServer/logic/datadef.go
... | ... | @@ -188,6 +188,32 @@ type GetnewlevelrewardResp struct { |
188 | 188 | Data GetnewlevelrewardData `json:"data"` |
189 | 189 | } |
190 | 190 | |
191 | +type QuerysigndataData struct { | |
192 | + Signround int `json:"signround"` | |
193 | + Continuessign int `json:"continuessign"` | |
194 | + IssignToday int `json:"issignToday"` | |
195 | +} | |
196 | + | |
197 | +type QuerysigndataResp struct { | |
198 | + Code int `json:"code"` | |
199 | + Message string `json:"message"` | |
200 | + Data QuerysigndataData `json:"data"` | |
201 | +} | |
202 | + | |
203 | +type UsersignReq struct { | |
204 | + Gameid string `json:"gameid"` | |
205 | + Channel string `json:"channel"` | |
206 | +} | |
207 | + | |
208 | +type UsersignData struct { | |
209 | + Goldnum int `json:"goldnum"` | |
210 | +} | |
211 | +type UsersignResp struct { | |
212 | + Code int `json:"code"` | |
213 | + Message string `json:"message"` | |
214 | + Data UsersignData `json:"data"` | |
215 | +} | |
216 | + | |
191 | 217 | //********************************************************************************************************** |
192 | 218 | |
193 | 219 | type TaskListDesc struct { |
... | ... | @@ -251,6 +277,9 @@ type UserData struct { |
251 | 277 | LastLoginTime int //上次登陆时间 |
252 | 278 | ContinueLoginDay int //连续登录天数 |
253 | 279 | GetFromGuanCnt int //当天从存钱款提取金币次数 |
280 | + SignRound int //签到轮数 | |
281 | + SignSum int //累计签到天数 | |
282 | + IsSignToday int //今日是否已经签到 1是 0否 | |
254 | 283 | WithDraw WithDrawInfo //提现记录信息 |
255 | 284 | Task TaskInfo //玩家任务完成相关信息 |
256 | 285 | Achieve AchieveMentInfo //玩家成就完成相关数据 | ... | ... |
src/HttpServer/logic/errordef.go
1 | 1 | package logic |
2 | 2 | |
3 | - | |
4 | 3 | const ( |
5 | - ERROR_OK =0 //没有错误 | |
6 | - ERROR_SRV_ERROR =1 //服务器错误 | |
7 | - ERROR_JSONUNMASH_ERROR =2 //json解析错误 | |
8 | - ERROR_WATCHADS_ZEOR =3 //看视频次数已经耗尽 | |
9 | - ERROR_GETCONFIG_FAILED =4 //获取配置失败 | |
10 | - ERROR_GUANGOLD_NOTENOUGH =5 //存钱罐金币不足 | |
11 | - ERROR_DRAWGUAN_FAILED =6 //从存钱罐提取金币不满足限制 | |
12 | - ERROR_DRAWGOLD_FAILED =7 //从存钱罐提取金币失败了 | |
13 | - ERROR_GETCASH_FAILED =8 //从后台提现失败了 | |
14 | - ERROR_GETCASH_GOLDNOTENOUGH_FAILED =9 //提现金币不足 | |
15 | - ERROR_ADDWITHDRAW_LISTFAILED =10 //添加提现记录失败 | |
16 | - ERROR_WITHDRAWLVLIMIT =11 //提现等级不够 | |
17 | - ERROR_WITHDRAWONLYONE =12 //新人专享只能提取一次 | |
18 | - ERROR_PRENOTFINISH =13 //前置档位未提现 | |
19 | - ERROR_TASKCANNOTGET =14 //当前任务未完成或已领取 | |
20 | - ERROR_TASKID_WRONG =15 //当前任务id错误 | |
21 | - ERROR_TASKPRE_NOTGET =16 //前置任务还未领取 | |
22 | - ERROR_LVREWARDALREADYGET =17 //当前等级奖励已经领取过了 | |
23 | -) | |
24 | 4 | \ No newline at end of file |
5 | + ERROR_OK = 0 //没有错误 | |
6 | + ERROR_SRV_ERROR = 1 //服务器错误 | |
7 | + ERROR_JSONUNMASH_ERROR = 2 //json解析错误 | |
8 | + ERROR_WATCHADS_ZEOR = 3 //看视频次数已经耗尽 | |
9 | + ERROR_GETCONFIG_FAILED = 4 //获取配置失败 | |
10 | + ERROR_GUANGOLD_NOTENOUGH = 5 //存钱罐金币不足 | |
11 | + ERROR_DRAWGUAN_FAILED = 6 //从存钱罐提取金币不满足限制 | |
12 | + ERROR_DRAWGOLD_FAILED = 7 //从存钱罐提取金币失败了 | |
13 | + ERROR_GETCASH_FAILED = 8 //从后台提现失败了 | |
14 | + ERROR_GETCASH_GOLDNOTENOUGH_FAILED = 9 //提现金币不足 | |
15 | + ERROR_ADDWITHDRAW_LISTFAILED = 10 //添加提现记录失败 | |
16 | + ERROR_WITHDRAWLVLIMIT = 11 //提现等级不够 | |
17 | + ERROR_WITHDRAWONLYONE = 12 //新人专享只能提取一次 | |
18 | + ERROR_PRENOTFINISH = 13 //前置档位未提现 | |
19 | + ERROR_TASKCANNOTGET = 14 //当前任务未完成或已领取 | |
20 | + ERROR_TASKID_WRONG = 15 //当前任务id错误 | |
21 | + ERROR_TASKPRE_NOTGET = 16 //前置任务还未领取 | |
22 | + ERROR_LVREWARDALREADYGET = 17 //当前等级奖励已经领取过了 | |
23 | + ERROR_SINGALREADYTODAY = 18 //今日已经签过到啦 | |
24 | + ERROR_SINGDATAFAILED = 19 //签到数据异常 | |
25 | +) | ... | ... |
src/HttpServer/logic/function.go
... | ... | @@ -579,6 +579,14 @@ func (u *UserData) HandlePassDay() { |
579 | 579 | } else { |
580 | 580 | logger.Error("HandlePassDay GetTaskInfo failer err=%v", err) |
581 | 581 | } |
582 | + | |
583 | + //签到数据处理 | |
584 | + u.IsSignToday = 0 | |
585 | + if u.SignSum >= 7 { | |
586 | + //进入新的一轮 | |
587 | + u.SignSum = 0 | |
588 | + u.SignRound++ | |
589 | + } | |
582 | 590 | } |
583 | 591 | |
584 | 592 | u.LastLoginTime = int(nowtime.Unix()) | ... | ... |
src/HttpServer/logic/httpserver.go
... | ... | @@ -3,6 +3,8 @@ package logic |
3 | 3 | import ( |
4 | 4 | "HttpServer/conf" |
5 | 5 | "common/logger" |
6 | + "encoding/json" | |
7 | + "fmt" | |
6 | 8 | "io/ioutil" |
7 | 9 | "strconv" |
8 | 10 | |
... | ... | @@ -37,27 +39,111 @@ func startServerHttpServe() { |
37 | 39 | //http.HandleFunc("/catcafe/QueryAllAccount", QueryAllAccount) //查询所有账号的等级信息等数据 |
38 | 40 | //------------------------------------------------------------- |
39 | 41 | |
40 | - | |
41 | - http.HandleFunc("/eliminatestar/login", UserLogin) //登录 | |
42 | - http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据 | |
43 | - http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频 | |
44 | - http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 | |
45 | - http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 | |
46 | - http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 | |
47 | - http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 | |
48 | - http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 | |
49 | - http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 | |
50 | - http.HandleFunc("/eliminatestar/onlinentf", Onlinentf) //在线通知 | |
51 | - http.HandleFunc("/eliminatestar/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度 | |
52 | - http.HandleFunc("/eliminatestar/querytaskinfo", Querytaskinfo) //拉取任务或者成就列表 | |
53 | - http.HandleFunc("/eliminatestar/gettaskreward", Gettaskreward) //领取任务或者成就奖励 | |
54 | - http.HandleFunc("/eliminatestar/getnewlevelreward", Getnewlevelreward) //领取任务或者成就奖励 | |
55 | - | |
42 | + http.HandleFunc("/eliminatestar/test", Testapi) //登录 | |
43 | + //---------------------------------------------------------------------------------------- | |
44 | + http.HandleFunc("/eliminatestar/login", UserLogin) //登录 | |
45 | + http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据 | |
46 | + http.HandleFunc("/eliminatestar/watchads", Watchads) //观看激励视频 | |
47 | + http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 | |
48 | + http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 | |
49 | + http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 | |
50 | + http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 | |
51 | + http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 | |
52 | + http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 | |
53 | + http.HandleFunc("/eliminatestar/onlinentf", Onlinentf) //在线通知 | |
54 | + http.HandleFunc("/eliminatestar/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度 | |
55 | + http.HandleFunc("/eliminatestar/querytaskinfo", Querytaskinfo) //拉取任务或者成就列表 | |
56 | + http.HandleFunc("/eliminatestar/gettaskreward", Gettaskreward) //领取任务或者成就奖励 | |
57 | + http.HandleFunc("/eliminatestar/getnewlevelreward", Getnewlevelreward) //领取任务或者成就奖励 | |
58 | + http.HandleFunc("/eliminatestar/querysigndata", Querysigndata) //获取签到数据 | |
59 | + http.HandleFunc("/eliminatestar/usersign", Usersign) //玩家签到 | |
56 | 60 | |
57 | 61 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
58 | 62 | CheckErr(err) |
59 | 63 | } |
60 | 64 | |
65 | +func Usersign(w http.ResponseWriter, r *http.Request) { | |
66 | + | |
67 | + Uuid := 0 | |
68 | + if len(r.Header) > 0 { | |
69 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
70 | + } | |
71 | + | |
72 | + if Uuid == 0 { | |
73 | + SetHeader(w) | |
74 | + //logger.Error("Uuid is nil!") | |
75 | + return | |
76 | + } | |
77 | + result, _ := ioutil.ReadAll(r.Body) | |
78 | + r.Body.Close() | |
79 | + | |
80 | + s := string(result) | |
81 | + logger.Info("Usersign , body:%v,uuid=%v", s, Uuid) | |
82 | + | |
83 | + HandlerUsersign(w, s, Uuid) | |
84 | +} | |
85 | + | |
86 | +func Querysigndata(w http.ResponseWriter, r *http.Request) { | |
87 | + | |
88 | + Uuid := 0 | |
89 | + if len(r.Header) > 0 { | |
90 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
91 | + } | |
92 | + | |
93 | + if Uuid == 0 { | |
94 | + SetHeader(w) | |
95 | + //logger.Error("Uuid is nil!") | |
96 | + return | |
97 | + } | |
98 | + result, _ := ioutil.ReadAll(r.Body) | |
99 | + r.Body.Close() | |
100 | + | |
101 | + s := string(result) | |
102 | + logger.Info("Querysigndata , body:%v,uuid=%v", s, Uuid) | |
103 | + | |
104 | + HandlerQuerysigndata(w, s, Uuid) | |
105 | +} | |
106 | + | |
107 | +func Testapi(w http.ResponseWriter, r *http.Request) { | |
108 | + | |
109 | + type TesaApiData struct { | |
110 | + Type int `json:"type"` //1金币 2经验 3存钱罐次数 | |
111 | + Value int `json:"value"` | |
112 | + } | |
113 | + Uuid := 0 | |
114 | + if len(r.Header) > 0 { | |
115 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
116 | + } | |
117 | + | |
118 | + if Uuid == 0 { | |
119 | + SetHeader(w) | |
120 | + //logger.Error("Uuid is nil!") | |
121 | + return | |
122 | + } | |
123 | + result, _ := ioutil.ReadAll(r.Body) | |
124 | + r.Body.Close() | |
125 | + | |
126 | + s := string(result) | |
127 | + logger.Info("Querysigndata , body:%v,uuid=%v", s, Uuid) | |
128 | + | |
129 | + var rdata GettaskrewardReq | |
130 | + err := json.Unmarshal([]byte(s), &rdata) | |
131 | + | |
132 | + if err != nil { | |
133 | + logger.Info("json decode Testapi data failed:%v,for:%v", err, s) | |
134 | + fmt.Fprint(w, "failed") | |
135 | + return | |
136 | + } | |
137 | + | |
138 | + uinfo, err := GetUserInfo(Uuid) | |
139 | + if err != nil || uinfo == nil { | |
140 | + logger.Error("redis failed err=%v", err) | |
141 | + fmt.Fprint(w, "failed") | |
142 | + return | |
143 | + } | |
144 | + | |
145 | +} | |
146 | + | |
61 | 147 | func Getnewlevelreward(w http.ResponseWriter, r *http.Request) { |
62 | 148 | |
63 | 149 | Uuid := 0 |
... | ... | @@ -79,7 +165,6 @@ func Getnewlevelreward(w http.ResponseWriter, r *http.Request) { |
79 | 165 | HandlerGetnewlevelreward(w, s, Uuid) |
80 | 166 | } |
81 | 167 | |
82 | - | |
83 | 168 | func Gettaskreward(w http.ResponseWriter, r *http.Request) { |
84 | 169 | |
85 | 170 | Uuid := 0 |
... | ... | @@ -122,7 +207,6 @@ func Querytaskinfo(w http.ResponseWriter, r *http.Request) { |
122 | 207 | HandlerQuerytaskinfo(w, s, Uuid) |
123 | 208 | } |
124 | 209 | |
125 | - | |
126 | 210 | func Updatetaskandachieve(w http.ResponseWriter, r *http.Request) { |
127 | 211 | |
128 | 212 | Uuid := 0 |
... | ... | @@ -144,7 +228,6 @@ func Updatetaskandachieve(w http.ResponseWriter, r *http.Request) { |
144 | 228 | HandlerUpdatetaskandachieve(w, s, Uuid) |
145 | 229 | } |
146 | 230 | |
147 | - | |
148 | 231 | func Onlinentf(w http.ResponseWriter, r *http.Request) { |
149 | 232 | |
150 | 233 | Uuid := 0 |
... | ... | @@ -187,7 +270,6 @@ func Getcashrecord(w http.ResponseWriter, r *http.Request) { |
187 | 270 | HandlerGetcashrecord(w, s, Uuid) |
188 | 271 | } |
189 | 272 | |
190 | - | |
191 | 273 | func Getcash(w http.ResponseWriter, r *http.Request) { |
192 | 274 | |
193 | 275 | Uuid := 0 |
... | ... | @@ -209,7 +291,6 @@ func Getcash(w http.ResponseWriter, r *http.Request) { |
209 | 291 | HandlerGetcash(w, s, Uuid) |
210 | 292 | } |
211 | 293 | |
212 | - | |
213 | 294 | func Querdrawinfo(w http.ResponseWriter, r *http.Request) { |
214 | 295 | |
215 | 296 | Uuid := 0 |
... | ... | @@ -252,9 +333,6 @@ func Drawguangold(w http.ResponseWriter, r *http.Request) { |
252 | 333 | HandlerDrawguangold(w, s, Uuid) |
253 | 334 | } |
254 | 335 | |
255 | - | |
256 | - | |
257 | - | |
258 | 336 | func Getguangold(w http.ResponseWriter, r *http.Request) { |
259 | 337 | |
260 | 338 | Uuid := 0 |
... | ... | @@ -297,7 +375,6 @@ func Queryguaninfo(w http.ResponseWriter, r *http.Request) { |
297 | 375 | HandlerQueryguaninfo(w, s, Uuid) |
298 | 376 | } |
299 | 377 | |
300 | - | |
301 | 378 | func Watchads(w http.ResponseWriter, r *http.Request) { |
302 | 379 | |
303 | 380 | Uuid := 0 |
... | ... | @@ -360,6 +437,3 @@ func Getuserdata(w http.ResponseWriter, r *http.Request) { |
360 | 437 | |
361 | 438 | HandlerGetuserdata(w, s, Uuid) |
362 | 439 | } |
363 | - | |
364 | - | |
365 | - | ... | ... |
src/HttpServer/logic/logic.go
... | ... | @@ -197,6 +197,33 @@ func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { |
197 | 197 | |
198 | 198 | } |
199 | 199 | |
200 | +func HandlerQuerysigndata(w http.ResponseWriter, data string, uuid int) { | |
201 | + SetHeader(w) | |
202 | + var resp QuerysigndataResp | |
203 | + resp.Code = 0 | |
204 | + | |
205 | + for { | |
206 | + | |
207 | + uinfo, err := GetUserInfo(uuid) | |
208 | + if err != nil || uinfo == nil { | |
209 | + logger.Error("redis failed err=%v", err) | |
210 | + resp.Message = "服务器错误" | |
211 | + resp.Code = ERROR_SRV_ERROR | |
212 | + break | |
213 | + } | |
214 | + | |
215 | + resp.Data.Continuessign = uinfo.SignSum | |
216 | + resp.Data.IssignToday = uinfo.IsSignToday | |
217 | + resp.Data.Signround = uinfo.SignRound | |
218 | + | |
219 | + resp.Code = ERROR_OK | |
220 | + break | |
221 | + } | |
222 | + | |
223 | + respstr, _ := json.Marshal(&resp) | |
224 | + fmt.Fprint(w, string(respstr)) | |
225 | +} | |
226 | + | |
200 | 227 | func HandlerGetnewlevelreward(w http.ResponseWriter, data string, uuid int) { |
201 | 228 | SetHeader(w) |
202 | 229 | var resp GetnewlevelrewardResp |
... | ... | @@ -269,6 +296,80 @@ func HandlerGetnewlevelreward(w http.ResponseWriter, data string, uuid int) { |
269 | 296 | |
270 | 297 | } |
271 | 298 | |
299 | +func HandlerUsersign(w http.ResponseWriter, data string, uuid int) { | |
300 | + SetHeader(w) | |
301 | + var resp UsersignResp | |
302 | + resp.Code = 0 | |
303 | + var rdata UsersignReq | |
304 | + err := json.Unmarshal([]byte(data), &rdata) | |
305 | + for { | |
306 | + if err != nil { | |
307 | + logger.Info("json decode HandlerUsersign data failed:%v,for:%v", err, data) | |
308 | + resp.Message = "网络错误" | |
309 | + resp.Code = ERROR_JSONUNMASH_ERROR | |
310 | + break | |
311 | + } | |
312 | + uinfo, err := GetUserInfo(uuid) | |
313 | + if err != nil || uinfo == nil { | |
314 | + logger.Error("redis failed err=%v", err) | |
315 | + resp.Message = "服务器错误" | |
316 | + resp.Code = ERROR_SRV_ERROR | |
317 | + break | |
318 | + } | |
319 | + | |
320 | + if uinfo.IsSignToday == 1 { | |
321 | + logger.Error("IsSignToday failed err=%v", err) | |
322 | + resp.Message = "今日已经签过到啦" | |
323 | + resp.Code = ERROR_SINGALREADYTODAY | |
324 | + break | |
325 | + } | |
326 | + | |
327 | + uinfo.SignSum++ | |
328 | + if uinfo.SignSum > 7 { | |
329 | + uinfo.SignSum = 7 | |
330 | + logger.Error("uinfo.SignSum failed") | |
331 | + resp.Message = "签到数据异常" | |
332 | + resp.Code = ERROR_SINGDATAFAILED | |
333 | + break | |
334 | + } | |
335 | + | |
336 | + //获取配置 | |
337 | + cfg := jsonconf.GetSignConfig(uinfo.SignRound, uinfo.SignSum) | |
338 | + if cfg == nil { | |
339 | + uinfo.SignSum-- | |
340 | + logger.Error("GetSignConfig failed err=%v", err) | |
341 | + resp.Message = "服务器错误" | |
342 | + resp.Code = ERROR_SRV_ERROR | |
343 | + break | |
344 | + } | |
345 | + | |
346 | + _, err = AddCoinToSdk(uuid, cfg.Num, rdata.Gameid, rdata.Channel, 100) | |
347 | + if err != nil { | |
348 | + uinfo.SignSum-- | |
349 | + logger.Error("AddCoinToSdk failed err=%v", err) | |
350 | + resp.Message = "服务器错误" | |
351 | + resp.Code = ERROR_SRV_ERROR | |
352 | + break | |
353 | + } | |
354 | + | |
355 | + uinfo.IsSignToday = 1 | |
356 | + uinfo.RealGold += cfg.Num | |
357 | + | |
358 | + resp.Data.Goldnum = uinfo.RealGold | |
359 | + | |
360 | + //保存数据 | |
361 | + err = SaveUserInfo(uinfo) | |
362 | + | |
363 | + resp.Code = ERROR_OK | |
364 | + break | |
365 | + } | |
366 | + | |
367 | + //回包 | |
368 | + respstr, _ := json.Marshal(&resp) | |
369 | + fmt.Fprint(w, string(respstr)) | |
370 | + | |
371 | +} | |
372 | + | |
272 | 373 | func HandlerGettaskreward(w http.ResponseWriter, data string, uuid int) { |
273 | 374 | SetHeader(w) |
274 | 375 | var resp GettaskrewardResp | ... | ... |