Commit f9dd70bcb58942edb71380a141a72ad8800e4243
1 parent
0b83ec05
Exists in
master
提交相关接口
Showing
4 changed files
with
434 additions
and
6 deletions
Show diff stats
src/HttpServer/logic/datadef.go
... | ... | @@ -3,15 +3,12 @@ package logic |
3 | 3 | |
4 | 4 | |
5 | 5 | type UserLoginReq struct { |
6 | - Fromid int `json:"fromid"` | |
7 | - Sharetype int `json:"sharetype"` | |
8 | 6 | Gameid string `json:"gameid"` |
9 | 7 | Channel string `json:"channel"` |
10 | 8 | } |
11 | 9 | |
12 | 10 | type UserLoginData struct { |
13 | 11 | Walletgold int `json:"walletgold"` |
14 | - Leftredbagcnt int `json:"leftredbagcnt"` | |
15 | 12 | } |
16 | 13 | |
17 | 14 | type UserLoginResp struct { |
... | ... | @@ -20,6 +17,68 @@ type UserLoginResp struct { |
20 | 17 | Data UserLoginData `json:"data"` |
21 | 18 | } |
22 | 19 | |
20 | +type GetuserdataReq struct { | |
21 | + Gameid string `json:"gameid"` | |
22 | + Channel string `json:"channel"` | |
23 | +} | |
24 | + | |
25 | +type GetuserdataData struct { | |
26 | + Walletgold int `json:"walletgold"` | |
27 | + Nowtime int `json:"nowtime"` | |
28 | + | |
29 | +} | |
30 | + | |
31 | +type GetuserdataResp struct { | |
32 | + Code int `json:"code"` | |
33 | + Message string `json:"message"` | |
34 | + Data GetuserdataData `json:"data"` | |
35 | +} | |
36 | + | |
37 | +type CommReq struct { | |
38 | + Gameid string `json:"gameid"` | |
39 | + Channel string `json:"channel"` | |
40 | +} | |
41 | + | |
42 | +type QuerdrawinfoResp struct { | |
43 | + Code int `json:"code"` | |
44 | + Message string `json:"message"` | |
45 | + Data WithDrawInfo `json:"data"` | |
46 | +} | |
47 | + | |
48 | +type GetcashReq struct { | |
49 | + Gameid string `json:"gameid"` | |
50 | + Channel string `json:"channel"` | |
51 | + Money float32 `json:"money"` | |
52 | + Openid string `json:"openid"` | |
53 | + Nickname string `json:"nickname"` | |
54 | + Headurl string `json:"headurl"` | |
55 | + Ver string `json:"ver"` | |
56 | + Ctype int `json:"ctype"` | |
57 | +} | |
58 | +type GetcashData struct { | |
59 | + Walletgold int `json:"walletgold"` | |
60 | +} | |
61 | +type GetcashResp struct { | |
62 | + Code int `json:"code"` | |
63 | + Message string `json:"message"` | |
64 | + Data GetcashData `json:"data"` | |
65 | +} | |
66 | + | |
67 | +type WithDrawList struct { | |
68 | + Withdata []WithDrawRecord `json:"withdata"` | |
69 | +} | |
70 | + | |
71 | +type GetcashrecordReq struct { | |
72 | + Gameid string `json:"gameid"` | |
73 | + Channel string `json:"channel"` | |
74 | +} | |
75 | + | |
76 | +type GetcashrecordResp struct { | |
77 | + Code int `json:"code"` | |
78 | + Message string `json:"message"` | |
79 | + Data WithDrawList `json:"data"` | |
80 | +} | |
81 | + | |
23 | 82 | //////////////////////////////////////////////////////////////////////////////////////// |
24 | 83 | |
25 | 84 | type GetCashListResp struct { | ... | ... |
src/HttpServer/logic/function.go
... | ... | @@ -10,6 +10,7 @@ import ( |
10 | 10 | "encoding/hex" |
11 | 11 | "encoding/json" |
12 | 12 | "errors" |
13 | + "fmt" | |
13 | 14 | "io/ioutil" |
14 | 15 | "net/http" |
15 | 16 | "sort" |
... | ... | @@ -50,6 +51,72 @@ func GetUserInfo(uniqueid string) (*UserData, error) { |
50 | 51 | return &tmp, nil |
51 | 52 | } |
52 | 53 | |
54 | +func (uinfo *UserData) GetSpecialWithDrawData(money float32) (int, *WithDrawDesc) { | |
55 | + //处理提现状态 | |
56 | + for k, val := range uinfo.WithDraw.SpecialCashdata { | |
57 | + if val.Cnum == money { | |
58 | + return k, &val | |
59 | + } | |
60 | + } | |
61 | + return -1, nil | |
62 | +} | |
63 | + | |
64 | +func (uinfo *UserData) GetWithDrawData(money float32) (int, *WithDrawDesc) { | |
65 | + //处理提现状态 | |
66 | + for k, val := range uinfo.WithDraw.Cashdata { | |
67 | + if val.Cnum == money { | |
68 | + return k, &val | |
69 | + } | |
70 | + } | |
71 | + return -1, nil | |
72 | +} | |
73 | + | |
74 | +func HandlerSyncuserdata(w http.ResponseWriter, data string, uuid int) { | |
75 | + SetHeader(w) | |
76 | + var resp GetuserdataResp | |
77 | + resp.Code = 0 | |
78 | + var rdata GetuserdataReq | |
79 | + err := json.Unmarshal([]byte(data), &rdata) | |
80 | + for { | |
81 | + if err != nil { | |
82 | + logger.Info("json decode HandlerGetuserdata data failed:%v,for:%v", err, data) | |
83 | + resp.Message = "json解析错误" | |
84 | + resp.Code = 1 | |
85 | + break | |
86 | + } | |
87 | + | |
88 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | |
89 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | |
90 | + data, err := GetUserInfo(uniqueuuid) | |
91 | + if err != nil || data == nil { | |
92 | + resp.Code = 1 | |
93 | + resp.Message = "ERROR_SRV_ERROR" | |
94 | + break | |
95 | + } | |
96 | + | |
97 | + //此处处理一下从sdk拉取钱包金币数量 | |
98 | + gold, err := GetCoinFromSdk(uuid, rdata.Gameid, rdata.Channel) | |
99 | + if err == nil { | |
100 | + data.RealGold = gold | |
101 | + } else { | |
102 | + logger.Error("GetCoinFromSdk failed err=%v", err) | |
103 | + } | |
104 | + | |
105 | + resp.Data.Walletgold = data.RealGold | |
106 | + resp.Data.Nowtime = int(time.Now().Unix()) | |
107 | + SaveUserInfo(data, uniqueuuid) | |
108 | + | |
109 | + resp.Code = 0 | |
110 | + break | |
111 | + } | |
112 | + | |
113 | + //回包 | |
114 | + respstr, _ := json.Marshal(&resp) | |
115 | + fmt.Fprint(w, string(respstr)) | |
116 | + | |
117 | + logger.Info("###HandlerSyncuserdata###rdata:%v", string(respstr)) | |
118 | +} | |
119 | + | |
53 | 120 | |
54 | 121 | func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid string) error { |
55 | 122 | |
... | ... | @@ -107,7 +174,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s |
107 | 174 | initdata.WithDraw.SpecialCashdata = append(initdata.WithDraw.SpecialCashdata, tmp) |
108 | 175 | } |
109 | 176 | |
110 | - resp.Data.Leftredbagcnt = initdata.WatchAddsTime | |
177 | + //resp.Data.Leftredbagcnt = initdata.WatchAddsTime | |
111 | 178 | resp.Data.Walletgold = initdata.RealGold |
112 | 179 | |
113 | 180 | ... | ... |
src/HttpServer/logic/httpserver.go
... | ... | @@ -36,7 +36,11 @@ func CheckErr(err error) { |
36 | 36 | func startServerHttpServe() { |
37 | 37 | |
38 | 38 | //---------------------------------------------------------------------------------------- |
39 | - http.HandleFunc("/eliminatestar/login", UserLogin) //登录 | |
39 | + http.HandleFunc("/brainhole/login", UserLogin) //登录 | |
40 | + http.HandleFunc("/brainhole/syncuserdata", Syncuserdata) //同步完结数据 | |
41 | + http.HandleFunc("/brainhole/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 | |
42 | + http.HandleFunc("/brainhole/getcash", Getcash) //提现 | |
43 | + http.HandleFunc("/brainhole/getcashrecord", Getcashrecord) //提现记录列表 | |
40 | 44 | |
41 | 45 | |
42 | 46 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
... | ... | @@ -44,8 +48,90 @@ func startServerHttpServe() { |
44 | 48 | } |
45 | 49 | |
46 | 50 | |
51 | +func Querdrawinfo(w http.ResponseWriter, r *http.Request) { | |
47 | 52 | |
53 | + Uuid := 0 | |
54 | + if len(r.Header) > 0 { | |
55 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
56 | + } | |
57 | + | |
58 | + if Uuid == 0 { | |
59 | + SetHeader(w) | |
60 | + //logger.Error("Uuid is nil!") | |
61 | + return | |
62 | + } | |
63 | + result, _ := ioutil.ReadAll(r.Body) | |
64 | + r.Body.Close() | |
65 | + | |
66 | + s := string(result) | |
67 | + logger.Info("Querdrawinfo , body:%v,uuid=%v", s, Uuid) | |
68 | + | |
69 | + HandlerQuerdrawinfo(w, s, Uuid) | |
70 | +} | |
71 | + | |
72 | +func Getcash(w http.ResponseWriter, r *http.Request) { | |
73 | + | |
74 | + Uuid := 0 | |
75 | + if len(r.Header) > 0 { | |
76 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
77 | + } | |
78 | + | |
79 | + if Uuid == 0 { | |
80 | + SetHeader(w) | |
81 | + //logger.Error("Uuid is nil!") | |
82 | + return | |
83 | + } | |
84 | + result, _ := ioutil.ReadAll(r.Body) | |
85 | + r.Body.Close() | |
86 | + | |
87 | + s := string(result) | |
88 | + logger.Info("Getcash , body:%v,uuid=%v", s, Uuid) | |
89 | + | |
90 | + HandlerGetcash(w, s, Uuid) | |
91 | +} | |
92 | + | |
93 | +func Getcashrecord(w http.ResponseWriter, r *http.Request) { | |
48 | 94 | |
95 | + Uuid := 0 | |
96 | + if len(r.Header) > 0 { | |
97 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
98 | + } | |
99 | + | |
100 | + if Uuid == 0 { | |
101 | + SetHeader(w) | |
102 | + //logger.Error("Uuid is nil!") | |
103 | + return | |
104 | + } | |
105 | + result, _ := ioutil.ReadAll(r.Body) | |
106 | + r.Body.Close() | |
107 | + | |
108 | + s := string(result) | |
109 | + logger.Info("Getcashrecord , body:%v,uuid=%v", s, Uuid) | |
110 | + | |
111 | + HandlerGetcashrecord(w, s, Uuid) | |
112 | +} | |
113 | + | |
114 | + | |
115 | +func Syncuserdata(w http.ResponseWriter, r *http.Request) { | |
116 | + | |
117 | + Uuid := 0 | |
118 | + if len(r.Header) > 0 { | |
119 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | |
120 | + } | |
121 | + | |
122 | + if Uuid == 0 { | |
123 | + SetHeader(w) | |
124 | + //logger.Error("Uuid is nil!") | |
125 | + return | |
126 | + } | |
127 | + result, _ := ioutil.ReadAll(r.Body) | |
128 | + r.Body.Close() | |
129 | + | |
130 | + s := string(result) | |
131 | + logger.Info("Syncuserdata , body:%v,uuid=%v", s, Uuid) | |
132 | + | |
133 | + HandlerSyncuserdata(w, s, Uuid) | |
134 | +} | |
49 | 135 | |
50 | 136 | func UserLogin(w http.ResponseWriter, r *http.Request) { |
51 | 137 | ... | ... |
src/HttpServer/logic/logic.go
... | ... | @@ -11,6 +11,222 @@ import ( |
11 | 11 | "time" |
12 | 12 | ) |
13 | 13 | |
14 | +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uuid int) { | |
15 | + SetHeader(w) | |
16 | + var resp QuerdrawinfoResp | |
17 | + resp.Code = 0 | |
18 | + var rdata CommReq | |
19 | + err := json.Unmarshal([]byte(data), &rdata) | |
20 | + for { | |
21 | + | |
22 | + if err != nil { | |
23 | + logger.Info("json decode HandlerQuerdrawinfo data failed:%v,for:%v", err, data) | |
24 | + resp.Message = "json解析错误" | |
25 | + resp.Code = 1 | |
26 | + break | |
27 | + } | |
28 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | |
29 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | |
30 | + uinfo, err := GetUserInfo(uniqueuuid) | |
31 | + if err != nil || uinfo == nil { | |
32 | + logger.Error("redis failed err=%v", err) | |
33 | + resp.Message = "服务器错误" | |
34 | + resp.Code = 1 | |
35 | + break | |
36 | + } | |
37 | + | |
38 | + //返回 | |
39 | + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...) | |
40 | + resp.Data.SpecialCashdata = append(resp.Data.SpecialCashdata, uinfo.WithDraw.SpecialCashdata...) | |
41 | + | |
42 | + resp.Code = 0 | |
43 | + break | |
44 | + } | |
45 | + | |
46 | + //回包 | |
47 | + respstr, _ := json.Marshal(&resp) | |
48 | + fmt.Fprint(w, string(respstr)) | |
49 | + | |
50 | +} | |
51 | + | |
52 | +func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { | |
53 | + SetHeader(w) | |
54 | + var resp GetcashResp | |
55 | + resp.Code = 0 | |
56 | + var rdata GetcashReq | |
57 | + err := json.Unmarshal([]byte(data), &rdata) | |
58 | + for { | |
59 | + if err != nil { | |
60 | + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data) | |
61 | + resp.Message = "json解析错误" | |
62 | + resp.Code = 1 | |
63 | + break | |
64 | + } | |
65 | + | |
66 | + | |
67 | + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 | |
68 | + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel | |
69 | + uinfo, err := GetUserInfo(uniqueuuid) | |
70 | + if err != nil || uinfo == nil { | |
71 | + logger.Error("redis failed err=%v", err) | |
72 | + resp.Message = "服务器错误" | |
73 | + resp.Code = 1 | |
74 | + break | |
75 | + } | |
76 | + | |
77 | + drawnum := int(rdata.Money * 100) | |
78 | + //需要判断一下金币是否足够 | |
79 | + if drawnum*100 > uinfo.RealGold { | |
80 | + logger.Error("gold nor enough failed err=%v", err) | |
81 | + resp.Message = "提现金币不足" | |
82 | + resp.Code = 2 | |
83 | + break | |
84 | + } | |
85 | + | |
86 | + //需要处理一下提现级别 | |
87 | + | |
88 | + index := 0 | |
89 | + var info *WithDrawDesc | |
90 | + if rdata.Ctype == 1 { | |
91 | + index, info = uinfo.GetWithDrawData(rdata.Money) | |
92 | + } else { | |
93 | + index, info = uinfo.GetSpecialWithDrawData(rdata.Money) | |
94 | + } | |
95 | + | |
96 | + if index == -1 || info == nil { | |
97 | + logger.Error("AddWithDrawList failed err=%v", err) | |
98 | + resp.Message = "网络错误" | |
99 | + resp.Code = 1 | |
100 | + break | |
101 | + } | |
102 | + | |
103 | + if uinfo.Lv < info.Limitlv { | |
104 | + logger.Error("AddWithDrawList failed err=%v", err) | |
105 | + resp.Message = "完成日常任务可以提升人物等级哦~" | |
106 | + resp.Code = 3 | |
107 | + break | |
108 | + } | |
109 | + | |
110 | + if info.Isnew == 0 { | |
111 | + logger.Error("AddWithDrawList failed err=%v", err) | |
112 | + resp.Message = "新人专享只能提取一次" | |
113 | + resp.Code = 4 | |
114 | + break | |
115 | + } | |
116 | + | |
117 | + if info.Preisfind == 0 { | |
118 | + logger.Error("HandlerGetcash Preisfind err=%v", err) | |
119 | + resp.Message = "请先完成前一档提现" | |
120 | + resp.Code = 5 | |
121 | + break | |
122 | + } | |
123 | + | |
124 | + //普通提现需要判断前置条件 | |
125 | + if rdata.Ctype == 1 { | |
126 | + //判断一下前置条件的下一档 | |
127 | + if index == len(uinfo.WithDraw.Cashdata)-1 { | |
128 | + //最后一档了不用处理 | |
129 | + } else { | |
130 | + if index < len(uinfo.WithDraw.Cashdata)-1 { | |
131 | + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1 | |
132 | + } | |
133 | + } | |
134 | + } | |
135 | + | |
136 | + //如果是2.2.7版本开启提现次数限制 | |
137 | + if rdata.Ver == "2.2.7" && uinfo.GetCashCnt > 0 { | |
138 | + logger.Error("HandlerGetcash GetCashCnt err=%v", err) | |
139 | + resp.Message = "当天已经提现过了,请明天再来" | |
140 | + resp.Code = 6 | |
141 | + break | |
142 | + } | |
143 | + | |
144 | + if uinfo.SumLoginDay < info.Day { | |
145 | + logger.Error("HandlerGetcash GetCashCnt err=%v", err) | |
146 | + resp.Message = "累计登陆天数不足" | |
147 | + resp.Code = 7 | |
148 | + break | |
149 | + } | |
150 | + | |
151 | + //2.2.5版本开启自动审核 | |
152 | + checkcoin := 2 | |
153 | + if rdata.Ver == "2.2.5" || rdata.Ver == "2.2.6" || rdata.Ver == "2.2.7" { | |
154 | + logger.Info("HandlerGetcash autocheckcoin") | |
155 | + if drawnum <= 150 { | |
156 | + //1.5挡位以下不需要审核 | |
157 | + checkcoin = 1 //临时关闭u | |
158 | + } | |
159 | + } | |
160 | + | |
161 | + gold, err := GetCashFromSDK(uuid, drawnum, rdata.Gameid, rdata.Channel, rdata.Openid, rdata.Nickname, rdata.Headurl, rdata.Ver, checkcoin) | |
162 | + if err != nil { | |
163 | + logger.Error("GetCashFromSDK failed err=%v", err) | |
164 | + resp.Message = "从后台提现失败了" | |
165 | + resp.Code = 8 | |
166 | + break | |
167 | + } | |
168 | + | |
169 | + | |
170 | + uinfo.GetCashCnt++ | |
171 | + //如果是前六挡 | |
172 | + if info.Cid <= 6 && rdata.Ctype == 1 { | |
173 | + uinfo.WithDraw.Cashdata[index].Isnew = 0 | |
174 | + } | |
175 | + if rdata.Ctype == 2 { | |
176 | + uinfo.WithDraw.SpecialCashdata[index].Isnew = 0 | |
177 | + } | |
178 | + | |
179 | + uinfo.RealGold = gold | |
180 | + //uinfo.RealGold -= drawnum * 100 | |
181 | + | |
182 | + resp.Data.Walletgold = uinfo.RealGold | |
183 | + SaveUserInfo(uinfo, uniqueuuid) | |
184 | + | |
185 | + resp.Code = 0 | |
186 | + break | |
187 | + } | |
188 | + | |
189 | + //回包 | |
190 | + respstr, _ := json.Marshal(&resp) | |
191 | + fmt.Fprint(w, string(respstr)) | |
192 | + | |
193 | +} | |
194 | + | |
195 | +func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) { | |
196 | + SetHeader(w) | |
197 | + var resp GetcashrecordResp | |
198 | + resp.Code = 0 | |
199 | + var rdata GetcashrecordReq | |
200 | + err := json.Unmarshal([]byte(data), &rdata) | |
201 | + for { | |
202 | + if err != nil { | |
203 | + logger.Info("json decode HandlerGetcashrecord data failed:%v,for:%v", err, data) | |
204 | + resp.Message = "json解析错误" | |
205 | + resp.Code = 1 | |
206 | + break | |
207 | + } | |
208 | + | |
209 | + list, err := GetCashList(uuid, rdata.Gameid, rdata.Channel, 0, 100) | |
210 | + if err != nil { | |
211 | + logger.Error("HandlerGetcashrecord failed err=%v", err) | |
212 | + resp.Message = "服务器错误" | |
213 | + resp.Code = 2 | |
214 | + break | |
215 | + } | |
216 | + if list != nil { | |
217 | + resp.Data.Withdata = append(resp.Data.Withdata, *list...) | |
218 | + } | |
219 | + | |
220 | + resp.Code = 0 | |
221 | + break | |
222 | + } | |
223 | + | |
224 | + //回包 | |
225 | + respstr, _ := json.Marshal(&resp) | |
226 | + fmt.Fprint(w, string(respstr)) | |
227 | + | |
228 | +} | |
229 | + | |
14 | 230 | func HandlerLogin(w http.ResponseWriter, data string, uuid int) { |
15 | 231 | SetHeader(w) |
16 | 232 | |
... | ... | @@ -157,7 +373,7 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR |
157 | 373 | SaveUserInfo(data, uniqueuid) |
158 | 374 | |
159 | 375 | resp.Data.Walletgold = data.RealGold |
160 | - resp.Data.Leftredbagcnt = data.WatchAddsTime | |
376 | + //resp.Data.Leftredbagcnt = data.WatchAddsTime | |
161 | 377 | |
162 | 378 | return nil |
163 | 379 | } |
164 | 380 | \ No newline at end of file | ... | ... |