From 72aa05d3355139bf4bec8b7154c0f6c6bf38c21d Mon Sep 17 00:00:00 2001 From: 陆恒 Date: Fri, 24 Jul 2020 15:36:03 +0800 Subject: [PATCH] 脑洞过关红包需求 --- src/HttpServer/jsonconf/GuanRedBag.json | 902 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/jsonconf/JiRedbag.json | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/jsonconf/jsonconf.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/constdef.go | 1 + src/HttpServer/logic/datadef.go | 31 +++++++++++++++++++++++++++++++ src/HttpServer/logic/function.go | 14 +++++++++++++- src/HttpServer/logic/httpserver.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/HttpServer/logic/logic.go | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 1288 insertions(+), 4 deletions(-) create mode 100644 src/HttpServer/jsonconf/GuanRedBag.json create mode 100644 src/HttpServer/jsonconf/JiRedbag.json diff --git a/src/HttpServer/jsonconf/GuanRedBag.json b/src/HttpServer/jsonconf/GuanRedBag.json new file mode 100644 index 0000000..5d2e2b1 --- /dev/null +++ b/src/HttpServer/jsonconf/GuanRedBag.json @@ -0,0 +1,902 @@ +[ + { + "type": 1, + "id": 1, + "cash": 12200 + }, + { + "type": 1, + "id": 2, + "cash": 10200 + }, + { + "type": 1, + "id": 3, + "cash": 10600 + }, + { + "type": 1, + "id": 4, + "cash": 10900 + }, + { + "type": 1, + "id": 5, + "cash": 10100 + }, + { + "type": 1, + "id": 6, + "cash": 12000 + }, + { + "type": 1, + "id": 7, + "cash": 11300 + }, + { + "type": 1, + "id": 8, + "cash": 11700 + }, + { + "type": 1, + "id": 9, + "cash": 10700 + }, + { + "type": 1, + "id": 10, + "cash": 11500 + }, + { + "type": 1, + "id": 11, + "cash": 11400 + }, + { + "type": 1, + "id": 12, + "cash": 10700 + }, + { + "type": 1, + "id": 13, + "cash": 10000 + }, + { + "type": 1, + "id": 14, + "cash": 10100 + }, + { + "type": 1, + "id": 15, + "cash": 10900 + }, + { + "type": 1, + "id": 16, + "cash": 9900 + }, + { + "type": 1, + "id": 17, + "cash": 10100 + }, + { + "type": 1, + "id": 18, + "cash": 10200 + }, + { + "type": 1, + "id": 19, + "cash": 11000 + }, + { + "type": 1, + "id": 20, + "cash": 10300 + }, + { + "type": 1, + "id": 21, + "cash": 7600 + }, + { + "type": 1, + "id": 22, + "cash": 6600 + }, + { + "type": 1, + "id": 23, + "cash": 6400 + }, + { + "type": 1, + "id": 24, + "cash": 5300 + }, + { + "type": 1, + "id": 25, + "cash": 5200 + }, + { + "type": 1, + "id": 26, + "cash": 6100 + }, + { + "type": 1, + "id": 27, + "cash": 2500 + }, + { + "type": 1, + "id": 28, + "cash": 6500 + }, + { + "type": 1, + "id": 29, + "cash": 3000 + }, + { + "type": 1, + "id": 30, + "cash": 7500 + }, + { + "type": 1, + "id": 31, + "cash": 7200 + }, + { + "type": 1, + "id": 32, + "cash": 4400 + }, + { + "type": 1, + "id": 33, + "cash": 7300 + }, + { + "type": 1, + "id": 34, + "cash": 6000 + }, + { + "type": 1, + "id": 35, + "cash": 5700 + }, + { + "type": 1, + "id": 36, + "cash": 11000 + }, + { + "type": 1, + "id": 37, + "cash": 5600 + }, + { + "type": 1, + "id": 38, + "cash": 7000 + }, + { + "type": 1, + "id": 39, + "cash": 5200 + }, + { + "type": 1, + "id": 40, + "cash": 6100 + }, + { + "type": 1, + "id": 41, + "cash": 3000 + }, + { + "type": 1, + "id": 42, + "cash": 5100 + }, + { + "type": 1, + "id": 43, + "cash": 7600 + }, + { + "type": 1, + "id": 44, + "cash": 5600 + }, + { + "type": 1, + "id": 45, + "cash": 5600 + }, + { + "type": 1, + "id": 46, + "cash": 6000 + }, + { + "type": 1, + "id": 47, + "cash": 2500 + }, + { + "type": 1, + "id": 48, + "cash": 5000 + }, + { + "type": 1, + "id": 49, + "cash": 5100 + }, + { + "type": 1, + "id": 50, + "cash": 7800 + }, + { + "type": 1, + "id": 51, + "cash": 5400 + }, + { + "type": 1, + "id": 52, + "cash": 7700 + }, + { + "type": 1, + "id": 53, + "cash": 6700 + }, + { + "type": 1, + "id": 54, + "cash": 1800 + }, + { + "type": 1, + "id": 55, + "cash": 1700 + }, + { + "type": 1, + "id": 56, + "cash": 2200 + }, + { + "type": 1, + "id": 57, + "cash": 1800 + }, + { + "type": 1, + "id": 58, + "cash": 1100 + }, + { + "type": 1, + "id": 59, + "cash": 1800 + }, + { + "type": 1, + "id": 60, + "cash": 2900 + }, + { + "type": 1, + "id": 61, + "cash": 2100 + }, + { + "type": 1, + "id": 62, + "cash": 1600 + }, + { + "type": 1, + "id": 63, + "cash": 11000 + }, + { + "type": 1, + "id": 64, + "cash": 2000 + }, + { + "type": 1, + "id": 65, + "cash": 2600 + }, + { + "type": 1, + "id": 66, + "cash": 1500 + }, + { + "type": 1, + "id": 67, + "cash": 2100 + }, + { + "type": 1, + "id": 68, + "cash": 2800 + }, + { + "type": 1, + "id": 69, + "cash": 2300 + }, + { + "type": 1, + "id": 70, + "cash": 2700 + }, + { + "type": 1, + "id": 71, + "cash": 2700 + }, + { + "type": 1, + "id": 72, + "cash": 1700 + }, + { + "type": 1, + "id": 73, + "cash": 1700 + }, + { + "type": 1, + "id": 74, + "cash": 1500 + }, + { + "type": 1, + "id": 75, + "cash": 2200 + }, + { + "type": 1, + "id": 76, + "cash": 1600 + }, + { + "type": 1, + "id": 77, + "cash": 1000 + }, + { + "type": 1, + "id": 78, + "cash": 2900 + }, + { + "type": 1, + "id": 79, + "cash": 2000 + }, + { + "type": 1, + "id": 80, + "cash": 2400 + }, + { + "type": 1, + "id": 81, + "cash": 1300 + }, + { + "type": 1, + "id": 82, + "cash": 2800 + }, + { + "type": 1, + "id": 83, + "cash": 1600 + }, + { + "type": 1, + "id": 84, + "cash": 2100 + }, + { + "type": 1, + "id": 85, + "cash": 1100 + }, + { + "type": 1, + "id": 86, + "cash": 1300 + }, + { + "type": 1, + "id": 87, + "cash": 1300 + }, + { + "type": 1, + "id": 88, + "cash": 1600 + }, + { + "type": 1, + "id": 89, + "cash": 1800 + }, + { + "type": 1, + "id": 90, + "cash": 1200 + }, + { + "type": 1, + "id": 91, + "cash": 1700 + }, + { + "type": 1, + "id": 92, + "cash": 1400 + }, + { + "type": 1, + "id": 93, + "cash": 1100 + }, + { + "type": 1, + "id": 94, + "cash": 1000 + }, + { + "type": 1, + "id": 95, + "cash": 2100 + }, + { + "type": 1, + "id": 96, + "cash": 2500 + }, + { + "type": 1, + "id": 97, + "cash": 2700 + }, + { + "type": 1, + "id": 98, + "cash": 1700 + }, + { + "type": 1, + "id": 99, + "cash": 2400 + }, + { + "type": 1, + "id": 100, + "cash": 2400 + }, + { + "type": 1, + "id": 101, + "cash": 1000 + }, + { + "type": 1, + "id": 102, + "cash": 1700 + }, + { + "type": 1, + "id": 103, + "cash": 1100 + }, + { + "type": 1, + "id": 104, + "cash": 1800 + }, + { + "type": 1, + "id": 105, + "cash": 1400 + }, + { + "type": 1, + "id": 106, + "cash": 2400 + }, + { + "type": 1, + "id": 107, + "cash": 1700 + }, + { + "type": 1, + "id": 108, + "cash": 2800 + }, + { + "type": 1, + "id": 109, + "cash": 1800 + }, + { + "type": 1, + "id": 110, + "cash": 2600 + }, + { + "type": 1, + "id": 111, + "cash": 1400 + }, + { + "type": 1, + "id": 112, + "cash": 1600 + }, + { + "type": 1, + "id": 113, + "cash": 1400 + }, + { + "type": 1, + "id": 114, + "cash": 2900 + }, + { + "type": 1, + "id": 115, + "cash": 2400 + }, + { + "type": 1, + "id": 116, + "cash": 2500 + }, + { + "type": 1, + "id": 117, + "cash": 2700 + }, + { + "type": 1, + "id": 118, + "cash": 1600 + }, + { + "type": 1, + "id": 119, + "cash": 2800 + }, + { + "type": 1, + "id": 120, + "cash": 2100 + }, + { + "type": 1, + "id": 121, + "cash": 1000 + }, + { + "type": 1, + "id": 122, + "cash": 2400 + }, + { + "type": 1, + "id": 123, + "cash": 1200 + }, + { + "type": 1, + "id": 124, + "cash": 1700 + }, + { + "type": 1, + "id": 125, + "cash": 1000 + }, + { + "type": 1, + "id": 126, + "cash": 1600 + }, + { + "type": 1, + "id": 127, + "cash": 1600 + }, + { + "type": 1, + "id": 128, + "cash": 1900 + }, + { + "type": 1, + "id": 129, + "cash": 2000 + }, + { + "type": 1, + "id": 130, + "cash": 2300 + }, + { + "type": 1, + "id": 131, + "cash": 2100 + }, + { + "type": 1, + "id": 132, + "cash": 1400 + }, + { + "type": 1, + "id": 133, + "cash": 2300 + }, + { + "type": 1, + "id": 134, + "cash": 2800 + }, + { + "type": 1, + "id": 135, + "cash": 200 + }, + { + "type": 1, + "id": 136, + "cash": 2000 + }, + { + "type": 1, + "id": 137, + "cash": 1200 + }, + { + "type": 1, + "id": 138, + "cash": 1200 + }, + { + "type": 1, + "id": 139, + "cash": 2900 + }, + { + "type": 1, + "id": 140, + "cash": 2100 + }, + { + "type": 1, + "id": 141, + "cash": 400 + }, + { + "type": 1, + "id": 142, + "cash": 2700 + }, + { + "type": 1, + "id": 143, + "cash": 100 + }, + { + "type": 1, + "id": 144, + "cash": 1300 + }, + { + "type": 1, + "id": 145, + "cash": 1400 + }, + { + "type": 1, + "id": 146, + "cash": 1200 + }, + { + "type": 1, + "id": 147, + "cash": 1200 + }, + { + "type": 1, + "id": 148, + "cash": 1000 + }, + { + "type": 1, + "id": 149, + "cash": 200 + }, + { + "type": 1, + "id": 150, + "cash": 2500 + }, + { + "type": 1, + "id": 151, + "cash": 1400 + }, + { + "type": 1, + "id": 152, + "cash": 1100 + }, + { + "type": 1, + "id": 153, + "cash": 1200 + }, + { + "type": 1, + "id": 154, + "cash": 1000 + }, + { + "type": 1, + "id": 155, + "cash": 2800 + }, + { + "type": 1, + "id": 156, + "cash": 2700 + }, + { + "type": 1, + "id": 157, + "cash": 1600 + }, + { + "type": 1, + "id": 158, + "cash": 400 + }, + { + "type": 1, + "id": 159, + "cash": 1000 + }, + { + "type": 1, + "id": 160, + "cash": 1400 + }, + { + "type": 1, + "id": 161, + "cash": 1700 + }, + { + "type": 1, + "id": 162, + "cash": 2200 + }, + { + "type": 1, + "id": 163, + "cash": 1200 + }, + { + "type": 1, + "id": 164, + "cash": 1100 + }, + { + "type": 1, + "id": 165, + "cash": 1100 + }, + { + "type": 1, + "id": 166, + "cash": 2200 + }, + { + "type": 1, + "id": 167, + "cash": 300 + }, + { + "type": 1, + "id": 168, + "cash": 1200 + }, + { + "type": 1, + "id": 169, + "cash": 1300 + }, + { + "type": 1, + "id": 170, + "cash": 2600 + }, + { + "type": 1, + "id": 171, + "cash": 1000 + }, + { + "type": 1, + "id": 172, + "cash": 2200 + }, + { + "type": 1, + "id": 173, + "cash": 1900 + }, + { + "type": 1, + "id": 174, + "cash": 2400 + }, + { + "type": 1, + "id": 175, + "cash": 500 + }, + { + "type": 1, + "id": 176, + "cash": 1000 + }, + { + "type": 1, + "id": 177, + "cash": 2300 + }, + { + "type": 1, + "id": 178, + "cash": 400 + }, + { + "type": 1, + "id": 179, + "cash": 1600 + }, + { + "type": 1, + "id": 180, + "cash": 1900 + } +] \ No newline at end of file diff --git a/src/HttpServer/jsonconf/JiRedbag.json b/src/HttpServer/jsonconf/JiRedbag.json new file mode 100644 index 0000000..3bba4f5 --- /dev/null +++ b/src/HttpServer/jsonconf/JiRedbag.json @@ -0,0 +1,67 @@ +[ + { + "type": 2, + "id": 1, + "cash": 12600 + }, + { + "type": 2, + "id": 2, + "cash": 11000 + }, + { + "type": 2, + "id": 3, + "cash": 9000 + }, + { + "type": 2, + "id": 4, + "cash": 8600 + }, + { + "type": 2, + "id": 5, + "cash": 10100 + }, + { + "type": 2, + "id": 6, + "cash": 9500 + }, + { + "type": 2, + "id": 7, + "cash": 8800 + }, + { + "type": 2, + "id": 8, + "cash": 6600 + }, + { + "type": 2, + "id": 9, + "cash": 6600 + }, + { + "type": 2, + "id": 10, + "cash": 6800 + }, + { + "type": 2, + "id": 11, + "cash": 6600 + }, + { + "type": 2, + "id": 12, + "cash": 8400 + }, + { + "type": 2, + "id": 13, + "cash": 6600 + } +] \ No newline at end of file diff --git a/src/HttpServer/jsonconf/jsonconf.go b/src/HttpServer/jsonconf/jsonconf.go index 167e973..6f280b9 100644 --- a/src/HttpServer/jsonconf/jsonconf.go +++ b/src/HttpServer/jsonconf/jsonconf.go @@ -32,9 +32,24 @@ type ActiveWithdrawConfigDesc struct { Day int `json:"day"` } +type GuanRedBagDesc struct { + Ctype int `json:"type"` + Id int `json:"id"` + Cash int `json:"cash"` +} + +type JiRedBagDesc struct { + Ctype int `json:"type"` + Id int `json:"id"` + Cash int `json:"cash"` +} + type GameConfig struct { WithDrawConfig []WithDrawDesc ActiveWithdrawConfig []ActiveWithdrawConfigDesc + GuanRedBag []GuanRedBagDesc + JiRedBag []JiRedBagDesc + } func GetJsonConf() *GameConfig { @@ -42,6 +57,24 @@ func GetJsonConf() *GameConfig { } +func GetJiConf(id int) *JiRedBagDesc { + for _,val := range g_jsonconf.JiRedBag { + if val.Id == id { + return &val + } + } + return nil +} + +func GetGuanConf(id int) *GuanRedBagDesc { + for _,val := range g_jsonconf.GuanRedBag { + if val.Id == id { + return &val + } + } + return nil +} + func file_get_contents(path string) ([]byte, error) { f, err := os.Open(path) @@ -81,6 +114,33 @@ func LoadJsonConf() error { return err } + + path = "../jsonconf/GuanRedBag.json" + content, err = file_get_contents(path) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + + err = json.Unmarshal([]byte(content), &g_jsonconf.GuanRedBag) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + + path = "../jsonconf/JiRedbag.json" + content, err = file_get_contents(path) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + + err = json.Unmarshal([]byte(content), &g_jsonconf.JiRedBag) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err) return nil } diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index bc2d731..e3072e0 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -56,6 +56,7 @@ const ( const ( WATCH_ADD_DAY_LIMIT = 50 //当天获取红包次数限制 FREE_REDBAG_NUM = 3 //玩家免费红包次数 + RANDNUMLIMIT = 10 //每日随机红包此树 READGOLDMULTI = 700 //阅读量到金币转化倍数 SDKOPGOLD_TYPEWE = 302 //微转发金币类型 ) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 5e41803..cd53526 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -9,6 +9,11 @@ type UserLoginReq struct { type UserLoginData struct { Walletgold int `json:"walletgold"` + Curji int `json:"curji"` + Curlevel int `json:"curlevel"` + Guanrednum int `json:"guanrednum"` + Jirednum int `json:"jirednum"` + Randnum int `json:"randnum"` } type UserLoginResp struct { @@ -92,6 +97,28 @@ type UploadlevelResp struct { Message string `json:"message"` } + + +type FetchredbagReq struct { + Rtype int `json:"rtype"` + Gameid string `json:"gameid"` + Channel string `json:"channel"` +} + +type FetchredbagData struct { + Guanrednum int `json:"guanrednum"` + Jirednum int `json:"jirednum"` + Randnum int `json:"randnum"` + Getgold int `json:"getgold"` + Walletgold int `json:"walletgold"` +} + +type FetchredbagResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data FetchredbagData `json:"data"` +} + //////////////////////////////////////////////////////////////////////////////////////// type GetCashListResp struct { @@ -162,6 +189,10 @@ type UserData struct { UpLvCostTime int //上一个等级升级时间 UpLvCostTimeSec int //上一个等级升级的时间点时刻 PassLevel int //当前关卡 + BigLevel int //当前等级 + GuanRedNum int //关卡红包领取进度 + JiRedNum int //等级红包领取进度 + RandNum int //随机红包剩余次数 ReadNum int //玩家微转发阅读量 GetCashCnt int //当天提现次数 WithDraw WithDrawInfo //提现记录信息 diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 94c6933..9ad90ab 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -118,6 +118,9 @@ func HandlerSyncuserdata(w http.ResponseWriter, data string, uuid int) { } + + + func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid string) error { var initdata UserData @@ -135,7 +138,11 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s initdata.WatchAddsTime = WATCH_ADD_DAY_LIMIT initdata.LeftFreeRB = FREE_REDBAG_NUM initdata.UpLvCostTime = 0 - initdata.PassLevel = 1 + initdata.PassLevel = 0 + initdata.BigLevel = 1 + initdata.GuanRedNum = 0 + initdata.JiRedNum = 0 + initdata.RandNum = RANDNUMLIMIT initdata.UpLvCostTimeSec = int(time.Now().Unix()) //todo 等待提现配置表 @@ -177,6 +184,11 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s //resp.Data.Leftredbagcnt = initdata.WatchAddsTime resp.Data.Walletgold = initdata.RealGold + resp.Data.Curji = initdata.BigLevel + resp.Data.Curlevel = initdata.PassLevel + resp.Data.Guanrednum = initdata.GuanRedNum + resp.Data.Jirednum = initdata.JiRedNum + resp.Data.Randnum = initdata.RandNum err := SaveUserInfo(&initdata, uniqueuid) diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index 44bef8f..d9281e9 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -43,6 +43,9 @@ func startServerHttpServe() { http.HandleFunc("/brainhole/getcash", Getcash) //提现 http.HandleFunc("/brainhole/getcashrecord", Getcashrecord) //提现记录列表 http.HandleFunc("/brainhole/uploadlevel", Uploadlevel) //上报当前关卡 + http.HandleFunc("/brainhole/uploadbiglevel", Uploadbiglevel) //上报当前等级 + http.HandleFunc("/brainhole/fetchredbag", Fetchredbag) //领取红包 + err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) @@ -92,6 +95,48 @@ func Getcash(w http.ResponseWriter, r *http.Request) { HandlerGetcash(w, s, Uuid) } +func Fetchredbag(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Fetchredbag , body:%v,uuid=%v", s, Uuid) + + HandlerFetchredbag(w, s, Uuid) +} + +func Uploadbiglevel(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Uploadbiglevel , body:%v,uuid=%v", s, Uuid) + + HandlerUploadbiglevel(w, s, Uuid) +} + func Uploadlevel(w http.ResponseWriter, r *http.Request) { Uuid := 0 diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index e8bf070..231de04 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -1,11 +1,13 @@ package logic import ( + "HttpServer/jsonconf" "HttpServer/redishandler" "common/logger" "common/redis" "encoding/json" "fmt" + "math/rand" "net/http" "strconv" "time" @@ -204,6 +206,167 @@ func HandlerGetcash(w http.ResponseWriter, data string, uuid int) { } +func HandlerFetchredbag(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp FetchredbagResp + resp.Code = 0 + var rdata FetchredbagReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerFetchredbag data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = 1 + break + } + + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 1 + break + } + + + + if rdata.Rtype == 1 { + //先判断一下是否可以领取 + if uinfo.GuanRedNum >= uinfo.PassLevel { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "没有可以领取的关卡红包" + resp.Code = 1 + break + } + + cfg := jsonconf.GetGuanConf(uinfo.GuanRedNum+1) + if cfg == nil { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "获取配置失败!" + resp.Code = 1 + break + } + + realgold, err := AddCoinToSdk(uuid, cfg.Cash, rdata.Gameid, rdata.Channel, 108) + if err !=nil { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "服务器错误!" + resp.Code = 1 + break + } + + resp.Data.Getgold = cfg.Cash + resp.Data.Walletgold = realgold + + uinfo.GuanRedNum ++ + }else if rdata.Rtype == 2 { + if uinfo.JiRedNum+1 >= uinfo.BigLevel { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "没有可以领取的等级红包" + resp.Code = 1 + break + } + + cfg := jsonconf.GetGuanConf(uinfo.JiRedNum) + if cfg == nil { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "获取配置失败!" + resp.Code = 1 + break + } + + realgold, err := AddCoinToSdk(uuid, cfg.Cash, rdata.Gameid, rdata.Channel, 108) + if err !=nil { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "服务器错误!" + resp.Code = 1 + break + } + + resp.Data.Getgold = cfg.Cash + resp.Data.Walletgold = realgold + + uinfo.JiRedNum ++ + }else { + if uinfo.RandNum <= 0 { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "没有可以领取的随机红包次数了!" + resp.Code = 1 + break + } + + getnum := rand.Intn(200) + 100 + realgold, err := AddCoinToSdk(uuid, getnum, rdata.Gameid, rdata.Channel, 108) + if err !=nil { + logger.Error("HandlerFetchredbag failed err=%v", err) + resp.Message = "服务器错误!" + resp.Code = 1 + break + } + + resp.Data.Getgold = getnum + resp.Data.Walletgold = realgold + + uinfo.RandNum-- + } + + + SaveUserInfo(uinfo,uniqueuuid) + + resp.Data.Randnum = uinfo.RandNum + resp.Data.Guanrednum = uinfo.GuanRedNum + resp.Data.Jirednum = uinfo.JiRedNum + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + +func HandlerUploadbiglevel(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp UploadlevelResp + resp.Code = 0 + var rdata UploadlevelReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerUploadbiglevel data failed:%v,for:%v", err, data) + resp.Message = "json解析错误" + resp.Code = 1 + break + } + + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = 1 + break + } + + if rdata.Level > uinfo.BigLevel { + uinfo.BigLevel = rdata.Level + } + + + SaveUserInfo(uinfo,uniqueuuid) + + resp.Code = 0 + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) + +} + func HandlerUploadlevel(w http.ResponseWriter, data string, uuid int) { SetHeader(w) var resp UploadlevelResp @@ -376,8 +539,7 @@ func (u *UserData) HandlePassDay(uuid int, channel string) { //todo 重置任务相关的数据 u.GetFromGuanCnt = 0 u.GetCashCnt = 0 - - + u.RandNum = RANDNUMLIMIT @@ -425,7 +587,11 @@ func GetUserData(uuid int, uniqueuid string, req *UserLoginReq, resp *UserLoginR SaveUserInfo(data, uniqueuid) resp.Data.Walletgold = data.RealGold - //resp.Data.Leftredbagcnt = data.WatchAddsTime + resp.Data.Curji = data.BigLevel + resp.Data.Curlevel = data.PassLevel + resp.Data.Guanrednum = data.GuanRedNum + resp.Data.Jirednum = data.JiRedNum + resp.Data.Randnum = data.RandNum return nil } \ No newline at end of file -- libgit2 0.21.0