Commit cb597df9872747cb6438d84987e27ce765198452
1 parent
13427da9
Exists in
master
提交
Showing
5 changed files
with
234 additions
and
3 deletions
Show diff stats
src/HttpServer/logic/datadef.go
| @@ -9,8 +9,8 @@ package logic | @@ -9,8 +9,8 @@ package logic | ||
| 9 | //"107":"签到罐" | 9 | //"107":"签到罐" |
| 10 | 10 | ||
| 11 | type UserLoginReq struct { | 11 | type UserLoginReq struct { |
| 12 | - Fromid int `json:"fromid"` | ||
| 13 | - Sharetype int `json:"sharetype"` | 12 | + Nickname string `json:"nickname"` |
| 13 | + Headurl string `json:"headurl"` | ||
| 14 | Gameid string `json:"gameid"` | 14 | Gameid string `json:"gameid"` |
| 15 | Channel string `json:"channel"` | 15 | Channel string `json:"channel"` |
| 16 | } | 16 | } |
| @@ -258,6 +258,26 @@ type QuerysigndataResp struct { | @@ -258,6 +258,26 @@ type QuerysigndataResp struct { | ||
| 258 | Data QuerysigndataData `json:"data"` | 258 | Data QuerysigndataData `json:"data"` |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | +type Queryrankinfolist struct { | ||
| 262 | + Rank int `json:"rank"` | ||
| 263 | + Nickname string `json:"nickname"` | ||
| 264 | + Headurl string `json:"headurl"` | ||
| 265 | + Socre int64 `json:"socre"` | ||
| 266 | + UniqueId string `json:"uniqueId"` | ||
| 267 | +} | ||
| 268 | + | ||
| 269 | +type QueryrankinfoData struct { | ||
| 270 | + Selfrank int `json:"selfrank"` | ||
| 271 | + Selfsocre int64 `json:"selfsocre"` | ||
| 272 | + Ranklist []Queryrankinfolist `json:"ranklist"` | ||
| 273 | +} | ||
| 274 | + | ||
| 275 | +type QueryrankinfoResp struct { | ||
| 276 | + Code int `json:"code"` | ||
| 277 | + Message string `json:"message"` | ||
| 278 | + Data QueryrankinfoData `json:"data"` | ||
| 279 | +} | ||
| 280 | + | ||
| 261 | type FetchredbagReq struct { | 281 | type FetchredbagReq struct { |
| 262 | Gameid string `json:"gameid"` | 282 | Gameid string `json:"gameid"` |
| 263 | Channel string `json:"channel"` | 283 | Channel string `json:"channel"` |
| @@ -351,6 +371,21 @@ type TaskInfo struct { | @@ -351,6 +371,21 @@ type TaskInfo struct { | ||
| 351 | PlaySmall int //当日是否试玩小游戏15s 次数 | 371 | PlaySmall int //当日是否试玩小游戏15s 次数 |
| 352 | } | 372 | } |
| 353 | 373 | ||
| 374 | +type UploadhigestscoreReq struct { | ||
| 375 | + Score int64 `json:"score"` | ||
| 376 | + Gameid string `json:"gameid"` | ||
| 377 | + Channel string `json:"channel"` | ||
| 378 | +} | ||
| 379 | + | ||
| 380 | +type UploadhigestscoreData struct { | ||
| 381 | +} | ||
| 382 | + | ||
| 383 | +type UploadhigestscoreResp struct { | ||
| 384 | + Code int `json:"code"` | ||
| 385 | + Message string `json:"message"` | ||
| 386 | + Data UploadhigestscoreData `json:"data"` | ||
| 387 | +} | ||
| 388 | + | ||
| 354 | // | 389 | // |
| 355 | type AchieveMentInfo struct { | 390 | type AchieveMentInfo struct { |
| 356 | WatchAdsCnt int //观看广告数 | 391 | WatchAdsCnt int //观看广告数 |
| @@ -427,6 +462,9 @@ type UserData struct { | @@ -427,6 +462,9 @@ type UserData struct { | ||
| 427 | ShakeTime int //摇一摇 | 462 | ShakeTime int //摇一摇 |
| 428 | FetchRedCnt int //领取红包次数计数 | 463 | FetchRedCnt int //领取红包次数计数 |
| 429 | IsNew int //新手状态 | 464 | IsNew int //新手状态 |
| 465 | + Hfen int64 //当天分数 | ||
| 466 | + Nickname string //昵称 | ||
| 467 | + HeadUrl string //头像 | ||
| 430 | FetchRdBagNum int //当天已领的红包 | 468 | FetchRdBagNum int //当天已领的红包 |
| 431 | WithDraw WithDrawInfo //提现记录信息 | 469 | WithDraw WithDrawInfo //提现记录信息 |
| 432 | //SpecialWithDraw WithDrawInfo //活跃提现记录信息 | 470 | //SpecialWithDraw WithDrawInfo //活跃提现记录信息 |
src/HttpServer/logic/function.go
| @@ -670,6 +670,8 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s | @@ -670,6 +670,8 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s | ||
| 670 | initdata.ShakeTime = SHAKELIMIT | 670 | initdata.ShakeTime = SHAKELIMIT |
| 671 | initdata.IsNew = 1 | 671 | initdata.IsNew = 1 |
| 672 | initdata.FetchRdBagNum = 0 | 672 | initdata.FetchRdBagNum = 0 |
| 673 | + initdata.Nickname = data.Nickname | ||
| 674 | + initdata.HeadUrl = data.Headurl | ||
| 673 | 675 | ||
| 674 | for _, val := range jsonconf.GetJsonConf().WithDrawConfig { | 676 | for _, val := range jsonconf.GetJsonConf().WithDrawConfig { |
| 675 | var tmp WithDrawDesc | 677 | var tmp WithDrawDesc |
| @@ -955,6 +957,10 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR | @@ -955,6 +957,10 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR | ||
| 955 | return err | 957 | return err |
| 956 | } | 958 | } |
| 957 | 959 | ||
| 960 | + | ||
| 961 | + //更新头像 | ||
| 962 | + data.HeadUrl = req.Headurl | ||
| 963 | + data.Nickname = req.Nickname | ||
| 958 | //此处要处理一下跨天逻辑 | 964 | //此处要处理一下跨天逻辑 |
| 959 | data.HandlePassDay(uuid, req.Channel) | 965 | data.HandlePassDay(uuid, req.Channel) |
| 960 | 966 | ||
| @@ -1142,6 +1148,14 @@ func GettotalParam(paramlist []string) string { | @@ -1142,6 +1148,14 @@ func GettotalParam(paramlist []string) string { | ||
| 1142 | return sumparam | 1148 | return sumparam |
| 1143 | } | 1149 | } |
| 1144 | 1150 | ||
| 1151 | +func (udata *UserData) AddToRank(unid string) error { | ||
| 1152 | + err := redishandler.GetRedisClient().Zadd(redis.USER_SCORE_RANK, float64(udata.Hfen), unid) | ||
| 1153 | + if err != nil { | ||
| 1154 | + logger.Error("AddToRank failed err=%v", err) | ||
| 1155 | + } | ||
| 1156 | + return err | ||
| 1157 | +} | ||
| 1158 | + | ||
| 1145 | func GetHashValue(signsum string) string { | 1159 | func GetHashValue(signsum string) string { |
| 1146 | /*h := sha1.New() | 1160 | /*h := sha1.New() |
| 1147 | h.Write([]byte(signsum)) | 1161 | h.Write([]byte(signsum)) |
src/HttpServer/logic/httpserver.go
| @@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
| 9 | "fmt" | 9 | "fmt" |
| 10 | "io/ioutil" | 10 | "io/ioutil" |
| 11 | "strconv" | 11 | "strconv" |
| 12 | + "time" | ||
| 12 | 13 | ||
| 13 | //"log" | 14 | //"log" |
| 14 | "net/http" | 15 | "net/http" |
| @@ -16,7 +17,15 @@ import ( | @@ -16,7 +17,15 @@ import ( | ||
| 16 | 17 | ||
| 17 | //定时处理倒计时 | 18 | //定时处理倒计时 |
| 18 | func StartHttpTicker() { | 19 | func StartHttpTicker() { |
| 19 | - | 20 | + for { |
| 21 | + now := time.Now() //获取当前时间,放到now里面,要给next用 | ||
| 22 | + next := now.Add(time.Hour * 24) //通过now偏移24小时 | ||
| 23 | + next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location()) //获取下一个凌晨的日期 | ||
| 24 | + t := time.NewTimer(next.Sub(now))//计算当前时间到凌晨的时间间隔,设置一个定时器 | ||
| 25 | + <-t.C | ||
| 26 | + redishandler.GetRedisClient().Delete(redis.USER_SCORE_RANK) | ||
| 27 | + logger.Info("Del USER_SCORE_RANK success!") | ||
| 28 | + } | ||
| 20 | } | 29 | } |
| 21 | 30 | ||
| 22 | func StartHttpServe() { | 31 | func StartHttpServe() { |
| @@ -64,6 +73,8 @@ func startServerHttpServe() { | @@ -64,6 +73,8 @@ func startServerHttpServe() { | ||
| 64 | http.HandleFunc("/ballbattle/fetchredbag", Fetchredbag) //领取红包 | 73 | http.HandleFunc("/ballbattle/fetchredbag", Fetchredbag) //领取红包 |
| 65 | http.HandleFunc("/ballbattle/savadata", Savadata) //保存数据 | 74 | http.HandleFunc("/ballbattle/savadata", Savadata) //保存数据 |
| 66 | http.HandleFunc("/ballbattle/getdata", Getdata) //获取数据 | 75 | http.HandleFunc("/ballbattle/getdata", Getdata) //获取数据 |
| 76 | + http.HandleFunc("/ballbattle/uploadscore", Uploadscore) //上报当天积分 | ||
| 77 | + http.HandleFunc("/ballbattle/queryrankinfo", Queryrankinfo) //获取排行榜信息 | ||
| 67 | // | 78 | // |
| 68 | http.HandleFunc("/ballbattle/readNumUpload", ReadNumUpload) //阅读量上报 | 79 | http.HandleFunc("/ballbattle/readNumUpload", ReadNumUpload) //阅读量上报 |
| 69 | http.HandleFunc("/ballbattle/queryreadgold", QueryReadGold) //获取微转发金币数 | 80 | http.HandleFunc("/ballbattle/queryreadgold", QueryReadGold) //获取微转发金币数 |
| @@ -144,6 +155,49 @@ func Savadata(w http.ResponseWriter, r *http.Request) { | @@ -144,6 +155,49 @@ func Savadata(w http.ResponseWriter, r *http.Request) { | ||
| 144 | HandlerSavadata(w, s, Uuid) | 155 | HandlerSavadata(w, s, Uuid) |
| 145 | } | 156 | } |
| 146 | 157 | ||
| 158 | + | ||
| 159 | +func Queryrankinfo(w http.ResponseWriter, r *http.Request) { | ||
| 160 | + | ||
| 161 | + Uuid := 0 | ||
| 162 | + if len(r.Header) > 0 { | ||
| 163 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + if Uuid == 0 { | ||
| 167 | + SetHeader(w) | ||
| 168 | + //logger.Error("Uuid is nil!") | ||
| 169 | + return | ||
| 170 | + } | ||
| 171 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 172 | + r.Body.Close() | ||
| 173 | + | ||
| 174 | + s := string(result) | ||
| 175 | + logger.Info("Queryrankinfo , body:%v,uuid=%v", s, Uuid) | ||
| 176 | + | ||
| 177 | + HandlerQueryrankinfo(w, s, Uuid) | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +func Uploadscore(w http.ResponseWriter, r *http.Request) { | ||
| 181 | + | ||
| 182 | + Uuid := 0 | ||
| 183 | + if len(r.Header) > 0 { | ||
| 184 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + if Uuid == 0 { | ||
| 188 | + SetHeader(w) | ||
| 189 | + //logger.Error("Uuid is nil!") | ||
| 190 | + return | ||
| 191 | + } | ||
| 192 | + result, _ := ioutil.ReadAll(r.Body) | ||
| 193 | + r.Body.Close() | ||
| 194 | + | ||
| 195 | + s := string(result) | ||
| 196 | + logger.Info("Uploadscore , body:%v,uuid=%v", s, Uuid) | ||
| 197 | + | ||
| 198 | + HandlerUploadscore(w, s, Uuid) | ||
| 199 | +} | ||
| 200 | + | ||
| 147 | func Getdata(w http.ResponseWriter, r *http.Request) { | 201 | func Getdata(w http.ResponseWriter, r *http.Request) { |
| 148 | 202 | ||
| 149 | Uuid := 0 | 203 | Uuid := 0 |
src/HttpServer/logic/logic.go
| @@ -525,6 +525,130 @@ func HandlerReadNumUpload(w http.ResponseWriter, data string) { | @@ -525,6 +525,130 @@ func HandlerReadNumUpload(w http.ResponseWriter, data string) { | ||
| 525 | fmt.Fprint(w, string(respstr)) | 525 | fmt.Fprint(w, string(respstr)) |
| 526 | } | 526 | } |
| 527 | 527 | ||
| 528 | + | ||
| 529 | +func HandlerUploadscore(w http.ResponseWriter, data string, uuid int) { | ||
| 530 | + SetHeader(w) | ||
| 531 | + var resp UploadhigestscoreResp | ||
| 532 | + resp.Code = 0 | ||
| 533 | + resp.Message = "success" | ||
| 534 | + var rdata UploadhigestscoreReq | ||
| 535 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 536 | + for { | ||
| 537 | + if err != nil { | ||
| 538 | + logger.Info("json decode HandlerUploadscore data failed:%v,for:%v", err, data) | ||
| 539 | + resp.Message = "网络错误" | ||
| 540 | + resp.Code = ERROR_JSONUNMASH_ERROR | ||
| 541 | + break | ||
| 542 | + } | ||
| 543 | + | ||
| 544 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | ||
| 545 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | ||
| 546 | + uinfo, err := GetUserInfo(uniqueuuid) | ||
| 547 | + if err != nil || uinfo == nil { | ||
| 548 | + logger.Error("redis failed err=%v", err) | ||
| 549 | + resp.Message = "服务器错误" | ||
| 550 | + resp.Code = ERROR_SRV_ERROR | ||
| 551 | + break | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + if uinfo.Hfen >= rdata.Score { | ||
| 555 | + //resp.Message = "服务器错误" | ||
| 556 | + resp.Code = 0 | ||
| 557 | + break | ||
| 558 | + } | ||
| 559 | + | ||
| 560 | + uinfo.Hfen = rdata.Score | ||
| 561 | + uinfo.AddToRank(uniqueuuid) | ||
| 562 | + //加入排行榜 | ||
| 563 | + SaveUserInfo(uinfo, uniqueuuid) | ||
| 564 | + | ||
| 565 | + resp.Code = ERROR_OK | ||
| 566 | + break | ||
| 567 | + } | ||
| 568 | + | ||
| 569 | + //回包 | ||
| 570 | + respstr, _ := json.Marshal(&resp) | ||
| 571 | + fmt.Fprint(w, string(respstr)) | ||
| 572 | +} | ||
| 573 | + | ||
| 574 | + | ||
| 575 | +func HandlerQueryrankinfo(w http.ResponseWriter, data string, uuid int) { | ||
| 576 | + SetHeader(w) | ||
| 577 | + var resp QueryrankinfoResp | ||
| 578 | + resp.Code = 0 | ||
| 579 | + resp.Message = "success" | ||
| 580 | + var rdata CommReq | ||
| 581 | + err := json.Unmarshal([]byte(data), &rdata) | ||
| 582 | + for { | ||
| 583 | + if err != nil { | ||
| 584 | + logger.Info("json decode HandlerQueryrankinfo data failed:%v,for:%v", err, data) | ||
| 585 | + resp.Message = "网络错误" | ||
| 586 | + resp.Code = ERROR_JSONUNMASH_ERROR | ||
| 587 | + break | ||
| 588 | + } | ||
| 589 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | ||
| 590 | + | ||
| 591 | + selfrank := -1 | ||
| 592 | + selfscore := int64(0) | ||
| 593 | + vv, err := redishandler.GetRedisClient().ZRevRangewithIndex(redis.USER_SCORE_RANK, 0, 99) | ||
| 594 | + if err == nil { | ||
| 595 | + rank := 0 | ||
| 596 | + for _, v := range vv { | ||
| 597 | + rank++ | ||
| 598 | + | ||
| 599 | + rinfobyte, _ := v.([]byte) | ||
| 600 | + logger.Info("HandlerQueryPlayerRank ,v=%v", string(rinfobyte)) | ||
| 601 | + //ruid, _ := strconv.Atoi(string(rinfobyte)) | ||
| 602 | + rindo, err := GetUserInfo(string(rinfobyte)) | ||
| 603 | + if err == nil && rindo != nil { | ||
| 604 | + var tmp Queryrankinfolist | ||
| 605 | + tmp.UniqueId = string(rinfobyte) | ||
| 606 | + tmp.Socre = rindo.Hfen | ||
| 607 | + tmp.Nickname = rindo.Nickname | ||
| 608 | + tmp.Headurl = rindo.HeadUrl | ||
| 609 | + tmp.Rank = rank | ||
| 610 | + | ||
| 611 | + resp.Data.Ranklist = append(resp.Data.Ranklist, tmp) | ||
| 612 | + } | ||
| 613 | + | ||
| 614 | + if string(rinfobyte) == uniqueuuid { | ||
| 615 | + selfrank = rank | ||
| 616 | + selfscore = rindo.Hfen | ||
| 617 | + } | ||
| 618 | + } | ||
| 619 | + } else { | ||
| 620 | + logger.Error("HandlerUpdateUserInfo redisfailed ") | ||
| 621 | + resp.Code = 1 | ||
| 622 | + resp.Message = "redisfailed" | ||
| 623 | + break | ||
| 624 | + } | ||
| 625 | + | ||
| 626 | + if selfrank == -1 { | ||
| 627 | + uinfo, err := GetUserInfo(uniqueuuid) | ||
| 628 | + if err != nil { | ||
| 629 | + logger.Info("GetUserInfo HandlerQueryrankinfo data failed:%v,for:%v", err, data) | ||
| 630 | + resp.Message = "GetUserInfo failed" | ||
| 631 | + resp.Code = 1 | ||
| 632 | + break | ||
| 633 | + } | ||
| 634 | + | ||
| 635 | + resp.Data.Selfsocre = uinfo.Hfen | ||
| 636 | + resp.Data.Selfrank = 101 //表示100+ | ||
| 637 | + } else { | ||
| 638 | + resp.Data.Selfrank = selfrank | ||
| 639 | + resp.Data.Selfsocre = selfscore | ||
| 640 | + } | ||
| 641 | + | ||
| 642 | + resp.Code = ERROR_OK | ||
| 643 | + break | ||
| 644 | + } | ||
| 645 | + | ||
| 646 | + //回包 | ||
| 647 | + respstr, _ := json.Marshal(&resp) | ||
| 648 | + fmt.Fprint(w, string(respstr)) | ||
| 649 | +} | ||
| 650 | + | ||
| 651 | + | ||
| 528 | func HandlerSavadata(w http.ResponseWriter, data string, uuid int) { | 652 | func HandlerSavadata(w http.ResponseWriter, data string, uuid int) { |
| 529 | SetHeader(w) | 653 | SetHeader(w) |
| 530 | var resp SavadataResp | 654 | var resp SavadataResp |
src/common/redis/def.go
| @@ -6,4 +6,5 @@ const ( | @@ -6,4 +6,5 @@ const ( | ||
| 6 | USER_TASKINFO_LIST = "BALLBATTLE_USER_TASKINFO_LIST" //任务列表数据缓存 | 6 | USER_TASKINFO_LIST = "BALLBATTLE_USER_TASKINFO_LIST" //任务列表数据缓存 |
| 7 | USER_ACHIEVEMENTINFO_LIST = "BALLBATTLE_USER_ACHIEVEMENTINFO_LIST" //成就列表数据缓存 | 7 | USER_ACHIEVEMENTINFO_LIST = "BALLBATTLE_USER_ACHIEVEMENTINFO_LIST" //成就列表数据缓存 |
| 8 | USER_SELFDATA_KEY = "BALLBATTLE_USER_SELFDATA_KEY" //玩家自定义数据 需要加上uuid与channel hset field为自定义的key value为保存的数据 | 8 | USER_SELFDATA_KEY = "BALLBATTLE_USER_SELFDATA_KEY" //玩家自定义数据 需要加上uuid与channel hset field为自定义的key value为保存的数据 |
| 9 | + USER_SCORE_RANK = "BALLBATTLE_USER_SCORE_RANK" //玩家排行榜 | ||
| 9 | ) | 10 | ) |