From aa959ad9864768010913a0448f7211645a540791 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Wed, 13 May 2020 15:54:19 +0800 Subject: [PATCH] 提现相关接口 --- src/HttpServer/logic/datadef.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/errordef.go | 3 +++ src/HttpServer/logic/function.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/httpserver.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/common/redis/def.go | 1 + 6 files changed, 329 insertions(+), 0 deletions(-) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 97076c7..febd970 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -77,6 +77,36 @@ type DrawguangoldResp struct { Data DrawguangoldData `json:"data"` } +type QuerdrawinfoResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data WithDrawInfo `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"` +} + +type GetcashData struct { + Walletgold int `json:"walletgold"` +} +type GetcashResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetcashData `json:"data"` +} + +type GetcashrecordResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data WithDrawList `json:"data"` +} + //********************************************************************************************************** type TaskInfo struct { @@ -87,6 +117,29 @@ type AchieveMentInfo struct { } + +type WithDrawList struct { + Withdata []WithDrawRecord `json:"withdata"` +} + +//提现记录结构 +type WithDrawRecord struct { + Withdrawtime int `json:"wichdrawtime"` + Withdrawmoney float32 `json:"withdrawmoney"` +} + +type WithDrawInfo struct { + Cashdata []WithDrawDesc `json:"cashdata"` +} + +type WithDrawDesc struct { + Cid int `json:"cid"` + Cnum float32 `json:"cnum"` + Isnew int `json:"isnew"` + Limitlv int `json:"limitlv"` + Preisfind int `json:"preisfind"` +} + //玩家数据 type UserData struct { Userid int //玩家id @@ -98,6 +151,7 @@ type UserData struct { LastLoginTime int //上次登陆时间 ContinueLoginDay int //连续登录天数 GetFromGuanCnt int //当天从存钱款提取金币次数 + WithDraw WithDrawInfo //提现记录信息 Task TaskInfo //玩家任务完成相关信息 Achieve AchieveMentInfo //玩家成就完成相关数据 } diff --git a/src/HttpServer/logic/errordef.go b/src/HttpServer/logic/errordef.go index 49ee989..ab1ba60 100644 --- a/src/HttpServer/logic/errordef.go +++ b/src/HttpServer/logic/errordef.go @@ -10,4 +10,7 @@ const ( ERROR_GUANGOLD_NOTENOUGH =5 //存钱罐金币不足 ERROR_DRAWGUAN_FAILED =6 //从存钱罐提取金币不满足限制 ERROR_DRAWGOLD_FAILED =7 //从存钱罐提取金币失败了 + ERROR_GETCASH_FAILED =8 //从后台提现失败了 + ERROR_GETCASH_GOLDNOTENOUGH_FAILED =9 //提现金币不足 + ERROR_ADDWITHDRAW_LISTFAILED =10 //添加提现记录失败 ) \ No newline at end of file diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 16a743c..73a63ef 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -56,6 +56,23 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) error{ initdata.RealGold = 0 initdata.WatchAddsTime =WATCH_ADD_DAY_LIMIT + for _,val := range jsonconf.GetJsonConf().WithDrawConfig { + var tmp WithDrawDesc + tmp.Cid = val.Id + tmp.Cnum = val.Money + if val.Isnew == 1 { + tmp.Isnew = 1 + }else { + tmp.Isnew = 2 + } + tmp.Limitlv = val.Level + if val.Id == 1 { + tmp.Preisfind = 1 + }else { + tmp.Preisfind = 0 + } + } + resp.Data.Guangold = initdata.GuanGold resp.Data.Leftads = initdata.WatchAddsTime resp.Data.Walletgold = initdata.RealGold @@ -145,7 +162,73 @@ func GetUserData(uuid int, resp *UserLoginResp) error{ return nil } +//获取提现记录 +func GetWithDrawList(uuid int) (*WithDrawList,error) { + var list *WithDrawList + list = nil + liststr,err := redishandler.GetRedisClient().HGet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) + if err != nil { + return nil,err + } + err = json.Unmarshal([]byte(liststr),list) + if err != nil { + return nil,err + } + return list,nil +} + +//添加提现记录 +func AddWithDrawList(uuid int,data *WithDrawRecord) error { + exist,err := redishandler.GetRedisClient().HExists(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) + if err != nil { + return err + } + if !exist { + //添加新的记录 + var tmp WithDrawList + tmp.Withdata = append(tmp.Withdata,*data) + + savestr,err := json.Marshal(&tmp) + if err != nil { + return err + } + err = redishandler.GetRedisClient().HSet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid),string(savestr)) + return err + } + + /*liststr,err := redishandler.GetRedisClient().HGet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid)) + if err != nil { + return err + } + + var list WithDrawList + err = json.Unmarshal([]byte(liststr),&list) + if err != nil { + return err + }*/ + + list,err := GetWithDrawList(uuid) + if err != nil || list == nil{ + return err + } + list.Withdata = append(list.Withdata,*data) + savestr,err := json.Marshal(&list) + if err != nil { + return err + } + err = redishandler.GetRedisClient().HSet(redis.USER_WITHDRAW_RECORDLIST,strconv.Itoa(uuid),string(savestr)) + return err + + + +} + func AddCoinToSdk(uuid int,goldnum int,gameid string,channel string,atype int) (int,error) { //暂时先不对接 接口调通遗憾对接后台 return 0,nil +} + +func GetCashFromSDK(uuid int,goldnum int,gameid ,channel,openid,nickname,headurl string) (int,error) { + //先不接 + return 0,nil } \ No newline at end of file diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 1df2bf5..e90e95a 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -43,10 +43,77 @@ func startServerHttpServe() { http.HandleFunc("/eliminatestar/queryguaninfo", Queryguaninfo) //获取存钱罐数据 http.HandleFunc("/eliminatestar/getguangold", Getguangold) //获取金币到存钱罐 http.HandleFunc("/eliminatestar/drawguangold", Drawguangold) //提取存钱罐的金币到个人钱包 + http.HandleFunc("/eliminatestar/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 + http.HandleFunc("/eliminatestar/getcash", Getcash) //提现 + http.HandleFunc("/eliminatestar/getcashrecord", Getcashrecord) //提现记录列表 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) CheckErr(err) } +func Getcashrecord(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //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) + + HandlerGetcashrecord(w, s, Uuid) +} + + +func Getcash(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //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) + + HandlerGetcash(w, s, Uuid) +} + + +func Querdrawinfo(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //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) + + HandlerQuerdrawinfo(w, s, Uuid) +} func Drawguangold(w http.ResponseWriter, r *http.Request) { @@ -70,6 +137,8 @@ func Drawguangold(w http.ResponseWriter, r *http.Request) { } + + func Getguangold(w http.ResponseWriter, r *http.Request) { Uuid := 0 diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 9713ae5..d21d20d 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "strconv" + "time" ) @@ -91,6 +92,124 @@ func HandlerWatchads(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetcashResp + resp.Code = 0 + var rdata GetcashReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerDrawguangold data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = ERROR_JSONUNMASH_ERROR + break + } + uinfo,err := GetUserInfo(uuid) + if err != nil || uinfo == nil{ + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + drawnum := int(rdata.Money*100) + //需要判断一下金币是否足够 + if drawnum * 100 > uinfo.RealGold { + logger.Error("gold nor enough failed err=%v", err) + resp.Message = "提现金币不足" + resp.Code = ERROR_GETCASH_GOLDNOTENOUGH_FAILED + break + } + + _,err = GetCashFromSDK(uuid,drawnum,rdata.Gameid,rdata.Channel,rdata.Openid,rdata.Nickname,rdata.Headurl) + if err != nil { + logger.Error("GetCashFromSDK failed err=%v", err) + resp.Message = "从后台提现失败了" + resp.Code = ERROR_GETCASH_FAILED + break + } + + uinfo.RealGold -= drawnum * 100 + + resp.Data.Walletgold = uinfo.RealGold + SaveUserInfo(uinfo) + + //需要保存一下提现记录 + data := new(WithDrawRecord) + data.Withdrawmoney = rdata.Money + data.Withdrawtime = int(time.Now().Unix()) + err = AddWithDrawList(uuid,data) + if err != nil { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "添加提现记录失败" + resp.Code = ERROR_ADDWITHDRAW_LISTFAILED + break + } + + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + + + +func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetcashrecordResp + resp.Code = 0 + for { + list,err := GetWithDrawList(uuid) + if err != nil || list == nil{ + logger.Error("HandlerGetcashrecord failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + resp.Data.Withdata = append(resp.Data.Withdata,list.Withdata...) + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QuerdrawinfoResp + resp.Code = 0 + for { + uinfo,err := GetUserInfo(uuid) + if err != nil || uinfo == nil{ + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + //返回 + 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 HandlerDrawguangold(w http.ResponseWriter, data string, uuid int) { diff --git a/src/common/redis/def.go b/src/common/redis/def.go index 76a75fe..aefb773 100644 --- a/src/common/redis/def.go +++ b/src/common/redis/def.go @@ -2,5 +2,6 @@ package redis const ( USER_DATA_KEY = "STARSTAR_USER_DATA_KEY" //玩家数据 + USER_WITHDRAW_RECORDLIST = "STARSTAR_USER_WITHDRAW_RECORDLIST" //玩家提现记录 ) -- libgit2 0.21.0