Commit 5cb04cde151510a63315b95e4c0d88d979f378b2

Authored by 陆恒
1 parent 82bb3859
Exists in master

提交接口

src/HttpServer/logic/datadef.go
... ... @@ -51,17 +51,20 @@ type DataDesc struct {
51 51  
52 52 type ExchangePosReq struct {
53 53 //Uuid int `json:"uuid"`
54   - Pos_1 int `json:"pos_1"`
55   - Pos_2 int `json:"pos_2"`
  54 + From int `json:"from"`
  55 + To int `json:"to"`
56 56 }
57 57  
  58 +type ExchangePosData struct {
  59 + CatList []CatPosInfo `json:"catList"`
  60 + Coin DoBuyCatCoin `json:"coin"`
  61 + NewCat int `json:"newCat"`
  62 + Reward float32 `json:"reward"`
  63 +}
58 64 type ExchangePosResp struct {
59   - Code int `json:"code"`
60   - Message string `json:"message"`
61   - Pos1_lv int `json:"pos1_lv"`
62   - Pos2_lv int `json:"pos2_lv"`
63   - Highest_lv int `json:"highest_lv"`
64   - Add_num int `json:"add_num"`
  65 + Code int `json:"code"`
  66 + Message string `json:"message"`
  67 + Data ExchangePosData `json:"data"`
65 68 }
66 69  
67 70 type ClickBoxReq struct {
... ... @@ -304,11 +307,11 @@ type QueryPlayerRankResp struct {
304 307 }
305 308  
306 309 type CatPosInfo struct {
307   - Position int `json:"position"`
308   - Cat int `json:"cat"`
309   - RedPacket int `json:"redPacket"`
310   - Time int `json:"time"`
311   - StartTime int `json:"startTime"`
  310 + Position int `json:"position"`
  311 + Cat int `json:"cat"`
  312 + RedPacket float32 `json:"redPacket"`
  313 + Time int `json:"time"`
  314 + StartTime int `json:"startTime"`
312 315 }
313 316  
314 317 type adRateData struct {
... ... @@ -484,7 +487,7 @@ type UserData struct {
484 487 RandGiftNum int //当前剩余空投猫粮次数
485 488 RandGiftDay int //记录当前猫粮日期,当日期变化则重置RandGiftNum
486 489 RandGiftTime int //记录上一次空投猫粮时间
487   - Redbag int //红包值 单位为分
  490 + Redbag float32 //红包值 单位为分
488 491 Head string //头像地址
489 492 NickName string //昵称
490 493 RealName string //实名
... ...
src/HttpServer/logic/function.go
... ... @@ -6,6 +6,7 @@ import (
6 6 "common/logger"
7 7 "common/redis"
8 8 "encoding/json"
  9 + "math/rand"
9 10 "sort"
10 11 "strconv"
11 12 "time"
... ... @@ -104,7 +105,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int) {
104 105 var d1 CatPosInfo
105 106 d1.Position = i
106 107 d1.Cat = 0
107   - if i == 0 {
  108 + if i == 0 || i == 1 {
108 109 d1.Cat = 2
109 110 }
110 111 udata.PosInfo = append(udata.PosInfo, d1)
... ... @@ -177,6 +178,156 @@ func getCatPutPos(uinfo *UserData, clv int) int {
177 178 return pos
178 179 }
179 180  
  181 +//处理红包猫自动合成
  182 +func DoAutoMergeRedCat(uinfo *UserData, uuid int) {
  183 + //首先处理五方招财猫逻辑
  184 + eastsum := 0
  185 + westsum := 0
  186 + southsum := 0
  187 + northsum := 0
  188 + middlesum := 0
  189 +
  190 + for _, v := range uinfo.PosInfo {
  191 + if v.Cat == 103 {
  192 + eastsum++
  193 + }
  194 + if v.Cat == 104 {
  195 + westsum++
  196 + }
  197 + if v.Cat == 105 {
  198 + southsum++
  199 + }
  200 + if v.Cat == 106 {
  201 + northsum++
  202 + }
  203 + if v.Cat == 107 {
  204 + middlesum++
  205 + }
  206 +
  207 + }
  208 +
  209 + //五方猫
  210 + if eastsum > 0 && westsum > 0 && northsum > 0 && southsum > 0 && middlesum > 0 {
  211 + //合成一天招财猫
  212 + //首先去除五只猫
  213 + onepos := -1
  214 + for k, v := range uinfo.PosInfo {
  215 + if v.Cat == 103 {
  216 + onepos = k
  217 + uinfo.PosInfo[k].Cat = 0
  218 + uinfo.PosInfo[k].RedPacket = 0
  219 + uinfo.PosInfo[k].Position = k
  220 + break
  221 + }
  222 + }
  223 + for k, v := range uinfo.PosInfo {
  224 + if v.Cat == 104 {
  225 + onepos = k
  226 + uinfo.PosInfo[k].Cat = 0
  227 + uinfo.PosInfo[k].RedPacket = 0
  228 + uinfo.PosInfo[k].Position = k
  229 + break
  230 + }
  231 + }
  232 + for k, v := range uinfo.PosInfo {
  233 + if v.Cat == 105 {
  234 + onepos = k
  235 + uinfo.PosInfo[k].Cat = 0
  236 + uinfo.PosInfo[k].RedPacket = 0
  237 + uinfo.PosInfo[k].Position = k
  238 + break
  239 + }
  240 + }
  241 + for k, v := range uinfo.PosInfo {
  242 + if v.Cat == 106 {
  243 + onepos = k
  244 + uinfo.PosInfo[k].Cat = 0
  245 + uinfo.PosInfo[k].RedPacket = 0
  246 + uinfo.PosInfo[k].Position = k
  247 + break
  248 + }
  249 + }
  250 + for k, v := range uinfo.PosInfo {
  251 + if v.Cat == 107 {
  252 + onepos = k
  253 + uinfo.PosInfo[k].Cat = 0
  254 + uinfo.PosInfo[k].RedPacket = 0
  255 + uinfo.PosInfo[k].Position = k
  256 + break
  257 + }
  258 + }
  259 + if onepos < 0 {
  260 + logger.Error("DoAutoMergeRedCat failed onepos=%v", onepos)
  261 + }
  262 + uinfo.PosInfo[onepos].Cat = 102 //1天招财猫
  263 + cfg := jsonconf.GetRedCatConfig(uinfo.PosInfo[onepos].Cat)
  264 + if cfg == nil {
  265 + logger.Error("DoAutoMergeRedCat getrdcfg failed lv=%v", uinfo.PosInfo[onepos].Cat)
  266 + } else {
  267 + uinfo.PosInfo[onepos].Time = 24 * 60 * 60
  268 + uinfo.PosInfo[onepos].RedPacket = cfg.Money
  269 + uinfo.PosInfo[onepos].StartTime = int(time.Now().Unix())
  270 + uinfo.PosInfo[onepos].Position = onepos
  271 + }
  272 +
  273 + }
  274 +
  275 +}
  276 +
  277 +//合成红包猫 返回红包猫等级 等级为red_catconfig的id+100
  278 +func MergeRedBagCat(uinfo *UserData, pos int) int {
  279 + rtpos := 0
  280 +
  281 + //走随机合成逻辑
  282 + sumrate := float32(0)
  283 + for _, v := range jsonconf.GetJsonConf().RedCatConfig {
  284 + sumrate += v.Rate
  285 + }
  286 + rand.Seed(time.Now().UnixNano())
  287 + randnum := rand.Intn(100)
  288 + tmprate := 0
  289 + for _, v := range jsonconf.GetJsonConf().RedCatConfig {
  290 + tmprate += int(v.Rate / sumrate)
  291 + if tmprate >= randnum {
  292 + uinfo.PosInfo[pos].Position = pos
  293 + uinfo.PosInfo[pos].Cat = 100 + v.Id
  294 + if v.Id == 13 {
  295 + uinfo.PosInfo[pos].Time = 10 * 60
  296 + uinfo.PosInfo[pos].StartTime = int(time.Now().Unix())
  297 + }
  298 + if v.Id == 14 {
  299 + uinfo.PosInfo[pos].Time = 15 * 60
  300 + uinfo.PosInfo[pos].StartTime = int(time.Now().Unix())
  301 + }
  302 + if v.Id == 2 {
  303 + uinfo.PosInfo[pos].Time = 24 * 60 * 60
  304 + uinfo.PosInfo[pos].StartTime = int(time.Now().Unix())
  305 + }
  306 + uinfo.PosInfo[pos].RedPacket = v.Money
  307 + rtpos = pos
  308 + break
  309 + }
  310 + }
  311 +
  312 + return rtpos
  313 +}
  314 +
  315 +func (uinfo *UserData) CheckBuyCatSHop() {
  316 + //检查可购买的猫是否会增加
  317 + //需要扩充一下商店
  318 + curshoplv := len(uinfo.BuyCatInfo)
  319 + if uinfo.Highestlv-5 > curshoplv {
  320 + var info BuyCatInfoData
  321 + info.Buytime = 0
  322 + cafcfg := jsonconf.GetCatConfig(uinfo.Highestlv - 5)
  323 + if cafcfg != nil {
  324 + info.CurPrice, _ = strconv.ParseInt(cafcfg.Price, 10, 64)
  325 + }
  326 + info.IsMaxBuytime = 0
  327 + uinfo.BuyCatInfo = append(uinfo.BuyCatInfo, info)
  328 + }
  329 +}
  330 +
180 331 func (udata *UserData) CalcGoldRate() int64 {
181 332 //计算出所有速率的和
182 333 //计算方式为 首先计算合成界面猫的产出速率,然后计算红毛包的产出速率,最后计算仓库中的猫的产出速率
... ...
src/HttpServer/logic/httpserver.go
... ... @@ -32,7 +32,9 @@ func startServerHttpServe() {
32 32 http.HandleFunc("/api/home/adRate", AcclecteGold) //看广告加速
33 33 http.HandleFunc("/api/home/shop", QueryBuyCat) //商店
34 34 http.HandleFunc("/api/home/leftRateTimes", LeftRateTimes) //剩余看广告加速次数
  35 + http.HandleFunc("/api/home/change", ExchangePos) //合成
35 36  
  37 + /////---------------------------------------------------------------------old
36 38 http.HandleFunc("/happycat/exchangetwoPos", ExchangePos) //交换位置
37 39 http.HandleFunc("/happycat/clickcatbox", ClickCatBox) //请求点击猫箱子
38 40 http.HandleFunc("/happycat/upgradecatbox", UpgradeCatBox) //请求点击猫箱子
... ... @@ -610,7 +612,7 @@ func AcclecteGold(w http.ResponseWriter, r *http.Request) {
610 612 func ExchangePos(w http.ResponseWriter, r *http.Request) {
611 613 Uuid := 0
612 614 if len(r.Header) > 0 {
613   - Uuid, _ = strconv.Atoi(r.Header.Get("Uuid"))
  615 + Uuid, _ = strconv.Atoi(r.Header.Get("uid"))
614 616 }
615 617 if Uuid == 0 {
616 618 SetHeader(w)
... ... @@ -622,7 +624,7 @@ func ExchangePos(w http.ResponseWriter, r *http.Request) {
622 624 s := string(result)
623 625 logger.Info("ExchangePos , body:%v,uuid=%v", s, Uuid)
624 626  
625   - //HandlerExchangePos(w, s, Uuid)
  627 + HandlerExchangePos(w, s, Uuid)
626 628 }
627 629  
628 630 func GetUserData(w http.ResponseWriter, r *http.Request) {
... ...
src/HttpServer/logic/logic.go
... ... @@ -512,3 +512,93 @@ func HandlerQueryBuyCat(w http.ResponseWriter, data string, uuid int) {
512 512 respstr, _ := json.Marshal(&resp)
513 513 fmt.Fprint(w, string(respstr))
514 514 }
  515 +
  516 +func HandlerExchangePos(w http.ResponseWriter, data string, uuid int) {
  517 + SetHeader(w)
  518 + var resp ExchangePosResp
  519 + resp.Code = 0
  520 + var rdata ExchangePosReq
  521 + err := json.Unmarshal([]byte(data), &rdata)
  522 + if err != nil {
  523 + logger.Info("json decode HandlerExchangePos data failed:%v", err, " for:%v", data)
  524 + resp.Message = "json unmarshal failed"
  525 + resp.Code = 1
  526 + respstr, _ := json.Marshal(&resp)
  527 + fmt.Fprint(w, string(respstr))
  528 + return
  529 + }
  530 +
  531 + for {
  532 + uinfo, err := GetUserInfo(strconv.Itoa(uuid))
  533 + if err != nil || uinfo == nil {
  534 + logger.Error("HandlerExchangePos getuserinfo failed=%v", err)
  535 + resp.Code = 1
  536 + resp.Message = "get userinfo failed"
  537 + break
  538 + }
  539 +
  540 + sumpos := len(uinfo.PosInfo) - 1
  541 + //检查位置索引的合法性
  542 + if rdata.From < 0 || rdata.To < 0 || rdata.From > sumpos || rdata.To > sumpos {
  543 + logger.Error("HandlerExchangePos pos index not legal failed=%v", err)
  544 + resp.Code = 1
  545 + resp.Message = "pos index not legal"
  546 + break
  547 + }
  548 +
  549 + //下面判断是交换还是合成
  550 + if uinfo.PosInfo[rdata.From].Cat == uinfo.PosInfo[rdata.To].Cat {
  551 + //相同 则合成
  552 + //首先判断是否是顶级猫了
  553 + if uinfo.PosInfo[rdata.From].Cat == 36 {
  554 + //todo 走红包猫的逻辑
  555 + MergeRedBagCat(uinfo, rdata.From)
  556 + DoAutoMergeRedCat(uinfo, uuid)
  557 + //此处处理一下红包猫的自动合成逻辑
  558 + if uinfo.Highestlv < 37 {
  559 + //非红包猫
  560 + uinfo.Highestlv = 37
  561 + uinfo.CheckBuyCatSHop()
  562 + }
  563 +
  564 + } else {
  565 + //
  566 + uinfo.PosInfo[rdata.From].Cat = 0
  567 + uinfo.PosInfo[rdata.To].Cat++
  568 + if uinfo.PosInfo[rdata.To].Cat > uinfo.Highestlv {
  569 + uinfo.Highestlv = uinfo.PosInfo[rdata.To].Cat
  570 + resp.Data.NewCat = uinfo.PosInfo[rdata.To].Cat
  571 + uinfo.CheckBuyCatSHop()
  572 + }
  573 +
  574 + }
  575 + } else {
  576 + //不相同 交换即可
  577 + if (uinfo.PosInfo[rdata.From].Cat == 108 && uinfo.PosInfo[rdata.To].Cat == 109) || (uinfo.PosInfo[rdata.From].Cat == 109 && uinfo.PosInfo[rdata.To].Cat == 108) {
  578 + //合成情侣猫
  579 + addredpacket := uinfo.PosInfo[rdata.From].RedPacket + uinfo.PosInfo[rdata.To].RedPacket
  580 + uinfo.PosInfo[rdata.From].Cat = 0
  581 + uinfo.PosInfo[rdata.From].RedPacket = 0
  582 + uinfo.PosInfo[rdata.To].Cat = 0
  583 + uinfo.PosInfo[rdata.To].RedPacket = 0
  584 + resp.Data.Reward = addredpacket
  585 + uinfo.Redbag += addredpacket
  586 + //todo 调用sdk接口
  587 + } else {
  588 + uinfo.PosInfo[rdata.From].Cat, uinfo.PosInfo[rdata.To].Cat = uinfo.PosInfo[rdata.To].Cat, uinfo.PosInfo[rdata.From].Cat
  589 + }
  590 + }
  591 + //重新计算速率
  592 + uinfo.CalcGoldRate()
  593 +
  594 + //保存玩家数据
  595 + SaveUserInfo(uinfo, strconv.Itoa(uuid))
  596 + resp.Code = 0
  597 + break
  598 + }
  599 +
  600 + //回包
  601 + respstr, _ := json.Marshal(&resp)
  602 + fmt.Fprint(w, string(respstr))
  603 +
  604 +}
... ...