Commit 87e4d89f08934fdc22f6aed5b8746d5f541f7b42

Authored by 陆恒
1 parent 537b64ea
Exists in master

提交提现相关接口

src/HttpServer/logic/datadef.go
... ... @@ -263,14 +263,22 @@ type QuerydrawrewardResp struct {
263 263 Data QuerydrawrewardData `json:"data"`
264 264 }
265 265  
  266 +type QuerygetcashinfoData struct {
  267 + Logindaysum int `json:"logindaysum"`
  268 + Logindaycontinue int `json:"logindaycontinue"`
  269 + Cashdata []WithDrawDesc `json:"cashdata"`
  270 +}
  271 +
  272 +type QuerygetcashinfoResp struct {
  273 + Code int `json:"code"`
  274 + Message string `json:"message"`
  275 + Data QuerygetcashinfoData `json:"data"`
  276 +}
  277 +
266 278 type GetcashReq struct {
267   - Gameid string `json:"gameid"`
268   - Channel string `json:"channel"`
269   - Money float32 `json:"money"`
270   - Openid string `json:"openid"`
271   - Nickname string `json:"nickname"`
272   - Headurl string `json:"headurl"`
273   - Ver string `json:"ver"`
  279 + Money float32 `json:"money"`
  280 + Openid string `json:"openid"`
  281 + Ver string `json:"ver"`
274 282 }
275 283  
276 284 type CommReq struct {
... ...
src/HttpServer/logic/function.go
... ... @@ -377,6 +377,16 @@ func InitTaskAndAchievement(uuid int, channel string) error {
377 377 return nil
378 378 }
379 379  
  380 +func (uinfo *UserData) GetWithDrawData(money float32) (int, *WithDrawDesc) {
  381 + //处理提现状态
  382 + for k, val := range uinfo.WithDraw.Cashdata {
  383 + if val.Cnum == money {
  384 + return k, &val
  385 + }
  386 + }
  387 + return -1, nil
  388 +}
  389 +
380 390 func InitUserInfo(resp *UserLoginResp, uniqueuid, gameid, channel string, uuid int) error {
381 391  
382 392 var initdata UserData
... ... @@ -477,6 +487,173 @@ func GetUserSelfData(uniqueid string) (string, error) {
477 487 return data, nil
478 488 }
479 489  
  490 +func GetCashList(uuid int, gameid string, channel string, start int, number int) (*[]WithDrawRecord, error) {
  491 + SERVERKEY := conf.GetCoinConf().Key
  492 + /*if gameid == "1015" {
  493 + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015
  494 + }*/
  495 +
  496 + var paramlist []string
  497 + var params GetCashListDesc
  498 + params.Sign_type = "md5"
  499 + params.Gameid = gameid
  500 + params.Channel = channel
  501 + params.Uid = uuid
  502 + params.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  503 + params.Start = start
  504 + params.Number = number
  505 + signtypestr := "sign_type=" + params.Sign_type
  506 + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  507 + paramgameid := "gameid=" + gameid
  508 + pchannel := "channel=" + channel
  509 + puid := "uid=" + strconv.Itoa(uuid)
  510 + pstart := "start=" + strconv.Itoa(start)
  511 + pnumber := "number=" + strconv.Itoa(number)
  512 + paramlist = append(paramlist, signtypestr)
  513 + paramlist = append(paramlist, timestampstr)
  514 + paramlist = append(paramlist, paramgameid)
  515 + paramlist = append(paramlist, pchannel)
  516 + paramlist = append(paramlist, puid)
  517 + if start != 0 {
  518 + paramlist = append(paramlist, pstart)
  519 + }
  520 +
  521 + paramlist = append(paramlist, pnumber)
  522 +
  523 + sumparam := GettotalParam(paramlist)
  524 + //加serverkey
  525 + signsum := sumparam + SERVERKEY
  526 + logger.Info("GetCashList sumparam=%v", signsum)
  527 +
  528 + //进行hash
  529 + sign := GetHashValue(signsum)
  530 + params.Sign = sign
  531 +
  532 + bys, err := json.Marshal(&params)
  533 + if err != nil {
  534 + logger.Error("GetCashList failed=%v", err)
  535 + return nil, err
  536 + }
  537 + res, err := DoHttpPost(bys, "api/server/tixian/lst")
  538 + if err != nil {
  539 + logger.Error("GetCashList failed=%v", err)
  540 + return nil, err
  541 + }
  542 +
  543 + logger.Info("GetCashList res=%v", res)
  544 +
  545 + var resp GetCashListResp
  546 + err = json.Unmarshal([]byte(res), &resp)
  547 + if err != nil {
  548 + logger.Error("GetCoinFromSdk failed=%v", err)
  549 + return nil, err
  550 + }
  551 +
  552 + if resp.Code != "0" {
  553 + logger.Error("GetCoinFromSdk failed=%v", resp.Msg)
  554 + return nil, err
  555 + }
  556 + return &resp.Data, nil
  557 +}
  558 +
  559 +func GetCashFromSDK(uuid int, goldnum int, gameid, channel, openid, nickname, headurl, ver string, checkcoin int) (int, error) {
  560 +
  561 + SERVERKEY := conf.GetCoinConf().Key
  562 +
  563 + if goldnum == 0 || uuid == 0 || gameid == "" || channel == "" || openid == "" || ver == "" {
  564 + logger.Error("GetCashFromSDK param empty")
  565 + return 0, errors.New("param empty")
  566 + }
  567 + var paramlist []string
  568 + var params TixianDesc
  569 + params.Sign_type = "md5"
  570 + params.Gameid = gameid
  571 + params.Channel = channel
  572 + params.Uid = uuid
  573 + params.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  574 + params.Headurl = headurl
  575 + params.Money = goldnum
  576 + params.Openid = openid
  577 + params.Nickname = nickname
  578 + params.Typ = 6
  579 + params.Ver = ver
  580 + params.Editcoin = 1
  581 + params.Checkcoin = checkcoin
  582 + signtypestr := "sign_type=" + params.Sign_type
  583 + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  584 + paramgameid := "gameid=" + gameid
  585 + pchannel := "channel=" + channel
  586 + puid := "uid=" + strconv.Itoa(uuid)
  587 + phead := "headurl=" + headurl
  588 + pnickname := "nickname=" + nickname
  589 + popenid := "openid=" + openid
  590 + pmoney := "money=" + strconv.Itoa(goldnum)
  591 + ptype := "typ=" + "6" //微信
  592 + ped := "editcoin=1"
  593 + pcheco := "checkcoin=" + strconv.Itoa(checkcoin)
  594 + //pver := "ver=" + params.Ver
  595 + paramlist = append(paramlist, signtypestr)
  596 + paramlist = append(paramlist, timestampstr)
  597 + paramlist = append(paramlist, paramgameid)
  598 + paramlist = append(paramlist, pchannel)
  599 + paramlist = append(paramlist, puid)
  600 + if headurl != "" {
  601 + paramlist = append(paramlist, phead)
  602 + }
  603 + if nickname != "" {
  604 + paramlist = append(paramlist, pnickname)
  605 + }
  606 + paramlist = append(paramlist, popenid)
  607 + paramlist = append(paramlist, pmoney)
  608 + paramlist = append(paramlist, ptype)
  609 + paramlist = append(paramlist, ped)
  610 + paramlist = append(paramlist, pcheco)
  611 + //paramlist = append(paramlist, pver)
  612 +
  613 + sumparam := GettotalParam(paramlist)
  614 + //加serverkey
  615 + signsum := sumparam + SERVERKEY
  616 +
  617 + //进行hash
  618 + sign := GetHashValue(signsum)
  619 + params.Sign = sign
  620 +
  621 + bys, err := json.Marshal(&params)
  622 + if err != nil {
  623 + logger.Error("GetCashFromSDK failed=%v", err)
  624 + return 0, err
  625 + }
  626 + res, err := DoHttpPost(bys, "api/server/tixian")
  627 + logger.Info("GetCashFromSDK sumparam is:%v,sign is:%v", signsum, sign)
  628 + logger.Info("GetCashFromSDK sumparam param=%v", string(bys))
  629 + if err != nil {
  630 + logger.Error("GetCashFromSDK failed=%v", err)
  631 + return 0, err
  632 + }
  633 +
  634 + logger.Info("GetCashFromSDK res=%v", res)
  635 +
  636 + var resp GetCashResp
  637 + err = json.Unmarshal([]byte(res), &resp)
  638 + if err != nil {
  639 + logger.Error("GetCashFromSDK failed=%v", err)
  640 + return 0, err
  641 + }
  642 +
  643 + if resp.Code != "0" {
  644 + logger.Error("GetCashFromSDK failed=%v", resp.Msg)
  645 + return 0, errors.New(resp.Msg)
  646 + }
  647 +
  648 + //拉取一下新的金币值
  649 + newnum, err := GetCoinFromSdk(uuid, gameid, channel)
  650 + if err != nil {
  651 + logger.Error("GetCashFromSDK failed=%v", err)
  652 + return 0, err
  653 + }
  654 + return newnum, nil
  655 +}
  656 +
480 657 func AddCoinToSdk(uuid int, goldnum int, gameid string, channel string, atype int) (int, error) {
481 658 SERVERKEY := conf.GetCoinConf().Key
482 659 /*if gameid == "1015" {
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -59,6 +59,9 @@ func startServerHttpServe() {
59 59 http.HandleFunc("/russiaxiaoxiao/uploadhigestscore", Uploadhigestscore) //上报玩家历史最高分
60 60 http.HandleFunc("/russiaxiaoxiao/queryrankinfo", Queryrankinfo) //查询排行榜
61 61 http.HandleFunc("/russiaxiaoxiao/querydrawreward", Querydrawreward) //请求抽奖
  62 + http.HandleFunc("/russiaxiaoxiao/querygetcashinfo", Querdrawinfo) //请求提现档位数据
  63 + http.HandleFunc("/russiaxiaoxiao/getcash", Getcash) //请求提现
  64 + http.HandleFunc("/russiaxiaoxiao/getcashrecord", Getcashrecord) //请求提现记录
62 65  
63 66 //..........................................
64 67 /*http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据
... ... @@ -427,65 +430,83 @@ func Onlinentf(w http.ResponseWriter, r *http.Request) {
427 430  
428 431 func Getcashrecord(w http.ResponseWriter, r *http.Request) {
429 432  
  433 + gameid := ""
  434 + channel := ""
  435 + uniqueid := ""
430 436 Uuid := 0
431 437 if len(r.Header) > 0 {
432 438 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  439 + gameid = r.Header.Get("Gameid")
  440 + channel = r.Header.Get("Channel")
  441 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
433 442 }
434 443  
435 444 if Uuid == 0 {
436 445 SetHeader(w)
437   - //logger.Error("Uuid is nil!")
  446 + logger.Error("Uuid is nil!")
438 447 return
439 448 }
440 449 result, _ := ioutil.ReadAll(r.Body)
441 450 r.Body.Close()
442 451  
443 452 s := string(result)
444   - logger.Info("Getcashrecord , body:%v,uuid=%v", s, Uuid)
  453 + logger.Info("Getcashrecord , body:%v,uuid=%v", s, uniqueid)
445 454  
446   - //HandlerGetcashrecord(w, s, Uuid)
  455 + HandlerGetcashrecord(w, s, uniqueid, gameid, channel, Uuid)
447 456 }
448 457  
449 458 func Getcash(w http.ResponseWriter, r *http.Request) {
450 459  
  460 + gameid := ""
  461 + channel := ""
  462 + uniqueid := ""
451 463 Uuid := 0
452 464 if len(r.Header) > 0 {
453 465 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  466 + gameid = r.Header.Get("Gameid")
  467 + channel = r.Header.Get("Channel")
  468 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
454 469 }
455 470  
456 471 if Uuid == 0 {
457 472 SetHeader(w)
458   - //logger.Error("Uuid is nil!")
  473 + logger.Error("Uuid is nil!")
459 474 return
460 475 }
461 476 result, _ := ioutil.ReadAll(r.Body)
462 477 r.Body.Close()
463 478  
464 479 s := string(result)
465   - logger.Info("Getcash , body:%v,uuid=%v", s, Uuid)
  480 + logger.Info("Getcash , body:%v,uuid=%v", s, uniqueid)
466 481  
467   - //HandlerGetcash(w, s, Uuid)
  482 + HandlerGetcash(w, s, uniqueid, gameid, channel, Uuid)
468 483 }
469 484  
470 485 func Querdrawinfo(w http.ResponseWriter, r *http.Request) {
471 486  
  487 + gameid := ""
  488 + channel := ""
  489 + uniqueid := ""
472 490 Uuid := 0
473 491 if len(r.Header) > 0 {
474 492 Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  493 + gameid = r.Header.Get("Gameid")
  494 + channel = r.Header.Get("Channel")
  495 + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel")
475 496 }
476 497  
477 498 if Uuid == 0 {
478 499 SetHeader(w)
479   - //logger.Error("Uuid is nil!")
  500 + logger.Error("Uuid is nil!")
480 501 return
481 502 }
482 503 result, _ := ioutil.ReadAll(r.Body)
483 504 r.Body.Close()
484 505  
485 506 s := string(result)
486   - logger.Info("Querdrawinfo , body:%v,uuid=%v", s, Uuid)
  507 + logger.Info("Querdrawinfo , body:%v,uuid=%v", s, uniqueid)
487 508  
488   - //HandlerQuerdrawinfo(w, s, Uuid)
  509 + HandlerQuerdrawinfo(w, s, uniqueid, gameid, channel, Uuid)
489 510 }
490 511  
491 512 func Querydrawreward(w http.ResponseWriter, r *http.Request) {
... ...
src/HttpServer/logic/logic.go
... ... @@ -8,6 +8,7 @@ import (
8 8 "encoding/json"
9 9 "fmt"
10 10 "net/http"
  11 + "strconv"
11 12 "time"
12 13 )
13 14  
... ... @@ -119,6 +120,165 @@ func HandlerUploaduserbasicinfo(w http.ResponseWriter, data string, uniqueuuid s
119 120 fmt.Fprint(w, string(respstr))
120 121 }
121 122  
  123 +func HandlerGetcashrecord(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  124 + SetHeader(w)
  125 + var resp GetcashrecordResp
  126 + resp.Code = 0
  127 + resp.Message = "success"
  128 + for {
  129 +
  130 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  131 + if err != nil || uinfo == nil {
  132 + logger.Error("HandlerGetcashrecord getuserinfo failed=%v", err)
  133 + resp.Code = 1
  134 + resp.Message = "get userinfo failed"
  135 + break
  136 + }
  137 + list, err := GetCashList(uuid, gameid, channel, 0, 100)
  138 + if err != nil {
  139 + logger.Error("HandlerGetcashrecord failed err=%v", err)
  140 + resp.Message = "服务器错误"
  141 + resp.Code = 1
  142 + break
  143 + }
  144 + if list != nil {
  145 + resp.Data.Withdata = append(resp.Data.Withdata, *list...)
  146 + }
  147 +
  148 + break
  149 + }
  150 +
  151 + //回包
  152 + respstr, _ := json.Marshal(&resp)
  153 + fmt.Fprint(w, string(respstr))
  154 +}
  155 +
  156 +func HandlerGetcash(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  157 + SetHeader(w)
  158 + var resp GetcashResp
  159 + resp.Code = 0
  160 + resp.Message = "success"
  161 + var rdata GetcashReq
  162 + err := json.Unmarshal([]byte(data), &rdata)
  163 + for {
  164 + if err != nil {
  165 + logger.Error("HandlerGetcash json unmarshal failed=%v", err)
  166 + resp.Code = 1
  167 + resp.Message = "json failed"
  168 + break
  169 + }
  170 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  171 + if err != nil || uinfo == nil {
  172 + logger.Error("HandlerGetcash getuserinfo failed=%v", err)
  173 + resp.Code = 1
  174 + resp.Message = "get userinfo failed"
  175 + break
  176 + }
  177 +
  178 + index, info := uinfo.GetWithDrawData(rdata.Money)
  179 + if index == -1 || info == nil {
  180 + logger.Error("HandlerGetcash GetWithDrawData failed=%v", err)
  181 + resp.Code = 1
  182 + resp.Message = "get GetWithDrawData failed"
  183 + break
  184 + }
  185 +
  186 + if info.Cnum == 30 {
  187 + //30的是连续登陆天数
  188 + if uinfo.ContinueLoginDay < info.Day {
  189 + logger.Error("HandlerGetcash notfit failed=%v", err)
  190 + resp.Code = 1
  191 + resp.Message = "提现条件不满足"
  192 + break
  193 + }
  194 + } else {
  195 + if uinfo.SumLoginDay < info.Day {
  196 + logger.Error("HandlerGetcash notfit failed=%v", err)
  197 + resp.Code = 1
  198 + resp.Message = "提现条件不满足"
  199 + break
  200 + }
  201 + }
  202 +
  203 + if info.Isnew == 0 {
  204 + logger.Error("HandlerGetcash notfit failed=%v", err)
  205 + resp.Code = 1
  206 + resp.Message = "新人专享只能提取一次"
  207 + break
  208 + }
  209 +
  210 + if info.Preisfind == 0 {
  211 + logger.Error("HandlerGetcash notfit failed=%v", err)
  212 + resp.Code = 1
  213 + resp.Message = "请先完成前一档提现"
  214 + break
  215 + }
  216 +
  217 + //判断一下前置条件的下一档
  218 + if index == len(uinfo.WithDraw.Cashdata)-1 {
  219 + //最后一档了不用处理
  220 + } else {
  221 + if index < len(uinfo.WithDraw.Cashdata)-1 {
  222 + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1
  223 + }
  224 + }
  225 +
  226 + checkcoin := 2 //不开启自动审核
  227 + drawnum := int(rdata.Money * 10000)
  228 + gold, err := GetCashFromSDK(uuid, drawnum, gameid, channel, rdata.Openid, uinfo.NickName, uinfo.HeadUrl, rdata.Ver, checkcoin)
  229 + if err != nil {
  230 + logger.Error("HandlerGetcash GetCashFromSDK failed failed=%v", err)
  231 + resp.Code = 1
  232 + resp.Message = "从后台提现失败了"
  233 + break
  234 +
  235 + }
  236 + if info.Isnew == 1 {
  237 + uinfo.WithDraw.Cashdata[index].Isnew = 0
  238 + }
  239 +
  240 + resp.Data.Walletgold = gold
  241 +
  242 + //保存
  243 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  244 +
  245 + break
  246 +
  247 + }
  248 + //回包
  249 + respstr, _ := json.Marshal(&resp)
  250 + fmt.Fprint(w, string(respstr))
  251 +}
  252 +
  253 +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
  254 + SetHeader(w)
  255 + var resp QuerygetcashinfoResp
  256 + resp.Code = 0
  257 + resp.Message = "success"
  258 +
  259 + for {
  260 +
  261 + uinfo, err := GetUserInfo(uniqueuuid)
  262 + if err != nil {
  263 + logger.Info("GetUserInfo HandlerQuerydrawreward data failed:%v,for:%v", err, data)
  264 + resp.Message = "GetUserInfo failed"
  265 + resp.Code = 1
  266 + break
  267 + }
  268 +
  269 + resp.Data.Logindaycontinue = uinfo.ContinueLoginDay
  270 + resp.Data.Logindaysum = uinfo.SumLoginDay
  271 + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...)
  272 +
  273 + resp.Code = ERROR_OK
  274 + break
  275 + }
  276 +
  277 + //回包
  278 + respstr, _ := json.Marshal(&resp)
  279 + fmt.Fprint(w, string(respstr))
  280 +}
  281 +
122 282 func HandlerQuerydrawreward(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) {
123 283 SetHeader(w)
124 284 var resp QuerydrawrewardResp
... ...