Commit db30a4ee7c08818ebc085a7b9c628da819d9df35
1 parent
ef8fdc0a
Exists in
master
增加抽奖功能
Showing
4 changed files
with
90 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -26,6 +26,7 @@ type UserLoginData struct { | @@ -26,6 +26,7 @@ type UserLoginData struct { | ||
26 | IsNew int `json:"isnew"` | 26 | IsNew int `json:"isnew"` |
27 | Issignshow int `json:"issignshow"` | 27 | Issignshow int `json:"issignshow"` |
28 | Leftredbagnum int `json:"leftredbagnum"` | 28 | Leftredbagnum int `json:"leftredbagnum"` |
29 | + Curtime int `json:"curtime"` | ||
29 | } | 30 | } |
30 | 31 | ||
31 | type UserLoginResp struct { | 32 | type UserLoginResp struct { |
@@ -470,6 +471,23 @@ type WithDrawDesc struct { | @@ -470,6 +471,23 @@ type WithDrawDesc struct { | ||
470 | Day int `json:"day"` | 471 | Day int `json:"day"` |
471 | } | 472 | } |
472 | 473 | ||
474 | +type TurntablebagReq struct { | ||
475 | + Num int `json:"num"` | ||
476 | + Gameid string `json:"gameid"` | ||
477 | + Channel string `json:"channel"` | ||
478 | +} | ||
479 | + | ||
480 | +type TurntablebagData struct { | ||
481 | + Getgoldnum int `json:"getgoldnum"` | ||
482 | + Walletgold int `json:"walletgold"` | ||
483 | +} | ||
484 | + | ||
485 | +type TurntablebagResp struct { | ||
486 | + Code int `json:"code"` | ||
487 | + Message string `json:"message"` | ||
488 | + Data TurntablebagData `json:"data"` | ||
489 | +} | ||
490 | + | ||
473 | //玩家数据 | 491 | //玩家数据 |
474 | type UserData struct { | 492 | type UserData struct { |
475 | Userid int //玩家id | 493 | Userid int //玩家id |
src/HttpServer/logic/function.go
@@ -688,6 +688,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s | @@ -688,6 +688,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s | ||
688 | resp.Data.IsNew = initdata.IsNew | 688 | resp.Data.IsNew = initdata.IsNew |
689 | resp.Data.Issignshow = initdata.SignShow | 689 | resp.Data.Issignshow = initdata.SignShow |
690 | resp.Data.Leftredbagnum = DAILYFETCHREDBAGNUMLIMIT - initdata.FetchRdBagNum | 690 | resp.Data.Leftredbagnum = DAILYFETCHREDBAGNUMLIMIT - initdata.FetchRdBagNum |
691 | + resp.Data.Curtime = int(time.Now().Unix()) | ||
691 | 692 | ||
692 | err := SaveUserInfo(&initdata, uniqueuid) | 693 | err := SaveUserInfo(&initdata, uniqueuid) |
693 | logger.Info("InitUserInfoddddd uinfo=%+v", initdata) | 694 | logger.Info("InitUserInfoddddd uinfo=%+v", initdata) |
@@ -982,6 +983,7 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR | @@ -982,6 +983,7 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR | ||
982 | resp.Data.IsNew = data.IsNew | 983 | resp.Data.IsNew = data.IsNew |
983 | resp.Data.Issignshow = data.SignShow | 984 | resp.Data.Issignshow = data.SignShow |
984 | resp.Data.Leftredbagnum = DAILYFETCHREDBAGNUMLIMIT - data.FetchRdBagNum | 985 | resp.Data.Leftredbagnum = DAILYFETCHREDBAGNUMLIMIT - data.FetchRdBagNum |
986 | + resp.Data.Curtime = int(time.Now().Unix()) | ||
985 | return nil | 987 | return nil |
986 | } | 988 | } |
987 | 989 |
src/HttpServer/logic/httpserver.go
@@ -77,6 +77,7 @@ func startServerHttpServe() { | @@ -77,6 +77,7 @@ func startServerHttpServe() { | ||
77 | http.HandleFunc("/sixstar/getdata", Getdata) //获取数据 | 77 | http.HandleFunc("/sixstar/getdata", Getdata) //获取数据 |
78 | http.HandleFunc("/sixstar/uploadscore", Uploadscore) //上报当天积分 | 78 | http.HandleFunc("/sixstar/uploadscore", Uploadscore) //上报当天积分 |
79 | http.HandleFunc("/sixstar/queryrankinfo", Queryrankinfo) //获取排行榜信息 | 79 | http.HandleFunc("/sixstar/queryrankinfo", Queryrankinfo) //获取排行榜信息 |
80 | + http.HandleFunc("/sixstar/turntablebag", Turntablebag) //转盘红包 | ||
80 | 81 | ||
81 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 82 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
82 | CheckErr(err) | 83 | CheckErr(err) |
@@ -153,6 +154,27 @@ func Savadata(w http.ResponseWriter, r *http.Request) { | @@ -153,6 +154,27 @@ func Savadata(w http.ResponseWriter, r *http.Request) { | ||
153 | HandlerSavadata(w, s, Uuid) | 154 | HandlerSavadata(w, s, Uuid) |
154 | } | 155 | } |
155 | 156 | ||
157 | +func Turntablebag(w http.ResponseWriter, r *http.Request) { | ||
158 | + | ||
159 | + Uuid := 0 | ||
160 | + if len(r.Header) > 0 { | ||
161 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
162 | + } | ||
163 | + | ||
164 | + if Uuid == 0 { | ||
165 | + SetHeader(w) | ||
166 | + //logger.Error("Uuid is nil!") | ||
167 | + return | ||
168 | + } | ||
169 | + result, _ := ioutil.ReadAll(r.Body) | ||
170 | + r.Body.Close() | ||
171 | + | ||
172 | + s := string(result) | ||
173 | + logger.Info("Turntablebag , body:%v,uuid=%v", s, Uuid) | ||
174 | + | ||
175 | + HandlerTurntablebag(w, s, Uuid) | ||
176 | +} | ||
177 | + | ||
156 | func Queryrankinfo(w http.ResponseWriter, r *http.Request) { | 178 | func Queryrankinfo(w http.ResponseWriter, r *http.Request) { |
157 | 179 | ||
158 | Uuid := 0 | 180 | Uuid := 0 |
src/HttpServer/logic/logic.go
@@ -800,6 +800,54 @@ func HandlerUploadscore(w http.ResponseWriter, data string, uuid int) { | @@ -800,6 +800,54 @@ func HandlerUploadscore(w http.ResponseWriter, data string, uuid int) { | ||
800 | fmt.Fprint(w, string(respstr)) | 800 | fmt.Fprint(w, string(respstr)) |
801 | } | 801 | } |
802 | 802 | ||
803 | +func HandlerTurntablebag(w http.ResponseWriter, data string, uuid int) { | ||
804 | + SetHeader(w) | ||
805 | + var resp TurntablebagResp | ||
806 | + resp.Code = 0 | ||
807 | + resp.Message = "success" | ||
808 | + var rdata TurntablebagReq | ||
809 | + err := json.Unmarshal([]byte(data), &rdata) | ||
810 | + for { | ||
811 | + if err != nil { | ||
812 | + logger.Info("json decode HandlerTurntablebag data failed:%v,for:%v", err, data) | ||
813 | + resp.Message = "网络错误" | ||
814 | + resp.Code = ERROR_JSONUNMASH_ERROR | ||
815 | + break | ||
816 | + } | ||
817 | + | ||
818 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | ||
819 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | ||
820 | + uinfo, err := GetUserInfo(uniqueuuid) | ||
821 | + if err != nil || uinfo == nil { | ||
822 | + logger.Error("redis failed err=%v", err) | ||
823 | + resp.Message = "服务器错误" | ||
824 | + resp.Code = ERROR_SRV_ERROR | ||
825 | + break | ||
826 | + } | ||
827 | + | ||
828 | + goldnum, _, err := AddCoinToSdk(uuid, rdata.Num, rdata.Gameid, rdata.Channel, 104) | ||
829 | + if err != nil { | ||
830 | + logger.Error("AddCoinToSdk failed rdata=%v", rdata) | ||
831 | + resp.Message = "网络错误" | ||
832 | + resp.Code = ERROR_SRV_ERROR | ||
833 | + break | ||
834 | + } | ||
835 | + uinfo.RealGold = goldnum | ||
836 | + | ||
837 | + resp.Data.Walletgold = goldnum | ||
838 | + resp.Data.Getgoldnum = rdata.Num | ||
839 | + //加入排行榜 | ||
840 | + SaveUserInfo(uinfo, uniqueuuid) | ||
841 | + | ||
842 | + resp.Code = ERROR_OK | ||
843 | + break | ||
844 | + } | ||
845 | + | ||
846 | + //回包 | ||
847 | + respstr, _ := json.Marshal(&resp) | ||
848 | + fmt.Fprint(w, string(respstr)) | ||
849 | +} | ||
850 | + | ||
803 | func HandlerSavadata(w http.ResponseWriter, data string, uuid int) { | 851 | func HandlerSavadata(w http.ResponseWriter, data string, uuid int) { |
804 | SetHeader(w) | 852 | SetHeader(w) |
805 | var resp SavadataResp | 853 | var resp SavadataResp |