Commit bc5eb843f70ab83c0f18b89d737c6228998ae611
1 parent
830ac855
Exists in
master
赌博猫相关
Showing
6 changed files
with
698 additions
and
50 deletions
Show diff stats
src/HttpServer/logic/datadef.go
... | ... | @@ -363,6 +363,52 @@ type PutWareHouseResp struct { |
363 | 363 | Data PutWareHouseData `json:"data"` |
364 | 364 | } |
365 | 365 | |
366 | +type QueryGamblingData struct { | |
367 | + CatId int `json:"catId"` | |
368 | + Round int `json:"round"` | |
369 | + RewardNumber int `json:"rewardNumber"` | |
370 | + MyNumber int `json:"myNumber"` | |
371 | + Status int `json:"status"` | |
372 | + Nickname string `json:"nickname"` | |
373 | + HeadImg string `json:"headImg"` | |
374 | +} | |
375 | + | |
376 | +type QueryGamblingResp struct { | |
377 | + Code int `json:"code"` | |
378 | + Message string `json:"message"` | |
379 | + Data []QueryGamblingData `json:"data"` | |
380 | +} | |
381 | + | |
382 | +type NumberListDesc struct { | |
383 | + Number int `json:"number"` | |
384 | + Choosed bool `json:"choosed"` | |
385 | +} | |
386 | + | |
387 | +type NumberListData struct { | |
388 | + Round int `json:"round"` | |
389 | + NumberList []NumberListDesc `json:"numberList"` | |
390 | +} | |
391 | + | |
392 | +type NumberListResp struct { | |
393 | + Code int `json:"code"` | |
394 | + Message string `json:"message"` | |
395 | + Data NumberListData `json:"data"` | |
396 | +} | |
397 | + | |
398 | +type ChooseNumReq struct { | |
399 | + Number int `json:"number"` | |
400 | + Round int `json:"round"` | |
401 | + CatId int `json:"catId"` | |
402 | +} | |
403 | + | |
404 | +type ChooseNumData struct { | |
405 | +} | |
406 | +type ChooseNumResp struct { | |
407 | + Code int `json:"code"` | |
408 | + Message string `json:"message"` | |
409 | + Data ChooseNumData `json:"data"` | |
410 | +} | |
411 | + | |
366 | 412 | type TakeWareHouseReq struct { |
367 | 413 | CatId string `json:"catId"` |
368 | 414 | } |
... | ... | @@ -627,48 +673,56 @@ type AchieveMentData struct { |
627 | 673 | |
628 | 674 | //玩家数据 |
629 | 675 | type UserData struct { |
630 | - UserId int //玩家id | |
631 | - RegTime int //注册时间 | |
632 | - Gold int64 //金币 | |
633 | - GoldSum int64 //玩家累计金币 | |
634 | - Love int64 //爱心值 | |
635 | - Goldrate int64 //金币生成速率 | |
636 | - Loverate int64 //爱心生产速率 | |
637 | - Highestlv int //当前最高猫等级 | |
638 | - InviteId int //邀请者uid | |
639 | - CurBoxLv int //当前猫箱子等级 | |
640 | - IsDouble int //当前加速标签 1表示3倍收益 0表示正常 | |
641 | - StartDoubleTime int //开始双倍时间 | |
642 | - DoubleLeftTimes int //剩余加速金币次数 | |
643 | - GetWatchAdsGoldTime int //看广告领金币次数 | |
644 | - DrawTicket int //抽奖券次数 | |
645 | - DrawTicketTimes int //剩余增加抽奖券次数 | |
646 | - DratMult int //下次抽奖的倍数 | |
647 | - DrawLastRewardId int //上一次的奖励ID | |
648 | - DrawTableCount int //当前抽奖次数 5次以后归零 | |
649 | - IsAuto int //当前是否自动合成 | |
650 | - IsBoxAcc int //是否处于加速生成箱子状态 | |
651 | - RandGiftNum int //当前剩余空投猫粮次数 | |
652 | - RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum | |
653 | - RandGiftTime int //记录上一次空投猫粮时间 | |
654 | - Redbag float32 //红包值 单位为分 | |
655 | - Head string //头像地址 | |
656 | - NickName string //昵称 | |
657 | - RealName string //实名 | |
658 | - IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是 | |
659 | - OfflineGold int64 //离线金币 | |
660 | - OfflineLove int64 //离线爱心 | |
661 | - LastLoginTime int //上次登陆时间 | |
662 | - LastTimingRewardHour int //上次领取整点奖励的时刻 | |
663 | - FlopCardCnt int //翻牌次数计数 | |
664 | - FlopCardLefCnt int //剩余翻拍次数 | |
665 | - CatShopInfo CatShopData //猫咖门店数据 | |
666 | - Taskinfo TaskData //任务数据 | |
667 | - AchieveMent AchieveMentData //成就数据 | |
668 | - PosInfo []CatPosInfo //位置信息 从0开始 | |
669 | - BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推 | |
670 | - CatRoomInfo []CatRoomData //猫咖店数据 | |
671 | - | |
676 | + UserId int //玩家id | |
677 | + RegTime int //注册时间 | |
678 | + Gold int64 //金币 | |
679 | + GoldSum int64 //玩家累计金币 | |
680 | + Love int64 //爱心值 | |
681 | + Goldrate int64 //金币生成速率 | |
682 | + Loverate int64 //爱心生产速率 | |
683 | + Highestlv int //当前最高猫等级 | |
684 | + InviteId int //邀请者uid | |
685 | + CurBoxLv int //当前猫箱子等级 | |
686 | + IsDouble int //当前加速标签 1表示3倍收益 0表示正常 | |
687 | + StartDoubleTime int //开始双倍时间 | |
688 | + DoubleLeftTimes int //剩余加速金币次数 | |
689 | + GetWatchAdsGoldTime int //看广告领金币次数 | |
690 | + DrawTicket int //抽奖券次数 | |
691 | + DrawTicketTimes int //剩余增加抽奖券次数 | |
692 | + DratMult int //下次抽奖的倍数 | |
693 | + DrawLastRewardId int //上一次的奖励ID | |
694 | + DrawTableCount int //当前抽奖次数 5次以后归零 | |
695 | + IsAuto int //当前是否自动合成 | |
696 | + IsBoxAcc int //是否处于加速生成箱子状态 | |
697 | + RandGiftNum int //当前剩余空投猫粮次数 | |
698 | + RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum | |
699 | + RandGiftTime int //记录上一次空投猫粮时间 | |
700 | + Redbag float32 //红包值 单位为分 | |
701 | + Head string //头像地址 | |
702 | + NickName string //昵称 | |
703 | + RealName string //实名 | |
704 | + IsFirstRedBgCat int //是否合成过红包猫 0表示否1表示是 | |
705 | + OfflineGold int64 //离线金币 | |
706 | + OfflineLove int64 //离线爱心 | |
707 | + LastLoginTime int //上次登陆时间 | |
708 | + LastTimingRewardHour int //上次领取整点奖励的时刻 | |
709 | + FlopCardCnt int //翻牌次数计数 | |
710 | + FlopCardLefCnt int //剩余翻拍次数 | |
711 | + CatShopInfo CatShopData //猫咖门店数据 | |
712 | + Taskinfo TaskData //任务数据 | |
713 | + AchieveMent AchieveMentData //成就数据 | |
714 | + PosInfo []CatPosInfo //位置信息 从0开始 | |
715 | + BuyCatInfo []BuyCatInfoData //商店购买猫数据 第一个元素为1级猫 第二个为2级猫以此类推 | |
716 | + CatRoomInfo []CatRoomData //猫咖店数据 | |
717 | + CaiPiaoInfo []UserCaiPiaoHistory //记录玩家参与过的赌博猫历史记录 | |
718 | + | |
719 | +} | |
720 | + | |
721 | +type UserCaiPiaoHistory struct { | |
722 | + Cnum int //选择的号码 | |
723 | + RewardNum int //当期开奖的号码 | |
724 | + Round int //轮数 | |
725 | + CatId int //猫ID | |
672 | 726 | } |
673 | 727 | |
674 | 728 | //仓库数据详情 |
... | ... | @@ -696,3 +750,35 @@ const ( |
696 | 750 | ACH_TYPE_GETSTORY = 9 //累计解锁新故事 |
697 | 751 | ACH_TYPE_GBESHOP = 10 //累计用于新店铺 |
698 | 752 | ) |
753 | + | |
754 | +//赌博猫相关数据结构 | |
755 | +type UserCaiPiaoInfo struct { | |
756 | + CatId int //猫ID | |
757 | + UserId int //uuid | |
758 | + ChooseNum int //选择号码 | |
759 | +} | |
760 | + | |
761 | +//当期奖池信息 | |
762 | +type CurDuboCatList struct { | |
763 | + CurRound int //当前轮次 | |
764 | + CurNum int //当前人数 | |
765 | + FakeNum int //当期不开奖号码 如果0表示当期真实开奖 | |
766 | + List []UserCaiPiaoInfo //当期彩池人数 | |
767 | +} | |
768 | + | |
769 | +//待开奖奖池信息 | |
770 | +type WaitDuboCatList struct { | |
771 | + CurRound int //当前轮次 | |
772 | + RewardNum int //开奖号码 | |
773 | + List []UserCaiPiaoInfo //当期彩池人数 | |
774 | + RewardUser int //中奖者ID 如果假中奖为0 | |
775 | +} | |
776 | + | |
777 | +//已开奖列表 | |
778 | +type AlreadyDuboCatList struct { | |
779 | + CurRound int //当前轮次 | |
780 | + RewardNum int //开奖号码 | |
781 | + List []UserCaiPiaoInfo //当期彩池人数 | |
782 | + RewardUser int //中奖者ID 如果假中奖为0 | |
783 | + TimeStr int //开奖时刻 | |
784 | +} | ... | ... |
src/HttpServer/logic/function.go
... | ... | @@ -12,6 +12,128 @@ import ( |
12 | 12 | "time" |
13 | 13 | ) |
14 | 14 | |
15 | +//生成数字 | |
16 | +func GenerateNums(start, end, count int) []int { | |
17 | + var nums []int | |
18 | + r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
19 | + for len(nums) < count { | |
20 | + //生成随机数 | |
21 | + num := r.Intn((end - start)) + start + 1 | |
22 | + //查重 | |
23 | + exist := false | |
24 | + for _, v := range nums { | |
25 | + if v == num { | |
26 | + exist = true | |
27 | + break | |
28 | + } | |
29 | + } | |
30 | + if !exist { | |
31 | + nums = append(nums, num) | |
32 | + } | |
33 | + } | |
34 | + return nums | |
35 | +} | |
36 | + | |
37 | +//生成新的一期初始化奖池随机数 | |
38 | +func NewCaiPiaoRound(start, end, count, round int) { | |
39 | + nums := GenerateNums(start, end, count) | |
40 | + //存入redis | |
41 | + fakenum := GetCaiPiaoFake(round) | |
42 | + var curround CurDuboCatList | |
43 | + curround.CurRound = round | |
44 | + curround.CurNum = 0 | |
45 | + curround.FakeNum = fakenum | |
46 | + | |
47 | + savestr, err := json.Marshal(&curround) | |
48 | + if err != nil { | |
49 | + err = redishandler.GetRedisClient().SetString(redis.CAIPIAOKAIJIANGCURRENT_KEY, string(savestr)) | |
50 | + if err != nil { | |
51 | + logger.Error("NewCaiPiaoRound err=%v", err) | |
52 | + } | |
53 | + } else { | |
54 | + logger.Error("NewCaiPiaoRound err=%v", err) | |
55 | + } | |
56 | + | |
57 | + //首先清楚原先的号码 | |
58 | + redishandler.GetRedisClient().Delete(redis.CAIPIAOLEFTNUM_KEY) | |
59 | + for _, val := range nums { | |
60 | + if fakenum == val { | |
61 | + continue | |
62 | + } | |
63 | + redishandler.GetRedisClient().HSet(redis.CAIPIAOLEFTNUM_KEY, strconv.Itoa(val), strconv.Itoa(val)) | |
64 | + } | |
65 | +} | |
66 | + | |
67 | +//获取已开奖赌博猫列表 | |
68 | +func GetWaitCaiCatList() []WaitDuboCatList { | |
69 | + var rtsl []WaitDuboCatList | |
70 | + vv, err := redishandler.GetRedisClient().HGetAllValues(redis.CAIPIAOKAIJIANGWAIT_KEY) | |
71 | + if err != nil { | |
72 | + //logger.Error("GetTeamListByCond err") | |
73 | + return rtsl | |
74 | + } | |
75 | + | |
76 | + for _, val := range vv { | |
77 | + //one := new(WaitDuboCatList) | |
78 | + var one WaitDuboCatList | |
79 | + bytestr := val.([]byte) | |
80 | + err = json.Unmarshal(bytestr, &one) | |
81 | + if err == nil { | |
82 | + rtsl = append(rtsl, one) | |
83 | + } | |
84 | + } | |
85 | + return rtsl | |
86 | +} | |
87 | + | |
88 | +//获取正在投注的赌博猫池子列表 | |
89 | +func GetCurCaiCatList() *CurDuboCatList { | |
90 | + curstr, err := redishandler.GetRedisClient().GetString(redis.CAIPIAOKAIJIANGCURRENT_KEY) | |
91 | + if err != nil { | |
92 | + return nil | |
93 | + } | |
94 | + prt := new(CurDuboCatList) | |
95 | + err = json.Unmarshal([]byte(curstr), prt) | |
96 | + if err != nil { | |
97 | + logger.Error("GetCurCaiCatList err=%v", err) | |
98 | + return nil | |
99 | + } | |
100 | + return prt | |
101 | +} | |
102 | + | |
103 | +//设置当前彩池 | |
104 | +func SetCurCaiCatList(c *CurDuboCatList) { | |
105 | + savestr, err := json.Marshal(c) | |
106 | + if err != nil { | |
107 | + logger.Error("SetCurCaiCatList err=%v", err) | |
108 | + } | |
109 | + | |
110 | + err = redishandler.GetRedisClient().SetString(redis.CAIPIAOKAIJIANGCURRENT_KEY, string(savestr)) | |
111 | + if err != nil { | |
112 | + logger.Error("SetCurCaiCatList err=%v", err) | |
113 | + } | |
114 | +} | |
115 | + | |
116 | +//赌博猫开奖真假接口 返回非零表示当期作弊号码 | |
117 | +func GetCaiPiaoFake(round int) int { | |
118 | + numstr, err := redishandler.GetRedisClient().HGet(redis.CAIPIAOISFAKE_KEY, strconv.Itoa(round)) | |
119 | + if err != nil { | |
120 | + return 0 | |
121 | + } | |
122 | + rtnum, err := strconv.Atoi(numstr) | |
123 | + if err != nil { | |
124 | + logger.Error("GetCaiPiaoFake failede err=%v", err) | |
125 | + return 0 | |
126 | + } | |
127 | + return rtnum | |
128 | +} | |
129 | + | |
130 | +func SetCaiPiaoFake(num, round int) { | |
131 | + err := redishandler.GetRedisClient().HSet(redis.CAIPIAOISFAKE_KEY, strconv.Itoa(round), strconv.Itoa(num)) | |
132 | + if err != nil { | |
133 | + logger.Error("SetCaiPiaoFake err=%v", err) | |
134 | + } | |
135 | +} | |
136 | + | |
15 | 137 | //加红包接口 |
16 | 138 | func (u *UserData) AddRedPackect(num float32) { |
17 | 139 | //todo 接后台 | ... | ... |
src/HttpServer/logic/httpserver.go
... | ... | @@ -50,6 +50,11 @@ func startServerHttpServe() { |
50 | 50 | http.HandleFunc("/api/package/catList", QueryWareHouse) //背包列表 |
51 | 51 | http.HandleFunc("/api/package/putToPackage", PutCattoWareHouse) //加入背包 |
52 | 52 | http.HandleFunc("/api/package/getFromPackage", TakeCatoutfromWareHouse) //背包中取出 |
53 | + http.HandleFunc("/api/gambling/catList", QueryGambling) //赌博猫列表 | |
54 | + http.HandleFunc("/api/gambling/numberList", NumberList) //获取号码 | |
55 | + http.HandleFunc("/api/gambling/chooseNum", ChooseNum) //选取号码 | |
56 | + http.HandleFunc("/api/gambling/autoChoose", AutoChoose) //自动选号码 | |
57 | + http.HandleFunc("/api/gambling/removeCat", RemoveCat) //清除猫 | |
53 | 58 | |
54 | 59 | /////---------------------------------------------------------------------old |
55 | 60 | http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 |
... | ... | @@ -428,6 +433,96 @@ func PutCattoWareHouse(w http.ResponseWriter, r *http.Request) { |
428 | 433 | HandlerPutCattoWareHouse(w, s, Uuid) |
429 | 434 | } |
430 | 435 | |
436 | +func RemoveCat(w http.ResponseWriter, r *http.Request) { | |
437 | + Uuid := 0 | |
438 | + if len(r.Header) > 0 { | |
439 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
440 | + } | |
441 | + if Uuid == 0 { | |
442 | + SetHeader(w) | |
443 | + return | |
444 | + } | |
445 | + result, _ := ioutil.ReadAll(r.Body) | |
446 | + r.Body.Close() | |
447 | + | |
448 | + s := string(result) | |
449 | + logger.Info("RemoveCat , body:%v,uuid=%v", s, Uuid) | |
450 | + | |
451 | + HandlerRemoveCat(w, s, Uuid) | |
452 | +} | |
453 | + | |
454 | +func AutoChoose(w http.ResponseWriter, r *http.Request) { | |
455 | + Uuid := 0 | |
456 | + if len(r.Header) > 0 { | |
457 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
458 | + } | |
459 | + if Uuid == 0 { | |
460 | + SetHeader(w) | |
461 | + return | |
462 | + } | |
463 | + result, _ := ioutil.ReadAll(r.Body) | |
464 | + r.Body.Close() | |
465 | + | |
466 | + s := string(result) | |
467 | + logger.Info("AutoChoose , body:%v,uuid=%v", s, Uuid) | |
468 | + | |
469 | + HandlerAutoChoose(w, s, Uuid) | |
470 | +} | |
471 | + | |
472 | +func ChooseNum(w http.ResponseWriter, r *http.Request) { | |
473 | + Uuid := 0 | |
474 | + if len(r.Header) > 0 { | |
475 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
476 | + } | |
477 | + if Uuid == 0 { | |
478 | + SetHeader(w) | |
479 | + return | |
480 | + } | |
481 | + result, _ := ioutil.ReadAll(r.Body) | |
482 | + r.Body.Close() | |
483 | + | |
484 | + s := string(result) | |
485 | + logger.Info("ChooseNum , body:%v,uuid=%v", s, Uuid) | |
486 | + | |
487 | + HandlerChooseNum(w, s, Uuid) | |
488 | +} | |
489 | + | |
490 | +func NumberList(w http.ResponseWriter, r *http.Request) { | |
491 | + Uuid := 0 | |
492 | + if len(r.Header) > 0 { | |
493 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
494 | + } | |
495 | + if Uuid == 0 { | |
496 | + SetHeader(w) | |
497 | + return | |
498 | + } | |
499 | + result, _ := ioutil.ReadAll(r.Body) | |
500 | + r.Body.Close() | |
501 | + | |
502 | + s := string(result) | |
503 | + logger.Info("NumberList , body:%v,uuid=%v", s, Uuid) | |
504 | + | |
505 | + HandlerNumberList(w, s, Uuid) | |
506 | +} | |
507 | + | |
508 | +func QueryGambling(w http.ResponseWriter, r *http.Request) { | |
509 | + Uuid := 0 | |
510 | + if len(r.Header) > 0 { | |
511 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
512 | + } | |
513 | + if Uuid == 0 { | |
514 | + SetHeader(w) | |
515 | + return | |
516 | + } | |
517 | + result, _ := ioutil.ReadAll(r.Body) | |
518 | + r.Body.Close() | |
519 | + | |
520 | + s := string(result) | |
521 | + logger.Info("QueryGambling , body:%v,uuid=%v", s, Uuid) | |
522 | + | |
523 | + HandlerQueryGambling(w, s, Uuid) | |
524 | +} | |
525 | + | |
431 | 526 | func TakeCatoutfromWareHouse(w http.ResponseWriter, r *http.Request) { |
432 | 527 | Uuid := 0 |
433 | 528 | if len(r.Header) > 0 { | ... | ... |
src/HttpServer/logic/logic.go
... | ... | @@ -21,6 +21,15 @@ var ( |
21 | 21 | func init() { |
22 | 22 | //m_userInfo = beegomap.NewBeeMap() |
23 | 23 | Maplock = new(sync.RWMutex) |
24 | + | |
25 | +} | |
26 | + | |
27 | +func MyInit() { | |
28 | + pc := GetCurCaiCatList() | |
29 | + if pc == nil { | |
30 | + //初始化彩池 | |
31 | + NewCaiPiaoRound(0, 200, 200, 1) | |
32 | + } | |
24 | 33 | } |
25 | 34 | |
26 | 35 | func SetHeader(w http.ResponseWriter) { |
... | ... | @@ -1308,6 +1317,335 @@ func HandlerQueryWareHouse(w http.ResponseWriter, data string, uuid int) { |
1308 | 1317 | fmt.Fprint(w, string(respstr)) |
1309 | 1318 | } |
1310 | 1319 | |
1320 | +func HandlerRemoveCat(w http.ResponseWriter, data string, uuid int) { | |
1321 | + SetHeader(w) | |
1322 | + var resp ChooseNumResp | |
1323 | + | |
1324 | + resp.Code = 0 | |
1325 | + resp.Message = "success" | |
1326 | + | |
1327 | + for { | |
1328 | + | |
1329 | + resp.Code = 0 | |
1330 | + | |
1331 | + break | |
1332 | + } | |
1333 | + respstr, _ := json.Marshal(&resp) | |
1334 | + fmt.Fprint(w, string(respstr)) | |
1335 | +} | |
1336 | + | |
1337 | +func HandlerAutoChoose(w http.ResponseWriter, data string, uuid int) { | |
1338 | + SetHeader(w) | |
1339 | + var resp ChooseNumResp | |
1340 | + | |
1341 | + resp.Code = 0 | |
1342 | + resp.Message = "success" | |
1343 | + | |
1344 | + for { | |
1345 | + | |
1346 | + //首先找一个可以选取的号码 | |
1347 | + cnum := 0 | |
1348 | + vv, err := redishandler.GetRedisClient().HGetAllKeys(redis.CAIPIAOLEFTNUM_KEY) | |
1349 | + if err != nil { | |
1350 | + logger.Error("HandlerAutoChoose getuserinfo failed=%v", err) | |
1351 | + resp.Code = 1 | |
1352 | + resp.Message = "HandlerAutoChoose failed" | |
1353 | + break | |
1354 | + } | |
1355 | + | |
1356 | + for _, val := range vv { | |
1357 | + //one := new(WaitDuboCatList) | |
1358 | + bytestr := val.([]byte) | |
1359 | + num, err := strconv.Atoi(string(bytestr)) | |
1360 | + if err == nil { | |
1361 | + cnum = num | |
1362 | + break | |
1363 | + } | |
1364 | + } | |
1365 | + | |
1366 | + if cnum == 0 { | |
1367 | + //已经没有被选的号码了 | |
1368 | + logger.Error("HandlerAutoChoose no num failed=%v", err) | |
1369 | + resp.Code = 1 | |
1370 | + resp.Message = "no num" | |
1371 | + break | |
1372 | + } | |
1373 | + | |
1374 | + //加入当前彩池 | |
1375 | + curpool := GetCurCaiCatList() | |
1376 | + if curpool == nil { | |
1377 | + //理论上会报错 | |
1378 | + logger.Error("HandlerChooseNum pool empty!!") | |
1379 | + resp.Message = " pool empty" | |
1380 | + resp.Code = 1 | |
1381 | + break | |
1382 | + } else { | |
1383 | + //将该号码移除 | |
1384 | + redishandler.GetRedisClient().HDel(redis.CAIPIAOLEFTNUM_KEY, strconv.Itoa(cnum)) | |
1385 | + //添加 | |
1386 | + var tmp UserCaiPiaoInfo | |
1387 | + tmp.ChooseNum = cnum | |
1388 | + tmp.CatId = 48 | |
1389 | + tmp.UserId = uuid | |
1390 | + curpool.List = append(curpool.List, tmp) | |
1391 | + curpool.CurNum = len(curpool.List) | |
1392 | + SetCurCaiCatList(curpool) | |
1393 | + //需要处理一下奖池是否满了 | |
1394 | + fullnum := 199 | |
1395 | + if curpool.FakeNum == 0 { | |
1396 | + fullnum++ | |
1397 | + } | |
1398 | + | |
1399 | + if curpool.CurNum >= fullnum { | |
1400 | + //已经满了 重新生成新的奖池 将原先的加入到待开奖列表 | |
1401 | + var waits WaitDuboCatList | |
1402 | + waits.CurRound = curpool.CurRound | |
1403 | + waits.RewardNum = 0 | |
1404 | + waits.RewardUser = 0 | |
1405 | + waits.List = append(waits.List, curpool.List...) | |
1406 | + | |
1407 | + savestr, _ := json.Marshal(&waits) | |
1408 | + err = redishandler.GetRedisClient().HSet(redis.CAIPIAOKAIJIANGWAIT_KEY, strconv.Itoa(waits.CurRound), string(savestr)) | |
1409 | + if err != nil { | |
1410 | + logger.Error("HandlerChooseNum err=%v", err) | |
1411 | + } | |
1412 | + | |
1413 | + //生成新的彩池 | |
1414 | + NewCaiPiaoRound(0, 200, 200, waits.CurRound+1) | |
1415 | + } | |
1416 | + | |
1417 | + } | |
1418 | + | |
1419 | + resp.Code = 0 | |
1420 | + | |
1421 | + break | |
1422 | + } | |
1423 | + respstr, _ := json.Marshal(&resp) | |
1424 | + fmt.Fprint(w, string(respstr)) | |
1425 | +} | |
1426 | + | |
1427 | +func HandlerChooseNum(w http.ResponseWriter, data string, uuid int) { | |
1428 | + SetHeader(w) | |
1429 | + var resp ChooseNumResp | |
1430 | + | |
1431 | + resp.Code = 0 | |
1432 | + resp.Message = "success" | |
1433 | + var rdata ChooseNumReq | |
1434 | + err := json.Unmarshal([]byte(data), &rdata) | |
1435 | + if err != nil { | |
1436 | + logger.Info("json decode HandlerChooseNum data failed:%v", err, " for:%v", data) | |
1437 | + resp.Message = "json unmarshal failed" | |
1438 | + resp.Code = 1 | |
1439 | + respstr, _ := json.Marshal(&resp) | |
1440 | + fmt.Fprint(w, string(respstr)) | |
1441 | + return | |
1442 | + } | |
1443 | + | |
1444 | + for { | |
1445 | + //先判断一下当前号码是否已被选取 | |
1446 | + isexist, err := redishandler.GetRedisClient().HExists(redis.CAIPIAOLEFTNUM_KEY, strconv.Itoa(rdata.Number)) | |
1447 | + if err != nil { | |
1448 | + logger.Info("HandlerChooseNum failed:%v", err, " for:%v", data) | |
1449 | + resp.Message = "redis failed" | |
1450 | + resp.Code = 1 | |
1451 | + break | |
1452 | + } | |
1453 | + | |
1454 | + if !isexist { | |
1455 | + //已经被选了 | |
1456 | + logger.Info("HandlerChooseNum number alreadypicked failed:%v", err, " for:%v", data) | |
1457 | + resp.Message = " alreadypicked" | |
1458 | + resp.Code = 100 | |
1459 | + break | |
1460 | + } | |
1461 | + | |
1462 | + //加入当前彩池 | |
1463 | + curpool := GetCurCaiCatList() | |
1464 | + if curpool == nil { | |
1465 | + //理论上会报错 | |
1466 | + logger.Error("HandlerChooseNum pool empty!!") | |
1467 | + resp.Message = " pool empty" | |
1468 | + resp.Code = 1 | |
1469 | + break | |
1470 | + } else { | |
1471 | + //将该号码移除 | |
1472 | + redishandler.GetRedisClient().HDel(redis.CAIPIAOLEFTNUM_KEY, strconv.Itoa(rdata.Number)) | |
1473 | + //添加 | |
1474 | + var tmp UserCaiPiaoInfo | |
1475 | + tmp.ChooseNum = rdata.Number | |
1476 | + tmp.CatId = rdata.CatId | |
1477 | + tmp.UserId = uuid | |
1478 | + curpool.List = append(curpool.List, tmp) | |
1479 | + curpool.CurNum = len(curpool.List) | |
1480 | + SetCurCaiCatList(curpool) | |
1481 | + //需要处理一下奖池是否满了 | |
1482 | + fullnum := 199 | |
1483 | + if curpool.FakeNum == 0 { | |
1484 | + fullnum++ | |
1485 | + } | |
1486 | + | |
1487 | + if curpool.CurNum >= fullnum { | |
1488 | + //已经满了 重新生成新的奖池 将原先的加入到待开奖列表 | |
1489 | + var waits WaitDuboCatList | |
1490 | + waits.CurRound = curpool.CurRound | |
1491 | + waits.RewardNum = 0 | |
1492 | + waits.RewardUser = 0 | |
1493 | + waits.List = append(waits.List, curpool.List...) | |
1494 | + | |
1495 | + savestr, _ := json.Marshal(&waits) | |
1496 | + err = redishandler.GetRedisClient().HSet(redis.CAIPIAOKAIJIANGWAIT_KEY, strconv.Itoa(waits.CurRound), string(savestr)) | |
1497 | + if err != nil { | |
1498 | + logger.Error("HandlerChooseNum err=%v", err) | |
1499 | + } | |
1500 | + | |
1501 | + //生成新的彩池 | |
1502 | + NewCaiPiaoRound(0, 200, 200, waits.CurRound+1) | |
1503 | + } | |
1504 | + | |
1505 | + } | |
1506 | + | |
1507 | + resp.Code = 0 | |
1508 | + | |
1509 | + break | |
1510 | + } | |
1511 | + respstr, _ := json.Marshal(&resp) | |
1512 | + fmt.Fprint(w, string(respstr)) | |
1513 | +} | |
1514 | + | |
1515 | +func HandlerNumberList(w http.ResponseWriter, data string, uuid int) { | |
1516 | + SetHeader(w) | |
1517 | + var resp NumberListResp | |
1518 | + | |
1519 | + resp.Code = 0 | |
1520 | + resp.Message = "success" | |
1521 | + | |
1522 | + for { | |
1523 | + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) | |
1524 | + if err != nil || uinfo == nil { | |
1525 | + logger.Error("HandlerNumberList getuserinfo failed=%v", err) | |
1526 | + resp.Code = 1 | |
1527 | + resp.Message = "get userinfo failed" | |
1528 | + break | |
1529 | + } | |
1530 | + //先选取号码 | |
1531 | + vv, err := redishandler.GetRedisClient().HGetAllKeys(redis.CAIPIAOLEFTNUM_KEY) | |
1532 | + if err != nil { | |
1533 | + logger.Error("HandlerNumberList getuserinfo failed=%v", err) | |
1534 | + resp.Code = 1 | |
1535 | + resp.Message = "HandlerNumberList failed" | |
1536 | + break | |
1537 | + } | |
1538 | + | |
1539 | + var numlist []int | |
1540 | + for _, val := range vv { | |
1541 | + //one := new(WaitDuboCatList) | |
1542 | + bytestr := val.([]byte) | |
1543 | + num, err := strconv.Atoi(string(bytestr)) | |
1544 | + if err == nil { | |
1545 | + numlist = append(numlist, num) | |
1546 | + } | |
1547 | + if len(numlist) >= 6 { | |
1548 | + break | |
1549 | + } | |
1550 | + } | |
1551 | + | |
1552 | + //查询当前奖池 | |
1553 | + curpool := GetCurCaiCatList() | |
1554 | + if curpool != nil { | |
1555 | + resp.Data.Round = curpool.CurRound | |
1556 | + } | |
1557 | + | |
1558 | + for _, val := range numlist { | |
1559 | + var tmp NumberListDesc | |
1560 | + tmp.Number = val | |
1561 | + tmp.Choosed = false | |
1562 | + resp.Data.NumberList = append(resp.Data.NumberList, tmp) | |
1563 | + } | |
1564 | + | |
1565 | + resp.Code = 0 | |
1566 | + | |
1567 | + break | |
1568 | + } | |
1569 | + respstr, _ := json.Marshal(&resp) | |
1570 | + fmt.Fprint(w, string(respstr)) | |
1571 | +} | |
1572 | + | |
1573 | +func HandlerQueryGambling(w http.ResponseWriter, data string, uuid int) { | |
1574 | + SetHeader(w) | |
1575 | + var resp QueryGamblingResp | |
1576 | + | |
1577 | + resp.Code = 0 | |
1578 | + resp.Message = "success" | |
1579 | + | |
1580 | + for { | |
1581 | + uinfo, err := GetUserInfo(strconv.Itoa(uuid)) | |
1582 | + if err != nil || uinfo == nil { | |
1583 | + logger.Error("HandlerQueryGambling getuserinfo failed=%v", err) | |
1584 | + resp.Code = 1 | |
1585 | + resp.Message = "get userinfo failed" | |
1586 | + break | |
1587 | + } | |
1588 | + | |
1589 | + //先查询已开奖的 | |
1590 | + for _, vv := range uinfo.CaiPiaoInfo { | |
1591 | + var tmp QueryGamblingData | |
1592 | + tmp.CatId = vv.CatId | |
1593 | + tmp.Nickname = uinfo.NickName | |
1594 | + tmp.HeadImg = uinfo.Head | |
1595 | + tmp.MyNumber = vv.Cnum | |
1596 | + tmp.RewardNumber = vv.RewardNum | |
1597 | + tmp.Round = vv.Round | |
1598 | + tmp.Status = 1 | |
1599 | + if vv.RewardNum == vv.Cnum { | |
1600 | + tmp.Status = 2 | |
1601 | + } | |
1602 | + | |
1603 | + resp.Data = append(resp.Data, tmp) | |
1604 | + } | |
1605 | + | |
1606 | + //查询待开奖的 | |
1607 | + waitlist := GetWaitCaiCatList() | |
1608 | + for _, vv := range waitlist { | |
1609 | + for _, val := range vv.List { | |
1610 | + if val.UserId == uuid { | |
1611 | + var tmp QueryGamblingData | |
1612 | + tmp.CatId = val.CatId | |
1613 | + tmp.Nickname = uinfo.NickName | |
1614 | + tmp.HeadImg = uinfo.Head | |
1615 | + tmp.MyNumber = val.ChooseNum | |
1616 | + tmp.RewardNumber = 0 //0表示未开奖 | |
1617 | + tmp.Round = vv.CurRound | |
1618 | + tmp.Status = 0 | |
1619 | + resp.Data = append(resp.Data, tmp) | |
1620 | + } | |
1621 | + } | |
1622 | + } | |
1623 | + | |
1624 | + //查询当前奖池 | |
1625 | + curpool := GetCurCaiCatList() | |
1626 | + if curpool != nil { | |
1627 | + for _, val := range curpool.List { | |
1628 | + if val.UserId == uuid { | |
1629 | + var tmp QueryGamblingData | |
1630 | + tmp.CatId = val.CatId | |
1631 | + tmp.Nickname = uinfo.NickName | |
1632 | + tmp.HeadImg = uinfo.Head | |
1633 | + tmp.MyNumber = val.ChooseNum | |
1634 | + tmp.RewardNumber = 0 //0表示未开奖 | |
1635 | + tmp.Round = curpool.CurRound | |
1636 | + tmp.Status = 0 | |
1637 | + resp.Data = append(resp.Data, tmp) | |
1638 | + } | |
1639 | + } | |
1640 | + } | |
1641 | + resp.Code = 0 | |
1642 | + | |
1643 | + break | |
1644 | + } | |
1645 | + respstr, _ := json.Marshal(&resp) | |
1646 | + fmt.Fprint(w, string(respstr)) | |
1647 | +} | |
1648 | + | |
1311 | 1649 | func HandlerPutCattoWareHouse(w http.ResponseWriter, data string, uuid int) { |
1312 | 1650 | SetHeader(w) |
1313 | 1651 | var resp PutWareHouseResp | ... | ... |
src/HttpServer/main/main.go
src/common/redis/def.go
1 | 1 | package redis |
2 | 2 | |
3 | 3 | const ( |
4 | - USER_INFO__KEY = "HAPPYCATSERVER_USER_USER_INFO" //玩家数据 | |
5 | - USER_LAST_CALC_TIME = "HAPPYCATSERVER_USER_LAST_CALC_TIME" //玩家上一次数据计算时间 | |
6 | - USER_INVITE_ID = "HAPPYCATSERVER_USER_INVITE_ID" //玩家邀请者ID | |
7 | - USER_STARTDOUBLE_TIME = "HAPPYCATSERVER_USER_STARTDOUBLE_TIME" //开启双倍时间 | |
8 | - USER_STARTAUTO_TIME = "HAPPYCATSERVER_USER_STARTAUTO_TIME" //开启自动合成时间 | |
9 | - USER_STARTACC_BOX_TIME = "HAPPYCATSERVER_USER_STARTACC_BOX_TIME" //开启加速成产箱子 | |
10 | - USER_WAREHOUSE_INFO = "HAPPYCATSERVER_USER_WAREHOUSE_INFO" //玩家仓库信息 | |
11 | - USER_GOLD_RANK = "HAPPYCATSERVER_USER_GOLD_RANK" //玩家排行榜,根据金币排 | |
4 | + USER_INFO__KEY = "HAPPYCATSERVER_USER_USER_INFO" //玩家数据 | |
5 | + USER_LAST_CALC_TIME = "HAPPYCATSERVER_USER_LAST_CALC_TIME" //玩家上一次数据计算时间 | |
6 | + USER_INVITE_ID = "HAPPYCATSERVER_USER_INVITE_ID" //玩家邀请者ID | |
7 | + USER_STARTDOUBLE_TIME = "HAPPYCATSERVER_USER_STARTDOUBLE_TIME" //开启双倍时间 | |
8 | + USER_STARTAUTO_TIME = "HAPPYCATSERVER_USER_STARTAUTO_TIME" //开启自动合成时间 | |
9 | + USER_STARTACC_BOX_TIME = "HAPPYCATSERVER_USER_STARTACC_BOX_TIME" //开启加速成产箱子 | |
10 | + USER_WAREHOUSE_INFO = "HAPPYCATSERVER_USER_WAREHOUSE_INFO" //玩家仓库信息 | |
11 | + USER_GOLD_RANK = "HAPPYCATSERVER_USER_GOLD_RANK" //玩家排行榜,根据金币排 | |
12 | + CAIPIAOISFAKE_KEY = "HAPPYCATSERVER_CAIPIAOISFAKE_KEY" //赌博毛是否真的开奖开关 hset field 为轮数 | |
13 | + CAIPIAOKAIJIANGHISTORY_KEY = "HAPPYCATSERVER_CAIPIAOKAIJIANGHISTORY_KEY" //已开奖的玩家开奖记录列表 hset field未轮数 | |
14 | + CAIPIAOKAIJIANGWAIT_KEY = "HAPPYCATSERVER_CAIPIAOKAIJIANGWAIT_KEY" //待开奖开奖的玩家开奖记录列表hset field未轮数 等待开奖 | |
15 | + CAIPIAOKAIJIANGCURRENT_KEY = "HAPPYCATSERVER_CAIPIAOKAIJIANGCURRENT_KEY" //当前轮次的奖池 未满人数未开奖将 CurDuboCatList | |
16 | + CAIPIAOLEFTNUM_KEY = "HAPPYCATSERVER_CAIPIAOLEFTNUM_KEY" //当期未选号码 | |
17 | + | |
12 | 18 | ) | ... | ... |