Commit 34263c32237ba5ffe9367b8c9b5f4d9fe4727c14

Authored by 陆恒
1 parent 3e479fb8
Exists in master

提交

src/HttpServer/jsonconf/jsonconf.go
@@ -12,55 +12,65 @@ var ( @@ -12,55 +12,65 @@ var (
12 ) 12 )
13 13
14 type CardDesc struct { 14 type CardDesc struct {
15 - Time int `json:"time"`  
16 - Ctype int `json:"type"`  
17 - Desc string `json:"desc"` 15 + Time int `json:"time"`
  16 + Ctype int `json:"type"`
  17 + Desc string `json:"desc"`
18 Flop_card string `json:"flop_card"` 18 Flop_card string `json:"flop_card"`
19 } 19 }
20 20
21 type CatDesc struct { 21 type CatDesc struct {
22 - Id int `json:"id"`  
23 - Name string `json:"name"`  
24 - Level_buy int `json:"level_buy"`  
25 - Rec_buy int `json:"rec_buy"`  
26 - Price string `json:"price"`  
27 - Gold_get string `json:"gold_get"`  
28 - Ratio float32 `json:"ratio"`  
29 - Increse_limit int `json:"increse_limit"`  
30 - Interval float32 `json:"interval"` 22 + Id int `json:"id"`
  23 + Name string `json:"name"`
  24 + Level_buy int `json:"level_buy"`
  25 + Rec_buy int `json:"rec_buy"`
  26 + Price string `json:"price"`
  27 + Gold_get string `json:"gold_get"`
  28 + Ratio float32 `json:"ratio"`
  29 + Increse_limit int `json:"increse_limit"`
  30 + Interval float32 `json:"interval"`
31 } 31 }
32 32
33 type RedCatDesc struct { 33 type RedCatDesc struct {
34 - Id int `json:"id"`  
35 - Name string `json:"name"`  
36 - Skin string `json:"skin"`  
37 - Money float32 `json:"money"`  
38 - Rate float32 `json:"rate"`  
39 - Is_37 int `json:"is_37"`  
40 - Dec_red string `json:"dec_red"`  
41 - Dec_get string `json:"dec_get"` 34 + Id int `json:"id"`
  35 + Name string `json:"name"`
  36 + Skin string `json:"skin"`
  37 + Money float32 `json:"money"`
  38 + Rate float32 `json:"rate"`
  39 + Is_37 int `json:"is_37"`
  40 + Dec_red string `json:"dec_red"`
  41 + Dec_get string `json:"dec_get"`
42 } 42 }
43 43
44 type TurnTableDesc struct { 44 type TurnTableDesc struct {
45 - Id int `json:"id"`  
46 - Ttype int `json:"type"`  
47 - Rate float32 `json:"rate"`  
48 - Parameter int `json:"parameter"`  
49 - Desc string `json:"desc"`  
50 - Idx int `json:"idx"` 45 + Id int `json:"id"`
  46 + Ttype int `json:"type"`
  47 + Rate float32 `json:"rate"`
  48 + Parameter int `json:"parameter"`
  49 + Desc string `json:"desc"`
  50 + Idx int `json:"idx"`
51 } 51 }
52 52
53 type GameConfig struct { 53 type GameConfig struct {
54 - CardConfig []CardDesc  
55 - CatConfig []CatDesc  
56 - RedCatConfig []RedCatDesc  
57 - TurnTableConfig []TurnTableDesc 54 + CardConfig []CardDesc
  55 + CatConfig []CatDesc
  56 + RedCatConfig []RedCatDesc
  57 + TurnTableConfig []TurnTableDesc
58 } 58 }
59 59
60 func GetJsonConf() *GameConfig { 60 func GetJsonConf() *GameConfig {
61 return g_jsonconf 61 return g_jsonconf
62 } 62 }
63 63
  64 +func GetTurnTable(ctype int) []TurnTableDesc {
  65 + var rtslice []TurnTableDesc
  66 + for _, v := range g_jsonconf.TurnTableConfig {
  67 + if v.Ttype == ctype {
  68 + rtslice = append(rtslice, v)
  69 + }
  70 + }
  71 + return rtslice
  72 +}
  73 +
