Commit a31d3583570d20201b5eef7fc45ca422b714d0aa

Authored by 陆恒
1 parent 87e4d89f
Exists in master

提交相关接口

src/HttpServer/jsonconf/TaskConfig.json
... ... @@ -3,6 +3,7 @@
3 3 "id": 1,
4 4 "type": 1,
5 5 "day_type": 1,
  6 + "aims": 5,
6 7 "active": 5,
7 8 "coin": 10,
8 9 "desc": "在线5min"
... ... @@ -11,6 +12,7 @@
11 12 "id": 2,
12 13 "type": 1,
13 14 "day_type": 1,
  15 + "aims": 30,
14 16 "active": 10,
15 17 "coin": 40,
16 18 "desc": "在线30mins"
... ... @@ -19,6 +21,7 @@
19 21 "id": 3,
20 22 "type": 1,
21 23 "day_type": 2,
  24 + "aims": 5,
22 25 "active": 5,
23 26 "coin": 30,
24 27 "desc": "游戏中消耗5次体力"
... ... @@ -27,6 +30,7 @@
27 30 "id": 4,
28 31 "type": 1,
29 32 "day_type": 3,
  33 + "aims": 1,
30 34 "active": 10,
31 35 "coin": 30,
32 36 "desc": "单局成绩超过2000分"
... ... @@ -35,6 +39,7 @@
35 39 "id": 5,
36 40 "type": 1,
37 41 "day_type": 4,
  42 + "aims": 5,
38 43 "active": 20,
39 44 "coin": 50,
40 45 "desc": "观看满5次视频"
... ... @@ -43,6 +48,7 @@
43 48 "id": 6,
44 49 "type": 1,
45 50 "day_type": 5,
  51 + "aims": 5,
46 52 "active": 20,
47 53 "coin": 40,
48 54 "desc": "进行转盘抽奖5次"
... ... @@ -51,6 +57,7 @@
51 57 "id": 7,
52 58 "type": 1,
53 59 "day_type": 6,
  60 + "aims": 3,
54 61 "active": 30,
55 62 "coin": 60,
56 63 "desc": "开福袋3次"
... ... @@ -59,6 +66,7 @@
59 66 "id": 8,
60 67 "type": 1,
61 68 "day_type": 7,
  69 + "aims": 1,
62 70 "active": 15,
63 71 "coin": 30,
64 72 "desc": "放飞火箭1次"
... ... @@ -67,6 +75,7 @@
67 75 "id": 9,
68 76 "type": 1,
69 77 "day_type": 8,
  78 + "aims": 2,
70 79 "active": 20,
71 80 "coin": 50,
72 81 "desc": "游戏内重生2次"
... ... @@ -75,6 +84,7 @@
75 84 "id": 10,
76 85 "type": 1,
77 86 "day_type": 9,
  87 + "aims": 5,
78 88 "active": 15,
79 89 "coin": 50,
80 90 "desc": "游戏中使用5次道具"
... ... @@ -83,6 +93,7 @@
83 93 "id": 11,
84 94 "type": 2,
85 95 "day_type": 0.0,
  96 + "aims": 0.0,
86 97 "active": 30,
87 98 "coin": 150,
88 99 "desc": ""
... ... @@ -91,6 +102,7 @@
91 102 "id": 12,
92 103 "type": 2,
93 104 "day_type": 0.0,
  105 + "aims": 0.0,
94 106 "active": 80,
95 107 "coin": 400,
96 108 "desc": ""
... ... @@ -99,6 +111,7 @@
99 111 "id": 13,
100 112 "type": 2,
101 113 "day_type": 0.0,
  114 + "aims": 0.0,
