diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 9d6afc3..1df517d 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -3,15 +3,12 @@ package logic type UserLoginReq struct { - Fromid int `json:"fromid"` - Sharetype int `json:"sharetype"` Gameid string `json:"gameid"` Channel string `json:"channel"` } type UserLoginData struct { Walletgold int `json:"walletgold"` - Leftredbagcnt int `json:"leftredbagcnt"` } type UserLoginResp struct { @@ -20,6 +17,68 @@ type UserLoginResp struct { Data UserLoginData `json:"data"` } +type GetuserdataReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` +} + +type GetuserdataData struct { + Walletgold int `json:"walletgold"` + Nowtime int `json:"nowtime"` + +} + +type GetuserdataResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetuserdataData `json:"data"` +} + +type CommReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` +} + +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"` + Ver string `json:"ver"` + Ctype int `json:"ctype"` +} +type GetcashData struct { + Walletgold int `json:"walletgold"` +} +type GetcashResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetcashData `json:"data"` +} + +type WithDrawList struct { + Withdata []WithDrawRecord `json:"withdata"` +} + +type GetcashrecordReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` +} + +type GetcashrecordResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data WithDrawList `json:"data"` +} + //////////////////////////////////////////////////////////////////////////////////////// type GetCashListResp struct { diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 875a8a2..8d710cb 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -10,6 +10,7 @@ import ( "encoding/hex" "encoding/json" "errors" + "fmt" "io/ioutil" "net/http" "sort" @@ -50,6 +51,72 @@ func GetUserInfo(uniqueid string) (*UserData, error) { return &tmp, nil } +func (uinfo *UserData) GetSpecialWithDrawData(money float32) (int, *WithDrawDesc) { + //处理提现状态 + for k, val := range uinfo.WithDraw.SpecialCashdata { + if val.Cnum == money { + return k, &val + } + } + return -1, 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 HandlerSyncuserdata(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetuserdataResp + resp.Code = 0 + var rdata GetuserdataReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerGetuserdata data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = 1 + break + } + + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + data, err := GetUserInfo(uniqueuuid) + if err != nil || data == nil { + resp.Code = 1 + resp.Message = "ERROR_SRV_ERROR" + break + } + + //此处处理一下从sdk拉取钱包金币数量 + gold, err := GetCoinFromSdk(uuid, rdata.Gameid, rdata.Channel) + if err == nil { + data.RealGold = gold + } else { + logger.Error("GetCoinFromSdk failed err=%v", err) + } + + resp.Data.Walletgold = data.RealGold + resp.Data.Nowtime = int(time.Now().Unix()) + SaveUserInfo(data, uniqueuuid) + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + + logger.Info("###HandlerSyncuserdata###rdata:%v", string(respstr)) +} + func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid string) error { @@ -107,7 +174,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s initdata.WithDraw.SpecialCashdata = append(initdata.WithDraw.SpecialCashdata, tmp) } - resp.Data.Leftredbagcnt = initdata.WatchAddsTime + //resp.Data.Leftredbagcnt = initdata.WatchAddsTime resp.Data.Walletgold = initdata.RealGold diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 5b76ed6..87ce6f1 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -36,7 +36,11 @@ func CheckErr(err error) { func startServerHttpServe() { //---------------------------------------------------------------------------------------- - http.HandleFunc("/eliminatestar/login", UserLogin) //登录 + http.HandleFunc("/brainhole/login", UserLogin) //登录 + http.HandleFunc("/brainhole/syncuserdata", Syncuserdata) //同步完结数据 + http.HandleFunc("/brainhole/querdrawinfo", Querdrawinfo) //获取提现档位信息接口 + http.HandleFunc("/brainhole/getcash", Getcash) //提现 + http.HandleFunc("/brainhole/getcashrecord", Getcashrecord) //提现记录列表 err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) @@ -44,8 +48,90 @@ func startServerHttpServe() { } +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 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 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 Syncuserdata(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("Syncuserdata , body:%v,uuid=%v", s, Uuid) + + HandlerSyncuserdata(w, s, Uuid) +} func UserLogin(w http.ResponseWriter, r *http.Request) { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 2acd41f..5ed503f 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -11,6 +11,222 @@ import ( "time" ) +func HandlerQuerdrawinfo(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QuerdrawinfoResp + resp.Code = 0 + var rdata CommReq + err := json.Unmarshal([]byte(data), &rdata) + for { + + if err != nil { + logger.Info("json decode HandlerQuerdrawinfo data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = 1 + break + } + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 1 + break + } + + //返回 + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...) + resp.Data.SpecialCashdata = append(resp.Data.SpecialCashdata, uinfo.WithDraw.SpecialCashdata...) + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + 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 = 1 + break + } + + + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 1 + break + } + + drawnum := int(rdata.Money * 100) + //需要判断一下金币是否足够 + if drawnum*100 > uinfo.RealGold { + logger.Error("gold nor enough failed err=%v", err) + resp.Message = "提现金币不足" + resp.Code = 2 + break + } + + //需要处理一下提现级别 + + index := 0 + var info *WithDrawDesc + if rdata.Ctype == 1 { + index, info = uinfo.GetWithDrawData(rdata.Money) + } else { + index, info = uinfo.GetSpecialWithDrawData(rdata.Money) + } + + if index == -1 || info == nil { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "网络错误" + resp.Code = 1 + break + } + + if uinfo.Lv < info.Limitlv { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "完成日常任务可以提升人物等级哦~" + resp.Code = 3 + break + } + + if info.Isnew == 0 { + logger.Error("AddWithDrawList failed err=%v", err) + resp.Message = "新人专享只能提取一次" + resp.Code = 4 + break + } + + if info.Preisfind == 0 { + logger.Error("HandlerGetcash Preisfind err=%v", err) + resp.Message = "请先完成前一档提现" + resp.Code = 5 + break + } + + //普通提现需要判断前置条件 + if rdata.Ctype == 1 { + //判断一下前置条件的下一档 + if index == len(uinfo.WithDraw.Cashdata)-1 { + //最后一档了不用处理 + } else { + if index < len(uinfo.WithDraw.Cashdata)-1 { + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1 + } + } + } + + //如果是2.2.7版本开启提现次数限制 + if rdata.Ver == "2.2.7" && uinfo.GetCashCnt > 0 { + logger.Error("HandlerGetcash GetCashCnt err=%v", err) + resp.Message = "当天已经提现过了,请明天再来" + resp.Code = 6 + break + } + + if uinfo.SumLoginDay < info.Day { + logger.Error("HandlerGetcash GetCashCnt err=%v", err) + resp.Message = "累计登陆天数不足" + resp.Code = 7 + break + } + + //2.2.5版本开启自动审核 + checkcoin := 2 + if rdata.Ver == "2.2.5" || rdata.Ver == "2.2.6" || rdata.Ver == "2.2.7" { + logger.Info("HandlerGetcash autocheckcoin") + if drawnum <= 150 { + //1.5挡位以下不需要审核 + checkcoin = 1 //临时关闭u + } + } + + gold, err := GetCashFromSDK(uuid, drawnum, rdata.Gameid, rdata.Channel, rdata.Openid, rdata.Nickname, rdata.Headurl, rdata.Ver, checkcoin) + if err != nil { + logger.Error("GetCashFromSDK failed err=%v", err) + resp.Message = "从后台提现失败了" + resp.Code = 8 + break + } + + + uinfo.GetCashCnt++ + //如果是前六挡 + if info.Cid <= 6 && rdata.Ctype == 1 { + uinfo.WithDraw.Cashdata[index].Isnew = 0 + } + if rdata.Ctype == 2 { + uinfo.WithDraw.SpecialCashdata[index].Isnew = 0 + } + + uinfo.RealGold = gold + //uinfo.RealGold -= drawnum * 100 + + resp.Data.Walletgold = uinfo.RealGold + SaveUserInfo(uinfo, uniqueuuid) + + resp.Code = 0 + 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 + var rdata GetcashrecordReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerGetcashrecord data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = 1 + break + } + + list, err := GetCashList(uuid, rdata.Gameid, rdata.Channel, 0, 100) + if err != nil { + logger.Error("HandlerGetcashrecord failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 2 + break + } + if list != nil { + resp.Data.Withdata = append(resp.Data.Withdata, *list...) + } + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerLogin(w http.ResponseWriter, data string, uuid int) { SetHeader(w) @@ -157,7 +373,7 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR SaveUserInfo(data, uniqueuid) resp.Data.Walletgold = data.RealGold - resp.Data.Leftredbagcnt = data.WatchAddsTime + //resp.Data.Leftredbagcnt = data.WatchAddsTime return nil } \ No newline at end of file -- libgit2 0.21.0