From a23ace635a26f7d7e77025d55638122618cd74f4 Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Tue, 16 Jun 2020 16:20:33 +0800 Subject: [PATCH] 有钱猫改动 --- src/HttpServer/conf/conf.go | 4 ++++ src/HttpServer/jsonconf/jsonconf.go | 18 ++++++++++++++++++ src/HttpServer/logic/constdef.go | 5 ++++- src/HttpServer/logic/datadef.go | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/HttpServer/logic/function.go | 447 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- src/HttpServer/logic/httpserver.go | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/HttpServer/logic/logic.go | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 1188 insertions(+), 14 deletions(-) diff --git a/src/HttpServer/conf/conf.go b/src/HttpServer/conf/conf.go index feb1b65..103458d 100644 --- a/src/HttpServer/conf/conf.go +++ b/src/HttpServer/conf/conf.go @@ -29,6 +29,10 @@ var ( config = new(TexasConf) ) +func GetCoinConf() ConiSrvConf { + return config.CoinSrv +} + func GetRedisConf() RedisConf { return config.Redis } diff --git a/src/HttpServer/jsonconf/jsonconf.go b/src/HttpServer/jsonconf/jsonconf.go index 977d6d5..dc8dbbe 100644 --- a/src/HttpServer/jsonconf/jsonconf.go +++ b/src/HttpServer/jsonconf/jsonconf.go @@ -76,6 +76,24 @@ type GameConfig struct { RMBConfig []RMBConfigDesc } +func GetBoxConfif(id int) *BoxConfigDesc { + for _, v := range g_jsonconf.BoxConfig { + if v.Id == id { + return &v + } + } + return nil +} + +func GetGiftConfif(id int) *BoxConfigDesc { + for _, v := range g_jsonconf.GiftConfig { + if v.Id == id { + return &v + } + } + return nil +} + func GetJsonConf() *GameConfig { return g_jsonconf } diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index ff7f974..0315e0a 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -59,5 +59,8 @@ const ( DRAWTICKETGETLIMIT = 5 //每日抽奖券获得次数 DRAWTICKETNUMLIMIT = 10 //抽奖券上限 WAREHOUSELIMIT = 15 //仓库容量上限 - + RANDGIFTLIMIT = 10 //每日随机红包上线次数 + BOXGIFTPOS = 10 //空格礼包固定位置 + BOXGIFTEXTRA = 1000 //空格礼包id下发额外加成值 + FLYBOXNUMLIMIT = 6 //飞天宝箱每日次数限制 ) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 12dc1e1..0e01a6e 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -15,9 +15,11 @@ type TestAddCatResp struct { } type UserLoginReq struct { - Lype int `json:"type"` - UserId int `json:"userId"` - Fromid int `json:"fromid"` + Lype int `json:"type"` + UserId int `json:"userId"` + Fromid int `json:"fromid"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` } type UserLoginData struct { @@ -78,6 +80,65 @@ type UserInfoResp struct { Data UserInfoData `json:"data"` } +type GetrandredbagReq struct { + Optype int `json:"optype"` +} + +type GetrandredbagData struct { + Getnum int `json:"getnum"` +} + +type GetrandredbagResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetrandredbagData `json:"data"` +} + +type GenerateboxData struct { + Boixid int `json:"boixid"` +} + +type GenerateboxResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GenerateboxData `json:"data"` +} + +type GetboxrewardReq struct { + Optype int `json:"optype"` +} + +type GetboxrewardData struct { + Getgold int64 `json:"getgold"` + Getredbag float32 `json:"getredbag"` +} + +type GetboxrewardResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetboxrewardData `json:"data"` +} + +type WithDrawRecord struct { + Coin int `json:"coin"` + Create_time int `json:"create_time"` + Money int `json:"money"` + No string `json:"no"` + Status int `json:"status"` + Statusmsg string `json:"statusmsg"` + Typ int `json:"typ"` +} + +type WithDrawList struct { + Withdata []WithDrawRecord `json:"withdata"` +} + +type GetcashrecordResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data WithDrawList `json:"data"` +} + type AddAdData struct { } @@ -417,6 +478,22 @@ type QueryGamblingData struct { HeadImg string `json:"headImg"` } +type GetcashReq struct { + Money float32 `json:"money"` + Openid string `json:"openid"` + Ver string `json:"ver"` +} + +type GetcashData struct { + Redbag float32 `json:"redbag"` +} + +type GetcashResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data GetcashData `json:"data"` +} + type QueryGamblingResp struct { Code int `json:"code"` Message string `json:"message"` @@ -576,6 +653,8 @@ type GetMainPageInfoData struct { Level int `json:"level"` TotalCashReward float32 `json:"totalCashReward"` Guide bool `json:"guide"` + Redbagnum int `json:"redbagnum"` + Flyboxnum int `json:"flyboxnum"` } type GetMainPageInfoResp struct { @@ -651,6 +730,18 @@ type GetOfflineRewardResp struct { Data GetOfflineRewardData `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 PosData struct { @@ -719,9 +810,25 @@ type AchieveMentData struct { HaveComplete map[int]int //记录已完成成就已完成则不再触发 } +type WithDrawDesc struct { + Cid int `json:"cid"` + Cnum float32 `json:"cnum"` + Isnew int `json:"isnew"` + Limitlv int `json:"limitlv"` + LoginDayLimit int `json:"loginDayLimit"` + Preisfind int `json:"preisfind"` + IsFit int `json:"isfit"` +} + +type WithDrawInfo struct { + Cashdata []WithDrawDesc `json:"cashdata"` +} + //玩家数据 type UserData struct { UserId int //玩家id + Gameid string //玩家Gameid + Channel string //玩家Channel RegTime int //注册时间 ContinueLoginDay int //连续登陆天数 SumLoginDay int //累计登录天数 @@ -760,6 +867,10 @@ type UserData struct { FlopCardLefCnt int //剩余翻拍次数 TodayZhaocai float32 //当天招财猫收益 IsNew int //是否需要引导 + RandRedBagLeftTime int //剩余随机红包次数 + SumRandRedBagTimes int //已领取的随机红包总次数 + StoreRandRedBag int //存储的随机红包个数 + FlyBoxNumTimes int //生意飞天宝箱次数 CatShopInfo CatShopData //猫咖门店数据 Taskinfo TaskData //任务数据 AchieveMent AchieveMentData //成就数据 @@ -768,6 +879,7 @@ type UserData struct { BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推 CatRoomInfo []CatRoomData //猫咖店数据 CaiPiaoInfo []UserCaiPiaoHistory //记录玩家参与过的赌博猫历史记录 + WithDraw WithDrawInfo //提现记录信息 } @@ -841,3 +953,73 @@ type AlreadyDuboCatList struct { RewardUser int //中奖者ID 如果假中奖为0 TimeStr int //开奖时刻 } + +//..... +type TixianDesc struct { + Sign string `json:"sign"` + Sign_type string `json:"sign_type"` + Time_stamp string `json:"time_stamp"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Uid int `json:"uid"` + Typ int `json:"typ"` + Money int `json:"money"` + Openid string `json:"openid"` + Nickname string `json:"nickname"` + Headurl string `json:"headurl"` + Editcoin int `json:"editcoin"` + Ver string `json:"ver"` + Checkcoin int `json:"checkcoin"` +} + +type GetCashResp struct { + Code string `json:"code"` + Msg string `json:"msg"` +} + +type GetCoinDesc struct { + Sign string `json:"sign"` + Sign_type string `json:"sign_type"` + Time_stamp string `json:"time_stamp"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Uid int `json:"uid"` +} + +type AddCoinResultData struct { + Mycoin int `json:"mycoin"` +} + +type AddCoinResp struct { + Code string `json:"code"` + Msg string `json:"msg"` + Data AddCoinResultData `json:"data"` +} + +type AddCoinDesc struct { + Sign string `json:"sign"` + Sign_type string `json:"sign_type"` + Time_stamp string `json:"time_stamp"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Uid int `json:"uid"` + Coin int `json:"coin"` + Typ int `json:"typ"` +} + +type GetCashListDesc struct { + Sign string `json:"sign"` + Sign_type string `json:"sign_type"` + Time_stamp string `json:"time_stamp"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Uid int `json:"uid"` + Start int `json:"start"` + Number int `json:"number"` +} + +type GetCashListResp struct { + Code string `json:"code"` + Msg string `json:"msg"` + Data []WithDrawRecord `json:"data"` +} diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 328cb58..1e08bcc 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -1,12 +1,19 @@ package logic import ( + "HttpServer/conf" "HttpServer/jsonconf" "HttpServer/redishandler" + "bytes" "common/logger" "common/redis" + "crypto/md5" + "encoding/hex" "encoding/json" + "errors" + "io/ioutil" "math/rand" + "net/http" "sort" "strconv" "time" @@ -127,10 +134,132 @@ func SetCaiPiaoFake(num, round int) { } } +//计算飞天宝箱 +func (u *UserData) GenerateFlyBoxID() int { + sumrate := 0 + tmprate := 0 + + rand.Seed(time.Now().UnixNano()) + randnum := rand.Intn(100) + cflist := jsonconf.GetJsonConf().BoxConfig + if len(cflist) == 0 { + logger.Error("GenerateFlyBoxID len failed ") + return 0 + } + idx := cflist[0].Id + for _, vv := range cflist { + sumrate += vv.Rate + } + for _, v := range cflist { + tmprate += int(v.Rate * 100 / sumrate) + if tmprate >= randnum { + idx = v.Id + break + } + } + + return idx +} + +//计算生成的箱子id +func (u *UserData) GenerateBox() int { + sumrate := 0 + tmprate := 0 + + rand.Seed(time.Now().UnixNano()) + randnum := rand.Intn(100) + cflist := jsonconf.GetJsonConf().GiftConfig + if len(cflist) == 0 { + logger.Error("CalcBoxId len failed ") + return 0 + } + idx := cflist[0].Id + for _, vv := range cflist { + sumrate += vv.Rate + } + for _, v := range cflist { + tmprate += int(v.Rate * 100 / sumrate) + if tmprate >= randnum { + idx = v.Id + break + } + } + + u.PosInfo[BOXGIFTPOS].Cat = idx + BOXGIFTEXTRA + SaveUserInfo(u, strconv.Itoa(u.UserId)) + return idx +} + +//计算领取随机红包值 +func (u *UserData) CalcRandRedBagNum() float32 { + //todo 用公式计算 + return 0.1 +} + //加红包接口 -func (u *UserData) AddRedPackect(num float32) { - //todo 接后台 - u.Redbag += num +func (u *UserData) AddRedPackect(num float32, atype int) (int, error) { + SERVERKEY := conf.GetCoinConf().Key + goldnum := int(num * 10000) + var paramlist []string + sign_type := "sign_type=md5" + paramlist = append(paramlist, sign_type) + time_stamp := "time_stamp=" + strconv.Itoa(int(time.Now().Unix())) + paramlist = append(paramlist, time_stamp) + paramgameid := "gameid=" + u.Gameid + paramlist = append(paramlist, paramgameid) + pchannel := "channel=" + u.Channel + paramlist = append(paramlist, pchannel) + puid := "uid=" + strconv.Itoa(u.UserId) + paramlist = append(paramlist, puid) + pcoin := "coin=" + strconv.Itoa(goldnum) + paramlist = append(paramlist, pcoin) + ptyp := "typ=" + strconv.Itoa(atype) + paramlist = append(paramlist, ptyp) + + sumparam := GettotalParam(paramlist) + //加serverkey + signsum := sumparam + SERVERKEY + logger.Info("AddCoinToSdk sumparam=%v", signsum) + + //进行hash + sign := GetHashValue(signsum) + + var req AddCoinDesc + req.Channel = u.Channel + req.Gameid = u.Gameid + req.Coin = goldnum + req.Sign = sign + req.Sign_type = "md5" + req.Time_stamp = strconv.Itoa(int(time.Now().Unix())) + req.Typ = atype + req.Uid = u.UserId + + bys, err := json.Marshal(&req) + if err != nil { + logger.Error("AddCoinToSdk failed=%v", err) + return 0, err + } + res, err := DoHttpPost(bys, "api/server/addcoin") + if err != nil { + logger.Error("AddCoinToSdk failed=%v", err) + return 0, err + } + + logger.Info("AddCoinToSdk res=%v", res) + var resp AddCoinResp + err = json.Unmarshal([]byte(res), &resp) + if err != nil { + logger.Error("AddCoinToSdk failed=%v", err) + return 0, err + } + + if resp.Code != "0" { + gold, _ := GetCoinFromSdk(u.UserId, u.Gameid, u.Channel) + logger.Error("AddCoinToSdk failed=%v", resp.Msg) + return gold, err + } + return resp.Data.Mycoin, nil + } //清空一个位置的猫 @@ -165,7 +294,7 @@ func (u *UserData) SetCatPos(pos int, catlv, time int, redpack float32, starttim func (u *UserData) GetLimitCatList() []int { var rtlist []int for k, v := range u.PosInfo { - if v.Cat > 36 { + if v.Cat > 36 && v.Cat < 1000 { rtlist = append(rtlist, k) } } @@ -340,6 +469,8 @@ func (u *UserData) HandlePassDay() { u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT u.DrawTicket = DRAWTICKETNUM u.DrawTicketTimes = DRAWTICKETGETLIMIT + u.RandRedBagLeftTime = RANDGIFTLIMIT + u.FlyBoxNumTimes = FLYBOXNUMLIMIT } u.LastLoginTime = int(nowtime.Unix()) @@ -359,6 +490,16 @@ func SaveUserInfo(data *UserData, uniqueid string) error { return err } +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 GetUserInfo(uid string) (*UserData, error) { data, err := redishandler.GetRedisClient().HGet(redis.USER_INFO__KEY, uid) @@ -403,13 +544,19 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { udata.FlopCardCnt = 1 udata.ContinueLoginDay = 1 udata.SumLoginDay = 1 + udata.RandRedBagLeftTime = RANDGIFTLIMIT + udata.FlyBoxNumTimes = FLYBOXNUMLIMIT + udata.SumRandRedBagTimes = 0 + udata.StoreRandRedBag = 0 + udata.Gameid = data.Gameid + udata.Channel = data.Channel //test udata.FlopCardLefCnt = 100 udata.NickName = "著名的沙雕玩家" udata.Head = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIjPolxbUHLkrrfTBDl9Nj6KDicqHibXnMfM6L9cY2IT95T2hmv5RWXLrmGas7ms1A1H0jg8kDQFcGw/132" //初始化16个猫爬架 - for i := 0; i < 16; i++ { + for i := 0; i < 12; i++ { var d1 CatPosInfo d1.Position = i @@ -419,12 +566,29 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { d1.Cat = 36 } udata.PosInfo = append(udata.PosInfo, d1) - var d2 DataDesc - d2.Pos = i - d2.Catlv = 0 } + //初始化提现档位 + for _, val := range jsonconf.GetJsonConf().RMBConfig { + var tmp WithDrawDesc + tmp.Cid = val.Id + tmp.Cnum = val.Rmb_num + if val.Time == 1 { + tmp.Isnew = 1 + } else { + tmp.Isnew = 2 + } + tmp.Limitlv = val.Cat_level + tmp.LoginDayLimit = val.Login_day + if val.Id == 1 { + tmp.Preisfind = 1 + } else { + tmp.Preisfind = 0 + } + udata.WithDraw.Cashdata = append(udata.WithDraw.Cashdata, tmp) + } + udata.Loverate = 0 udata.CalcGoldRate() @@ -896,3 +1060,270 @@ func (w *UserWareHouseData) GetWarePosById(cid int) int { } return -1 } + +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 GettotalParam(paramlist []string) string { + //排序 + sort.Strings(paramlist) + + //拼接 + sumparam := "" + for _, val := range paramlist { + sumparam += val + } + + return sumparam +} + +func GetHashValue(signsum string) string { + /*h := sha1.New() + h.Write([]byte(signsum)) + bs := h.Sum(nil) + sign := hex.EncodeToString(bs)*/ + ctx := md5.New() + ctx.Write([]byte(signsum)) + return hex.EncodeToString(ctx.Sum(nil)) +} + +func DoHttpPost(bys []byte, apistr string) (string, error) { + body := bytes.NewBuffer(bys) + url1 := conf.GetCoinConf().Host + apistr //"api/server/addcoin" + + res, err := http.Post(url1, "application/json;charset=utf-8", body) + if err != nil { + logger.Error("DoHttpPost failed err=%v", err) + return "", err + } + result, _ := ioutil.ReadAll(res.Body) + defer res.Body.Close() + + return string(result), nil +} + +func GetCoinFromSdk(uuid int, gameid string, channel string) (int, error) { + + SERVERKEY := conf.GetCoinConf().Key + /*if gameid == "1015" { + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015 + }*/ + + var paramlist []string + var params GetCoinDesc + params.Sign_type = "md5" + params.Gameid = gameid + params.Channel = channel + params.Uid = uuid + params.Time_stamp = strconv.Itoa(int(time.Now().Unix())) + 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) + paramlist = append(paramlist, signtypestr) + paramlist = append(paramlist, timestampstr) + paramlist = append(paramlist, paramgameid) + paramlist = append(paramlist, pchannel) + paramlist = append(paramlist, puid) + + sumparam := GettotalParam(paramlist) + //加serverkey + signsum := sumparam + SERVERKEY + + //进行hash + sign := GetHashValue(signsum) + params.Sign = sign + logger.Info("GetCoinFromSdk sumparam is:%v,sign is:", signsum, sign) + + bys, err := json.Marshal(¶ms) + if err != nil { + logger.Error("GetCoinFromSdk failed=%v", err) + return 0, err + } + res, err := DoHttpPost(bys, "api/server/getcoin") + if err != nil { + logger.Error("GetCoinFromSdk failed=%v", err) + return 0, err + } + + logger.Info("GetCoinFromSdk res=%v", res) + + var resp AddCoinResp + err = json.Unmarshal([]byte(res), &resp) + if err != nil { + logger.Error("GetCoinFromSdk failed=%v", err) + return 0, err + } + + if resp.Code != "0" { + logger.Error("GetCoinFromSdk failed=%v", resp.Msg) + return 0, err + } + + return resp.Data.Mycoin, 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 +} diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index a5a5c85..a041951 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -46,7 +46,7 @@ func StartHttpTicker() { cfg := jsonconf.GetRedCatConfig(48) if cfg != nil { - uinfo.AddRedPackect(cfg.Money) + uinfo.AddRedPackect(cfg.Money, 100) } var tmp UserCaiPiaoHistory @@ -139,6 +139,14 @@ func startServerHttpServe() { http.HandleFunc("/api/gambling/removeCat", RemoveCat) //清除猫 http.HandleFunc("/api/user/info", UserInfo) //个人信息 http.HandleFunc("api/ad/add", AddAd) //看广告 + //新增的接口 + http.HandleFunc("/happycat/getrandredbag", Getrandredbag) //领取随机红包 + http.HandleFunc("/happycat/generatebox", Generatebox) //请求刷出空格礼包 + http.HandleFunc("/happycat/getboxreward", Getboxreward) // 请求领取空格礼包 + http.HandleFunc("/happycat/getflyboxreward", Getflyboxreward) // 请求领取飞天宝箱 + http.HandleFunc("/happycat/querygetcashinfo", Querygetcashinfo) // 请求提现档位信息 + http.HandleFunc("/happycat/getcash", Getcash) // 请求提现 + http.HandleFunc("/happycat/getcashrecord", Getcashrecord) // 请求提现 /////---------------------------------------------------------------------old //http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 @@ -1129,6 +1137,132 @@ func AddAd(w http.ResponseWriter, r *http.Request) { HandlerAddAd(w, s, Uuid) } +func Getcashrecord(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + 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("uid")) + } + if Uuid == 0 { + SetHeader(w) + 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 Querygetcashinfo(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Querygetcashinfo , body:%v,uuid=%v", s, Uuid) + + HandlerQuerygetcashinfo(w, s, Uuid) +} + +func Getflyboxreward(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Getflyboxreward , body:%v,uuid=%v", s, Uuid) + + HandlerGetflyboxreward(w, s, Uuid) +} + +func Getboxreward(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Getboxreward , body:%v,uuid=%v", s, Uuid) + + HandlerGetboxreward(w, s, Uuid) +} + +func Generatebox(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Generatebox , body:%v,uuid=%v", s, Uuid) + + HandlerGeneratebox(w, s, Uuid) +} + +func Getrandredbag(w http.ResponseWriter, r *http.Request) { + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) + } + if Uuid == 0 { + SetHeader(w) + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Getrandredbag , body:%v,uuid=%v", s, Uuid) + + HandlerGetrandredbag(w, s, Uuid) +} + func TestaddCat(w http.ResponseWriter, r *http.Request) { Uuid := 0 if len(r.Header) > 0 { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index b3ee7b9..776b371 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -255,6 +255,406 @@ func HandlerAddAd(w http.ResponseWriter, data string, uuid int) { fmt.Fprint(w, string(respstr)) } +func HandlerGetflyboxreward(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetboxrewardResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerGetflyboxreward getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //获取剩余次数 + if uinfo.FlyBoxNumTimes < 1 { + logger.Error("HandlerGetflyboxreward not times failed=%v", err) + resp.Code = 1 + resp.Message = "已经没有剩余宝箱次数了" + break + } + + boxid := uinfo.GenerateFlyBoxID() + cfg := jsonconf.GetBoxConfif(boxid) + if cfg == nil { + logger.Error("HandlerGetboxreward getcfgfailed failed=%v", boxid) + resp.Code = 1 + resp.Message = "getcfgfailed" + break + } + if cfg.Ttype == 1 { + //金币 + resp.Data.Getgold = int64(float32(uinfo.Goldrate) * cfg.Time) + + uinfo.Gold += resp.Data.Getgold + } else if cfg.Ttype == 2 { + //红包 + resp.Data.Getredbag = cfg.Time + uinfo.AddRedPackect(resp.Data.Getredbag, 100) + } + + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + 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 + 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, uinfo.Gameid, uinfo.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, 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.Highestlv < info.Limitlv || uinfo.ContinueLoginDay < info.LoginDayLimit { + logger.Error("HandlerGetcash notfit failed=%v", err) + resp.Code = 1 + resp.Message = "提现条件不满足" + break + } + } else { + if uinfo.Highestlv < info.Limitlv || uinfo.SumLoginDay < info.LoginDayLimit { + 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, uinfo.Gameid, uinfo.Channel, rdata.Openid, uinfo.NickName, uinfo.Head, 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.Redbag = float32(gold) / 10000 + + //保存 + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + break + + } + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerQuerygetcashinfo(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QuerygetcashinfoResp + resp.Code = 0 + resp.Message = "success" + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerGetflyboxreward getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //返回 + resp.Data.Logindaycontinue = uinfo.ContinueLoginDay + resp.Data.Logindaysum = uinfo.SumLoginDay + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...) + + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerGetboxreward(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetboxrewardResp + resp.Code = 0 + resp.Message = "success" + var rdata GetboxrewardReq + err := json.Unmarshal([]byte(data), &rdata) + + for { + if err != nil { + logger.Error("HandlerGetboxreward 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("HandlerGetboxreward getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + if uinfo.PosInfo[BOXGIFTPOS].Cat < BOXGIFTEXTRA { + //没有存在合法的空格礼物 + logger.Error("HandlerGetboxreward empty failed=%v", err) + resp.Code = 1 + resp.Message = "empty" + break + } + + //获取配置 + boxid := uinfo.PosInfo[BOXGIFTPOS].Cat - BOXGIFTEXTRA + cfg := jsonconf.GetGiftConfif(boxid) + if cfg == nil { + logger.Error("HandlerGetboxreward getcfgfailed failed=%v", err) + resp.Code = 1 + resp.Message = "getcfgfailed" + break + } + + mult := int64(1) + if rdata.Optype == 2 { + mult = 2 + } + + if cfg.Ttype == 1 { + //金币 + resp.Data.Getgold = int64(float32(uinfo.Goldrate) * cfg.Time) + resp.Data.Getgold = resp.Data.Getgold * mult + uinfo.Gold += resp.Data.Getgold + } else if cfg.Ttype == 2 { + //红包 + resp.Data.Getredbag = cfg.Time * float32(mult) + uinfo.AddRedPackect(resp.Data.Getredbag, 100) + } + + uinfo.CleadPos(BOXGIFTPOS) + + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerGeneratebox(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GenerateboxResp + resp.Code = 0 + resp.Message = "success" + + for { + + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) + if err != nil || uinfo == nil { + logger.Error("HandlerGeneratebox getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + if uinfo.PosInfo[BOXGIFTPOS].Cat != 0 { + //位置被占用无法生成 + logger.Error("HandlerGeneratebox not empty failed=%v", err) + resp.Code = -1 + resp.Message = "not empty" + break + } + + boxid := uinfo.GenerateBox() + resp.Data.Boixid = boxid + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerGetrandredbag(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp GetrandredbagResp + resp.Code = 0 + resp.Message = "success" + var rdata GetrandredbagReq + err := json.Unmarshal([]byte(data), &rdata) + + for { + + if err != nil { + logger.Error("HandlerGetrandredbag 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("HandlerGetrandredbag getuserinfo failed=%v", err) + resp.Code = 1 + resp.Message = "get userinfo failed" + break + } + + //直接领取 + if rdata.Optype == 1 { + //直接领取 + if uinfo.RandRedBagLeftTime < 1 { + //已经没有领取次数了 + logger.Error("HandlerGetrandredbag storenum not enough failed=%v", err) + resp.Code = 1 + resp.Message = "storenum not enougd" + break + } + + addnum := uinfo.CalcRandRedBagNum() + uinfo.AddRedPackect(addnum, 100) + addgold := int(addnum * 10000) + resp.Data.Getnum = addgold + + uinfo.SumRandRedBagTimes++ + uinfo.RandRedBagLeftTime-- + } else if rdata.Optype == 2 { + //存储 + if uinfo.StoreRandRedBag >= 1 { + //不能存更多 + logger.Error("HandlerGetrandredbag storenum failed=%v", err) + resp.Code = 1 + resp.Message = "storenum failed" + break + } + + uinfo.StoreRandRedBag++ + resp.Data.Getnum = 0 + break + } else { + //领取存储的红包 + if uinfo.StoreRandRedBag < 1 || uinfo.RandRedBagLeftTime < 1 { + //没有可以领取的 + logger.Error("HandlerGetrandredbag storenum not enough failed=%v", err) + resp.Code = 1 + resp.Message = "storenum not enougd" + break + } + + //加红包 + //计算一下零取值 + addnum := uinfo.CalcRandRedBagNum() + uinfo.AddRedPackect(addnum, 100) + addgold := int(addnum * 10000) + resp.Data.Getnum = addgold + + uinfo.StoreRandRedBag-- + uinfo.SumRandRedBagTimes++ + uinfo.RandRedBagLeftTime-- + + } + + SaveUserInfo(uinfo, strconv.Itoa(uuid)) + + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerUserInfo(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp UserInfoResp @@ -587,6 +987,8 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { if uinfo.IsNew == 0 { resp.Data.Guide = false } + resp.Data.Redbagnum = uinfo.StoreRandRedBag + resp.Data.Flyboxnum = uinfo.FlyBoxNumTimes resp.Code = 0 break } @@ -936,7 +1338,7 @@ func HandlerRecvRedCat(w http.ResponseWriter, data string, uuid int) { addredpack = addredpack * 2 } - uinfo.AddRedPackect(addredpack) + uinfo.AddRedPackect(addredpack, 100) uinfo.CleadPos(cpos) uinfo.CalcGoldRate() -- libgit2 0.21.0