64 func GetCatConfig(lv int) *CatDesc { 74 func GetCatConfig(lv int) *CatDesc {
65 for _, v := range g_jsonconf.CatConfig { 75 for _, v := range g_jsonconf.CatConfig {
66 if v.Id == lv { 76 if v.Id == lv {
@@ -70,6 +80,16 @@ func GetCatConfig(lv int) *CatDesc { @@ -70,6 +80,16 @@ func GetCatConfig(lv int) *CatDesc {
70 return nil 80 return nil
71 } 81 }
72 82
  83 +//获取转盘配置
  84 +func GetTurnTableCfg(id int) *TurnTableDesc {
  85 + for _, v := range g_jsonconf.TurnTableConfig {
  86 + if v.Id == id {
  87 + return &v
  88 + }
  89 + }
  90 + return nil
  91 +}
  92 +
73 //获取红包猫配置 93 //获取红包猫配置
74 func GetRedCatConfig(lv int) *RedCatDesc { 94 func GetRedCatConfig(lv int) *RedCatDesc {
75 reallv := lv - 100 95 reallv := lv - 100
@@ -84,7 +104,6 @@ func GetRedCatConfig(lv int) *RedCatDesc { @@ -84,7 +104,6 @@ func GetRedCatConfig(lv int) *RedCatDesc {
84 return nil 104 return nil
85 } 105 }
86 106
87 -  
88 func file_get_contents(path string) ([]byte, error) { 107 func file_get_contents(path string) ([]byte, error) {
89 f, err := os.Open(path) 108 f, err := os.Open(path)
90 if err != nil { 109 if err != nil {
@@ -148,8 +167,6 @@ func LoadJsonConf() error { @@ -148,8 +167,6 @@ func LoadJsonConf() error {
148 return err 167 return err
149 } 168 }
150 169
151 -  
152 -  
153 logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err) 170 logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err)
154 return err 171 return err
155 } 172 }
src/HttpServer/logic/datadef.go
@@ -210,6 +210,30 @@ type AddTicketResp struct { @@ -210,6 +210,30 @@ type AddTicketResp struct {
210 Data AddTicketData `json:"data"` 210 Data AddTicketData `json:"data"`
211 } 211 }
212 212
  213 +type MultipleData struct {
  214 +}
  215 +
  216 +type MultipleReq struct {
  217 + RewardId int `json:"rewardId"`
  218 +}
  219 +
  220 +type MultipleResp struct {
  221 + Code int `json:"code"`
  222 + Message string `json:"message"`
  223 + Data MultipleData `json:"data"`
  224 +}
  225 +
  226 +type DrawTableData struct {
  227 + RewardId int `json:"rewardId"`
  228 + Coin string `json:"coin"`
  229 +}
  230 +
  231 +type DrawTableResp struct {
  232 + Code int `json:"code"`
  233 + Message string `json:"message"`
  234 + Data DrawTableData `json:"data"`
  235 +}
  236 +
213 type AcclecteBoxResp struct { 237 type AcclecteBoxResp struct {
214 Code int `json:"code"` 238 Code int `json:"code"`
215 Message string `json:"message"` 239 Message string `json:"message"`
@@ -584,6 +608,9 @@ type UserData struct { @@ -584,6 +608,9 @@ type UserData struct {
584 GetWatchAdsGoldTime int //看广告领金币次数 608 GetWatchAdsGoldTime int //看广告领金币次数
585 DrawTicket int //抽奖券次数 609 DrawTicket int //抽奖券次数
586 DrawTicketTimes int //剩余增加抽奖券次数 610 DrawTicketTimes int //剩余增加抽奖券次数
  611 + DratMult int //下次抽奖的倍数
  612 + DrawLastRewardId int //上一次的奖励ID
  613 + DrawTableCount int //当前抽奖次数 5次以后归零
587 IsAuto int //当前是否自动合成 614 IsAuto int //当前是否自动合成
588 IsBoxAcc int //是否处于加速生成箱子状态 615 IsBoxAcc int //是否处于加速生成箱子状态
589 RandGiftNum int //当前剩余空投猫粮次数 616 RandGiftNum int //当前剩余空投猫粮次数
src/HttpServer/logic/function.go
@@ -73,6 +73,52 @@ func (u *UserData) GetCatPos(catlv int) int { @@ -73,6 +73,52 @@ func (u *UserData) GetCatPos(catlv int) int {
73 return pos 73 return pos
74 } 74 }
75 75
  76 +//转盘抽奖 返回抽到的奖项的id
  77 +func (u *UserData) DrawTable() int {
  78 + idx := -1
  79 + if u.DrawTableCount != 3 {
  80 + //抽a类型
  81 + sumrate := float32(0)
  82 + tmprate := 0
  83 + rand.Seed(time.Now().UnixNano())
  84 + randnum := rand.Intn(100)
  85 + cflist := jsonconf.GetTurnTable(1)
  86 + for _, vv := range cflist {
  87 + sumrate += vv.Rate
  88 + }
  89 +
  90 + for _, v := range cflist {
  91 + tmprate += int(v.Rate / sumrate)
  92 + if tmprate >= randnum {
  93 + idx = v.Id
  94 + break
  95 + }
  96 + }
  97 +
  98 + } else {
  99 + //抽b类型
  100 + sumrate := float32(0)
  101 + tmprate := 0
  102 + rand.Seed(time.Now().UnixNano())
  103 + randnum := rand.Intn(100)
  104 + cflist := jsonconf.GetTurnTable(2)
  105 + for _, vv := range cflist {
  106 + sumrate += vv.Rate
  107 + }
  108 +
  109 + for _, v := range cflist {
  110 + tmprate += int(v.Rate / sumrate)
  111 + if tmprate >= randnum {
  112 + idx = v.Id
  113 + break
  114 + }
  115 + }
  116 + }
  117 +
  118 + logger.Info("DrawTable idx=%v", idx)
  119 + return idx
  120 +}
  121 +
76 func (u *UserData) HandlePassDay() { 122 func (u *UserData) HandlePassDay() {
77 isdiffday := false 123 isdiffday := false
78 nowtime := time.Now() 124 nowtime := time.Now()
@@ -108,7 +154,7 @@ func (u *UserData) HandlePassDay() { @@ -108,7 +154,7 @@ func (u *UserData) HandlePassDay() {
108 u.DoubleLeftTimes = ACCGOLDRATELIMIT 154 u.DoubleLeftTimes = ACCGOLDRATELIMIT
109 u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT 155 u.GetWatchAdsGoldTime = WATCHADSGOLDLIMIT
110 u.DrawTicket = DRAWTICKETNUM 156 u.DrawTicket = DRAWTICKETNUM
111 - u.DoubleLeftTimes = DRAWTICKETGETLIMIT 157 + u.DrawTicketTimes = DRAWTICKETGETLIMIT
112 } 158 }
113 159
114 u.LastLoginTime = int(nowtime.Unix()) 160 u.LastLoginTime = int(nowtime.Unix())
@@ -166,7 +212,9 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) { @@ -166,7 +212,9 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
166 udata.RegTime = int(time.Now().Unix()) 212 udata.RegTime = int(time.Now().Unix())
167 udata.LastLoginTime = int(time.Now().Unix()) 213 udata.LastLoginTime = int(time.Now().Unix())
168 udata.DrawTicket = DRAWTICKETNUM 214 udata.DrawTicket = DRAWTICKETNUM
169 - udata.DoubleLeftTimes = DRAWTICKETGETLIMIT 215 + udata.DrawTicketTimes = DRAWTICKETGETLIMIT
  216 + udata.DratMult = 1
  217 + udata.DrawTableCount = 1
170 218
171 //初始化16个猫爬架 219 //初始化16个猫爬架
172 for i := 0; i < 16; i++ { 220 for i := 0; i < 16; i++ {
src/HttpServer/logic/httpserver.go
@@ -43,6 +43,8 @@ func startServerHttpServe() { @@ -43,6 +43,8 @@ func startServerHttpServe() {
43 http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表 43 http.HandleFunc("/api/home/limitCatList", LimitCatList) //分红猫列表
44 http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页 44 http.HandleFunc("/api/turntable/index", QueryTurntable) //转盘主页
45 http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券 45 http.HandleFunc("/api/turntable/addTicket", AddTicket) //增加抽奖券
  46 + http.HandleFunc("/api/turntable/multiple", Multiple) //增加倍数
  47 + http.HandleFunc("/api/turntable/draw", DrawTable) //抽奖
46 48
47 /////---------------------------------------------------------------------old 49 /////---------------------------------------------------------------------old
48 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置 50 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置
@@ -637,6 +639,42 @@ func RedCatList(w http.ResponseWriter, r *http.Request) { @@ -637,6 +639,42 @@ func RedCatList(w http.ResponseWriter, r *http.Request) {
637 //HandlerRecvTimingReward(w, s, Uuid) 639 //HandlerRecvTimingReward(w, s, Uuid)
638 } 640 }
639 641
  642 +func DrawTable(w http.ResponseWriter, r *http.Request) {
  643 + Uuid := 0
  644 + if len(r.Header) > 0 {
  645 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  646 + }
  647 + if Uuid == 0 {
  648 + SetHeader(w)
  649 + return
  650 + }
  651 + result, _ := ioutil.ReadAll(r.Body)
  652 + r.Body.Close()
  653 +
  654 + s := string(result)
  655 + logger.Info("DrawTable , body:%v,uuid=%v", s, Uuid)
  656 +
  657 + HandlerDrawTable(w, s, Uuid)
  658 +}
  659 +
  660 +func Multiple(w http.ResponseWriter, r *http.Request) {
  661 + Uuid := 0
  662 + if len(r.Header) > 0 {
  663 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
  664 + }
  665 + if Uuid == 0 {
  666 + SetHeader(w)
  667 + return
  668 + }
  669 + result, _ := ioutil.ReadAll(r.Body)
  670 + r.Body.Close()
  671 +
  672 + s := string(result)
  673 + logger.Info("Multiple , body:%v,uuid=%v", s, Uuid)
  674 +
  675 + HandlerMultiple(w, s, Uuid)
  676 +}
  677 +
640 func AddTicket(w http.ResponseWriter, r *http.Request) { 678 func AddTicket(w http.ResponseWriter, r *http.Request) {
641 Uuid := 0 679 Uuid := 0
642 if len(r.Header) > 0 { 680 if len(r.Header) > 0 {
src/HttpServer/logic/logic.go
@@ -403,6 +403,112 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) { @@ -403,6 +403,112 @@ func HandlerGetMainPageInfo(w http.ResponseWriter, data string, uuid int) {
403 fmt.Fprint(w, string(respstr)) 403 fmt.Fprint(w, string(respstr))
404 } 404 }
405 405
  406 +func HandlerDrawTable(w http.ResponseWriter, data string, uuid int) {
  407 + SetHeader(w)
  408 + var resp DrawTableResp
  409 + resp.Code = 0
  410 + resp.Message = "success"
  411 +
  412 + for {
  413 +
  414 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  415 + if err != nil || uinfo == nil {
  416 + logger.Error("HandlerDrawTable getuserinfo failed=%v", err)
  417 + resp.Code = 1
  418 + resp.Message = "get userinfo failed"
  419 + break
  420 + }
  421 +
  422 + //抽奖券数量是否足够
  423 + if uinfo.DrawTicket <= 0 {
  424 + logger.Error("HandlerDrawTable ticketnotenough failed=%v", err)
  425 + resp.Code = 1
  426 + resp.Message = "ticketnotenough"
  427 + break
  428 + }
  429 +
  430 + //根据抽奖次数
  431 + tid := uinfo.DrawTable()
  432 + tablecfg := jsonconf.GetTurnTableCfg(tid)
  433 + if tablecfg == nil {
  434 + logger.Error("HandlerDrawTable tid failed=%v", tid)
  435 + resp.Code = 1
  436 + resp.Message = "tidnotright"
  437 + break
  438 + }
  439 +
  440 + //加金币 此处现金概率为零不做处理
  441 +
  442 + addgold := int64(tablecfg.Parameter) * uinfo.Goldrate
  443 + if uinfo.DratMult != 1 {
  444 + addgold = addgold * int64(uinfo.DratMult)
  445 + }
  446 +
  447 + uinfo.DrawTicket--
  448 + uinfo.DratMult = 1
  449 + uinfo.DrawTableCount++
  450 + if uinfo.DrawTableCount > 5 {
  451 + uinfo.DrawTableCount = 1
  452 + }
  453 +
  454 + uinfo.Gold += addgold
  455 +
  456 + resp.Data.Coin = strconv.FormatInt(uinfo.Gold, 10)
  457 + resp.Data.RewardId = tid
  458 + resp.Code = 0
  459 + break
  460 + }
  461 +
  462 + //回包
  463 + logger.Info("HandlerDrawTable resp=%+v", resp)
  464 + respstr, _ := json.Marshal(&resp)
  465 + fmt.Fprint(w, string(respstr))
  466 +
  467 +}
  468 +
  469 +func HandlerMultiple(w http.ResponseWriter, data string, uuid int) {
  470 + SetHeader(w)
  471 + var resp MultipleResp
  472 + resp.Code = 0
  473 + resp.Message = "success"
  474 + var rdata MultipleReq
  475 +
  476 + err := json.Unmarshal([]byte(data), &rdata)
  477 + for {
  478 + if err != nil {
  479 + logger.Error("HandlerMultiple json unmarshal failed=%v", err)
  480 + resp.Code = 1
  481 + resp.Message = "json failed"
  482 + break
  483 + }
  484 +
  485 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  486 + if err != nil || uinfo == nil {
  487 + logger.Error("HandlerMultiple getuserinfo failed=%v", err)
  488 + resp.Code = 1
  489 + resp.Message = "get userinfo failed"
  490 + break
  491 + }
  492 + cfg := jsonconf.GetTurnTableCfg(rdata.RewardId)
  493 + if cfg == nil {
  494 + logger.Error("HandlerMultiple getcfgfailed failed=%v", rdata.RewardId)
  495 + resp.Code = 1
  496 + resp.Message = "getcfgfailed failed"
  497 + break
  498 + }
  499 +
  500 + uinfo.DratMult = cfg.Parameter
  501 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  502 + resp.Code = 0
  503 + break
  504 + }
  505 +
  506 + //回包
  507 + respstr, _ := json.Marshal(&resp)
  508 + fmt.Fprint(w, string(respstr))
  509 +
  510 +}
  511 +
406 func HandlerAddTicket(w http.ResponseWriter, data string, uuid int) { 512 func HandlerAddTicket(w http.ResponseWriter, data string, uuid int) {
407 SetHeader(w) 513 SetHeader(w)
408 var resp AddTicketResp 514 var resp AddTicketResp