Commit ffa660e15e950426a2cb23227ec0bbb3ee0b7f6c

Authored by 陆恒
1 parent 36cd6a7f
Exists in master

提交新的内容

src/HttpServer/logic/datadef.go
@@ -285,6 +285,41 @@ type SavadataResp struct { @@ -285,6 +285,41 @@ type SavadataResp struct {
285 Message string `json:"message"` 285 Message string `json:"message"`
286 } 286 }
287 287
  288 +type UploadhigestscoreReq struct {
  289 + Score int64 `json:"score"`
  290 + Gameid string `json:"gameid"`
  291 + Channel string `json:"channel"`
  292 +}
  293 +
  294 +type UploadhigestscoreData struct {
  295 +}
  296 +
  297 +type UploadhigestscoreResp struct {
  298 + Code int `json:"code"`
  299 + Message string `json:"message"`
  300 + Data UploadhigestscoreData `json:"data"`
  301 +}
  302 +
  303 +type Queryrankinfolist struct {
  304 + Rank int `json:"rank"`
  305 + Nickname string `json:"nickname"`
  306 + Headurl string `json:"headurl"`
  307 + Socre int64 `json:"socre"`
  308 + UniqueId string `json:"uniqueId"`
  309 +}
  310 +
  311 +type QueryrankinfoData struct {
  312 + Selfrank int `json:"selfrank"`
  313 + Selfsocre int64 `json:"selfsocre"`
  314 + Ranklist []Queryrankinfolist `json:"ranklist"`
  315 +}
  316 +
  317 +type QueryrankinfoResp struct {
  318 + Code int `json:"code"`
  319 + Message string `json:"message"`
  320 + Data QueryrankinfoData `json:"data"`
  321 +}
  322 +
