Commit a23ace635a26f7d7e77025d55638122618cd74f4

Authored by 陆恒
1 parent 42701512
Exists in master

有钱猫改动

src/HttpServer/conf/conf.go
... ... @@ -29,6 +29,10 @@ var (
29 29 config = new(TexasConf)
30 30 )
31 31  
  32 +func GetCoinConf() ConiSrvConf {
  33 + return config.CoinSrv
  34 +}
  35 +
32 36 func GetRedisConf() RedisConf {
33 37 return config.Redis
34 38 }
... ...
src/HttpServer/jsonconf/jsonconf.go
... ... @@ -76,6 +76,24 @@ type GameConfig struct {
76 76 RMBConfig []RMBConfigDesc
77 77 }
78 78  
  79 +func GetBoxConfif(id int) *BoxConfigDesc {
  80 + for _, v := range g_jsonconf.BoxConfig {
  81 + if v.Id == id {
  82 + return &v
  83 + }
  84 + }
  85 + return nil
  86 +}
  87 +
  88 +func GetGiftConfif(id int) *BoxConfigDesc {
  89 + for _, v := range g_jsonconf.GiftConfig {
  90 + if v.Id == id {
  91 + return &v
  92 + }
  93 + }
  94 + return nil
  95 +}
  96 +
79 97 func GetJsonConf() *GameConfig {
80 98 return g_jsonconf
81 99 }
... ...
src/HttpServer/logic/constdef.go
... ... @@ -59,5 +59,8 @@ const (
59 59 DRAWTICKETGETLIMIT = 5 //每日抽奖券获得次数
60 60 DRAWTICKETNUMLIMIT = 10 //抽奖券上限
61 61 WAREHOUSELIMIT = 15 //仓库容量上限
62   -
  62 + RANDGIFTLIMIT = 10 //每日随机红包上线次数
  63 + BOXGIFTPOS = 10 //空格礼包固定位置
  64 + BOXGIFTEXTRA = 1000 //空格礼包id下发额外加成值
  65 + FLYBOXNUMLIMIT = 6 //飞天宝箱每日次数限制
63 66 )
... ...
src/HttpServer/logic/datadef.go
... ... @@ -15,9 +15,11 @@ type TestAddCatResp struct {
15 15 }
16 16  
17 17 type UserLoginReq struct {
18   - Lype int `json:"type"`
19   - UserId int `json:"userId"`
20   - Fromid int `json:"fromid"`
  18 + Lype int `json:"type"`
  19 + UserId int `json:"userId"`
  20 + Fromid int `json:"fromid"`
  21 + Gameid string `json:"gameid"`
  22 + Channel string `json:"channel"`
21 23 }
22 24  
23 25 type UserLoginData struct {
... ... @@ -78,6 +80,65 @@ type UserInfoResp struct {
78 80 Data UserInfoData `json:"data"`
79 81 }
80 82  
  83 +type GetrandredbagReq struct {
  84 + Optype int `json:"optype"`
  85 +}
  86 +
  87 +type GetrandredbagData struct {
  88 + Getnum int `json:"getnum"`
  89 +}
  90 +
  91 +type GetrandredbagResp struct {
  92 + Code int `json:"code"`
  93 + Message string `json:"message"`
  94 + Data GetrandredbagData `json:"data"`
  95 +}
  96 +
  97 +type GenerateboxData struct {
  98 + Boixid int `json:"boixid"`
  99 +}
  100 +
  101 +type GenerateboxResp struct {
  102 + Code int `json:"code"`
  103 + Message string `json:"message"`
  104 + Data GenerateboxData `json:"data"`
  105 +}
  106 +
  107 +type GetboxrewardReq struct {
  108 + Optype int `json:"optype"`
  109 +}
  110 +
  111 +type GetboxrewardData struct {
  112 + Getgold int64 `json:"getgold"`
  113 + Getredbag float32 `json:"getredbag"`
  114 +}
  115 +
  116 +type GetboxrewardResp struct {
  117 + Code int `json:"code"`
  118 + Message string `json:"message"`
  119 + Data GetboxrewardData `json:"data"`
  120 +}
  121 +
  122 +type WithDrawRecord struct {
  123 + Coin int `json:"coin"`
  124 + Create_time int `json:"create_time"`
  125 + Money int `json:"money"`
  126 + No string `json:"no"`
  127 + Status int `json:"status"`
  128 + Statusmsg string `json:"statusmsg"`
  129 + Typ int `json:"typ"`
  130 +}
  131 +
  132 +type WithDrawList struct {
  133 + Withdata []WithDrawRecord `json:"withdata"`
  134 +}
  135 +
  136 +type GetcashrecordResp struct {
  137 + Code int `json:"code"`
  138 + Message string `json:"message"`
  139 + Data WithDrawList `json:"data"`
  140 +}
  141 +
81 142 type AddAdData struct {
82 143 }
83 144  
... ... @@ -417,6 +478,22 @@ type QueryGamblingData struct {
417 478 HeadImg string `json:"headImg"`
418 479 }
419 480  
  481 +type GetcashReq struct {
  482 + Money float32 `json:"money"`
  483 + Openid string `json:"openid"`
  484 + Ver string `json:"ver"`
  485 +}
  486 +
  487 +type GetcashData struct {
  488 + Redbag float32 `json:"redbag"`
  489 +}
  490 +
  491 +type GetcashResp struct {
  492 + Code int `json:"code"`
  493 + Message string `json:"message"`
  494 + Data GetcashData `json:"data"`
  495 +}
  496 +
420 497 type QueryGamblingResp struct {
421 498 Code int `json:"code"`
422 499 Message string `json:"message"`
... ... @@ -576,6 +653,8 @@ type GetMainPageInfoData struct {
576 653 Level int `json:"level"`
577 654 TotalCashReward float32 `json:"totalCashReward"`
578 655 Guide bool `json:"guide"`
  656 + Redbagnum int `json:"redbagnum"`
  657 + Flyboxnum int `json:"flyboxnum"`
579 658 }
580 659  
581 660 type GetMainPageInfoResp struct {
... ... @@ -651,6 +730,18 @@ type GetOfflineRewardResp struct {
651 730 Data GetOfflineRewardData `json:"data"`
652 731 }
653 732  
  733 +type QuerygetcashinfoData struct {
  734 + Logindaysum int `json:"logindaysum"`
  735 + Logindaycontinue int `json:"logindaycontinue"`
  736 + Cashdata []WithDrawDesc `json:"cashdata"`
  737 +}
  738 +
  739 +type QuerygetcashinfoResp struct {
  740 + Code int `json:"code"`
  741 + Message string `json:"message"`
  742 + Data QuerygetcashinfoData `json:"data"`
  743 +}
  744 +
654 745 //**********************************************************************************************************
655 746  
656 747 type PosData struct {
... ... @@ -719,9 +810,25 @@ type AchieveMentData struct {
719 810 HaveComplete map[int]int //记录已完成成就已完成则不再触发
720 811 }
721 812  
  813 +type WithDrawDesc struct {
  814 + Cid int `json:"cid"`
  815 + Cnum float32 `json:"cnum"`
  816 + Isnew int `json:"isnew"`
  817 + Limitlv int `json:"limitlv"`
  818 + LoginDayLimit int `json:"loginDayLimit"`
  819 + Preisfind int `json:"preisfind"`
  820 + IsFit int `json:"isfit"`
  821 +}
  822 +
  823 +type WithDrawInfo struct {
  824 + Cashdata []WithDrawDesc `json:"cashdata"`
  825 +}
  826 +
722 827 //玩家数据
723 828 type UserData struct {
724 829 UserId int //玩家id
  830 + Gameid string //玩家Gameid
  831 + Channel string //玩家Channel
725 832 RegTime int //注册时间
726 833 ContinueLoginDay int //连续登陆天数
727 834 SumLoginDay int //累计登录天数
... ... @@ -760,6 +867,10 @@ type UserData struct {
760 867 FlopCardLefCnt int //剩余翻拍次数
761 868 TodayZhaocai float32 //当天招财猫收益
762 869 IsNew int //是否需要引导
  870 + RandRedBagLeftTime int //剩余随机红包次数
  871 + SumRandRedBagTimes int //已领取的随机红包总次数
  872 + StoreRandRedBag int //存储的随机红包个数
  873 + FlyBoxNumTimes int //生意飞天宝箱次数
763 874 CatShopInfo CatShopData //猫咖门店数据
764 875 Taskinfo TaskData //任务数据
765 876 AchieveMent AchieveMentData //成就数据
... ... @@ -768,6 +879,7 @@ type UserData struct {
768 879 BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推
769 880 CatRoomInfo []CatRoomData //猫咖店数据
770 881 CaiPiaoInfo []UserCaiPiaoHistory //记录玩家参与过的赌博猫历史记录
  882 + WithDraw WithDrawInfo //提现记录信息
771 883  
772 884 }
773 885  
... ... @@ -841,3 +953,73 @@ type AlreadyDuboCatList struct {
841 953 RewardUser int //中奖者ID 如果假中奖为0
842 954 TimeStr int //开奖时刻
843 955 }
  956 +
  957 +//.....
  958 +type TixianDesc struct {
  959 + Sign string `json:"sign"`
  960 + Sign_type string `json:"sign_type"`
  961 + Time_stamp string `json:"time_stamp"`
  962 + Gameid string `json:"gameid"`
  963 + Channel string `json:"channel"`
  964 + Uid int `json:"uid"`
  965 + Typ int `json:"typ"`
  966 + Money int `json:"money"`
  967 + Openid string `json:"openid"`
  968 + Nickname string `json:"nickname"`
  969 + Headurl string `json:"headurl"`
  970 + Editcoin int `json:"editcoin"`
  971 + Ver string `json:"ver"`
  972 + Checkcoin int `json:"checkcoin"`
  973 +}
  974 +
  975 +type GetCashResp struct {
  976 + Code string `json:"code"`
  977 + Msg string `json:"msg"`
  978 +}
  979 +
  980 +type GetCoinDesc struct {
  981 + Sign string `json:"sign"`
  982 + Sign_type string `json:"sign_type"`
  983 + Time_stamp string `json:"time_stamp"`
  984 + Gameid string `json:"gameid"`
  985 + Channel string `json:"channel"`
  986 + Uid int `json:"uid"`
  987 +}
  988 +
  989 +type AddCoinResultData struct {
  990 + Mycoin int `json:"mycoin"`
  991 +}
  992 +
  993 +type AddCoinResp struct {
  994 + Code string `json:"code"`
  995 + Msg string `json:"msg"`
  996 + Data AddCoinResultData `json:"data"`
  997 +}
  998 +
  999 +type AddCoinDesc struct {
  1000 + Sign string `json:"sign"`
  1001 + Sign_type string `json:"sign_type"`
  1002 + Time_stamp string `json:"time_stamp"`
  1003 + Gameid string `json:"gameid"`
  1004 + Channel string `json:"channel"`
  1005 + Uid int `json:"uid"`
  1006 + Coin int `json:"coin"`
  1007 + Typ int `json:"typ"`
  1008 +}
  1009 +
  1010 +type GetCashListDesc struct {
  1011 + Sign string `json:"sign"`
  1012 + Sign_type string `json:"sign_type"`
  1013 + Time_stamp string `json:"time_stamp"`
  1014 + Gameid string `json:"gameid"`
  1015 + Channel string `json:"channel"`
  1016 + Uid int `json:"uid"`
  1017 + Start int `json:"start"`
  1018 + Number int `json:"number"`
  1019 +}
  1020 +
  1021 +type GetCashListResp struct {
  1022 + Code string `json:"code"`
  1023 + Msg string `json:"msg"`
  1024 + Data []WithDrawRecord `json:"data"`
  1025 +}
... ...
src/HttpServer/logic/function.go
1 1 package logic
2 2  
3 3 import (
  4 + "HttpServer/conf"
4 5 "HttpServer/jsonconf"
5 6 "HttpServer/redishandler"
  7 + "bytes"
6 8 "common/logger"
7 9 "common/redis"
  10 + "crypto/md5"
  11 + "encoding/hex"
8 12 "encoding/json"
  13 + "errors"
  14 + "io/ioutil"
9 15 "math/rand"
  16 + "net/http"
10 17 "sort"
11 18 "strconv"
12 19 "time"
... ... @@ -127,10 +134,132 @@ func SetCaiPiaoFake(num, round int) {
127 134 }
128 135 }
129 136  
  137 +//计算飞天宝箱
  138 +func (u *UserData) GenerateFlyBoxID() int {
  139 + sumrate := 0
  140 + tmprate := 0
  141 +
  142 + rand.Seed(time.Now().UnixNano())
  143 + randnum := rand.Intn(100)
  144 + cflist := jsonconf.GetJsonConf().BoxConfig
  145 + if len(cflist) == 0 {
  146 + logger.Error("GenerateFlyBoxID len failed ")
  147 + return 0
  148 + }
  149 + idx := cflist[0].Id
  150 + for _, vv := range cflist {
  151 + sumrate += vv.Rate
  152 + }
  153 + for _, v := range cflist {
  154 + tmprate += int(v.Rate * 100 / sumrate)
  155 + if tmprate >= randnum {
  156 + idx = v.Id
  157 + break
  158 + }
  159 + }
  160 +
  161 + return idx
  162 +}
  163 +
  164 +//计算生成的箱子id
  165 +func (u *UserData) GenerateBox() int {
  166 + sumrate := 0
  167 + tmprate := 0
  168 +
  169 + rand.Seed(time.Now().UnixNano())
  170 + randnum := rand.Intn(100)
  171 + cflist := jsonconf.GetJsonConf().GiftConfig
  172 + if len(cflist) == 0 {
  173 + logger.Error("CalcBoxId len failed ")
  174 + return 0
  175 + }
  176 + idx := cflist[0].Id
  177 + for _, vv := range cflist {
  178 + sumrate += vv.Rate
  179 + }
  180 + for _, v := range cflist {
  181 + tmprate += int(v.Rate * 100 / sumrate)
  182 + if tmprate >= randnum {
  183 + idx = v.Id
  184 + break
  185 + }
  186 + }
  187 +
  188 + u.PosInfo[BOXGIFTPOS].Cat = idx + BOXGIFTEXTRA
  189 + SaveUserInfo(u, strconv.Itoa(u.UserId))
  190 + return idx
  191 +}
  192 +
  193 +//计算领取随机红包值
  194 +func (u *UserData) CalcRandRedBagNum() float32 {
  195 + //todo 用公式计算
  196 + return 0.1
  197 +}
  198 +
130 199 //加红包接口
131   -func (u *UserData) AddRedPackect(num float32) {
132   - //todo 接后台
133   - u.Redbag += num
  200 +func (u *UserData) AddRedPackect(num float32, atype int) (int, error) {
  201 + SERVERKEY := conf.GetCoinConf().Key
  202 + goldnum := int(num * 10000)
  203 + var paramlist []string
  204 + sign_type := "sign_type=md5"
  205 + paramlist = append(paramlist, sign_type)
  206 + time_stamp := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  207 + paramlist = append(paramlist, time_stamp)
  208 + paramgameid := "gameid=" + u.Gameid
  209 + paramlist = append(paramlist, paramgameid)
  210 + pchannel := "channel=" + u.Channel
  211 + paramlist = append(paramlist, pchannel)
  212 + puid := "uid=" + strconv.Itoa(u.UserId)
  213 + paramlist = append(paramlist, puid)
  214 + pcoin := "coin=" + strconv.Itoa(goldnum)
  215 + paramlist = append(paramlist, pcoin)
  216 + ptyp := "typ=" + strconv.Itoa(atype)
  217 + paramlist = append(paramlist, ptyp)
  218 +
  219 + sumparam := GettotalParam(paramlist)
  220 + //加serverkey
  221 + signsum := sumparam + SERVERKEY
  222 + logger.Info("AddCoinToSdk sumparam=%v", signsum)
  223 +
  224 + //进行hash
  225 + sign := GetHashValue(signsum)
  226 +
  227 + var req AddCoinDesc
  228 + req.Channel = u.Channel
  229 + req.Gameid = u.Gameid
  230 + req.Coin = goldnum
  231 + req.Sign = sign
  232 + req.Sign_type = "md5"
  233 + req.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  234 + req.Typ = atype
  235 + req.Uid = u.UserId
  236 +
  237 + bys, err := json.Marshal(&req)
  238 + if err != nil {
  239 + logger.Error("AddCoinToSdk failed=%v", err)
  240 + return 0, err
  241 + }
  242 + res, err := DoHttpPost(bys, "api/server/addcoin")
  243 + if err != nil {
  244 + logger.Error("AddCoinToSdk failed=%v", err)
  245 + return 0, err
  246 + }
  247 +
  248 + logger.Info("AddCoinToSdk res=%v", res)
  249 + var resp AddCoinResp
  250 + err = json.Unmarshal([]byte(res), &resp)
  251 + if err != nil {
  252 + logger.Error("AddCoinToSdk failed=%v", err)
  253 + return 0, err
  254 + }
  255 +
  256 + if resp.Code != "0" {
  257 + gold, _ := GetCoinFromSdk(u.UserId, u.Gameid, u.Channel)
  258 + logger.Error("AddCoinToSdk failed=%v", resp.Msg)
  259 + return gold, err
  260 + }
  261 + return resp.Data.Mycoin, nil
  262 +
134 263 }
135 264  
136 265 //清空一个位置的猫
... ... @@ -165,7 +294,7 @@ func (u *UserData) SetCatPos(pos int, catlv, time int, redpack float32, starttim
165 294 func (u *UserData) GetLimitCatList() []int {
166 295 var rtlist []int
167 296 for k, v := range u.PosInfo {
168   - if v.Cat > 36 {
  297 + if v.Cat > 36 && v.Cat < 1000 {
169 298 rtlist = append(rtlist, k)
170 299 }
171 300 }
... ... @@ -340,6 +469,8 @@ func (u *UserData) HandlePassDay() {
340 469 u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT
341 470 u.DrawTicket = DRAWTICKETNUM
342 471 u.DrawTicketTimes = DRAWTICKETGETLIMIT
  472 + u.RandRedBagLeftTime = RANDGIFTLIMIT
  473 + u.FlyBoxNumTimes = FLYBOXNUMLIMIT
343 474 }
344 475  
345 476 u.LastLoginTime = int(nowtime.Unix())
... ... @@ -359,6 +490,16 @@ func SaveUserInfo(data *UserData, uniqueid string) error {
359 490 return err
360 491 }
361 492  
  493 +func (uinfo *UserData) GetWithDrawData(money float32) (int, *WithDrawDesc) {
  494 + //处理提现状态
  495 + for k, val := range uinfo.WithDraw.Cashdata {
  496 + if val.Cnum == money {
  497 + return k, &val
  498 + }
  499 + }
  500 + return -1, nil
  501 +}
  502 +
362 503 func GetUserInfo(uid string) (*UserData, error) {
363 504  
364 505 data, err := redishandler.GetRedisClient().HGet(redis.USER_INFO__KEY, uid)
... ... @@ -403,13 +544,19 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
403 544 udata.FlopCardCnt = 1
404 545 udata.ContinueLoginDay = 1
405 546 udata.SumLoginDay = 1
  547 + udata.RandRedBagLeftTime = RANDGIFTLIMIT
  548 + udata.FlyBoxNumTimes = FLYBOXNUMLIMIT
  549 + udata.SumRandRedBagTimes = 0
  550 + udata.StoreRandRedBag = 0
  551 + udata.Gameid = data.Gameid
  552 + udata.Channel = data.Channel
406 553 //test
407 554 udata.FlopCardLefCnt = 100
408 555 udata.NickName = "著名的沙雕玩家"
409 556 udata.Head = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIjPolxbUHLkrrfTBDl9Nj6KDicqHibXnMfM6L9cY2IT95T2hmv5RWXLrmGas7ms1A1H0jg8kDQFcGw/132"
410 557  
411 558 //初始化16个猫爬架
412   - for i := 0; i < 16; i++ {
  559 + for i := 0; i < 12; i++ {
413 560 var d1 CatPosInfo
414 561 d1.Position = i
415 562  
... ... @@ -419,12 +566,29 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
419 566 d1.Cat = 36
420 567 }
421 568 udata.PosInfo = append(udata.PosInfo, d1)
422   - var d2 DataDesc
423   - d2.Pos = i
424   - d2.Catlv = 0
425 569  
426 570 }
427 571  
  572 + //初始化提现档位
  573 + for _, val := range jsonconf.GetJsonConf().RMBConfig {
  574 + var tmp WithDrawDesc
  575 + tmp.Cid = val.Id
  576 + tmp.Cnum = val.Rmb_num
  577 + if val.Time == 1 {
  578 + tmp.Isnew = 1
  579 + } else {
  580 + tmp.Isnew = 2
  581 + }
  582 + tmp.Limitlv = val.Cat_level
  583 + tmp.LoginDayLimit = val.Login_day
  584 + if val.Id == 1 {
  585 + tmp.Preisfind = 1
  586 + } else {
  587 + tmp.Preisfind = 0
  588 + }
  589 + udata.WithDraw.Cashdata = append(udata.WithDraw.Cashdata, tmp)
  590 + }
  591 +
428 592 udata.Loverate = 0
429 593 udata.CalcGoldRate()
430 594  
... ... @@ -896,3 +1060,270 @@ func (w *UserWareHouseData) GetWarePosById(cid int) int {
896 1060 }
897 1061 return -1
898 1062 }
  1063 +
  1064 +func GetCashFromSDK(uuid int, goldnum int, gameid, channel, openid, nickname, headurl, ver string, checkcoin int) (int, error) {
  1065 +
  1066 + SERVERKEY := conf.GetCoinConf().Key
  1067 +
  1068 + if goldnum == 0 || uuid == 0 || gameid == "" || channel == "" || openid == "" || ver == "" {
  1069 + logger.Error("GetCashFromSDK param empty")
  1070 + return 0, errors.New("param empty")
  1071 + }
  1072 + var paramlist []string
  1073 + var params TixianDesc
  1074 + params.Sign_type = "md5"
  1075 + params.Gameid = gameid
  1076 + params.Channel = channel
  1077 + params.Uid = uuid
  1078 + params.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  1079 + params.Headurl = headurl
  1080 + params.Money = goldnum
  1081 + params.Openid = openid
  1082 + params.Nickname = nickname
  1083 + params.Typ = 6
  1084 + params.Ver = ver
  1085 + params.Editcoin = 1
  1086 + params.Checkcoin = checkcoin
  1087 + signtypestr := "sign_type=" + params.Sign_type
  1088 + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  1089 + paramgameid := "gameid=" + gameid
  1090 + pchannel := "channel=" + channel
  1091 + puid := "uid=" + strconv.Itoa(uuid)
  1092 + phead := "headurl=" + headurl
  1093 + pnickname := "nickname=" + nickname
  1094 + popenid := "openid=" + openid
  1095 + pmoney := "money=" + strconv.Itoa(goldnum)
  1096 + ptype := "typ=" + "6" //微信
  1097 + ped := "editcoin=1"
  1098 + pcheco := "checkcoin=" + strconv.Itoa(checkcoin)
  1099 + //pver := "ver=" + params.Ver
  1100 + paramlist = append(paramlist, signtypestr)
  1101 + paramlist = append(paramlist, timestampstr)
  1102 + paramlist = append(paramlist, paramgameid)
  1103 + paramlist = append(paramlist, pchannel)
  1104 + paramlist = append(paramlist, puid)
  1105 + if headurl != "" {
  1106 + paramlist = append(paramlist, phead)
  1107 + }
  1108 + if nickname != "" {
  1109 + paramlist = append(paramlist, pnickname)
  1110 + }
  1111 + paramlist = append(paramlist, popenid)
  1112 + paramlist = append(paramlist, pmoney)
  1113 + paramlist = append(paramlist, ptype)
  1114 + paramlist = append(paramlist, ped)
  1115 + paramlist = append(paramlist, pcheco)
  1116 + //paramlist = append(paramlist, pver)
  1117 +
  1118 + sumparam := GettotalParam(paramlist)
  1119 + //加serverkey
  1120 + signsum := sumparam + SERVERKEY
  1121 +
  1122 + //进行hash
  1123 + sign := GetHashValue(signsum)
  1124 + params.Sign = sign
  1125 +
  1126 + bys, err := json.Marshal(&params)
  1127 + if err != nil {
  1128 + logger.Error("GetCashFromSDK failed=%v", err)
  1129 + return 0, err
  1130 + }
  1131 + res, err := DoHttpPost(bys, "api/server/tixian")
  1132 + logger.Info("GetCashFromSDK sumparam is:%v,sign is:%v", signsum, sign)
  1133 + logger.Info("GetCashFromSDK sumparam param=%v", string(bys))
  1134 + if err != nil {
  1135 + logger.Error("GetCashFromSDK failed=%v", err)
  1136 + return 0, err
  1137 + }
  1138 +
  1139 + logger.Info("GetCashFromSDK res=%v", res)
  1140 +
  1141 + var resp GetCashResp
  1142 + err = json.Unmarshal([]byte(res), &resp)
  1143 + if err != nil {
  1144 + logger.Error("GetCashFromSDK failed=%v", err)
  1145 + return 0, err
  1146 + }
  1147 +
  1148 + if resp.Code != "0" {
  1149 + logger.Error("GetCashFromSDK failed=%v", resp.Msg)
  1150 + return 0, errors.New(resp.Msg)
  1151 + }
  1152 +
  1153 + //拉取一下新的金币值
  1154 + newnum, err := GetCoinFromSdk(uuid, gameid, channel)
  1155 + if err != nil {
  1156 + logger.Error("GetCashFromSDK failed=%v", err)
  1157 + return 0, err
  1158 + }
  1159 + return newnum, nil
  1160 +}
  1161 +
  1162 +func GettotalParam(paramlist []string) string {
  1163 + //排序
  1164 + sort.Strings(paramlist)
  1165 +
  1166 + //拼接
  1167 + sumparam := ""
  1168 + for _, val := range paramlist {
  1169 + sumparam += val
  1170 + }
  1171 +
  1172 + return sumparam
  1173 +}
  1174 +
  1175 +func GetHashValue(signsum string) string {
  1176 + /*h := sha1.New()
  1177 + h.Write([]byte(signsum))
  1178 + bs := h.Sum(nil)
  1179 + sign := hex.EncodeToString(bs)*/
  1180 + ctx := md5.New()
  1181 + ctx.Write([]byte(signsum))
  1182 + return hex.EncodeToString(ctx.Sum(nil))
  1183 +}
  1184 +
  1185 +func DoHttpPost(bys []byte, apistr string) (string, error) {
  1186 + body := bytes.NewBuffer(bys)
  1187 + url1 := conf.GetCoinConf().Host + apistr //"api/server/addcoin"
  1188 +
  1189 + res, err := http.Post(url1, "application/json;charset=utf-8", body)
  1190 + if err != nil {
  1191 + logger.Error("DoHttpPost failed err=%v", err)
  1192 + return "", err
  1193 + }
  1194 + result, _ := ioutil.ReadAll(res.Body)
  1195 + defer res.Body.Close()
  1196 +
  1197 + return string(result), nil
  1198 +}
  1199 +
  1200 +func GetCoinFromSdk(uuid int, gameid string, channel string) (int, error) {
  1201 +
  1202 + SERVERKEY := conf.GetCoinConf().Key
  1203 + /*if gameid == "1015" {
  1204 + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015
  1205 + }*/
  1206 +
  1207 + var paramlist []string
  1208 + var params GetCoinDesc
  1209 + params.Sign_type = "md5"
  1210 + params.Gameid = gameid
  1211 + params.Channel = channel
  1212 + params.Uid = uuid
  1213 + params.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  1214 + signtypestr := "sign_type=" + params.Sign_type
  1215 + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  1216 + paramgameid := "gameid=" + gameid
  1217 + pchannel := "channel=" + channel
  1218 + puid := "uid=" + strconv.Itoa(uuid)
  1219 + paramlist = append(paramlist, signtypestr)
  1220 + paramlist = append(paramlist, timestampstr)
  1221 + paramlist = append(paramlist, paramgameid)
  1222 + paramlist = append(paramlist, pchannel)
  1223 + paramlist = append(paramlist, puid)
  1224 +
  1225 + sumparam := GettotalParam(paramlist)
  1226 + //加serverkey
  1227 + signsum := sumparam + SERVERKEY
  1228 +
  1229 + //进行hash
  1230 + sign := GetHashValue(signsum)
  1231 + params.Sign = sign
  1232 + logger.Info("GetCoinFromSdk sumparam is:%v,sign is:", signsum, sign)
  1233 +
  1234 + bys, err := json.Marshal(&params)
  1235 + if err != nil {
  1236 + logger.Error("GetCoinFromSdk failed=%v", err)
  1237 + return 0, err
  1238 + }
  1239 + res, err := DoHttpPost(bys, "api/server/getcoin")
  1240 + if err != nil {
  1241 + logger.Error("GetCoinFromSdk failed=%v", err)
  1242 + return 0, err
  1243 + }
  1244 +
  1245 + logger.Info("GetCoinFromSdk res=%v", res)
  1246 +
  1247 + var resp AddCoinResp
  1248 + err = json.Unmarshal([]byte(res), &resp)
  1249 + if err != nil {
  1250 + logger.Error("GetCoinFromSdk failed=%v", err)
  1251 + return 0, err
  1252 + }
  1253 +
  1254 + if resp.Code != "0" {
  1255 + logger.Error("GetCoinFromSdk failed=%v", resp.Msg)
  1256 + return 0, err
  1257 + }
  1258 +
  1259 + return resp.Data.Mycoin, nil
  1260 +}
  1261 +
  1262 +func GetCashList(uuid int, gameid string, channel string, start int, number int) (*[]WithDrawRecord, error) {
  1263 + SERVERKEY := conf.GetCoinConf().Key
  1264 + /*if gameid == "1015" {
  1265 + SERVERKEY = XIAOXINGXING_SERVERKEYTEST_1015
  1266 + }*/
  1267 +
  1268 + var paramlist []string
  1269 + var params GetCashListDesc
  1270 + params.Sign_type = "md5"
  1271 + params.Gameid = gameid
  1272 + params.Channel = channel
  1273 + params.Uid = uuid
  1274 + params.Time_stamp = strconv.Itoa(int(time.Now().Unix()))
  1275 + params.Start = start
  1276 + params.Number = number
  1277 + signtypestr := "sign_type=" + params.Sign_type
  1278 + timestampstr := "time_stamp=" + strconv.Itoa(int(time.Now().Unix()))
  1279 + paramgameid := "gameid=" + gameid
  1280 + pchannel := "channel=" + channel
  1281 + puid := "uid=" + strconv.Itoa(uuid)
  1282 + pstart := "start=" + strconv.Itoa(start)
  1283 + pnumber := "number=" + strconv.Itoa(number)
  1284 + paramlist = append(paramlist, signtypestr)
  1285 + paramlist = append(paramlist, timestampstr)
  1286 + paramlist = append(paramlist, paramgameid)
  1287 + paramlist = append(paramlist, pchannel)
  1288 + paramlist = append(paramlist, puid)
  1289 + if start != 0 {
  1290 + paramlist = append(paramlist, pstart)
  1291 + }
  1292 +
  1293 + paramlist = append(paramlist, pnumber)
  1294 +
  1295 + sumparam := GettotalParam(paramlist)
  1296 + //加serverkey
  1297 + signsum := sumparam + SERVERKEY
  1298 + logger.Info("GetCashList sumparam=%v", signsum)
  1299 +
  1300 + //进行hash
  1301 + sign := GetHashValue(signsum)
  1302 + params.Sign = sign
  1303 +
  1304 + bys, err := json.Marshal(&params)
  1305 + if err != nil {
  1306 + logger.Error("GetCashList failed=%v", err)
  1307 + return nil, err
  1308 + }
  1309 + res, err := DoHttpPost(bys, "api/server/tixian/lst")
  1310 + if err != nil {
  1311 + logger.Error("GetCashList failed=%v", err)
  1312 + return nil, err
  1313 + }
  1314 +
  1315 + logger.Info("GetCashList res=%v", res)
  1316 +
  1317 + var resp GetCashListResp
  1318 + err = json.Unmarshal([]byte(res), &resp)
  1319 + if err != nil {
  1320 + logger.Error("GetCoinFromSdk failed=%v", err)
  1321 + return nil, err
  1322 + }
  1323 +
  1324 + if resp.Code != "0" {
  1325 + logger.Error("GetCoinFromSdk failed=%v", resp.Msg)
  1326 + return nil, err
  1327 + }
  1328 + return &resp.Data, nil
  1329 +}
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -46,7 +46,7 @@ func StartHttpTicker() {
46 46 cfg := jsonconf.GetRedCatConfig(48)
47 47 if cfg != nil {
48 48  
49   - uinfo.AddRedPackect(cfg.Money)
  49 + uinfo.AddRedPackect(cfg.Money, 100)
50 50 }
51 51  
52 52 var tmp UserCaiPiaoHistory
... ... @@ -139,6 +139,14 @@ func startServerHttpServe() {
139 139 http.HandleFunc("/api/gambling/removeCat", RemoveCat) //清除猫
140 140 http.HandleFunc("/api/user/info", UserInfo) //个人信息
141 141 http.HandleFunc("api/ad/add", AddAd) //看广告
  142 + //新增的接口
  143 + http.HandleFunc("/happycat/getrandredbag", Getrandredbag) //领取随机红包
  144 + http.HandleFunc("/happycat/generatebox", Generatebox) //请求刷出空格礼包
  145 + http.HandleFunc("/happycat/getboxreward", Getboxreward) // 请求领取空格礼包
  146 + http.HandleFunc("/happycat/getflyboxreward", Getflyboxreward) // 请求领取飞天宝箱
  147 + http.HandleFunc("/happycat/querygetcashinfo", Querygetcashinfo) // 请求提现档位信息
  148 + http.HandleFunc("/happycat/getcash", Getcash) // 请求提现
  149 + http.HandleFunc("/happycat/getcashrecord", Getcashrecord) // 请求提现
142 150  
143 151 /////---------------------------------------------------------------------old
144 152 //http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置
... ... @@ -1129,6 +1137,132 @@ func AddAd(w http.ResponseWriter, r *http.Request) {
1129 1137 HandlerAddAd(w, s, Uuid)
1130 1138 }
1131 1139  
  1140 +func Getcashrecord(w http.ResponseWriter, r *http.Request) {
  1141 + Uuid := 0
  1142 + if len(r.Header) > 0 {
  1143 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1144 + }
  1145 + if Uuid == 0 {
  1146 + SetHeader(w)
  1147 + return
  1148 + }
  1149 + result, _ := ioutil.ReadAll(r.Body)
  1150 + r.Body.Close()
  1151 +
  1152 + s := string(result)
  1153 + logger.Info("Getcashrecord , body:%v,uuid=%v", s, Uuid)
  1154 +
  1155 + HandlerGetcashrecord(w, s, Uuid)
  1156 +}
  1157 +
  1158 +func Getcash(w http.ResponseWriter, r *http.Request) {
  1159 + Uuid := 0
  1160 + if len(r.Header) > 0 {
  1161 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1162 + }
  1163 + if Uuid == 0 {
  1164 + SetHeader(w)
  1165 + return
  1166 + }
  1167 + result, _ := ioutil.ReadAll(r.Body)
  1168 + r.Body.Close()
  1169 +
  1170 + s := string(result)
  1171 + logger.Info("Getcash , body:%v,uuid=%v", s, Uuid)
  1172 +
  1173 + HandlerGetcash(w, s, Uuid)
  1174 +}
  1175 +
  1176 +func Querygetcashinfo(w http.ResponseWriter, r *http.Request) {
  1177 + Uuid := 0
  1178 + if len(r.Header) > 0 {
  1179 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1180 + }
  1181 + if Uuid == 0 {
  1182 + SetHeader(w)
  1183 + return
  1184 + }
  1185 + result, _ := ioutil.ReadAll(r.Body)
  1186 + r.Body.Close()
  1187 +
  1188 + s := string(result)
  1189 + logger.Info("Querygetcashinfo , body:%v,uuid=%v", s, Uuid)
  1190 +
  1191 + HandlerQuerygetcashinfo(w, s, Uuid)
  1192 +}
  1193 +
  1194 +func Getflyboxreward(w http.ResponseWriter, r *http.Request) {
  1195 + Uuid := 0
  1196 + if len(r.Header) > 0 {
  1197 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1198 + }
  1199 + if Uuid == 0 {
  1200 + SetHeader(w)
  1201 + return
  1202 + }
  1203 + result, _ := ioutil.ReadAll(r.Body)
  1204 + r.Body.Close()
  1205 +
  1206 + s := string(result)
  1207 + logger.Info("Getflyboxreward , body:%v,uuid=%v", s, Uuid)
  1208 +
  1209 + HandlerGetflyboxreward(w, s, Uuid)
  1210 +}
  1211 +
  1212 +func Getboxreward(w http.ResponseWriter, r *http.Request) {
  1213 + Uuid := 0
  1214 + if len(r.Header) > 0 {
  1215 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1216 + }
  1217 + if Uuid == 0 {
  1218 + SetHeader(w)
  1219 + return
  1220 + }
  1221 + result, _ := ioutil.ReadAll(r.Body)
  1222 + r.Body.Close()
  1223 +
  1224 + s := string(result)
  1225 + logger.Info("Getboxreward , body:%v,uuid=%v", s, Uuid)
  1226 +
  1227 + HandlerGetboxreward(w, s, Uuid)
  1228 +}
  1229 +
  1230 +func Generatebox(w http.ResponseWriter, r *http.Request) {
  1231 + Uuid := 0
  1232 + if len(r.Header) > 0 {
  1233 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1234 + }
  1235 + if Uuid == 0 {
  1236 + SetHeader(w)
  1237 + return
  1238 + }
  1239 + result, _ := ioutil.ReadAll(r.Body)
  1240 + r.Body.Close()
  1241 +
  1242 + s := string(result)
  1243 + logger.Info("Generatebox , body:%v,uuid=%v", s, Uuid)
  1244 +
  1245 + HandlerGeneratebox(w, s, Uuid)
  1246 +}
  1247 +
  1248 +func Getrandredbag(w http.ResponseWriter, r *http.Request) {
  1249 + Uuid := 0
  1250 + if len(r.Header) > 0 {
  1251 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  1252 + }
  1253 + if Uuid == 0 {
  1254 + SetHeader(w)
  1255 + return
  1256 + }
  1257 + result, _ := ioutil.ReadAll(r.Body)
  1258 + r.Body.Close()
  1259 +
  1260 + s := string(result)
  1261 + logger.Info("Getrandredbag , body:%v,uuid=%v", s, Uuid)
  1262 +
  1263 + HandlerGetrandredbag(w, s, Uuid)
  1264 +}
  1265 +
1132 1266 func TestaddCat(w http.ResponseWriter, r *http.Request) {
1133 1267 Uuid := 0
1134 1268 if len(r.Header) > 0 {
... ...
src/HttpServer/logic/logic.go
... ... @@ -255,6 +255,406 @@ func HandlerAddAd(w http.ResponseWriter, data string, uuid int) {
255 255 fmt.Fprint(w, string(respstr))
256 256 }
257 257  
  258 +func HandlerGetflyboxreward(w http.ResponseWriter, data string, uuid int) {
  259 + SetHeader(w)
  260 + var resp GetboxrewardResp
  261 + resp.Code = 0
  262 + resp.Message = "success"
  263 +
  264 + for {
  265 +
  266 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  267 + if err != nil || uinfo == nil {
  268 + logger.Error("HandlerGetflyboxreward getuserinfo failed=%v", err)
  269 + resp.Code = 1
  270 + resp.Message = "get userinfo failed"
  271 + break
  272 + }
  273 +
  274 + //获取剩余次数
  275 + if uinfo.FlyBoxNumTimes < 1 {
  276 + logger.Error("HandlerGetflyboxreward not times failed=%v", err)
  277 + resp.Code = 1
  278 + resp.Message = "已经没有剩余宝箱次数了"
  279 + break
  280 + }
  281 +
  282 + boxid := uinfo.GenerateFlyBoxID()
  283 + cfg := jsonconf.GetBoxConfif(boxid)
  284 + if cfg == nil {
  285 + logger.Error("HandlerGetboxreward getcfgfailed failed=%v", boxid)
  286 + resp.Code = 1
  287 + resp.Message = "getcfgfailed"
  288 + break
  289 + }
  290 + if cfg.Ttype == 1 {
  291 + //金币
  292 + resp.Data.Getgold = int64(float32(uinfo.Goldrate) * cfg.Time)
  293 +
  294 + uinfo.Gold += resp.Data.Getgold
  295 + } else if cfg.Ttype == 2 {
  296 + //红包
  297 + resp.Data.Getredbag = cfg.Time
  298 + uinfo.AddRedPackect(resp.Data.Getredbag, 100)
  299 + }
  300 +
  301 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  302 +
  303 + break
  304 + }
  305 +
  306 + //回包
  307 + respstr, _ := json.Marshal(&resp)
  308 + fmt.Fprint(w, string(respstr))
  309 +}
  310 +
  311 +func HandlerGetcashrecord(w http.ResponseWriter, data string, uuid int) {
  312 + SetHeader(w)
  313 + var resp GetcashrecordResp
  314 + resp.Code = 0
  315 + resp.Message = "success"
  316 + for {
  317 +
  318 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  319 + if err != nil || uinfo == nil {
  320 + logger.Error("HandlerGetcashrecord getuserinfo failed=%v", err)
  321 + resp.Code = 1
  322 + resp.Message = "get userinfo failed"
  323 + break
  324 + }
  325 + list, err := GetCashList(uuid, uinfo.Gameid, uinfo.Channel, 0, 100)
  326 + if err != nil {
  327 + logger.Error("HandlerGetcashrecord failed err=%v", err)
  328 + resp.Message = "服务器错误"
  329 + resp.Code = 1
  330 + break
  331 + }
  332 + if list != nil {
  333 + resp.Data.Withdata = append(resp.Data.Withdata, *list...)
  334 + }
  335 +
  336 + break
  337 + }
  338 +
  339 + //回包
  340 + respstr, _ := json.Marshal(&resp)
  341 + fmt.Fprint(w, string(respstr))
  342 +}
  343 +
  344 +func HandlerGetcash(w http.ResponseWriter, data string, uuid int) {
  345 + SetHeader(w)
  346 + var resp GetcashResp
  347 + resp.Code = 0
  348 + resp.Message = "success"
  349 + var rdata GetcashReq
  350 + err := json.Unmarshal([]byte(data), &rdata)
  351 + for {
  352 + if err != nil {
  353 + logger.Error("HandlerGetcash json unmarshal failed=%v", err)
  354 + resp.Code = 1
  355 + resp.Message = "json failed"
  356 + break
  357 + }
  358 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  359 + if err != nil || uinfo == nil {
  360 + logger.Error("HandlerGetcash getuserinfo failed=%v", err)
  361 + resp.Code = 1
  362 + resp.Message = "get userinfo failed"
  363 + break
  364 + }
  365 +
  366 + index, info := uinfo.GetWithDrawData(rdata.Money)
  367 + if index == -1 || info == nil {
  368 + logger.Error("HandlerGetcash GetWithDrawData failed=%v", err)
  369 + resp.Code = 1
  370 + resp.Message = "get GetWithDrawData failed"
  371 + break
  372 + }
  373 +
  374 + if info.Cnum == 30 {
  375 + //30的是连续登陆天数
  376 + if uinfo.Highestlv < info.Limitlv || uinfo.ContinueLoginDay < info.LoginDayLimit {
  377 + logger.Error("HandlerGetcash notfit failed=%v", err)
  378 + resp.Code = 1
  379 + resp.Message = "提现条件不满足"
  380 + break
  381 + }
  382 + } else {
  383 + if uinfo.Highestlv < info.Limitlv || uinfo.SumLoginDay < info.LoginDayLimit {
  384 + logger.Error("HandlerGetcash notfit failed=%v", err)
  385 + resp.Code = 1
  386 + resp.Message = "提现条件不满足"
  387 + break
  388 + }
  389 + }
  390 +
  391 + if info.Isnew == 0 {
  392 + logger.Error("HandlerGetcash notfit failed=%v", err)
  393 + resp.Code = 1
  394 + resp.Message = "新人专享只能提取一次"
  395 + break
  396 + }
  397 +
  398 + if info.Preisfind == 0 {
  399 + logger.Error("HandlerGetcash notfit failed=%v", err)
  400 + resp.Code = 1
  401 + resp.Message = "请先完成前一档提现"
  402 + break
  403 + }
  404 +
  405 + //判断一下前置条件的下一档
  406 + if index == len(uinfo.WithDraw.Cashdata)-1 {
  407 + //最后一档了不用处理
  408 + } else {
  409 + if index < len(uinfo.WithDraw.Cashdata)-1 {
  410 + uinfo.WithDraw.Cashdata[index+1].Preisfind = 1
  411 + }
  412 + }
  413 +
  414 + checkcoin := 2 //不开启自动审核
  415 + drawnum := int(rdata.Money * 10000)
  416 + gold, err := GetCashFromSDK(uuid, drawnum, uinfo.Gameid, uinfo.Channel, rdata.Openid, uinfo.NickName, uinfo.Head, rdata.Ver, checkcoin)
  417 + if err != nil {
  418 + logger.Error("HandlerGetcash GetCashFromSDK failed failed=%v", err)
  419 + resp.Code = 1
  420 + resp.Message = "从后台提现失败了"
  421 + break
  422 +
  423 + }
  424 + if info.Isnew == 1 {
  425 + uinfo.WithDraw.Cashdata[index].Isnew = 0
  426 + }
  427 +
  428 + resp.Data.Redbag = float32(gold) / 10000
  429 +
  430 + //保存
  431 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  432 +
  433 + break
  434 +
  435 + }
  436 + //回包
  437 + respstr, _ := json.Marshal(&resp)
  438 + fmt.Fprint(w, string(respstr))
  439 +}
  440 +
  441 +func HandlerQuerygetcashinfo(w http.ResponseWriter, data string, uuid int) {
  442 + SetHeader(w)
  443 + var resp QuerygetcashinfoResp
  444 + resp.Code = 0
  445 + resp.Message = "success"
  446 + for {
  447 +
  448 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  449 + if err != nil || uinfo == nil {
  450 + logger.Error("HandlerGetflyboxreward getuserinfo failed=%v", err)
  451 + resp.Code = 1
  452 + resp.Message = "get userinfo failed"
  453 + break
  454 + }
  455 +
  456 + //返回
  457 + resp.Data.Logindaycontinue = uinfo.ContinueLoginDay
  458 + resp.Data.Logindaysum = uinfo.SumLoginDay
  459 + resp.Data.Cashdata = append(resp.Data.Cashdata, uinfo.WithDraw.Cashdata...)
  460 +
  461 + break
  462 + }
  463 +
  464 + //回包
  465 + respstr, _ := json.Marshal(&resp)
  466 + fmt.Fprint(w, string(respstr))
  467 +}
  468 +
  469 +func HandlerGetboxreward(w http.ResponseWriter, data string, uuid int) {
  470 + SetHeader(w)
  471 + var resp GetboxrewardResp
  472 + resp.Code = 0
  473 + resp.Message = "success"
  474 + var rdata GetboxrewardReq
  475 + err := json.Unmarshal([]byte(data), &rdata)
  476 +
  477 + for {
  478 + if err != nil {
  479 + logger.Error("HandlerGetboxreward json unmarshal failed=%v", err)
  480 + resp.Code = 1
  481 + resp.Message = "json failed"
  482 + break
  483 + }
  484 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  485 + if err != nil || uinfo == nil {
  486 + logger.Error("HandlerGetboxreward getuserinfo failed=%v", err)
  487 + resp.Code = 1
  488 + resp.Message = "get userinfo failed"
  489 + break
  490 + }
  491 + if uinfo.PosInfo[BOXGIFTPOS].Cat < BOXGIFTEXTRA {
  492 + //没有存在合法的空格礼物
  493 + logger.Error("HandlerGetboxreward empty failed=%v", err)
  494 + resp.Code = 1
  495 + resp.Message = "empty"
  496 + break
  497 + }
  498 +
  499 + //获取配置
  500 + boxid := uinfo.PosInfo[BOXGIFTPOS].Cat - BOXGIFTEXTRA
  501 + cfg := jsonconf.GetGiftConfif(boxid)
  502 + if cfg == nil {
  503 + logger.Error("HandlerGetboxreward getcfgfailed failed=%v", err)
  504 + resp.Code = 1
  505 + resp.Message = "getcfgfailed"
  506 + break
  507 + }
  508 +
  509 + mult := int64(1)
  510 + if rdata.Optype == 2 {
  511 + mult = 2
  512 + }
  513 +
  514 + if cfg.Ttype == 1 {
  515 + //金币
  516 + resp.Data.Getgold = int64(float32(uinfo.Goldrate) * cfg.Time)
  517 + resp.Data.Getgold = resp.Data.Getgold * mult
  518 + uinfo.Gold += resp.Data.Getgold
  519 + } else if cfg.Ttype == 2 {
  520 + //红包
  521 + resp.Data.Getredbag = cfg.Time * float32(mult)
  522 + uinfo.AddRedPackect(resp.Data.Getredbag, 100)
  523 + }
  524 +
  525 + uinfo.CleadPos(BOXGIFTPOS)
  526 +
  527 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  528 +
  529 + break
  530 + }
  531 +
  532 + //回包
  533 + respstr, _ := json.Marshal(&resp)
  534 + fmt.Fprint(w, string(respstr))
  535 +}
  536 +
  537 +func HandlerGeneratebox(w http.ResponseWriter, data string, uuid int) {
  538 + SetHeader(w)
  539 + var resp GenerateboxResp
  540 + resp.Code = 0
  541 + resp.Message = "success"
  542 +
  543 + for {
  544 +
  545 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  546 + if err != nil || uinfo == nil {
  547 + logger.Error("HandlerGeneratebox getuserinfo failed=%v", err)
  548 + resp.Code = 1
  549 + resp.Message = "get userinfo failed"
  550 + break
  551 + }
  552 + if uinfo.PosInfo[BOXGIFTPOS].Cat != 0 {
  553 + //位置被占用无法生成
  554 + logger.Error("HandlerGeneratebox not empty failed=%v", err)
  555 + resp.Code = -1
  556 + resp.Message = "not empty"
  557 + break
  558 + }
  559 +
  560 + boxid := uinfo.GenerateBox()
  561 + resp.Data.Boixid = boxid
  562 + break
  563 + }
  564 +
  565 + //回包
  566 + respstr, _ := json.Marshal(&resp)
  567 + fmt.Fprint(w, string(respstr))
  568 +}
  569 +
  570 +func HandlerGetrandredbag(w http.ResponseWriter, data string, uuid int) {
  571 + SetHeader(w)
  572 + var resp GetrandredbagResp
  573 + resp.Code = 0
  574 + resp.Message = "success"
  575 + var rdata GetrandredbagReq
  576 + err := json.Unmarshal([]byte(data), &rdata)
  577 +
  578 + for {
  579 +
  580 + if err != nil {
  581 + logger.Error("HandlerGetrandredbag json unmarshal failed=%v", err)
  582 + resp.Code = 1
  583 + resp.Message = "json failed"
  584 + break
  585 + }
  586 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  587 + if err != nil || uinfo == nil {
  588 + logger.Error("HandlerGetrandredbag getuserinfo failed=%v", err)
  589 + resp.Code = 1
  590 + resp.Message = "get userinfo failed"
  591 + break
  592 + }
  593 +
  594 + //直接领取
  595 + if rdata.Optype == 1 {
  596 + //直接领取
  597 + if uinfo.RandRedBagLeftTime < 1 {
  598 + //已经没有领取次数了
  599 + logger.Error("HandlerGetrandredbag storenum not enough failed=%v", err)
  600 + resp.Code = 1
  601 + resp.Message = "storenum not enougd"
  602 + break
  603 + }
  604 +
  605 + addnum := uinfo.CalcRandRedBagNum()
  606 + uinfo.AddRedPackect(addnum, 100)
  607 + addgold := int(addnum * 10000)
  608 + resp.Data.Getnum = addgold
  609 +
  610 + uinfo.SumRandRedBagTimes++
  611 + uinfo.RandRedBagLeftTime--
  612 + } else if rdata.Optype == 2 {
  613 + //存储
  614 + if uinfo.StoreRandRedBag >= 1 {
  615 + //不能存更多
  616 + logger.Error("HandlerGetrandredbag storenum failed=%v", err)
  617 + resp.Code = 1
  618 + resp.Message = "storenum failed"
  619 + break
  620 + }
  621 +
  622 + uinfo.StoreRandRedBag++
  623 + resp.Data.Getnum = 0
  624 + break
  625 + } else {
  626 + //领取存储的红包
  627 + if uinfo.StoreRandRedBag < 1 || uinfo.RandRedBagLeftTime < 1 {
  628 + //没有可以领取的
  629 + logger.Error("HandlerGetrandredbag storenum not enough failed=%v", err)
  630 + resp.Code = 1
  631 + resp.Message = "storenum not enougd"
  632 + break
  633 + }
  634 +
  635 + //加红包
  636 + //计算一下零取值
  637 + addnum := uinfo.CalcRandRedBagNum()
  638 + uinfo.AddRedPackect(addnum, 100)
  639 + addgold := int(addnum * 10000)
  640 + resp.Data.Getnum = addgold
  641 +
  642 + uinfo.StoreRandRedBag--
  643 + uinfo.SumRandRedBagTimes++
  644 + uinfo.RandRedBagLeftTime--
  645 +
  646 + }
  647 +
  648 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  649 +
  650 + break
  651 + }
  652 +
  653 + //回包
  654 + respstr, _ := json.Marshal(&resp)
  655 + fmt.Fprint(w, string(respstr))
  656 +}
  657 +
258 658 func HandlerUserInfo(w http.ResponseWriter, data string, uuid int) {
259 659 SetHeader(w)
260 660 var resp UserInfoResp
... ... @@ -587,6 +987,8 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) {
587 987 if uinfo.IsNew == 0 {
588 988 resp.Data.Guide = false
589 989 }
  990 + resp.Data.Redbagnum = uinfo.StoreRandRedBag
  991 + resp.Data.Flyboxnum = uinfo.FlyBoxNumTimes
590 992 resp.Code = 0
591 993 break
592 994 }
... ... @@ -936,7 +1338,7 @@ func HandlerRecvRedCat(w http.ResponseWriter, data string, uuid int) {
936 1338 addredpack = addredpack * 2
937 1339 }
938 1340  
939   - uinfo.AddRedPackect(addredpack)
  1341 + uinfo.AddRedPackect(addredpack, 100)
940 1342 uinfo.CleadPos(cpos)
941 1343  
942 1344 uinfo.CalcGoldRate()
... ...