102 115 "active": 150,
103 116 "coin": 600,
104 117 "desc": ""
... ...
src/HttpServer/jsonconf/jsonconf.go
... ... @@ -24,6 +24,7 @@ type TaskDesc struct {
24 24 Id int `json:"id"`
25 25 Type int `json:"type"`
26 26 Day_type int `json:"day_type"`
  27 + Aims int `json:"aims"`
27 28 Active int `json:"active"`
28 29 Coin int `json:"coin"`
29 30 Desc string `json:"desc"`
... ...
src/HttpServer/logic/constdef.go
... ... @@ -2,34 +2,36 @@ package logic
2 2  
3 3 //任务成就类型枚举 协议上报用
4 4 const (
5   - TASKTYPE_PASSLEVEL = 1 //表示通过x关卡
6   - TASKTYPE_GETREDBAG = 2 //3表示观看x次广告
7   - TASKTYPE_WATCHADS = 3 //领取x次红包
8   - TASKTYPE_KILLSTAR = 4 //4表示消除x颗星星
9   - TASKTYPE_USEITEM = 5 //5表示使用x次道具
10   - TASKTYPE_PLAYSMALLGAMES = 6 //6表示试玩15s小游戏
11   -
  5 + TASKTYPE_COSTTILI = 1 //消耗体力
  6 + TASKTYPE_REACH2000 = 2 //表示单句达到2000
  7 + TASKTYPE_WATCHADS = 3 //表示观看视频次数
  8 + TASKTYPE_TURNTABLE = 4 //4抽奖次数
  9 + TASKTYPE_LUCKYBAG = 5 //5表示福袋次数
  10 + TASKTYPE_ROCKETTIMES = 6 //6表示火箭次数
  11 + TASKTYPE_RELIVECNT = 7 //表示重生
  12 + TASKTYPE_USEITEMTIMES = 8 //8表示使用道具次数
  13 + ACHIEVE_KILLLINE = 9 //表示消除行数
12 14 )
13 15  
14 16 //任务类型 对应表
15 17 const (
16   - DAILY_TASKTYPE_LOGIN = 1 //1 每日登录
17   - DAILY_TASKTYPE_GETGUANCNT = 2 //提取存钱罐
18   - DAILY_TASKTYPE_PASSLEVEL = 3 //近日通过关
19   - DAILY_TASKTYPE_USEITEM = 4 //使用道具数
20   - DAILY_TASKTYPE_GETREDBAG = 5 //领取红包次数
21   - DAILY_TASKTYPE_GETGUANGOLD = 6 //收取金币x枚
22   - DAILY_TASKTYPE_ONLINEMIN = 7 //在线分钟数
23   - DAILY_TASKTYPE_PLAYSMALLGAME = 8 //试玩小游戏15s
  18 + DAILY_TASKTYPE_ONLINEMIN = 1 //在线分钟数
  19 + DAILY_TASKTYPE_COSTTILI = 2 //使用体力
  20 + DAILY_TASKTYPE_REACH2000 = 3 //单局达到2000
  21 + DAILY_TASKTYPE_WATCHAD = 4 //观看视频次数
  22 + DAILY_TASKTYPE_DRAMTURN = 5 //抽奖次数
  23 + DAILY_TASKTYPE_GETLUCKYBAG = 6 //开福袋次数
  24 + DAILY_TASKTYPE_USEROCKET = 7 //开火箭次数
  25 + DAILY_TASKTYPE_RELIVE = 8 //重生次数
  26 + DAILY_TASKTYPE_USEITEME = 9 //使用道具次数
24 27 )
25 28  
26 29 //成就类型 对应表
27 30 const (
28   - ACHIEVETYPE_WATCHADDS = 1 //累计观看广告次数
29   - ACHIEVETYPE_USERLV = 2 //人物等级
30   - ACHIEVETYPE_KILLSTAR = 3 //累计消除星星数
31   - ACHIEVETYPE_GETGUANCNT = 4 //累计存钱罐提取
32   - ACHIEVETYPE_USEITEMCNT = 5 //累计道具使用
  31 + ACHIEVETYPE_GETSCORE = 1 //累计达到分数
  32 + ACHIEVETYPE_LOGINDAY = 2 //累计登录天数
  33 + ACHIEVETYPE_WATCHADDS = 3 //累计观看广告次数
  34 + ACHIEVETYPE_KILLLINE = 4 //累计消除行数
33 35  
34 36 )
35 37  
... ...
src/HttpServer/logic/datadef.go
... ... @@ -312,10 +312,8 @@ type OnlinentfResp struct {
312 312 }
313 313  
314 314 type UpdatetaskReq struct {
315   - Tasktype int `json:"tasktype"`
316   - Value int `json:"value"`
317   - Gameid string `json:"gameid"`
318   - Channel string `json:"channel"`
  315 + Tasktype int `json:"tasktype"`
  316 + Value int `json:"value"`
319 317 }
320 318  
321 319 type UpdatetaskResp struct {
... ... @@ -324,9 +322,7 @@ type UpdatetaskResp struct {
324 322 }
325 323  
326 324 type QuerytaskinfoReq struct {
327   - Tasktype int `json:"tasktype"`
328   - Gameid string `json:"gameid"`
329   - Channel string `json:"channel"`
  325 + Tasktype int `json:"tasktype"`
330 326 }
331 327  
332 328 type QuerytaskinfoResp struct {
... ... @@ -336,21 +332,13 @@ type QuerytaskinfoResp struct {
336 332 }
337 333  
338 334 type GettaskrewardReq struct {
339   - Tasktype int `json:"tasktype"`
340   - Taskid int `json:"taskid"`
341   - Gameid string `json:"gameid"`
342   - Channel string `json:"channel"`
  335 + Tasktype int `json:"tasktype"`
  336 + Taskid int `json:"taskid"`
343 337 }
344 338  
345 339 type GettaskrewardData struct {
346   - Lv int `json:"lv"`
347   - Costtime int `json:"costtime"`
348   - Rewardstar int `json:"rewardstar"`
349   - Chuiitem int `json:"chuiitem"`
350   - Shuaitem int `json:"shuaitem"`
351   - Swapitem int `json:"swapitem"`
352   - Eliminitem int `json:"eliminitem"`
353 340 Goldnum int `json:"goldnum"`
  341 + Walletgold int `json:"walletgold"`
354 342 }
355 343 type GettaskrewardResp struct {
356 344 Code int `json:"code"`
... ... @@ -443,24 +431,29 @@ type TaskListDesc struct {
443 431  
444 432 type TaskList struct {
445 433 Taskdata []TaskListDesc `json:"taskdata"`
  434 + Huoyue int `json:"huoyue"`
446 435 }
447 436  
448 437 //其中提取次数和当日登陆在userdata中记录
449 438 type TaskInfo struct {
450   - OnlineMin int //在线分钟数
451   - PassLevel int //通过关卡数
452   - UseItemCnt int //使用道具次数
453   - GetRedbagCnt int //领取红包次数
454   - GetGuanGold int //收集金币数
455   - PlaySmall int //当日是否试玩小游戏15s 次数
  439 + OnlineMin int //在线分钟数
  440 + CostTili int //在游戏内消耗体力
  441 + OutScore int //单局超过2000分次数
  442 + WatchAdCnt int //观看视频次数
  443 + DrawTurnTableCnt int //转盘抽奖次数
  444 + OpenLuckBagCnt int //开福袋次数
  445 + UseRocketCnt int //开火箭次数
  446 + RelivegCnt int //重生次数
  447 + UseItemCnt int //使用道具次数
  448 + HuoYue int //当天活跃值
456 449 }
457 450  
458 451 //
459 452 type AchieveMentInfo struct {
460   - WatchAdsCnt int //观看广告数
461   - KillStar int //消除星星数
462   - SumGetGuan int //存钱罐累计提取
463   - SumUseItemCnt int //使用道具次数累计
  453 + WatchAdsCnt int //观看视频数
  454 + KillStar int //消除行数
  455 + //SumGetGuan int //存钱罐累计提取
  456 + //SumUseItemCnt int //使用道具次数累计
464 457 }
465 458  
466 459 type WithDrawList struct {
... ...
src/HttpServer/logic/function.go
... ... @@ -25,6 +25,302 @@ func SetHeader(w http.ResponseWriter) {
25 25 w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Uuid,Gameid,Channel")
26 26 }
27 27  
  28 +func (v *TaskList) Len() int {
  29 + return len(v.Taskdata)
  30 +}
  31 +
  32 +func (v *TaskList) Swap(i, j int) {
  33 + v.Taskdata[i], v.Taskdata[j] = v.Taskdata[j], v.Taskdata[i]
  34 +}
  35 +
  36 +func (v *TaskList) Less(i, j int) bool {
  37 + if v.Taskdata[i].Taskstatus == v.Taskdata[j].Taskstatus {
  38 + return v.Taskdata[i].Taskid < v.Taskdata[j].Taskid
  39 + }
  40 + return v.Taskdata[i].Taskstatus > v.Taskdata[j].Taskstatus
  41 +}
  42 +
  43 +func GetTaskConfig(taskid int) *jsonconf.TaskDesc {
  44 + for _, val := range jsonconf.GetJsonConf().TaskConfig {
  45 + if val.Id == taskid {
  46 + return &val
  47 + }
  48 + }
  49 + return nil
  50 +}
  51 +
  52 +func GetAchieveConfig(taskid int) *jsonconf.AchieveDesc {
  53 + for _, val := range jsonconf.GetJsonConf().AchieventConfig {
  54 + if val.Id == taskid {
  55 + return &val
  56 + }
  57 + }
  58 + return nil
  59 +}
  60 +
  61 +func (uinfo *UserData) CalcAchieveProgress(ttype int) int {
  62 + rtval := 0
  63 + switch ttype {
  64 + case ACHIEVETYPE_GETSCORE:
  65 + rtval = int(uinfo.HighScore)
  66 + case ACHIEVETYPE_LOGINDAY:
  67 + rtval = uinfo.SumLoginDay
  68 + case ACHIEVETYPE_WATCHADDS:
  69 + rtval = uinfo.Achieve.WatchAdsCnt
  70 + case ACHIEVETYPE_KILLLINE:
  71 + rtval = uinfo.Achieve.KillStar
  72 + default:
  73 + logger.Error("CalcAchieveProgress type wrong ttype=%v", ttype)
  74 + }
  75 +
  76 + return rtval
  77 +}
  78 +
  79 +func (uinfo *UserData) CalcAchieveList(list *TaskList, uniqueid string) *TaskList {
  80 + newlist := new(TaskList)
  81 + curtype := -1 //记录当前类型
  82 +
  83 + //第一遍首先将所有进度设置为正确的状态
  84 + for k, val := range list.Taskdata {
  85 + cfg := GetAchieveConfig(val.Taskid)
  86 + if cfg == nil {
  87 + logger.Error("CalcAchieveList GetTaskConfig failed id=%v", val.Taskid)
  88 + continue
  89 + }
  90 +
  91 + list.Taskdata[k].Taskprogress = uinfo.CalcAchieveProgress(cfg.Type)
  92 + if val.Taskstatus == 1 {
  93 + switch cfg.Type {
  94 + case ACHIEVETYPE_GETSCORE:
  95 + if uinfo.HighScore >= int64(cfg.Aim) {
  96 + list.Taskdata[k].Taskstatus = 2
  97 + }
  98 + case ACHIEVETYPE_LOGINDAY:
  99 + if uinfo.SumLoginDay >= cfg.Aim {
  100 + list.Taskdata[k].Taskstatus = 2
  101 + }
  102 + case ACHIEVETYPE_KILLLINE:
  103 + if uinfo.Achieve.KillStar >= cfg.Aim {
  104 + list.Taskdata[k].Taskstatus = 2
  105 + }
  106 + case ACHIEVETYPE_WATCHADDS:
  107 + if uinfo.Achieve.WatchAdsCnt >= cfg.Aim {
  108 + list.Taskdata[k].Taskstatus = 2
  109 + }
  110 +
  111 + default:
  112 + logger.Error("CalcAchieveProgress type wrong ttype=%v", cfg.Type)
  113 + }
  114 + }
  115 +
  116 + }
  117 +
  118 + for k, val := range list.Taskdata {
  119 +
  120 + cfg := GetAchieveConfig(val.Taskid)
  121 + if cfg == nil {
  122 + logger.Error("CalcAchieveList GetTaskConfig failed id=%v", val.Taskid)
  123 + continue
  124 + }
  125 +
  126 + if val.Taskstatus == 2 {
  127 + //未领取已完成 只需要加入第一种
  128 + if curtype == cfg.Type {
  129 + continue
  130 + } else {
  131 + //将类型加入返回列表
  132 + newlist.Taskdata = append(newlist.Taskdata, list.Taskdata[k])
  133 + curtype = cfg.Type
  134 + }
  135 + } else if val.Taskstatus == 1 {
  136 + //未完成 返回第一个
  137 + if curtype == cfg.Type {
  138 + continue
  139 + } else {
  140 + //将类型加入返回列表
  141 + newlist.Taskdata = append(newlist.Taskdata, list.Taskdata[k])
  142 + curtype = cfg.Type
  143 + }
  144 + } else {
  145 + //已领取 需要判断一下是否最后一项
  146 + if k != len(list.Taskdata)-1 {
  147 + //不是最后一条数据
  148 + nextcfg := GetAchieveConfig(list.Taskdata[k+1].Taskid)
  149 + if nextcfg != nil {
  150 + if nextcfg.Type != cfg.Type {
  151 + //下面一天不是此类型了
  152 + newlist.Taskdata = append(newlist.Taskdata, list.Taskdata[k])
  153 + curtype = cfg.Type
  154 + }
  155 + }
  156 +
  157 + } else {
  158 + //最后一条 加入
  159 + newlist.Taskdata = append(newlist.Taskdata, list.Taskdata[k])
  160 + curtype = cfg.Type
  161 + }
  162 + }
  163 +
  164 + }
  165 +
  166 + //保存旧的列表
  167 + SaveTaskInfo(uniqueid, 2, list)
  168 +
  169 + //将返回的列表排序
  170 + sort.Sort(newlist)
  171 + logger.Info("CalcAchieveList alist=%v", newlist)
  172 + return newlist
  173 +}
  174 +
  175 +//处理领取任务
  176 +func (uinfo *UserData) HandleGetTaskReward(req *GettaskrewardReq, resp *GettaskrewardResp, list *TaskList, uuid int, gameid, channel string) error {
  177 + isfind := false
  178 + index := -1
  179 + var taskdesc *TaskListDesc
  180 + for k, val := range list.Taskdata {
  181 + if val.Taskid == req.Taskid {
  182 + isfind = true
  183 + index = k
  184 + taskdesc = &val
  185 + break
  186 + }
  187 + }
  188 +
  189 + logger.Info("HandleGetTaskReward index=%v taskdesc=%v", index, taskdesc)
  190 + if isfind && taskdesc != nil && index != -1 {
  191 + if taskdesc.Taskstatus != 2 {
  192 + //状态不是可领取状态 无法领取
  193 + resp.Code = ERROR_TASKCANNOTGET
  194 + resp.Message = "当前任务未完成或已领取"
  195 + return errors.New("当前任务未完成或已领取")
  196 + }
  197 +
  198 + //状态对的情况 如果是成就下需要判断前置条件是否被
  199 + if req.Tasktype == 2 && index > 0 {
  200 + precfg := GetAchieveConfig(list.Taskdata[index-1].Taskid)
  201 + nowcfg := GetAchieveConfig(taskdesc.Taskid)
  202 + logger.Info("HandleGetTaskRewardGetTaskConfig precfg=%v nowcfg=%v", precfg, nowcfg)
  203 + if precfg != nil && nowcfg != nil && precfg.Type == nowcfg.Type && list.Taskdata[index-1].Taskstatus != 0 {
  204 + resp.Code = ERROR_TASKPRE_NOTGET
  205 + resp.Message = "前置任务还未领取"
  206 + return errors.New("当前任务未完成或已领取")
  207 + }
  208 + }
  209 + } else {
  210 + resp.Code = ERROR_TASKID_WRONG
  211 + resp.Message = "当前任务id错误"
  212 + return errors.New("当前任务id错误")
  213 + }
  214 +
  215 + var cfg *jsonconf.AchieveDesc
  216 + var cfg1 *jsonconf.TaskDesc
  217 +
  218 + addgold := 0
  219 + if req.Tasktype == 2 {
  220 + cfg = GetAchieveConfig(taskdesc.Taskid)
  221 + if cfg == nil {
  222 + resp.Code = ERROR_SRV_ERROR
  223 + resp.Message = "网络错误"
  224 + return errors.New("获取配置失败")
  225 + }
  226 + addgold = cfg.Coin
  227 + } else {
  228 + cfg1 = GetTaskConfig(taskdesc.Taskid)
  229 + if cfg1 == nil {
  230 + resp.Code = ERROR_SRV_ERROR
  231 + resp.Message = "网络错误"
  232 + return errors.New("获取配置失败")
  233 + }
  234 + addgold = cfg1.Coin
  235 + }
  236 +
  237 + //将状态置位已领取
  238 + list.Taskdata[index].Taskstatus = 0
  239 + //发奖励
  240 + realgold, err := AddCoinToSdk(uuid, addgold, gameid, channel, REDBAGTYPE_102)
  241 + if err != nil {
  242 + logger.Info("GetUserInfo HandlerDrawguangold data failed:%v,for:%v", err)
  243 + resp.Message = "后台提现失败"
  244 + resp.Code = 1
  245 + return errors.New("后台提现失败")
  246 + }
  247 +
  248 + uinfo.RealGold = realgold
  249 + resp.Data.Goldnum = addgold
  250 + resp.Data.Walletgold = uinfo.RealGold
  251 +
  252 + return nil
  253 +}
  254 +
  255 +func (uinfo *UserData) CalcTaskList(list *TaskList, uniqueid string) {
  256 +
  257 + for k, val := range list.Taskdata {
  258 + //未完成的才做判断
  259 + if val.Taskstatus != 1 {
  260 + continue
  261 + }
  262 + cfg := GetTaskConfig(val.Taskid)
  263 + if cfg == nil {
  264 + logger.Error("CalcTaskList GetTaskConfig failed id=%v", val.Taskid)
  265 + continue
  266 + }
  267 +
  268 + if cfg.Day_type == DAILY_TASKTYPE_ONLINEMIN {
  269 + list.Taskdata[k].Taskprogress = uinfo.Task.OnlineMin
  270 + if uinfo.Task.OnlineMin >= cfg.Aims {
  271 + list.Taskdata[k].Taskstatus = 2
  272 + }
  273 + } else if cfg.Day_type == DAILY_TASKTYPE_COSTTILI {
  274 + list.Taskdata[k].Taskprogress = uinfo.Task.CostTili
  275 + if uinfo.Task.CostTili >= cfg.Aims {
  276 + list.Taskdata[k].Taskstatus = 2
  277 + }
  278 + } else if cfg.Day_type == DAILY_TASKTYPE_REACH2000 {
  279 + list.Taskdata[k].Taskprogress = uinfo.Task.OutScore
  280 + if uinfo.Task.OutScore >= cfg.Aims {
  281 + list.Taskdata[k].Taskstatus = 2
  282 + }
  283 + } else if cfg.Day_type == DAILY_TASKTYPE_WATCHAD {
  284 + list.Taskdata[k].Taskprogress = uinfo.Task.WatchAdCnt
  285 + if uinfo.Task.WatchAdCnt >= cfg.Aims {
  286 + list.Taskdata[k].Taskstatus = 2
  287 + }
  288 + } else if cfg.Day_type == DAILY_TASKTYPE_DRAMTURN {
  289 + list.Taskdata[k].Taskprogress = uinfo.Task.DrawTurnTableCnt
  290 + if uinfo.Task.DrawTurnTableCnt >= cfg.Aims {
  291 + list.Taskdata[k].Taskstatus = 2
  292 + }
  293 + } else if cfg.Day_type == DAILY_TASKTYPE_GETLUCKYBAG {
  294 + list.Taskdata[k].Taskprogress = uinfo.Task.OpenLuckBagCnt
  295 + if uinfo.Task.OpenLuckBagCnt >= cfg.Aims {
  296 + list.Taskdata[k].Taskstatus = 2
  297 + }
  298 + } else if cfg.Day_type == DAILY_TASKTYPE_USEROCKET {
  299 + list.Taskdata[k].Taskprogress = uinfo.Task.UseRocketCnt
  300 + if uinfo.Task.UseRocketCnt >= cfg.Aims {
  301 + list.Taskdata[k].Taskstatus = 2
  302 + }
  303 + } else if cfg.Day_type == DAILY_TASKTYPE_RELIVE {
  304 + list.Taskdata[k].Taskprogress = uinfo.Task.RelivegCnt
  305 + if uinfo.Task.RelivegCnt > cfg.Aims {
  306 + list.Taskdata[k].Taskstatus = 2
  307 + }
  308 + } else if cfg.Day_type == DAILY_TASKTYPE_USEITEME {
  309 + list.Taskdata[k].Taskprogress = uinfo.Task.UseItemCnt
  310 + if uinfo.Task.UseItemCnt > cfg.Aims {
  311 + list.Taskdata[k].Taskstatus = 2
  312 + }
  313 + }
  314 +
  315 + }
  316 +
  317 + //需要保存到redis
  318 + SaveTaskInfo(uniqueid, 1, list)
  319 +
  320 + //排序
  321 + sort.Sort(list)
  322 +}
  323 +
28 324 func (u *UserData) IsRedIdInList(id int) bool {
29 325 for _, v := range u.RedBagFetchIdlist {
30 326 if v == id {
... ... @@ -74,12 +370,17 @@ func (u *UserData) HandlePassDay(uuid int, channel string) {
74 370 u.GetFromGuanCnt = 0
75 371 u.GetCashCnt = 0
76 372  
77   - u.Task.GetGuanGold = 0
78   - u.Task.GetRedbagCnt = 0
79   - u.Task.OnlineMin = 0
80   - u.Task.PassLevel = 0
81 373 u.Task.UseItemCnt = 0
82   - u.Task.PlaySmall = 0
  374 + u.Task.CostTili = 0
  375 + u.Task.OnlineMin = 0
  376 + u.Task.DrawTurnTableCnt = 0
  377 + u.Task.HuoYue = 0
  378 + u.Task.OpenLuckBagCnt = 0
  379 + u.Task.OutScore = 0
  380 + u.Task.UseRocketCnt = 0
  381 + u.Task.RelivegCnt = 0
  382 + u.Task.WatchAdCnt = 0
  383 +
83 384 u.RedBagFetchIdlist = u.RedBagFetchIdlist[:0]
84 385 u.LuckyBagLeftTimes = LUCKYBAGDAYLIMIT
85 386 u.FreeTicket = FREETICKETCOUNT
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -45,23 +45,27 @@ func startServerHttpServe() {
45 45 http.HandleFunc("/eliminatestar/addcoin", Addcoin) //测试接口
46 46 http.HandleFunc("/eliminatestar/clear", ClearData) //清除账号
47 47 //----------------------------------------------------------------------------------------
48   - http.HandleFunc("/russiaxiaoxiao/login", UserLogin) //登录
49   - http.HandleFunc("/russiaxiaoxiao/uploaduserbasicinfo", Uploaduserbasicinfo) //上传基本信息
50   - http.HandleFunc("/russiaxiaoxiao/updatedata", Updatedata) //update数据
51   - http.HandleFunc("/russiaxiaoxiao/syncuserdata", Syncuserdata) //同步玩家数据
52   - http.HandleFunc("/russiaxiaoxiao/getguangold", Getguangold) //获取金币存入存钱罐
53   - http.HandleFunc("/russiaxiaoxiao/drawguangold", Drawguangold) //提取存钱罐金币
54   - http.HandleFunc("/russiaxiaoxiao/fetchfenredbag", Fetchfenredbag) //请求领取每日消除红包
55   - http.HandleFunc("/russiaxiaoxiao/fetchluckybag", Fetchluckybag) //请求领取每日福袋
56   - http.HandleFunc("/russiaxiaoxiao/quersigndata", Quersigndata) //获取签到数据
57   - http.HandleFunc("/russiaxiaoxiao/dosign", Dosign) //签到
58   - http.HandleFunc("/russiaxiaoxiao/fetchoffliengold", Fetchoffliengold) //请求领取离线金币
59   - http.HandleFunc("/russiaxiaoxiao/uploadhigestscore", Uploadhigestscore) //上报玩家历史最高分
60   - http.HandleFunc("/russiaxiaoxiao/queryrankinfo", Queryrankinfo) //查询排行榜
61   - http.HandleFunc("/russiaxiaoxiao/querydrawreward", Querydrawreward) //请求抽奖
62   - http.HandleFunc("/russiaxiaoxiao/querygetcashinfo", Querdrawinfo) //请求提现档位数据
63   - http.HandleFunc("/russiaxiaoxiao/getcash", Getcash) //请求提现
64   - http.HandleFunc("/russiaxiaoxiao/getcashrecord", Getcashrecord) //请求提现记录
  48 + http.HandleFunc("/russiaxiaoxiao/login", UserLogin) //登录
  49 + http.HandleFunc("/russiaxiaoxiao/uploaduserbasicinfo", Uploaduserbasicinfo) //上传基本信息
  50 + http.HandleFunc("/russiaxiaoxiao/updatedata", Updatedata) //update数据
  51 + http.HandleFunc("/russiaxiaoxiao/syncuserdata", Syncuserdata) //同步玩家数据
  52 + http.HandleFunc("/russiaxiaoxiao/getguangold", Getguangold) //获取金币存入存钱罐
  53 + http.HandleFunc("/russiaxiaoxiao/drawguangold", Drawguangold) //提取存钱罐金币
  54 + http.HandleFunc("/russiaxiaoxiao/fetchfenredbag", Fetchfenredbag) //请求领取每日消除红包
  55 + http.HandleFunc("/russiaxiaoxiao/fetchluckybag", Fetchluckybag) //请求领取每日福袋
  56 + http.HandleFunc("/russiaxiaoxiao/quersigndata", Quersigndata) //获取签到数据
  57 + http.HandleFunc("/russiaxiaoxiao/dosign", Dosign) //签到
  58 + http.HandleFunc("/russiaxiaoxiao/fetchoffliengold", Fetchoffliengold) //请求领取离线金币
  59 + http.HandleFunc("/russiaxiaoxiao/uploadhigestscore", Uploadhigestscore) //上报玩家历史最高分
  60 + http.HandleFunc("/russiaxiaoxiao/queryrankinfo", Queryrankinfo) //查询排行榜
  61 + http.HandleFunc("/russiaxiaoxiao/querydrawreward", Querydrawreward) //请求抽奖
  62 + http.HandleFunc("/russiaxiaoxiao/querygetcashinfo", Querdrawinfo) //请求提现档位数据
  63 + http.HandleFunc("/russiaxiaoxiao/getcash", Getcash) //请求提现
  64 + http.HandleFunc("/russiaxiaoxiao/getcashrecord", Getcashrecord) //请求提现记录
  65 + http.HandleFunc("/russiaxiaoxiao/onlinentf", Onlinentf) //在线通知 一分钟一次
  66 + http.HandleFunc("/russiaxiaoxiao/updatetaskandachieve", Updatetaskandachieve) //上报任务进度
  67 + http.HandleFunc("/russiaxiaoxiao/querytaskinfo", Querytaskinfo) //查询成就和任务列表
  68 + http.HandleFunc("/russiaxiaoxiao/gettaskreward", Gettaskreward) //查询成就和任务列表
65 69  
66 70 //..........................................
67 71 /*http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据
... ... @@ -346,86 +350,110 @@ func Getnewlevelreward(w http.ResponseWriter, r *http.Request) {
346 350  
347 351 func Gettaskreward(w http.ResponseWriter, r *http.Request) {
348 352  
  353 + gameid := ""
  354 + channel := ""
  355 + uniqueid := ""
349 356 Uuid := 0
350 357 if len(r.Header) > 0 {
351 358 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  359 + gameid = r.Header.Get("Gameid")
  360 + channel = r.Header.Get("Channel")
  361 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
352 362 }
353 363  
354 364 if Uuid == 0 {
355 365 SetHeader(w)
356   - //logger.Error("Uuid is nil!")
  366 + logger.Error("Uuid is nil!")
357 367 return
358 368 }
359 369 result, _ := ioutil.ReadAll(r.Body)
360 370 r.Body.Close()
361 371  
362 372 s := string(result)
363   - logger.Info("Gettaskreward , body:%v,uuid=%v", s, Uuid)
  373 + logger.Info("Gettaskreward , body:%v,uuid=%v", s, uniqueid)
364 374  
365   - //HandlerGettaskreward(w, s, Uuid)
  375 + HandlerGettaskreward(w, s, uniqueid, gameid, channel, Uuid)
366 376 }
367 377  
368 378 func Querytaskinfo(w http.ResponseWriter, r *http.Request) {
369 379  
  380 + gameid := ""
  381 + channel := ""
  382 + uniqueid := ""
370 383 Uuid := 0
371 384 if len(r.Header) > 0 {
372 385 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  386 + gameid = r.Header.Get("Gameid")
  387 + channel = r.Header.Get("Channel")
  388 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
373 389 }
374 390  
375 391 if Uuid == 0 {
376 392 SetHeader(w)
377   - //logger.Error("Uuid is nil!")
  393 + logger.Error("Uuid is nil!")
378 394 return
379 395 }
380 396 result, _ := ioutil.ReadAll(r.Body)
381 397 r.Body.Close()
382 398  
383 399 s := string(result)
384   - logger.Info("Querytaskinfo , body:%v,uuid=%v", s, Uuid)
  400 + logger.Info("Querytaskinfo , body:%v,uuid=%v", s, uniqueid)
385 401  
386   - //HandlerQuerytaskinfo(w, s, Uuid)
  402 + HandlerQuerytaskinfo(w, s, uniqueid, gameid, channel, Uuid)
387 403 }
388 404  
389 405 func Updatetaskandachieve(w http.ResponseWriter, r *http.Request) {
390 406  
  407 + gameid := ""
  408 + channel := ""
  409 + uniqueid := ""
391 410 Uuid := 0
392 411 if len(r.Header) > 0 {
393 412 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  413 + gameid = r.Header.Get("Gameid")
  414 + channel = r.Header.Get("Channel")
  415 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
394 416 }
395 417  
396 418 if Uuid == 0 {
397 419 SetHeader(w)
398   - //logger.Error("Uuid is nil!")
  420 + logger.Error("Uuid is nil!")
399 421 return
400 422 }
401 423 result, _ := ioutil.ReadAll(r.Body)
402 424 r.Body.Close()
403 425  
404 426 s := string(result)
405   - logger.Info("Updatetaskandachieve , body:%v,uuid=%v", s, Uuid)
  427 + logger.Info("Updatetaskandachieve , body:%v,uuid=%v", s, uniqueid)
406 428  
407   - //HandlerUpdatetaskandachieve(w, s, Uuid)
  429 + HandlerUpdatetaskandachieve(w, s, uniqueid, gameid, channel, Uuid)
408 430 }
409 431  
410 432 func Onlinentf(w http.ResponseWriter, r *http.Request) {
411 433  
  434 + gameid := ""
  435 + channel := ""
  436 + uniqueid := ""
412 437 Uuid := 0
413 438 if len(r.Header) > 0 {
414 439 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  440 + gameid = r.Header.Get("Gameid")
  441 + channel = r.Header.Get("Channel")
  442 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
415 443 }
416 444  
417 445 if Uuid == 0 {
418 446 SetHeader(w)
419   - //logger.Error("Uuid is nil!")
  447 + logger.Error("Uuid is nil!")
420 448 return
421 449 }
422 450 result, _ := ioutil.ReadAll(r.Body)
423 451 r.Body.Close()
424 452  
425 453 s := string(result)
426   - logger.Info("Onlinentf , body:%v,uuid=%v", s, Uuid)
  454 + logger.Info("Onlinentf , body:%v,uuid=%v", s, uniqueid)
427 455  
428   - // HandlerOnlinentf(w, s, Uuid)
  456 + HandlerOnlinentf(w, s, uniqueid, gameid, channel, Uuid)
429 457 }
430 458  
431 459 func Getcashrecord(w http.ResponseWriter, r *http.Request) {
... ...
src/HttpServer/logic/logic.go
... ... @@ -120,6 +120,206 @@ func HandlerUploaduserbasicinfo(w http.ResponseWriter, data string, uniqueuuid s
120 120 fmt.Fprint(w, string(respstr))
121 121 }
122 122  
  123 +func HandlerGettaskreward(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  124 + SetHeader(w)
  125 + var resp GettaskrewardResp
  126 + resp.Code = 0
  127 + var rdata GettaskrewardReq
  128 + err := json.Unmarshal([]byte(data), &rdata)
  129 + for {
  130 + if err != nil {
  131 + logger.Info("json decode HandlerGettaskreward data failed:%v,for:%v", err, data)
  132 + resp.Message = "网络错误"
  133 + resp.Code = ERROR_JSONUNMASH_ERROR
  134 + break
  135 + }
  136 +
  137 + uinfo, err := GetUserInfo(uniqueuuid)
  138 + if err != nil || uinfo == nil {
  139 + logger.Error("HandlerGettaskreward redis failed err=%v", err)
  140 + resp.Message = "服务器错误"
  141 + resp.Code = ERROR_SRV_ERROR
  142 + break
  143 + }
  144 +
  145 + //需要先计算出任务或者成就
  146 + var tasklist *TaskList
  147 + //先查询一下当前的任务数据
  148 + tasklist, err = GetTaskInfo(uuid, rdata.Tasktype, channel)
  149 + if err != nil || tasklist == nil {
  150 + logger.Error("GetTaskInfo failed err=%v", err)
  151 + resp.Message = "服务器错误"
  152 + resp.Code = ERROR_SRV_ERROR
  153 + break
  154 + }
  155 +
  156 + err = uinfo.HandleGetTaskReward(&rdata, &resp, tasklist, uuid, gameid, channel)
  157 + logger.Info("HandlerGettaskreward tasklist=%v", tasklist)
  158 + logger.Info("HandlerGettaskreward uinfo=%v", uinfo)
  159 + if err != nil {
  160 + logger.Error("HandleGetTaskReward failed err=%v", err)
  161 + resp.Message = "奖励已经领取"
  162 + resp.Code = ERROR_SRV_ERROR
  163 + break
  164 + }
  165 +
  166 + //保存数据
  167 + err = SaveUserInfo(uinfo, uniqueuuid)
  168 + err = SaveTaskInfo(uniqueuuid, rdata.Tasktype, tasklist)
  169 +
  170 + resp.Code = ERROR_OK
  171 + break
  172 + }
  173 +
  174 + //回包
  175 + respstr, _ := json.Marshal(&resp)
  176 + fmt.Fprint(w, string(respstr))
  177 +}
  178 +
  179 +func HandlerQuerytaskinfo(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  180 + SetHeader(w)
  181 + var resp QuerytaskinfoResp
  182 + resp.Code = 0
  183 + var rdata QuerytaskinfoReq
  184 + err := json.Unmarshal([]byte(data), &rdata)
  185 + for {
  186 + if err != nil {
  187 + logger.Info("json decode HandlerQuerytaskinfo data failed:%v,for:%v", err, data)
  188 + resp.Message = "网络错误"
  189 + resp.Code = ERROR_JSONUNMASH_ERROR
  190 + break
  191 + }
  192 +
  193 + uinfo, err := GetUserInfo(uniqueuuid)
  194 + if err != nil || uinfo == nil {
  195 + logger.Error("HandlerQuerytaskinfo redis failed err=%v", err)
  196 + resp.Message = "服务器错误"
  197 + resp.Code = ERROR_SRV_ERROR
  198 + break
  199 + }
  200 +
  201 + uinfo.HandlePassDay(uuid, channel)
  202 +
  203 + //需要先计算出任务或者成就
  204 + var tasklist *TaskList
  205 + //先查询一下当前的任务数据
  206 + tasklist, err = GetTaskInfo(uuid, rdata.Tasktype, channel)
  207 + if err != nil || tasklist == nil {
  208 + logger.Error("HandlerQuerytaskinfo redis failed err=%v", err)
  209 + resp.Message = "服务器错误"
  210 + resp.Code = ERROR_SRV_ERROR
  211 + break
  212 + }
  213 +
  214 + if rdata.Tasktype == 1 {
  215 + uinfo.CalcTaskList(tasklist, uniqueuuid)
  216 + } else if rdata.Tasktype == 2 {
  217 + tasklist = uinfo.CalcAchieveList(tasklist, uniqueuuid)
  218 + } else {
  219 + uinfo.CalcTaskList(tasklist, uniqueuuid)
  220 + }
  221 +
  222 + if tasklist == nil {
  223 + logger.Error("redis failed err=%v", err)
  224 + resp.Message = "服务器错误"
  225 + resp.Code = ERROR_SRV_ERROR
  226 + break
  227 + }
  228 +
  229 + resp.Data.Taskdata = append(resp.Data.Taskdata, tasklist.Taskdata...)
  230 +
  231 + resp.Code = ERROR_OK
  232 + break
  233 + }
  234 +
  235 + //回包
  236 + logger.Info("HandlerQuerytaskinfo,uuid=%v resp=%v", uuid, resp)
  237 + respstr, _ := json.Marshal(&resp)
  238 + fmt.Fprint(w, string(respstr))
  239 +}
  240 +
  241 +func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  242 + SetHeader(w)
  243 + var resp UpdatetaskResp
  244 + resp.Code = 0
  245 + var rdata UpdatetaskReq
  246 + err := json.Unmarshal([]byte(data), &rdata)
  247 + for {
  248 +
  249 + if err != nil {
  250 + logger.Info("json decode HandlerUpdatetaskandachieve data failed:%v,for:%v", err, data)
  251 + resp.Message = "json解析错误"
  252 + resp.Code = ERROR_JSONUNMASH_ERROR
  253 + break
  254 + }
  255 + uinfo, err := GetUserInfo(uniqueuuid)
  256 + if err != nil || uinfo == nil {
  257 + logger.Error("HandlerUpdatetaskandachieve redis failed err=%v", err)
  258 + resp.Message = "服务器错误"
  259 + resp.Code = ERROR_SRV_ERROR
  260 + break
  261 + }
  262 +
  263 + switch rdata.Tasktype {
  264 + case TASKTYPE_COSTTILI:
  265 + uinfo.Task.CostTili += rdata.Value
  266 + case TASKTYPE_REACH2000:
  267 + uinfo.Task.OutScore += rdata.Value
  268 + case TASKTYPE_WATCHADS:
  269 + uinfo.Achieve.WatchAdsCnt += rdata.Value
  270 + uinfo.Task.WatchAdCnt += rdata.Value
  271 + case TASKTYPE_TURNTABLE:
  272 + uinfo.Task.DrawTurnTableCnt += rdata.Value
  273 + case TASKTYPE_LUCKYBAG:
  274 + uinfo.Task.OpenLuckBagCnt += rdata.Value
  275 + case TASKTYPE_ROCKETTIMES:
  276 + uinfo.Task.UseRocketCnt += rdata.Value
  277 + case TASKTYPE_RELIVECNT:
  278 + uinfo.Task.RelivegCnt += rdata.Value
  279 + case TASKTYPE_USEITEMTIMES:
  280 + uinfo.Task.UseItemCnt += rdata.Value
  281 + case ACHIEVE_KILLLINE:
  282 + uinfo.Achieve.KillStar += rdata.Value
  283 + }
  284 + logger.Info("HandlerUpdatetaskandachieve uinfo=%v rdata=%v", uinfo, rdata)
  285 + SaveUserInfo(uinfo, uniqueuuid)
  286 + resp.Code = ERROR_OK
  287 + break
  288 + }
  289 +
  290 + //回包
  291 + respstr, _ := json.Marshal(&resp)
  292 + fmt.Fprint(w, string(respstr))
  293 +}
  294 +
  295 +func HandlerOnlinentf(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  296 + SetHeader(w)
  297 + var resp OnlinentfResp
  298 + resp.Code = 0
  299 + resp.Message = "success"
  300 + for {
  301 +
  302 + uinfo, err := GetUserInfo(uniqueuuid)
  303 + if err != nil || uinfo == nil {
  304 + logger.Error("redis failed err=%v", err)
  305 + resp.Message = "服务器错误"
  306 + resp.Code = ERROR_SRV_ERROR
  307 + break
  308 + }
  309 +
  310 + uinfo.Task.OnlineMin++
  311 +
  312 + SaveUserInfo(uinfo, uniqueuuid)
  313 +
  314 + resp.Code = ERROR_OK
  315 + break
  316 + }
  317 +
  318 + //回包
  319 + respstr, _ := json.Marshal(&resp)
  320 + fmt.Fprint(w, string(respstr))
  321 +}
  322 +
123 323 func HandlerGetcashrecord(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
124 324 SetHeader(w)
125 325 var resp GetcashrecordResp
... ...