288 type GetdataReq struct { 323 type GetdataReq struct {
289 Gameid string `json:"gameid"` 324 Gameid string `json:"gameid"`
290 Channel string `json:"channel"` 325 Channel string `json:"channel"`
@@ -428,6 +463,9 @@ type UserData struct { @@ -428,6 +463,9 @@ type UserData struct {
428 FetchRedCnt int //领取红包次数计数 463 FetchRedCnt int //领取红包次数计数
429 IsNew int //新手状态 464 IsNew int //新手状态
430 FetchRdBagNum int //当天已领的红包 465 FetchRdBagNum int //当天已领的红包
  466 + Hfen int64 //当日最高积分 用于计算排行榜
  467 + Nickname string //逆臣
  468 + HeadUrl string //头像
431 WithDraw WithDrawInfo //提现记录信息 469 WithDraw WithDrawInfo //提现记录信息
432 //SpecialWithDraw WithDrawInfo //活跃提现记录信息 470 //SpecialWithDraw WithDrawInfo //活跃提现记录信息
433 Task TaskInfo //玩家任务完成相关信息 471 Task TaskInfo //玩家任务完成相关信息
src/HttpServer/logic/function.go
@@ -856,6 +856,14 @@ func (u *UserData) CalcTotalCnt() int { @@ -856,6 +856,14 @@ func (u *UserData) CalcTotalCnt() int {
856 return usertime 856 return usertime
857 } 857 }
858 858
  859 +func (udata *UserData) AddToRank(unid string) error {
  860 + err := redishandler.GetRedisClient().Zadd(redis.USER_SCORE_RANK, float64(udata.Hfen), unid)
  861 + if err != nil {
  862 + logger.Error("AddToRank failed err=%v", err)
  863 + }
  864 + return err
  865 +}
  866 +
859 func (u *UserData) HandlePassDay(uuid int, channel string) { 867 func (u *UserData) HandlePassDay(uuid int, channel string) {
860 isdiffday := false 868 isdiffday := false
861 nowtime := time.Now() 869 nowtime := time.Now()
@@ -904,6 +912,7 @@ func (u *UserData) HandlePassDay(uuid int, channel string) { @@ -904,6 +912,7 @@ func (u *UserData) HandlePassDay(uuid int, channel string) {
904 u.Task.PlaySmall = 0 912 u.Task.PlaySmall = 0
905 u.ShakeTime = SHAKELIMIT 913 u.ShakeTime = SHAKELIMIT
906 u.FetchRdBagNum = 0 914 u.FetchRdBagNum = 0
  915 + u.Hfen = 0
907 916
908 //任务也需要处理 917 //任务也需要处理
909 /*tasklist, err := GetTaskInfo(u.Userid, 1) 918 /*tasklist, err := GetTaskInfo(u.Userid, 1)
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,6 +17,15 @@ import ( @@ -16,6 +17,15 @@ import (
16 17
17 //定时处理倒计时 18 //定时处理倒计时
18 func StartHttpTicker() { 19 func StartHttpTicker() {
  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 + }
19 29
20 } 30 }
21 31
@@ -41,33 +51,31 @@ func startServerHttpServe() { @@ -41,33 +51,31 @@ func startServerHttpServe() {
41 //http.HandleFunc("/catcafe/QueryAllAccount", QueryAllAccount) //查询所有账号的等级信息等数据 51 //http.HandleFunc("/catcafe/QueryAllAccount", QueryAllAccount) //查询所有账号的等级信息等数据
42 //------------------------------------------------------------- 52 //-------------------------------------------------------------
43 53
44 - http.HandleFunc("/ballbattle/test", Testapi) //测试接口  
45 - http.HandleFunc("/ballbattle/addcoin", Addcoin) //测试接口  
46 - http.HandleFunc("/ballbattle/clear", ClearData) //清除账号 54 + http.HandleFunc("/sixstar/test", Testapi) //测试接口
  55 + http.HandleFunc("/sixstar/addcoin", Addcoin) //测试接口
  56 + http.HandleFunc("/sixstar/clear", ClearData) //清除账号
47 //---------------------------------------------------------------------------------------- 57 //----------------------------------------------------------------------------------------
48 - http.HandleFunc("/ballbattle/login", UserLogin) //登录  
49 - http.HandleFunc("/ballbattle/getuserdata", Getuserdata) //获取玩家数据  
50 - http.HandleFunc("/ballbattle/watchads", Watchads) //观看激励视频  
51 - http.HandleFunc("/ballbattle/queryguaninfo", Queryguaninfo) //获取存钱罐数据  
52 - http.HandleFunc("/ballbattle/getguangold", Getguangold) //获取金币到存钱罐  
53 - http.HandleFunc("/ballbattle/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包  
54 - http.HandleFunc("/ballbattle/querdrawinfo", Querdrawinfo) //获取提现档位信息接口  
55 - http.HandleFunc("/ballbattle/getcash", Getcash) //提现  
56 - http.HandleFunc("/ballbattle/getcashrecord", Getcashrecord) //提现记录列表  
57 - http.HandleFunc("/ballbattle/onlinentf", Onlinentf) //在线通知  
58 - http.HandleFunc("/ballbattle/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度  
59 - http.HandleFunc("/ballbattle/querytaskinfo", Querytaskinfo) //拉取任务或者成就列表  
60 - http.HandleFunc("/ballbattle/gettaskreward", Gettaskreward) //领取任务或者成就奖励  
61 - http.HandleFunc("/ballbattle/getnewlevelreward", Getnewlevelreward) //领取任务或者成就奖励  
62 - http.HandleFunc("/ballbattle/querysigndata", Querysigndata) //获取签到数据  
63 - http.HandleFunc("/ballbattle/usersign", Usersign) //玩家签到  
64 - http.HandleFunc("/ballbattle/fetchredbag", Fetchredbag) //领取红包  
65 - http.HandleFunc("/ballbattle/savadata", Savadata) //保存数据  
66 - http.HandleFunc("/ballbattle/getdata", Getdata) //获取数据  
67 - //  
68 - http.HandleFunc("/ballbattle/readNumUpload", ReadNumUpload) //阅读量上报  
69 - http.HandleFunc("/ballbattle/queryreadgold", QueryReadGold) //获取微转发金币数  
70 - http.HandleFunc("/ballbattle/fetchreadgold", Fetchreadgold) //领取微转发金币数 58 + http.HandleFunc("/sixstar/login", UserLogin) //登录
  59 + http.HandleFunc("/sixstar/getuserdata", Getuserdata) //获取玩家数据
  60 + http.HandleFunc("/sixstar/watchads", Watchads) //观看激励视频
  61 + http.HandleFunc("/sixstar/queryguaninfo", Queryguaninfo) //获取存钱罐数据
  62 + http.HandleFunc("/sixstar/getguangold", Getguangold) //获取金币到存钱罐
  63 + http.HandleFunc("/sixstar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包
  64 + http.HandleFunc("/sixstar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口
  65 + http.HandleFunc("/sixstar/getcash", Getcash) //提现
  66 + http.HandleFunc("/sixstar/getcashrecord", Getcashrecord) //提现记录列表
  67 + http.HandleFunc("/sixstar/onlinentf", Onlinentf) //在线通知
  68 + http.HandleFunc("/sixstar/updatetaskandachieve", Updatetaskandachieve) //上报任务事件进度
  69 + http.HandleFunc("/sixstar/querytaskinfo", Querytaskinfo) //拉取任务或者成就列表
  70 + http.HandleFunc("/sixstar/gettaskreward", Gettaskreward) //领取任务或者成就奖励
  71 + http.HandleFunc("/sixstar/getnewlevelreward", Getnewlevelreward) //领取任务或者成就奖励
  72 + http.HandleFunc("/sixstar/querysigndata", Querysigndata) //获取签到数据
  73 + http.HandleFunc("/sixstar/usersign", Usersign) //玩家签到
  74 + http.HandleFunc("/sixstar/fetchredbag", Fetchredbag) //领取红包
  75 + http.HandleFunc("/sixstar/savadata", Savadata) //保存数据
  76 + http.HandleFunc("/sixstar/getdata", Getdata) //获取数据
  77 + http.HandleFunc("/sixstar/uploadscore", Uploadscore) //上报当天积分
  78 + http.HandleFunc("/sixstar/queryrankinfo", Queryrankinfo) //获取排行榜信息
71 79
72 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) 80 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil)
73 CheckErr(err) 81 CheckErr(err)
@@ -144,6 +152,48 @@ func Savadata(w http.ResponseWriter, r *http.Request) { @@ -144,6 +152,48 @@ func Savadata(w http.ResponseWriter, r *http.Request) {
144 HandlerSavadata(w, s, Uuid) 152 HandlerSavadata(w, s, Uuid)
145 } 153 }
146 154
  155 +func Queryrankinfo(w http.ResponseWriter, r *http.Request) {
  156 +
  157 + Uuid := 0
  158 + if len(r.Header) > 0 {
  159 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  160 + }
  161 +
  162 + if Uuid == 0 {
  163 + SetHeader(w)
  164 + //logger.Error("Uuid is nil!")
  165 + return
  166 + }
  167 + result, _ := ioutil.ReadAll(r.Body)
  168 + r.Body.Close()
  169 +
  170 + s := string(result)
  171 + logger.Info("Queryrankinfo , body:%v,uuid=%v", s, Uuid)
  172 +
  173 + HandlerQueryrankinfo(w, s, Uuid)
  174 +}
  175 +
  176 +func Uploadscore(w http.ResponseWriter, r *http.Request) {
  177 +
  178 + Uuid := 0
  179 + if len(r.Header) > 0 {
  180 + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  181 + }
  182 +
  183 + if Uuid == 0 {
  184 + SetHeader(w)
  185 + //logger.Error("Uuid is nil!")
  186 + return
  187 + }
  188 + result, _ := ioutil.ReadAll(r.Body)
  189 + r.Body.Close()
  190 +
  191 + s := string(result)
  192 + logger.Info("Uploadscore , body:%v,uuid=%v", s, Uuid)
  193 +
  194 + HandlerUploadscore(w, s, Uuid)
  195 +}
  196 +
147 func Getdata(w http.ResponseWriter, r *http.Request) { 197 func Getdata(w http.ResponseWriter, r *http.Request) {
148 198
149 Uuid := 0 199 Uuid := 0
src/HttpServer/logic/logic.go
@@ -525,6 +525,127 @@ func HandlerReadNumUpload(w http.ResponseWriter, data string) { @@ -525,6 +525,127 @@ func HandlerReadNumUpload(w http.ResponseWriter, data string) {
525 fmt.Fprint(w, string(respstr)) 525 fmt.Fprint(w, string(respstr))
526 } 526 }
527 527
  528 +func HandlerQueryrankinfo(w http.ResponseWriter, data string, uuid int) {
  529 + SetHeader(w)
  530 + var resp QueryrankinfoResp
  531 + resp.Code = 0
  532 + resp.Message = "success"
  533 + var rdata CommReq
  534 + err := json.Unmarshal([]byte(data), &rdata)
  535 + for {
  536 + if err != nil {
  537 + logger.Info("json decode HandlerQueryrankinfo data failed:%v,for:%v", err, data)
  538 + resp.Message = "网络错误"
  539 + resp.Code = ERROR_JSONUNMASH_ERROR
  540 + break
  541 + }
  542 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel
  543 +
  544 + selfrank := -1
  545 + selfscore := int64(0)
  546 + vv, err := redishandler.GetRedisClient().ZRevRangewithIndex(redis.USER_SCORE_RANK, 0, 99)
  547 + if err == nil {
  548 + rank := 0
  549 + for _, v := range vv {
  550 + rank++
  551 +
  552 + rinfobyte, _ := v.([]byte)
  553 + logger.Info("HandlerQueryPlayerRank ,v=%v", string(rinfobyte))
  554 + //ruid, _ := strconv.Atoi(string(rinfobyte))
  555 + rindo, err := GetUserInfo(string(rinfobyte))
  556 + if err == nil && rindo != nil {
  557 + var tmp Queryrankinfolist
  558 + tmp.UniqueId = string(rinfobyte)
  559 + tmp.Socre = rindo.Hfen
  560 + tmp.Nickname = rindo.Nickname
  561 + tmp.Headurl = rindo.HeadUrl
  562 + tmp.Rank = rank
  563 +
  564 + resp.Data.Ranklist = append(resp.Data.Ranklist, tmp)
  565 + }
  566 +
  567 + if string(rinfobyte) == uniqueuuid {
  568 + selfrank = rank
  569 + selfscore = rindo.Hfen
  570 + }
  571 + }
  572 + } else {
  573 + logger.Error("HandlerUpdateUserInfo redisfailed ")
  574 + resp.Code = 1
  575 + resp.Message = "redisfailed"
  576 + break
  577 + }
  578 +
  579 + if selfrank == -1 {
  580 + uinfo, err := GetUserInfo(uniqueuuid)
  581 + if err != nil {
  582 + logger.Info("GetUserInfo HandlerQueryrankinfo data failed:%v,for:%v", err, data)
  583 + resp.Message = "GetUserInfo failed"
  584 + resp.Code = 1
  585 + break
  586 + }
  587 +
  588 + resp.Data.Selfsocre = uinfo.Hfen
  589 + resp.Data.Selfrank = 101 //表示100+
  590 + } else {
  591 + resp.Data.Selfrank = selfrank
  592 + resp.Data.Selfsocre = selfscore
  593 + }
  594 +
  595 + resp.Code = ERROR_OK
  596 + break
  597 + }
  598 +
  599 + //回包
  600 + respstr, _ := json.Marshal(&resp)
  601 + fmt.Fprint(w, string(respstr))
  602 +}
  603 +
  604 +func HandlerUploadscore(w http.ResponseWriter, data string, uuid int) {
  605 + SetHeader(w)
  606 + var resp UploadhigestscoreResp
  607 + resp.Code = 0
  608 + resp.Message = "success"
  609 + var rdata UploadhigestscoreReq
  610 + err := json.Unmarshal([]byte(data), &rdata)
  611 + for {
  612 + if err != nil {
  613 + logger.Info("json decode HandlerUploadscore data failed:%v,for:%v", err, data)
  614 + resp.Message = "网络错误"
  615 + resp.Code = ERROR_JSONUNMASH_ERROR
  616 + break
  617 + }
  618 +
  619 + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据
  620 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel
  621 + uinfo, err := GetUserInfo(uniqueuuid)
  622 + if err != nil || uinfo == nil {
  623 + logger.Error("redis failed err=%v", err)
  624 + resp.Message = "服务器错误"
  625 + resp.Code = ERROR_SRV_ERROR
  626 + break
  627 + }
  628 +
  629 + if uinfo.Hfen >= rdata.Score {
  630 + //resp.Message = "服务器错误"
  631 + resp.Code = 0
  632 + break
  633 + }
  634 +
  635 + uinfo.Hfen = rdata.Score
  636 + uinfo.AddToRank(uniqueuuid)
  637 + //加入排行榜
  638 + SaveUserInfo(uinfo, uniqueuuid)
  639 +
  640 + resp.Code = ERROR_OK
  641 + break
  642 + }
  643 +
  644 + //回包
  645 + respstr, _ := json.Marshal(&resp)
  646 + fmt.Fprint(w, string(respstr))
  647 +}
  648 +
528 func HandlerSavadata(w http.ResponseWriter, data string, uuid int) { 649 func HandlerSavadata(w http.ResponseWriter, data string, uuid int) {
529 SetHeader(w) 650 SetHeader(w)
530 var resp SavadataResp 651 var resp SavadataResp
src/common/redis/def.go
1 package redis 1 package redis
2 2
3 const ( 3 const (
4 - USER_DATA_KEY = "BALLBATTLE_USER_DATA_KEY" //玩家数据  
5 - USER_WITHDRAW_RECORDLIST = "BALLBATTLE_USER_WITHDRAW_RECORDLIST" //玩家提现记录  
6 - USER_TASKINFO_LIST = "BALLBATTLE_USER_TASKINFO_LIST" //任务列表数据缓存  
7 - USER_ACHIEVEMENTINFO_LIST = "BALLBATTLE_USER_ACHIEVEMENTINFO_LIST" //成就列表数据缓存  
8 - USER_SELFDATA_KEY = "BALLBATTLE_USER_SELFDATA_KEY" //玩家自定义数据 需要加上uuid与channel hset field为自定义的key value为保存的数据 4 + USER_DATA_KEY = "SIXSTAR_USER_DATA_KEY" //玩家数据
  5 + USER_WITHDRAW_RECORDLIST = "SIXSTAR_USER_WITHDRAW_RECORDLIST" //玩家提现记录
  6 + USER_TASKINFO_LIST = "SIXSTARE_USER_TASKINFO_LIST" //任务列表数据缓存
  7 + USER_ACHIEVEMENTINFO_LIST = "SIXSTAR_USER_ACHIEVEMENTINFO_LIST" //成就列表数据缓存
  8 + USER_SELFDATA_KEY = "SIXSTAR_USER_SELFDATA_KEY" //玩家自定义数据 需要加上uuid与channel hset field为自定义的key value为保存的数据
  9 + USER_SCORE_RANK = "SIXSTAR_USER_SCORE_RANK" //玩家排行榜
9 ) 10 )