diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index ebe43b9..e7dbb34 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -263,14 +263,22 @@ type QuerydrawrewardResp struct { Data QuerydrawrewardData `json:"data"` } +type QuerygetcashinfoData struct { + Logindaysum int `json:"logindaysum"` + Logindaycontinue int `json:"logindaycontinue"` + Cashdata []WithDrawDesc `json:"cashdata"` +} + +type QuerygetcashinfoResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data QuerygetcashinfoData `json:"data"` +} + type GetcashReq struct { - Gameid string `json:"gameid"` - Channel string `json:"channel"` - Money float32 `json:"money"` - Openid string `json:"openid"` - Nickname string `json:"nickname"` - Headurl string `json:"headurl"` - Ver string `json:"ver"` + Money float32 `json:"money"` + Openid string `json:"openid"` + Ver string `json:"ver"` } type CommReq struct { diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index cb7d252..0cc6f92 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -377,6 +377,16 @@ func InitTaskAndAchievement(uuid int, channel string) error { return nil } +func (uinfo *UserData) GetWithDrawData(money float32) (int, *WithDrawDesc) { + //处理提现状态 + for k, val := range uinfo.WithDraw.Cashdata { + if val.Cnum == money { + return k, &val + } + } + return -1, nil +} + func InitUserInfo(resp *UserLoginResp, uniqueuid, gameid, channel string, uuid int) error { var initdata UserData @@ -477,6 +487,173 @@ func GetUserSelfData(uniqueid string) (string, error) { return data, nil } +func GetCashList(uuid int, gameid string, channel string, start int, number int) (*[]WithDrawRecord, error) { + SERVERKEY := conf.GetCoinConf().Key + /*if gameid == "1015" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015 + }*/ + + var paramlist []string + var params GetCashListDesc + params.Sign_type = "md5" + params.Gameid = gameid + params.Channel = channel + params.Uid = uuid + params.Time_stamp = strconv.Itoa(int(time.Now().Unix())) + params.Start = start + params.Number = number + signtypestr := "sign_type=" + params.Sign_type + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix())) + paramgameid := "gameid=" + gameid + pchannel := "channel=" + channel + puid := "uid=" + strconv.Itoa(uuid) + pstart := "start=" + strconv.Itoa(start) + pnumber := "number=" + strconv.Itoa(number) + paramlist = append(paramlist, signtypestr) + paramlist = append(paramlist, timestampstr) + paramlist = append(paramlist, paramgameid) + paramlist = append(paramlist, pchannel) + paramlist = append(paramlist, puid) + if start != 0 { + paramlist = append(paramlist, pstart) + } + + paramlist = append(paramlist, pnumber) + + sumparam := GettotalParam(paramlist) + //加serverkey + signsum := sumparam + SERVERKEY + logger.Info("GetCashList sumparam=%v", signsum) + + //进行hash + sign := GetHashValue(signsum) + params.Sign = sign + + bys, err := json.Marshal(¶ms) + if err != nil { + logger.Error("GetCashList failed=%v", err) + return nil, err + } + res, err := DoHttpPost(bys, "api/server/tixian/lst") + if err != nil { + logger.Error("GetCashList failed=%v", err) + return nil, err + } + + logger.Info("GetCashList res=%v", res) + + var resp GetCashListResp + err = json.Unmarshal([]byte(res), &resp) + if err != nil { + logger.Error("GetCoinFromSdk failed=%v", err) + return nil, err + } + + if resp.Code != "0" { + logger.Error("GetCoinFromSdk failed=%v", resp.Msg) + return nil, err + } + return &resp.Data, nil +} + +func GetCashFromSDK(uuid int, goldnum int, gameid, channel, openid, nickname, headurl, ver string, checkcoin int) (int, error) { + + SERVERKEY := conf.GetCoinConf().Key + + if goldnum == 0 || uuid == 0 || gameid == "" || channel == "" || openid == "" || ver == "" { + logger.Error("GetCashFromSDK param empty") + return 0, errors.New("param empty") + } + var paramlist []string + var params TixianDesc + params.Sign_type = "md5" + params.Gameid = gameid + params.Channel = channel + params.Uid = uuid + params.Time_stamp = strconv.Itoa(int(time.Now().Unix())) + params.Headurl = headurl + params.Money = goldnum + params.Openid = openid + params.Nickname = nickname + params.Typ = 6 + params.Ver = ver + params.Editcoin = 1 + params.Checkcoin = checkcoin + signtypestr := "sign_type=" + params.Sign_type + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix())) + paramgameid := "gameid=" + gameid + pchannel := "channel=" + channel + puid := "uid=" + strconv.Itoa(uuid) + phead := "headurl=" + headurl + pnickname := "nickname=" + nickname + popenid := "openid=" + openid + pmoney := "money=" + strconv.Itoa(goldnum) + ptype := "typ=" + "6" //微信 + ped := "editcoin=1" + pcheco := "checkcoin=" + strconv.Itoa(checkcoin) + //pver := "ver=" + params.Ver + paramlist = append(paramlist, signtypestr) + paramlist = append(paramlist, timestampstr) + paramlist = append(paramlist, paramgameid) + paramlist = append(paramlist, pchannel) + paramlist = append(paramlist, puid) + if headurl != "" { + paramlist = append(paramlist, phead) + } + if nickname != "" { + paramlist = append(paramlist, pnickname) + } + paramlist = append(paramlist, popenid) + paramlist = append(paramlist, pmoney) + paramlist = append(paramlist, ptype) + paramlist = append(paramlist, ped) + paramlist = append(paramlist, pcheco) + //paramlist = append(paramlist, pver) + + sumparam := GettotalParam(paramlist) + //加serverkey + signsum := sumparam + SERVERKEY + + //进行hash + sign := GetHashValue(signsum) + params.Sign = sign + + bys, err := json.Marshal(¶ms) + if err != nil { + logger.Error("GetCashFromSDK failed=%v", err) + return 0, err + } + res, err := DoHttpPost(bys, "api/server/tixian") + logger.Info("GetCashFromSDK sumparam is:%v,sign is:%v", signsum, sign) + logger.Info("GetCashFromSDK sumparam param=%v", string(bys)) + if err != nil { + logger.Error("GetCashFromSDK failed=%v", err) + return 0, err + } + + logger.Info("GetCashFromSDK res=%v", res) + + var resp GetCashResp + err = json.Unmarshal([]byte(res), &resp) + if err != nil { + logger.Error("GetCashFromSDK failed=%v", err) + return 0, err + } + + if resp.Code != "0" { + logger.Error("GetCashFromSDK failed=%v", resp.Msg) + return 0, errors.New(resp.Msg) + } + + //拉取一下新的金币值 + newnum, err := GetCoinFromSdk(uuid, gameid, channel) + if err != nil { + logger.Error("GetCashFromSDK failed=%v", err) + return 0, err + } + return newnum, nil +} + func AddCoinToSdk(uuid int, goldnum int, gameid string, channel string, atype int) (int, error) { SERVERKEY := conf.GetCoinConf().Key /*if gameid == "1015" { diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index a7cc90a..e78e3ed 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -59,6 +59,9 @@ func startServerHttpServe() { http.HandleFunc("/russiaxiaoxiao/uploadhigestscore", Uploadhigestscore) //上报玩家历史最高分 http.HandleFunc("/russiaxiaoxiao/queryrankinfo", Queryrankinfo) //查询排行榜 http.HandleFunc("/russiaxiaoxiao/querydrawreward", Querydrawreward) //请求抽奖 + http.HandleFunc("/russiaxiaoxiao/querygetcashinfo", Querdrawinfo) //请求提现档位数据 + http.HandleFunc("/russiaxiaoxiao/getcash", Getcash) //请求提现 + http.HandleFunc("/russiaxiaoxiao/getcashrecord", Getcashrecord) //请求提现记录 //.......................................... /*http.HandleFunc("/eliminatestar/getuserdata", Getuserdata) //获取玩家数据 @@ -427,65 +430,83 @@ func Onlinentf(w http.ResponseWriter, r *http.Request) { func Getcashrecord(w http.ResponseWriter, r *http.Request) { + gameid := "" + channel := "" + uniqueid := "" Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + gameid = r.Header.Get("Gameid") + channel = r.Header.Get("Channel") + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel") } if Uuid == 0 { SetHeader(w) - //logger.Error("Uuid is nil!") + logger.Error("Uuid is nil!") return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) - logger.Info("Getcashrecord , body:%v,uuid=%v", s, Uuid) + logger.Info("Getcashrecord , body:%v,uuid=%v", s, uniqueid) - //HandlerGetcashrecord(w, s, Uuid) + HandlerGetcashrecord(w, s, uniqueid, gameid, channel, Uuid) } func Getcash(w http.ResponseWriter, r *http.Request) { + gameid := "" + channel := "" + uniqueid := "" Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + gameid = r.Header.Get("Gameid") + channel = r.Header.Get("Channel") + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel") } if Uuid == 0 { SetHeader(w) - //logger.Error("Uuid is nil!") + logger.Error("Uuid is nil!") return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) - logger.Info("Getcash , body:%v,uuid=%v", s, Uuid) + logger.Info("Getcash , body:%v,uuid=%v", s, uniqueid) - //HandlerGetcash(w, s, Uuid) + HandlerGetcash(w, s, uniqueid, gameid, channel, Uuid) } func Querdrawinfo(w http.ResponseWriter, r *http.Request) { + gameid := "" + channel := "" + uniqueid := "" Uuid := 0 if len(r.Header) > 0 { Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + gameid = r.Header.Get("Gameid") + channel = r.Header.Get("Channel") + uniqueid = r.Header.Get("Uuid") + r.Header.Get("Channel") } if Uuid == 0 { SetHeader(w) - //logger.Error("Uuid is nil!") + logger.Error("Uuid is nil!") return } result, _ := ioutil.ReadAll(r.Body) r.Body.Close() s := string(result) - logger.Info("Querdrawinfo , body:%v,uuid=%v", s, Uuid) + logger.Info("Querdrawinfo , body:%v,uuid=%v", s, uniqueid) - //HandlerQuerdrawinfo(w, s, Uuid) + HandlerQuerdrawinfo(w, s, uniqueid, gameid, channel, Uuid) } func Querydrawreward(w http.ResponseWriter, r *http.Request) { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index e2c04ce..e4bd614 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" "time" ) @@ -119,6 +120,165 @@ func HandlerUploaduserbasicinfo(w http.ResponseWriter, data string, uniqueuuid s fmt.Fprint(w, string(respstr)) } +func HandlerGetcashrecord(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) { + SetHeader(w) + var resp GetcashrecordResp + resp.Code = 0 + resp.Message = "success" + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerGetcashrecord getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + list, err := GetCashList(uuid, gameid, channel, 0, 100) + if err != nil { + logger.Error("HandlerGetcashrecord failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 1 + break + } + if list != nil { + resp.Data.Withdata = append(resp.Data.Withdata, *list...) + } + + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerGetcash(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) { + SetHeader(w) + var resp GetcashResp + resp.Code = 0 + resp.Message = "success" + var rdata GetcashReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Error("HandlerGetcash json unmarshal failed=%v", err) + resp.Code = 1 + resp.Message = "json failed" + break + } + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerGetcash getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + index, info := uinfo.GetWithDrawData(rdata.Money) + if index == -1 || info == nil { + logger.Error("HandlerGetcash GetWithDrawData failed=%v", err) + resp.Code = 1 + resp.Message = "get GetWithDrawData failed" + break + } + + if info.Cnum == 30 { + //30的是连续登陆天数 + if uinfo.ContinueLoginDay < info.Day { + logger.Error("HandlerGetcash notfit failed=%v", err) + resp.Code = 1 + resp.Message = "提现条件不满足" + break + } + } else { + if uinfo.SumLoginDay < info.Day { + logger.Error("HandlerGetcash notfit failed=%v", err) + resp.Code = 1 + resp.Message = "提现条件不满足" + break + } + } + + if info.Isnew == 0 { + logger.Error("HandlerGetcash notfit failed=%v", err) + resp.Code = 1 + resp.Message = "新人专享只能提取一次" + break + } + + if info.Preisfind == 0 { + logger.Error("HandlerGetcash notfit failed=%v", err) + resp.Code = 1 + resp.Message = "请先完成前一档提现" + break + } + + //判断一下前置条件的下一档 + if index == len(uinfo.WithDraw.Cashdata)-1 { + //最后一档了不用处理 + } else { + if index < len(uinfo.WithDraw.Cashdata)-1 { + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1 + } + } + + checkcoin := 2 //不开启自动审核 + drawnum := int(rdata.Money * 10000) + gold, err := GetCashFromSDK(uuid, drawnum, gameid, channel, rdata.Openid, uinfo.NickName, uinfo.HeadUrl, rdata.Ver, checkcoin) + if err != nil { + logger.Error("HandlerGetcash GetCashFromSDK failed failed=%v", err) + resp.Code = 1 + resp.Message = "从后台提现失败了" + break + + } + if info.Isnew == 1 { + uinfo.WithDraw.Cashdata[index].Isnew = 0 + } + + resp.Data.Walletgold = gold + + //保存 + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + break + + } + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) { + SetHeader(w) + var resp QuerygetcashinfoResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil { + logger.Info("GetUserInfo HandlerQuerydrawreward data failed:%v,for:%v", err, data) + resp.Message = "GetUserInfo failed" + resp.Code = 1 + break + } + + resp.Data.Logindaycontinue = uinfo.ContinueLoginDay + resp.Data.Logindaysum = uinfo.SumLoginDay + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...) + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerQuerydrawreward(w http.ResponseWriter, data string, uniqueuuid, gameid, channel string, uuid int) { SetHeader(w) var resp QuerydrawrewardResp -- libgit2 0.21.0