Commit aa959ad9864768010913a0448f7211645a540791
1 parent
63a5d683
Exists in
master
and in
4 other branches
提现相关接口
Showing
6 changed files
with
329 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/datadef.go
@@ -77,6 +77,36 @@ type DrawguangoldResp struct { | @@ -77,6 +77,36 @@ type DrawguangoldResp struct { | ||
77 | Data DrawguangoldData `json:"data"` | 77 | Data DrawguangoldData `json:"data"` |
78 | } | 78 | } |
79 | 79 | ||
80 | +type QuerdrawinfoResp struct { | ||
81 | + Code int `json:"code"` | ||
82 | + Message string `json:"message"` | ||
83 | + Data WithDrawInfo `json:"data"` | ||
84 | +} | ||
85 | + | ||
86 | +type GetcashReq struct { | ||
87 | + Gameid string `json:"gameid"` | ||
88 | + Channel string `json:"channel"` | ||
89 | + Money float32 `json:"money"` | ||
90 | + Openid string `json:"openid"` | ||
91 | + Nickname string `json:"nickname"` | ||
92 | + Headurl string `json:"headurl"` | ||
93 | +} | ||
94 | + | ||
95 | +type GetcashData struct { | ||
96 | + Walletgold int `json:"walletgold"` | ||
97 | +} | ||
98 | +type GetcashResp struct { | ||
99 | + Code int `json:"code"` | ||
100 | + Message string `json:"message"` | ||
101 | + Data GetcashData `json:"data"` | ||
102 | +} | ||
103 | + | ||
104 | +type GetcashrecordResp struct { | ||
105 | + Code int `json:"code"` | ||
106 | + Message string `json:"message"` | ||
107 | + Data WithDrawList `json:"data"` | ||
108 | +} | ||
109 | + | ||
80 | //********************************************************************************************************** | 110 | //********************************************************************************************************** |
81 | 111 | ||
82 | type TaskInfo struct { | 112 | type TaskInfo struct { |
@@ -87,6 +117,29 @@ type AchieveMentInfo struct { | @@ -87,6 +117,29 @@ type AchieveMentInfo struct { | ||
87 | 117 | ||
88 | } | 118 | } |
89 | 119 | ||
120 | + | ||
121 | +type WithDrawList struct { | ||
122 | + Withdata []WithDrawRecord `json:"withdata"` | ||
123 | +} | ||
124 | + | ||
125 | +//提现记录结构 | ||
126 | +type WithDrawRecord struct { | ||
127 | + Withdrawtime int `json:"wichdrawtime"` | ||
128 | + Withdrawmoney float32 `json:"withdrawmoney"` | ||
129 | +} | ||
130 | + | ||
131 | +type WithDrawInfo struct { | ||
132 | + Cashdata []WithDrawDesc `json:"cashdata"` | ||
133 | +} | ||
134 | + | ||
135 | +type WithDrawDesc struct { | ||
136 | + Cid int `json:"cid"` | ||
137 | + Cnum float32 `json:"cnum"` | ||
138 | + Isnew int `json:"isnew"` | ||
139 | + Limitlv int `json:"limitlv"` | ||
140 | + Preisfind int `json:"preisfind"` | ||
141 | +} | ||
142 | + | ||
90 | //玩家数据 | 143 | //玩家数据 |
91 | type UserData struct { | 144 | type UserData struct { |
92 | Userid int //玩家id | 145 | Userid int //玩家id |
@@ -98,6 +151,7 @@ type UserData struct { | @@ -98,6 +151,7 @@ type UserData struct { | ||
98 | LastLoginTime int //上次登陆时间 | 151 | LastLoginTime int //上次登陆时间 |
99 | ContinueLoginDay int //连续登录天数 | 152 | ContinueLoginDay int //连续登录天数 |
100 | GetFromGuanCnt int //当天从存钱款提取金币次数 | 153 | GetFromGuanCnt int //当天从存钱款提取金币次数 |
154 | + WithDraw WithDrawInfo //提现记录信息 | ||
101 | Task TaskInfo //玩家任务完成相关信息 | 155 | Task TaskInfo //玩家任务完成相关信息 |
102 | Achieve AchieveMentInfo //玩家成就完成相关数据 | 156 | Achieve AchieveMentInfo //玩家成就完成相关数据 |
103 | } | 157 | } |
src/HttpServer/logic/errordef.go
@@ -10,4 +10,7 @@ const ( | @@ -10,4 +10,7 @@ const ( | ||
10 | ERROR_GUANGOLD_NOTENOUGH =5 //存钱罐金币不足 | 10 | ERROR_GUANGOLD_NOTENOUGH =5 //存钱罐金币不足 |
11 | ERROR_DRAWGUAN_FAILED =6 //从存钱罐提取金币不满足限制 | 11 | ERROR_DRAWGUAN_FAILED =6 //从存钱罐提取金币不满足限制 |
12 | ERROR_DRAWGOLD_FAILED =7 //从存钱罐提取金币失败了 | 12 | ERROR_DRAWGOLD_FAILED =7 //从存钱罐提取金币失败了 |
13 | + ERROR_GETCASH_FAILED =8 //从后台提现失败了 | ||
14 | + ERROR_GETCASH_GOLDNOTENOUGH_FAILED =9 //提现金币不足 | ||
15 | + ERROR_ADDWITHDRAW_LISTFAILED =10 //添加提现记录失败 | ||
13 | ) | 16 | ) |
14 | \ No newline at end of file | 17 | \ No newline at end of file |
src/HttpServer/logic/function.go
@@ -56,6 +56,23 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) error{ | @@ -56,6 +56,23 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) error{ | ||
56 | initdata.RealGold = 0 | 56 | initdata.RealGold = 0 |
57 | initdata.WatchAddsTime =WATCH_ADD_DAY_LIMIT | 57 | initdata.WatchAddsTime =WATCH_ADD_DAY_LIMIT |
58 | 58 | ||
59 | + for _,val := range jsonconf.GetJsonConf().WithDrawConfig { | ||
60 | + var tmp WithDrawDesc | ||
61 | + tmp.Cid = val.Id | ||
62 | + tmp.Cnum = val.Money | ||
63 | + if val.Isnew == 1 { | ||
64 | + tmp.Isnew = 1 | ||
65 | + }else { | ||
66 | + tmp.Isnew = 2 | ||
67 | + } | ||
68 | + tmp.Limitlv = val.Level | ||
69 | + if val.Id == 1 { | ||
70 | + tmp.Preisfind = 1 | ||
71 | + }else { | ||
72 | + tmp.Preisfind = 0 | ||
73 | + } | ||
74 | + } | ||
75 | + | ||
59 | resp.Data.Guangold = initdata.GuanGold | 76 | resp.Data.Guangold = initdata.GuanGold |
60 | resp.Data.Leftads = initdata.WatchAddsTime | 77 | resp.Data.Leftads = initdata.WatchAddsTime |
61 | resp.Data.Walletgold = initdata.RealGold | 78 | resp.Data.Walletgold = initdata.RealGold |
@@ -145,7 +162,73 @@ func GetUserData(uuid int, resp *UserLoginResp) error{ | @@ -145,7 +162,73 @@ func GetUserData(uuid int, resp *UserLoginResp) error{ | ||
145 | return nil | 162 | return nil |
146 | } | 163 | } |
147 | 164 | ||
165 | +//获取提现记录 | ||
166 | +func GetWithDrawList(uuid int) (*WithDrawList,error) { | ||
167 | + var list *WithDrawList | ||
168 | + list = nil | ||
169 | + liststr,err := redishandler.GetRedisClient().HGet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) | ||
170 | + if err != nil { | ||
171 | + return nil,err | ||
172 | + } | ||
173 | + err = json.Unmarshal([]byte(liststr),list) | ||
174 | + if err != nil { | ||
175 | + return nil,err | ||
176 | + } | ||
177 | + return list,nil | ||
178 | +} | ||
179 | + | ||
180 | +//添加提现记录 | ||
181 | +func AddWithDrawList(uuid int,data *WithDrawRecord) error { | ||
182 | + exist,err := redishandler.GetRedisClient().HExists(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) | ||
183 | + if err != nil { | ||
184 | + return err | ||
185 | + } | ||
186 | + if !exist { | ||
187 | + //添加新的记录 | ||
188 | + var tmp WithDrawList | ||
189 | + tmp.Withdata = append(tmp.Withdata,*data) | ||
190 | + | ||
191 | + savestr,err := json.Marshal(&tmp) | ||
192 | + if err != nil { | ||
193 | + return err | ||
194 | + } | ||
195 | + err = redishandler.GetRedisClient().HSet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid),string(savestr)) | ||
196 | + return err | ||
197 | + } | ||
198 | + | ||
199 | + /*liststr,err := redishandler.GetRedisClient().HGet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) | ||
200 | + if err != nil { | ||
201 | + return err | ||
202 | + } | ||
203 | + | ||
204 | + var list WithDrawList | ||
205 | + err = json.Unmarshal([]byte(liststr),&list) | ||
206 | + if err != nil { | ||
207 | + return err | ||
208 | + }*/ | ||
209 | + | ||
210 | + list,err := GetWithDrawList(uuid) | ||
211 | + if err != nil || list == nil{ | ||
212 | + return err | ||
213 | + } | ||
214 | + list.Withdata = append(list.Withdata,*data) | ||
215 | + savestr,err := json.Marshal(&list) | ||
216 | + if err != nil { | ||
217 | + return err | ||
218 | + } | ||
219 | + err = redishandler.GetRedisClient().HSet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid),string(savestr)) | ||
220 | + return err | ||
221 | + | ||
222 | + | ||
223 | + | ||
224 | +} | ||
225 | + | ||
148 | func AddCoinToSdk(uuid int,goldnum int,gameid string,channel string,atype int) (int,error) { | 226 | func AddCoinToSdk(uuid int,goldnum int,gameid string,channel string,atype int) (int,error) { |
149 | //暂时先不对接 接口调通遗憾对接后台 | 227 | //暂时先不对接 接口调通遗憾对接后台 |
150 | return 0,nil | 228 | return 0,nil |
229 | +} | ||
230 | + | ||
231 | +func GetCashFromSDK(uuid int,goldnum int,gameid ,channel,openid,nickname,headurl string) (int,error) { | ||
232 | + //先不接 | ||
233 | + return 0,nil | ||
151 | } | 234 | } |
152 | \ No newline at end of file | 235 | \ No newline at end of file |
src/HttpServer/logic/httpserver.go
@@ -43,10 +43,77 @@ func startServerHttpServe() { | @@ -43,10 +43,77 @@ func startServerHttpServe() { | ||
43 | http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 | 43 | http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 |
44 | http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 | 44 | http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 |
45 | http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 | 45 | http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 |
46 | + http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 | ||
47 | + http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 | ||
48 | + http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 | ||
46 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) | 49 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
47 | CheckErr(err) | 50 | CheckErr(err) |
48 | } | 51 | } |
49 | 52 | ||
53 | +func Getcashrecord(w http.ResponseWriter, r *http.Request) { | ||
54 | + | ||
55 | + Uuid := 0 | ||
56 | + if len(r.Header) > 0 { | ||
57 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
58 | + } | ||
59 | + | ||
60 | + if Uuid == 0 { | ||
61 | + SetHeader(w) | ||
62 | + //logger.Error("Uuid is nil!") | ||
63 | + return | ||
64 | + } | ||
65 | + result, _ := ioutil.ReadAll(r.Body) | ||
66 | + r.Body.Close() | ||
67 | + | ||
68 | + s := string(result) | ||
69 | + logger.Info("Getcashrecord , body:%v,uuid=%v", s, Uuid) | ||
70 | + | ||
71 | + HandlerGetcashrecord(w, s, Uuid) | ||
72 | +} | ||
73 | + | ||
74 | + | ||
75 | +func Getcash(w http.ResponseWriter, r *http.Request) { | ||
76 | + | ||
77 | + Uuid := 0 | ||
78 | + if len(r.Header) > 0 { | ||
79 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
80 | + } | ||
81 | + | ||
82 | + if Uuid == 0 { | ||
83 | + SetHeader(w) | ||
84 | + //logger.Error("Uuid is nil!") | ||
85 | + return | ||
86 | + } | ||
87 | + result, _ := ioutil.ReadAll(r.Body) | ||
88 | + r.Body.Close() | ||
89 | + | ||
90 | + s := string(result) | ||
91 | + logger.Info("Getcash , body:%v,uuid=%v", s, Uuid) | ||
92 | + | ||
93 | + HandlerGetcash(w, s, Uuid) | ||
94 | +} | ||
95 | + | ||
96 | + | ||
97 | +func Querdrawinfo(w http.ResponseWriter, r *http.Request) { | ||
98 | + | ||
99 | + Uuid := 0 | ||
100 | + if len(r.Header) > 0 { | ||
101 | + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) | ||
102 | + } | ||
103 | + | ||
104 | + if Uuid == 0 { | ||
105 | + SetHeader(w) | ||
106 | + //logger.Error("Uuid is nil!") | ||
107 | + return | ||
108 | + } | ||
109 | + result, _ := ioutil.ReadAll(r.Body) | ||
110 | + r.Body.Close() | ||
111 | + | ||
112 | + s := string(result) | ||
113 | + logger.Info("Querdrawinfo , body:%v,uuid=%v", s, Uuid) | ||
114 | + | ||
115 | + HandlerQuerdrawinfo(w, s, Uuid) | ||
116 | +} | ||
50 | 117 | ||
51 | func Drawguangold(w http.ResponseWriter, r *http.Request) { | 118 | func Drawguangold(w http.ResponseWriter, r *http.Request) { |
52 | 119 | ||
@@ -70,6 +137,8 @@ func Drawguangold(w http.ResponseWriter, r *http.Request) { | @@ -70,6 +137,8 @@ func Drawguangold(w http.ResponseWriter, r *http.Request) { | ||
70 | } | 137 | } |
71 | 138 | ||
72 | 139 | ||
140 | + | ||
141 | + | ||
73 | func Getguangold(w http.ResponseWriter, r *http.Request) { | 142 | func Getguangold(w http.ResponseWriter, r *http.Request) { |
74 | 143 | ||
75 | Uuid := 0 | 144 | Uuid := 0 |
src/HttpServer/logic/logic.go
@@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
9 | "fmt" | 9 | "fmt" |
10 | "net/http" | 10 | "net/http" |
11 | "strconv" | 11 | "strconv" |
12 | + "time" | ||
12 | ) | 13 | ) |
13 | 14 | ||
14 | 15 | ||
@@ -91,6 +92,124 @@ func HandlerWatchads(w http.ResponseWriter, data string, uuid int) { | @@ -91,6 +92,124 @@ func HandlerWatchads(w http.ResponseWriter, data string, uuid int) { | ||
91 | fmt.Fprint(w, string(respstr)) | 92 | fmt.Fprint(w, string(respstr)) |
92 | } | 93 | } |
93 | 94 | ||
95 | +func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { | ||
96 | + SetHeader(w) | ||
97 | + var resp GetcashResp | ||
98 | + resp.Code = 0 | ||
99 | + var rdata GetcashReq | ||
100 | + err := json.Unmarshal([]byte(data), &rdata) | ||
101 | + for { | ||
102 | + if err != nil { | ||
103 | + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data) | ||
104 | + resp.Message = "json解析错误" | ||
105 | + resp.Code = ERROR_JSONUNMASH_ERROR | ||
106 | + break | ||
107 | + } | ||
108 | + uinfo,err := GetUserInfo(uuid) | ||
109 | + if err != nil || uinfo == nil{ | ||
110 | + logger.Error("redis failed err=%v", err) | ||
111 | + resp.Message = "服务器错误" | ||
112 | + resp.Code = ERROR_SRV_ERROR | ||
113 | + break | ||
114 | + } | ||
115 | + | ||
116 | + drawnum := int(rdata.Money*100) | ||
117 | + //需要判断一下金币是否足够 | ||
118 | + if drawnum * 100 > uinfo.RealGold { | ||
119 | + logger.Error("gold nor enough failed err=%v", err) | ||
120 | + resp.Message = "提现金币不足" | ||
121 | + resp.Code = ERROR_GETCASH_GOLDNOTENOUGH_FAILED | ||
122 | + break | ||
123 | + } | ||
124 | + | ||
125 | + _,err = GetCashFromSDK(uuid,drawnum,rdata.Gameid,rdata.Channel,rdata.Openid,rdata.Nickname,rdata.Headurl) | ||
126 | + if err != nil { | ||
127 | + logger.Error("GetCashFromSDK failed err=%v", err) | ||
128 | + resp.Message = "从后台提现失败了" | ||
129 | + resp.Code = ERROR_GETCASH_FAILED | ||
130 | + break | ||
131 | + } | ||
132 | + | ||
133 | + uinfo.RealGold -= drawnum * 100 | ||
134 | + | ||
135 | + resp.Data.Walletgold = uinfo.RealGold | ||
136 | + SaveUserInfo(uinfo) | ||
137 | + | ||
138 | + //需要保存一下提现记录 | ||
139 | + data := new(WithDrawRecord) | ||
140 | + data.Withdrawmoney = rdata.Money | ||
141 | + data.Withdrawtime = int(time.Now().Unix()) | ||
142 | + err = AddWithDrawList(uuid,data) | ||
143 | + if err != nil { | ||
144 | + logger.Error("AddWithDrawList failed err=%v", err) | ||
145 | + resp.Message = "添加提现记录失败" | ||
146 | + resp.Code = ERROR_ADDWITHDRAW_LISTFAILED | ||
147 | + break | ||
148 | + } | ||
149 | + | ||
150 | + | ||
151 | + resp.Code = ERROR_OK | ||
152 | + break | ||
153 | + } | ||
154 | + | ||
155 | + //回包 | ||
156 | + respstr, _ := json.Marshal(&resp) | ||
157 | + fmt.Fprint(w, string(respstr)) | ||
158 | + | ||
159 | +} | ||
160 | + | ||
161 | + | ||
162 | + | ||
163 | +func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) { | ||
164 | + SetHeader(w) | ||
165 | + var resp GetcashrecordResp | ||
166 | + resp.Code = 0 | ||
167 | + for { | ||
168 | + list,err := GetWithDrawList(uuid) | ||
169 | + if err != nil || list == nil{ | ||
170 | + logger.Error("HandlerGetcashrecord failed err=%v", err) | ||
171 | + resp.Message = "服务器错误" | ||
172 | + resp.Code = ERROR_SRV_ERROR | ||
173 | + break | ||
174 | + } | ||
175 | + | ||
176 | + resp.Data.Withdata = append(resp.Data.Withdata,list.Withdata...) | ||
177 | + | ||
178 | + resp.Code = ERROR_OK | ||
179 | + break | ||
180 | + } | ||
181 | + | ||
182 | + //回包 | ||
183 | + respstr, _ := json.Marshal(&resp) | ||
184 | + fmt.Fprint(w, string(respstr)) | ||
185 | + | ||
186 | +} | ||
187 | + | ||
188 | +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uuid int) { | ||
189 | + SetHeader(w) | ||
190 | + var resp QuerdrawinfoResp | ||
191 | + resp.Code = 0 | ||
192 | + for { | ||
193 | + uinfo,err := GetUserInfo(uuid) | ||
194 | + if err != nil || uinfo == nil{ | ||
195 | + logger.Error("redis failed err=%v", err) | ||
196 | + resp.Message = "服务器错误" | ||
197 | + resp.Code = ERROR_SRV_ERROR | ||
198 | + break | ||
199 | + } | ||
200 | + | ||
201 | + //返回 | ||
202 | + resp.Data.Cashdata = append(resp.Data.Cashdata,uinfo.WithDraw.Cashdata...) | ||
203 | + | ||
204 | + resp.Code = ERROR_OK | ||
205 | + break | ||
206 | + } | ||
207 | + | ||
208 | + //回包 | ||
209 | + respstr, _ := json.Marshal(&resp) | ||
210 | + fmt.Fprint(w, string(respstr)) | ||
211 | + | ||
212 | +} | ||
94 | 213 | ||
95 | 214 | ||
96 | func HandlerDrawguangold(w http.ResponseWriter, data string, uuid int) { | 215 | func HandlerDrawguangold(w http.ResponseWriter, data string, uuid int) { |
src/common/redis/def.go