Commit 29088ea926098bef3389dd1d79f638f1b72481f3
1 parent
b2d071a9
Exists in
master
and in
1 other branch
feat:配置,请求和返回封装
Showing
23 changed files
with
524 additions
and
200 deletions
Show diff stats
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +include "local.conf" |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +{ | ||
| 2 | + "redis": { | ||
| 3 | + "host": "127.0.0.1", | ||
| 4 | + "port": "6379", | ||
| 5 | + "pwd": "123456", | ||
| 6 | + "Db": "15", | ||
| 7 | + "prefix": "xl::" | ||
| 8 | + }, | ||
| 9 | + "func": { | ||
| 10 | + "open": false, | ||
| 11 | + "ip": { | ||
| 12 | + "times": 10, | ||
| 13 | + "nums": 500 | ||
| 14 | + }, | ||
| 15 | + "kernel": { | ||
| 16 | + "times": 2, | ||
| 17 | + "nums": 5 | ||
| 18 | + }, | ||
| 19 | + "member": { | ||
| 20 | + "times": 1, | ||
| 21 | + "nums": 5 | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | +} |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +{ | ||
| 2 | + "redis": { | ||
| 3 | + "host": "172.21.0.25", | ||
| 4 | + "port": "6379", | ||
| 5 | + "pwd": "crs-lzslccdc:redis@YXp8Jk#MV", | ||
| 6 | + "Db": "6", | ||
| 7 | + "prefix": "xl::" | ||
| 8 | + }, | ||
| 9 | + "func": { | ||
| 10 | + "open": true, | ||
| 11 | + "ip": { | ||
| 12 | + "times": 5, | ||
| 13 | + "nums": 1000 | ||
| 14 | + }, | ||
| 15 | + "kernel": { | ||
| 16 | + "times": 1, | ||
| 17 | + "nums": 5 | ||
| 18 | + }, | ||
| 19 | + "member": { | ||
| 20 | + "times": 1, | ||
| 21 | + "nums": 5 | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | +} |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +{ | ||
| 2 | + "redis": { | ||
| 3 | + "host": "r-2ze017e28qb0bk81pd.redis.rds.aliyuncs.com", | ||
| 4 | + "port": "6379", | ||
| 5 | + "pwd": "2S9fS9Cmz5tzKLUb", | ||
| 6 | + "Db": "15", | ||
| 7 | + "prefix": "xl::" | ||
| 8 | + }, | ||
| 9 | + "func": { | ||
| 10 | + "open": true, | ||
| 11 | + "ip": { | ||
| 12 | + "times": 5, | ||
| 13 | + "nums": 1000 | ||
| 14 | + }, | ||
| 15 | + "kernel": { | ||
| 16 | + "times": 1, | ||
| 17 | + "nums": 5 | ||
| 18 | + }, | ||
| 19 | + "member": { | ||
| 20 | + "times": 1, | ||
| 21 | + "nums": 5 | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | +} |
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | + | ||
| 2 | + | ||
| 3 | +[mysql] | ||
| 4 | +yuedao = root:12345678@tcp(127.0.0.1:3306)/yuedao?charset=utf8mb4 | ||
| 5 | +api = root:12345678@tcp(127.0.0.1:3306)/weixinapi?charset=utf8mb4 | ||
| 6 | +member = root:12345678@tcp(127.0.0.1:3306)/weixinmember?charset=utf8mb4 | ||
| 7 | +game = root:12345678@tcp(127.0.0.1:3306)/weixingame?charset=utf8mb4 | ||
| 8 | +mods = root:12345678@tcp(127.0.0.1:3306)/apimods?charset=utf8mb4 | ||
| 9 | +mergecommon = root:12345678@tcp(127.0.0.1:3306)/merge_common?charset=utf8mb4 | ||
| 10 | +merge_config = root:12345678@tcp(127.0.0.1:3306)/merge_config?charset=utf8mb4 | ||
| 11 | +merge_rank = root:12345678@tcp(127.0.0.1:3306)/merge_rank?charset=utf8mb4 | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +[alilog] | ||
| 15 | +on = 1 | ||
| 16 | +debug = 0 | ||
| 17 | +endpoint = cn-beijing.log.aliyuncs.com | ||
| 18 | +accesskeyid = LTAI4FeZnr6n2sRohi8drNb2 | ||
| 19 | +accesskeysecret = wGi2ttNHVS9AZLMy6AMxRpY8WHQ5V6 | ||
| 20 | +project = wxsdk-api | ||
| 21 | +tableerror = error | ||
| 22 | +tabledebug = debug | ||
| 23 | +URL = https://wxsdk-api.cn-beijing.log.aliyuncs.com | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +[sdk] | ||
| 27 | +checktoken = http://127.0.0.1:8901/api/f8029bce6f2/ | ||
| 28 | +getmemberinfo = http://127.0.0.1:8901/api/8937250090b/getmemberinfo | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +[thinkingdata] | ||
| 32 | +url = https://analysis.d3games.com | ||
| 33 | +debug = 1 | ||
| 34 | +token = dRXGfB80SviFC6pM6pXa0om2Mqms64KUfGic1PPOJoRVvHjkcBNrrVFy4XWqEzj9 | ||
| 0 | \ No newline at end of file | 35 | \ No newline at end of file |
| @@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
| 1 | + | ||
| 2 | + | ||
| 3 | +[mysql] | ||
| 4 | +yuedao = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/yuedao?charset=utf8mb4 | ||
| 5 | +api = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/weixinapi?charset=utf8mb4 | ||
| 6 | +member = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/weixinmember?charset=utf8mb4 | ||
| 7 | +game = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/weixingame?charset=utf8mb4 | ||
| 8 | +mods = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/apimods?charset=utf8mb4 | ||
| 9 | +mergecommon = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/merge_common?charset=utf8mb4 | ||
| 10 | +merge_config = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/merge_config?charset=utf8mb4 | ||
| 11 | +merge_rank = root:7a8dbecfc9464057@tcp(127.0.0.1:3306)/merge_rank?charset=utf8mb4 | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +[alilog] | ||
| 16 | +on = 1 | ||
| 17 | +debug = 0 | ||
| 18 | +endpoint = cn-beijing.log.aliyuncs.com | ||
| 19 | +accesskeyid = LTAI4FeZnr6n2sRohi8drNb2 | ||
| 20 | +accesskeysecret = wGi2ttNHVS9AZLMy6AMxRpY8WHQ5V6 | ||
| 21 | +project = wxsdk-api | ||
| 22 | +tableerror = error | ||
| 23 | +tabledebug = debug | ||
| 24 | +URL = https://wxsdk-api.cn-beijing.log.aliyuncs.com | ||
| 25 | + | ||
| 26 | +[sdk] | ||
| 27 | +checktoken = https://login-wxsdk-pre.d3games.com/api/f8029bce6f2/ | ||
| 28 | +getmemberinfo = https://login-wxsdk-pre.d3games.com/api/8937250090b/getmemberinfo | ||
| 29 | + | ||
| 30 | +[thinkingdata] | ||
| 31 | +url = https://analysis.d3games.com | ||
| 32 | +debug = 1 | ||
| 33 | +token = dRXGfB80SviFC6pM6pXa0om2Mqms64KUfGic1PPOJoRVvHjkcBNrrVFy4XWqEzj9 | ||
| 0 | \ No newline at end of file | 34 | \ No newline at end of file |
| @@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
| 1 | + | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +[mysql] | ||
| 5 | +yuedao = yuedao:74D5aa541R8a7@tcp(rm-2ze98w5620qsrm1mk.mysql.rds.aliyuncs.com:3306)/yuedao?charset=utf8mb4 | ||
| 6 | +api = root:ZSwbNF2n3wYeLh6Z@tcp(rm-2ze11t38cwh286v05.mysql.rds.aliyuncs.com:3306)/weixinapi?charset=utf8mb4 | ||
| 7 | +member = root:ZSwbNF2n3wYeLh6Z@tcp(rm-2ze11t38cwh286v05.mysql.rds.aliyuncs.com:3306)/weixinmember?charset=utf8mb4 | ||
| 8 | +game = root:ZSwbNF2n3wYeLh6Z@tcp(rm-2ze11t38cwh286v05.mysql.rds.aliyuncs.com:3306)/weixingame?charset=utf8mb4 | ||
| 9 | +mods = apimods:v72U8RMxQ@tcp(rm-2ze98w5620qsrm1mk.mysql.rds.aliyuncs.com:3306)/apimods?charset=utf8mb4 | ||
| 10 | +mergecommon = merge:v72U83RM2xQ@tcp(rm-2ze98w5620qsrm1mk.mysql.rds.aliyuncs.com:3306)/merge_common?charset=utf8mb4 | ||
| 11 | +merge_config = merge:v72U83RM2xQ@tcp(rm-2ze98w5620qsrm1mk.mysql.rds.aliyuncs.com:3306)/merge_config?charset=utf8mb4 | ||
| 12 | +merge_rank = merge:v72U83RM2xQ@tcp(rm-2ze98w5620qsrm1mk.mysql.rds.aliyuncs.com:3306)/merge_rank?charset=utf8mb4 | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +[alilog] | ||
| 16 | +on = 1 | ||
| 17 | +debug = 0 | ||
| 18 | +endpoint = cn-beijing-intranet.log.aliyuncs.com | ||
| 19 | +accesskeyid = LTAI4FeZnr6n2sRohi8drNb2 | ||
| 20 | +accesskeysecret = wGi2ttNHVS9AZLMy6AMxRpY8WHQ5V6 | ||
| 21 | +project = wxsdk-api | ||
| 22 | +tableerror = error | ||
| 23 | +tabledebug = debug | ||
| 24 | +URL = https://wxsdk-api.cn-beijing.log.aliyuncs.com | ||
| 25 | + | ||
| 26 | +[sdk] | ||
| 27 | +checktoken = https://login-wxsdk.d3games.com/api/f8029bce6f2/ | ||
| 28 | +getmemberinfo = https://login-wxsdk.d3games.com/api/8937250090b/getmemberinfo | ||
| 29 | + | ||
| 30 | +[thinkingdata] | ||
| 31 | +url = http://172.17.141.83 | ||
| 32 | +debug = 0 | ||
| 33 | +token = dRXGfB80SviFC6pM6pXa0om2Mqms64KUfGic1PPOJoRVvHjkcBNrrVFy4XWqEzj9 | ||
| 0 | \ No newline at end of file | 34 | \ No newline at end of file |
| @@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
| 1 | +appname = api-game | ||
| 2 | +httpport = 9100 | ||
| 3 | +runmode = dev | ||
| 4 | +autorender = false | ||
| 5 | +copyrequestbody = true | ||
| 6 | +EnableDocs = false | ||
| 7 | + | ||
| 8 | +env = local | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +[redis] | ||
| 12 | +host = 127.0.0.1 | ||
| 13 | +port = 6379 | ||
| 14 | +pwd = 123456 | ||
| 15 | +db = 12 | ||
| 16 | +prefix = merge:: | ||
| 17 | +tokendb = 13 | ||
| 18 | +cachedb = 14 | ||
| 19 | +sdkdb = 8 | ||
| 20 | +sdkprefix = wxapi:: | ||
| 21 | + | ||
| 22 | +[log] | ||
| 23 | +path = /var/logs/merge/ | ||
| 24 | +maxlines = 1000000 | ||
| 25 | +maxdays = 1000 | ||
| 26 | +rotate = true | ||
| 27 | +dellogger = false | ||
| 28 | +level = 1 | ||
| 29 | + | ||
| 30 | +include "/conf/local.conf" | ||
| 0 | \ No newline at end of file | 31 | \ No newline at end of file |
| @@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
| 1 | +appname = api-game | ||
| 2 | +httpport = 80 | ||
| 3 | +runmode = dev | ||
| 4 | +autorender = false | ||
| 5 | +copyrequestbody = true | ||
| 6 | +EnableDocs = false | ||
| 7 | + | ||
| 8 | +env = pre | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +[redis] | ||
| 12 | +host = 172.21.0.25 | ||
| 13 | +port = 6379 | ||
| 14 | +pwd = crs-lzslccdc:redis@YXp8Jk#MV | ||
| 15 | +db = 6 | ||
| 16 | +prefix = merge:: | ||
| 17 | +tokendb = 6 | ||
| 18 | +cachedb = 6 | ||
| 19 | +sdkdb = 6 | ||
| 20 | +sdkprefix = wxapi:: | ||
| 21 | + | ||
| 22 | +[log] | ||
| 23 | +path = /var/logs/merge/ | ||
| 24 | +maxlines = 1000000 | ||
| 25 | +maxdays = 1000 | ||
| 26 | +rotate = true | ||
| 27 | +dellogger = false | ||
| 28 | +level = 8 | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +include "/conf/pre.conf" | ||
| 0 | \ No newline at end of file | 32 | \ No newline at end of file |
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | +appname = api-game | ||
| 2 | +httpport = 80 | ||
| 3 | +runmode = prod | ||
| 4 | +autorender = false | ||
| 5 | +copyrequestbody = true | ||
| 6 | +EnableDocs = false | ||
| 7 | + | ||
| 8 | +env = prod | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +[redis] | ||
| 13 | +host = r-2ze017e28qb0bk81pd.redis.rds.aliyuncs.com | ||
| 14 | +port = 6379 | ||
| 15 | +pwd = 2S9fS9Cmz5tzKLUb | ||
| 16 | +db = 6 | ||
| 17 | +prefix = merge:: | ||
| 18 | +tokendb = 6 | ||
| 19 | +cachedb = 6 | ||
| 20 | +sdkdb = 10 | ||
| 21 | +sdkprefix = wxapi:: | ||
| 22 | + | ||
| 23 | +[log] | ||
| 24 | +path = /var/logs/merge/ | ||
| 25 | +maxlines = 100000000 | ||
| 26 | +maxdays = 7 | ||
| 27 | +rotate = true | ||
| 28 | +dellogger = false | ||
| 29 | +level = 5 | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +include "/conf/prod.conf" | ||
| 0 | \ No newline at end of file | 33 | \ No newline at end of file |
controllers/base.go
| 1 | package controllers | 1 | package controllers |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - constd "apigame/service/constd" | 4 | + "apigame/service/constd" |
| 5 | "apigame/sign" | 5 | "apigame/sign" |
| 6 | + "encoding/json" | ||
| 6 | "github.com/astaxie/beego" | 7 | "github.com/astaxie/beego" |
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| 10 | +var debugMode = true | ||
| 11 | + | ||
| 9 | type BaseController struct { | 12 | type BaseController struct { |
| 10 | beego.Controller | 13 | beego.Controller |
| 11 | } | 14 | } |
| 12 | 15 | ||
| 13 | // RetData 返回封装 | 16 | // RetData 返回封装 |
| 14 | -func (c *BaseController) RetData(resp map[string]interface{}) { | 17 | +func (c *BaseController) RetData(resp map[string]any) { |
| 15 | c.Data["json"] = resp | 18 | c.Data["json"] = resp |
| 16 | c.ServeJSON() | 19 | c.ServeJSON() |
| 17 | } | 20 | } |
| 18 | 21 | ||
| 22 | +// RetRspData 返回封装 | ||
| 23 | +func (c *BaseController) RetRspData(rspData any) { | ||
| 24 | + resp := make(map[string]any) | ||
| 25 | + resp["data"] = rspData | ||
| 26 | + c.RetData(resp) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// RetCode 返回错误封装 | ||
| 30 | +func (c *BaseController) RetCode(code string) { | ||
| 31 | + resp := make(map[string]interface{}) | ||
| 32 | + resp = constd.CodeMsg(resp, code) | ||
| 33 | + c.RetData(resp) | ||
| 34 | +} | ||
| 35 | + | ||
| 19 | // GetPostData 获取 PostData | 36 | // GetPostData 获取 PostData |
| 20 | func (c *BaseController) GetPostData(postData any) bool { | 37 | func (c *BaseController) GetPostData(postData any) bool { |
| 21 | 38 | ||
| 39 | + req := c.Ctx.Input.RequestBody | ||
| 40 | + if debugMode { | ||
| 41 | + err := json.Unmarshal(req, &postData) | ||
| 42 | + if err != nil { | ||
| 43 | + c.RetCode(constd.RECODE_PARAMERROR) | ||
| 44 | + return false | ||
| 45 | + } | ||
| 46 | + return true | ||
| 47 | + } | ||
| 48 | + | ||
| 22 | // 接收参数,验证签名登录 | 49 | // 接收参数,验证签名登录 |
| 23 | - code, err := sign.Check(c.Ctx.Input.RequestBody, &postData, true, true) | 50 | + code, err := sign.Check(req, &postData, true, true) |
| 24 | if err != nil { | 51 | if err != nil { |
| 25 | resp := make(map[string]interface{}) | 52 | resp := make(map[string]interface{}) |
| 26 | resp = constd.CodeMsg(resp, code) | 53 | resp = constd.CodeMsg(resp, code) |
controllers/error.go
| @@ -4,38 +4,30 @@ type ErrorController struct { | @@ -4,38 +4,30 @@ type ErrorController struct { | ||
| 4 | BaseController | 4 | BaseController |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | -func (c *ErrorController) Error401() { | 7 | +func (c *ErrorController) ErrorXXX(code, msg string) { |
| 8 | resp := make(map[string]interface{}) | 8 | resp := make(map[string]interface{}) |
| 9 | defer c.RetData(resp) | 9 | defer c.RetData(resp) |
| 10 | - resp["code"] = "401" | ||
| 11 | - resp["msg"] = "未经授权,请求要求验证身份" | 10 | + resp["code"] = code |
| 11 | + resp["msg"] = msg | ||
| 12 | c.RetData(resp) | 12 | c.RetData(resp) |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | +func (c *ErrorController) Error401() { | ||
| 16 | + c.ErrorXXX("401", "未经授权,请求要求验证身份") | ||
| 17 | +} | ||
| 18 | + | ||
| 15 | func (c *ErrorController) Error403() { | 19 | func (c *ErrorController) Error403() { |
| 16 | - resp := make(map[string]interface{}) | ||
| 17 | - defer c.RetData(resp) | ||
| 18 | - resp["code"] = "403" | ||
| 19 | - resp["msg"] = "服务器拒绝请求" | 20 | + c.ErrorXXX("403", "服务器拒绝请求") |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | func (c *ErrorController) Error404() { | 23 | func (c *ErrorController) Error404() { |
| 23 | - resp := make(map[string]interface{}) | ||
| 24 | - defer c.RetData(resp) | ||
| 25 | - resp["code"] = "404" | ||
| 26 | - resp["msg"] = "很抱歉您访问的地址或者方法不存在" | 24 | + c.ErrorXXX("404", "很抱歉您访问的地址或者方法不存在") |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | func (c *ErrorController) Error500() { | 27 | func (c *ErrorController) Error500() { |
| 30 | - resp := make(map[string]interface{}) | ||
| 31 | - defer c.RetData(resp) | ||
| 32 | - resp["code"] = "500" | ||
| 33 | - resp["msg"] = "server error" | 28 | + c.ErrorXXX("500", "server error") |
| 34 | } | 29 | } |
| 35 | 30 | ||
| 36 | func (c *ErrorController) Error503() { | 31 | func (c *ErrorController) Error503() { |
| 37 | - resp := make(map[string]interface{}) | ||
| 38 | - defer c.RetData(resp) | ||
| 39 | - resp["code"] = "503" | ||
| 40 | - resp["msg"] = "服务器目前无法使用(由于超载或停机维护)" | 32 | + c.ErrorXXX("503", "服务器目前无法使用(由于超载或停机维护)") |
| 41 | } | 33 | } |
| @@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
| 1 | +package controllers | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "apigame/dto" | ||
| 5 | +) | ||
| 6 | + | ||
| 7 | +// HtCardHolderController 绑定控制器 | ||
| 8 | +type HtCardHolderController struct { | ||
| 9 | + BaseController | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +func (c *HtCardHolderController) Info() { | ||
| 13 | + // 获取请求 | ||
| 14 | + var req dto.ReqHtCardHolderInfo | ||
| 15 | + if !c.GetPostData(&req) { | ||
| 16 | + return | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + rsp := dto.RspHtCardHolderInfo{ | ||
| 20 | + HtCardHolderInfo: dto.HtCardHolderInfo{ | ||
| 21 | + BagList: make(map[int]int), | ||
| 22 | + }, | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + rsp.BagList[1] = 2 | ||
| 26 | + rsp.BagList[2] = 5 | ||
| 27 | + | ||
| 28 | + c.RetRspData(rsp) | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +func (c *HtCardHolderController) Open() { | ||
| 32 | + // 获取请求 | ||
| 33 | + var req dto.ReqHtCardHolderOpen | ||
| 34 | + if !c.GetPostData(&req) { | ||
| 35 | + return | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + rsp := dto.NewBaseRsp() | ||
| 39 | + | ||
| 40 | + rsp["nowid"] = 1 | ||
| 41 | + rsp["award"] = "2" | ||
| 42 | + | ||
| 43 | + c.RetRspData(rsp) | ||
| 44 | +} |
controllers/ht-draw.go
| @@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
| 1 | -package controllers | ||
| 2 | - | ||
| 3 | -import "apigame/dto" | ||
| 4 | - | ||
| 5 | -// HtDrawController 绑定控制器 | ||
| 6 | -type HtDrawController struct { | ||
| 7 | - BaseController | ||
| 8 | -} | ||
| 9 | - | ||
| 10 | -func (c *HtDrawController) Draw() { | ||
| 11 | - | ||
| 12 | - //接收参数,验证签名登录 | ||
| 13 | - var postData dto.ReqHtDraw | ||
| 14 | - | ||
| 15 | - if !c.GetPostData(&postData) { | ||
| 16 | - return | ||
| 17 | - } | ||
| 18 | - | ||
| 19 | - resp := make(map[string]any) | ||
| 20 | - | ||
| 21 | - var data = make(map[string]interface{}) | ||
| 22 | - | ||
| 23 | - data["nowid"] = 1 | ||
| 24 | - data["award"] = 2 | ||
| 25 | - resp["data"] = data | ||
| 26 | - | ||
| 27 | - c.RetData(resp) | ||
| 28 | - | ||
| 29 | -} |
dto/base.go
| @@ -12,3 +12,9 @@ type BaseSign struct { | @@ -12,3 +12,9 @@ type BaseSign struct { | ||
| 12 | Ver string `form:"ver" json:"ver"` | 12 | Ver string `form:"ver" json:"ver"` |
| 13 | GameID string `form:"gameid" json:"gameid"` | 13 | GameID string `form:"gameid" json:"gameid"` |
| 14 | } | 14 | } |
| 15 | + | ||
| 16 | +type BaseRsp map[string]any | ||
| 17 | + | ||
| 18 | +func NewBaseRsp() BaseRsp { | ||
| 19 | + return make(map[string]any) | ||
| 20 | +} |
| @@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
| 1 | +package dto | ||
| 2 | + | ||
| 3 | +// 海滩卡包 | ||
| 4 | + | ||
| 5 | +// HtCardHolderInfo 卡包信息 | ||
| 6 | +type HtCardHolderInfo struct { | ||
| 7 | + BagList map[int]int | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +// ReqHtCardHolderInfo 请求 卡包信息 | ||
| 11 | +type ReqHtCardHolderInfo struct { | ||
| 12 | + BaseSign | ||
| 13 | + BaseLoginInfo | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +// RspHtCardHolderInfo 返回 卡包信息 | ||
| 17 | +type RspHtCardHolderInfo struct { | ||
| 18 | + HtCardHolderInfo | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// ReqHtCardHolderOpen 请求 打开卡包 | ||
| 22 | +type ReqHtCardHolderOpen struct { | ||
| 23 | + BaseSign | ||
| 24 | + BaseLoginInfo | ||
| 25 | + ID string `form:"id" json:"id" valid:"Required"` // 卡包ID | ||
| 26 | +} |
dto/ht-draw.go
main.go
| @@ -2,7 +2,7 @@ package main | @@ -2,7 +2,7 @@ package main | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | _ "apigame/routers" | 4 | _ "apigame/routers" |
| 5 | - ht_draw "apigame/service/ht-draw" | 5 | + ht_draw "apigame/service/ht-cardholder" |
| 6 | "fmt" | 6 | "fmt" |
| 7 | "github.com/astaxie/beego" | 7 | "github.com/astaxie/beego" |
| 8 | "github.com/astaxie/beego/plugins/cors" | 8 | "github.com/astaxie/beego/plugins/cors" |
routers/router.go
| @@ -11,8 +11,10 @@ func init() { | @@ -11,8 +11,10 @@ func init() { | ||
| 11 | prefix := "/3ad7e4ab92ae2249" | 11 | prefix := "/3ad7e4ab92ae2249" |
| 12 | 12 | ||
| 13 | // 海滩项目 | 13 | // 海滩项目 |
| 14 | - // 海滩抽奖 | ||
| 15 | - beego.Router(prefix+"/ht/draw", &controllers.HtDrawController{}, "post:Draw") | 14 | + // 卡包信息 |
| 15 | + beego.Router(prefix+"/ht/cardholder/info", &controllers.HtCardHolderController{}, "post:Info") | ||
| 16 | + // 卡包打开 | ||
| 17 | + beego.Router(prefix+"/ht/cardholder/open", &controllers.HtCardHolderController{}, "post:Open") | ||
| 16 | 18 | ||
| 17 | beego.ErrorController(&controllers.ErrorController{}) | 19 | beego.ErrorController(&controllers.ErrorController{}) |
| 18 | } | 20 | } |
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +package ht_cardholder | ||
| 2 | + | ||
| 3 | +// CardConfig 卡牌表 | ||
| 4 | +type CardConfig struct { | ||
| 5 | + Id int `json:"id"` // ID | ||
| 6 | + GroupId int `json:"groupid"` // 卡组id | ||
| 7 | + IsGoldCard int `json:"isgoldcard"` // 是否是金卡 | ||
| 8 | + Star int `json:"star"` // 星级 | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +// CardholderConfig 卡包开卡规则表 | ||
| 12 | +type CardholderConfig struct { | ||
| 13 | + Id int `json:"id"` // ID | ||
| 14 | + GuaranteedStar int `json:"guaranteedstar"` // 保底卡星级序列ID | ||
| 15 | + IsGoldCardholder int `json:"isgoldcardholder"` // 是否是金卡包 | ||
| 16 | + IsNew int `json:"isnew"` // 是否是新卡包 | ||
| 17 | + NormalCardNumber int `json:"normalcardnumber"` // 非保底卡数量 | ||
| 18 | + MinimumGuaranteeCardId int `json:"minimumguaranteecardid"` // 非保底卡牌序列ID | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +// NormalCardStarSequence 非保底卡星级ID | ||
| 22 | +type NormalCardStarSequence struct { | ||
| 23 | + Id int `json:"id"` // ID | ||
| 24 | + Cohort int `json:"cohort"` // 用户分组 | ||
| 25 | + StarSequenceId int `json:"starsequenceid"` // 用户序列组ID | ||
| 26 | + NormalCardSequenceId []int `json:"normalcardsequenceid"` // 非保底星级序列 | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// CardSequenceConfig 星级ID对应的卡片 | ||
| 30 | +type CardSequenceConfig struct { | ||
| 31 | + Id int `json:"id"` // SequenceId 用户序列组ID | ||
| 32 | + Cohort int `json:"cohort"` // 用户分组 | ||
| 33 | + CardIdList []int `json:"cardidlist"` // 卡牌抽取序列 | ||
| 34 | +} |
| @@ -0,0 +1,102 @@ | @@ -0,0 +1,102 @@ | ||
| 1 | +package ht_cardholder | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | +) | ||
| 6 | + | ||
| 7 | +var ( | ||
| 8 | + ConfigVersion = "1" // 版本号 | ||
| 9 | + CardConfigs = make(map[int]CardConfig) // 卡牌表 | ||
| 10 | + CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表 | ||
| 11 | + NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID | ||
| 12 | + CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片 | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +// Init 初始化 | ||
| 16 | +func Init() { | ||
| 17 | + TryUpdateConfigs() | ||
| 18 | + | ||
| 19 | + DumpConfigs() | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +// TryUpdateConfigs 尝试更新配置表 | ||
| 23 | +func TryUpdateConfigs() { | ||
| 24 | + // todo 装填虚拟数据 | ||
| 25 | + UseSimulateConfigs() | ||
| 26 | + | ||
| 27 | + // todo 读取mysql配置 | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +// UseSimulateConfigs 装填虚拟数据 | ||
| 31 | +func UseSimulateConfigs() { | ||
| 32 | + | ||
| 33 | + ConfigVersion = "2" | ||
| 34 | + | ||
| 35 | + // 卡牌表 i=卡组ID j=卡牌顺序 | ||
| 36 | + for i := 1; i <= 9; i++ { | ||
| 37 | + for j := 1; j <= 9; j++ { | ||
| 38 | + conf := CardConfig{ | ||
| 39 | + Id: i*100 + j, | ||
| 40 | + GroupId: i, | ||
| 41 | + IsGoldCard: 0, | ||
| 42 | + Star: 1, | ||
| 43 | + } | ||
| 44 | + if j == 9 { | ||
| 45 | + conf.IsGoldCard = 1 | ||
| 46 | + conf.Star = 2 | ||
| 47 | + } | ||
| 48 | + CardConfigs[conf.Id] = conf | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + // 卡包开卡规则表 | ||
| 52 | + CardholderConfigs[1] = CardholderConfig{ | ||
| 53 | + Id: 1, | ||
| 54 | + GuaranteedStar: 1, | ||
| 55 | + NormalCardNumber: 2, | ||
| 56 | + MinimumGuaranteeCardId: 1, | ||
| 57 | + } | ||
| 58 | + CardholderConfigs[2] = CardholderConfig{ | ||
| 59 | + Id: 2, | ||
| 60 | + GuaranteedStar: 2, | ||
| 61 | + NormalCardNumber: 3, | ||
| 62 | + MinimumGuaranteeCardId: 2, | ||
| 63 | + } | ||
| 64 | + CardholderConfigs[3] = CardholderConfig{ | ||
| 65 | + Id: 3, | ||
| 66 | + GuaranteedStar: 3, | ||
| 67 | + NormalCardNumber: 4, | ||
| 68 | + MinimumGuaranteeCardId: 3, | ||
| 69 | + } | ||
| 70 | + // 非保底卡星级ID i=非保底卡星级ID j=用户分组 | ||
| 71 | + for i := 1; i <= 3; i++ { | ||
| 72 | + for j := 1; j <= 2; j++ { | ||
| 73 | + conf := NormalCardStarSequence{ | ||
| 74 | + Id: i, | ||
| 75 | + Cohort: j, | ||
| 76 | + NormalCardSequenceId: []int{i, i, i, j}, | ||
| 77 | + } | ||
| 78 | + NormalCardStarSequences = append(NormalCardStarSequences, conf) | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + // 星级ID对应的卡片 | ||
| 82 | + for i := 1; i <= 3; i++ { | ||
| 83 | + for j := 1; j <= 2; j++ { | ||
| 84 | + conf := CardSequenceConfig{ | ||
| 85 | + Id: i, | ||
| 86 | + Cohort: j, | ||
| 87 | + CardIdList: []int{101, 102, 103, 104, 102, 105, 106, 107, 108, 109}, | ||
| 88 | + } | ||
| 89 | + CardSequenceConfigs = append(CardSequenceConfigs, conf) | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +func DumpConfigs() { | ||
| 96 | + | ||
| 97 | + fmt.Println(ConfigVersion) | ||
| 98 | + fmt.Println(CardConfigs) | ||
| 99 | + fmt.Println(CardholderConfigs) | ||
| 100 | + fmt.Println(NormalCardStarSequences) | ||
| 101 | + fmt.Println(CardSequenceConfigs) | ||
| 102 | +} |
service/ht-draw/config.go
| @@ -1,34 +0,0 @@ | @@ -1,34 +0,0 @@ | ||
| 1 | -package ht_draw | ||
| 2 | - | ||
| 3 | -// CardConfig 卡牌表 | ||
| 4 | -type CardConfig struct { | ||
| 5 | - Id int `json:"id"` // ID | ||
| 6 | - GroupId int `json:"groupid"` // 卡组id | ||
| 7 | - IsGoldCard int `json:"isgoldcard"` // 是否是金卡 | ||
| 8 | - Star int `json:"star"` // 星级 | ||
| 9 | -} | ||
| 10 | - | ||
| 11 | -// CardholderConfig 卡包开卡规则表 | ||
| 12 | -type CardholderConfig struct { | ||
| 13 | - Id int `json:"id"` // ID | ||
| 14 | - GuaranteedStar int `json:"guaranteedstar"` // 保底卡星级序列ID | ||
| 15 | - IsGoldCardholder int `json:"isgoldcardholder"` // 是否是金卡包 | ||
| 16 | - IsNew int `json:"isnew"` // 是否是新卡包 | ||
| 17 | - NormalCardNumber int `json:"normalcardnumber"` // 非保底卡数量 | ||
| 18 | - MinimumGuaranteeCardId int `json:"minimumguaranteecardid"` // 非保底卡牌序列ID | ||
| 19 | -} | ||
| 20 | - | ||
| 21 | -// NormalCardStarSequence 非保底卡星级ID | ||
| 22 | -type NormalCardStarSequence struct { | ||
| 23 | - Id int `json:"id"` // ID | ||
| 24 | - Cohort int `json:"cohort"` // 用户分组 | ||
| 25 | - StarSequenceId int `json:"starsequenceid"` // 用户序列组ID | ||
| 26 | - NormalCardSequenceId []int `json:"normalcardsequenceid"` // 非保底星级序列 | ||
| 27 | -} | ||
| 28 | - | ||
| 29 | -// CardSequenceConfig 星级ID对应的卡片 | ||
| 30 | -type CardSequenceConfig struct { | ||
| 31 | - Id int `json:"id"` // SequenceId 用户序列组ID | ||
| 32 | - Cohort int `json:"cohort"` // 用户分组 | ||
| 33 | - CardIdList []int `json:"cardidlist"` // 卡牌抽取序列 | ||
| 34 | -} |
service/ht-draw/configs.go
| @@ -1,102 +0,0 @@ | @@ -1,102 +0,0 @@ | ||
| 1 | -package ht_draw | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "fmt" | ||
| 5 | -) | ||
| 6 | - | ||
| 7 | -var ( | ||
| 8 | - ConfigVersion = "1" // 版本号 | ||
| 9 | - CardConfigs = make(map[int]CardConfig) // 卡牌表 | ||
| 10 | - CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表 | ||
| 11 | - NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID | ||
| 12 | - CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片 | ||
| 13 | -) | ||
| 14 | - | ||
| 15 | -// Init 初始化 | ||
| 16 | -func Init() { | ||
| 17 | - TryUpdateConfigs() | ||
| 18 | - | ||
| 19 | - DumpConfigs() | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -// TryUpdateConfigs 尝试更新配置表 | ||
| 23 | -func TryUpdateConfigs() { | ||
| 24 | - // todo 装填虚拟数据 | ||
| 25 | - UseSimulateConfigs() | ||
| 26 | - | ||
| 27 | - // todo 读取mysql配置 | ||
| 28 | -} | ||
| 29 | - | ||
| 30 | -// UseSimulateConfigs 装填虚拟数据 | ||
| 31 | -func UseSimulateConfigs() { | ||
| 32 | - | ||
| 33 | - ConfigVersion = "2" | ||
| 34 | - | ||
| 35 | - // 卡牌表 i=卡组ID j=卡牌顺序 | ||
| 36 | - for i := 1; i <= 9; i++ { | ||
| 37 | - for j := 1; j <= 9; j++ { | ||
| 38 | - conf := CardConfig{ | ||
| 39 | - Id: i*100 + j, | ||
| 40 | - GroupId: i, | ||
| 41 | - IsGoldCard: 0, | ||
| 42 | - Star: 1, | ||
| 43 | - } | ||
| 44 | - if j == 9 { | ||
| 45 | - conf.IsGoldCard = 1 | ||
| 46 | - conf.Star = 2 | ||
| 47 | - } | ||
| 48 | - CardConfigs[conf.Id] = conf | ||
| 49 | - } | ||
| 50 | - } | ||
| 51 | - // 卡包开卡规则表 | ||
| 52 | - CardholderConfigs[1] = CardholderConfig{ | ||
| 53 | - Id: 1, | ||
| 54 | - GuaranteedStar: 1, | ||
| 55 | - NormalCardNumber: 2, | ||
| 56 | - MinimumGuaranteeCardId: 1, | ||
| 57 | - } | ||
| 58 | - CardholderConfigs[2] = CardholderConfig{ | ||
| 59 | - Id: 2, | ||
| 60 | - GuaranteedStar: 2, | ||
| 61 | - NormalCardNumber: 3, | ||
| 62 | - MinimumGuaranteeCardId: 2, | ||
| 63 | - } | ||
| 64 | - CardholderConfigs[3] = CardholderConfig{ | ||
| 65 | - Id: 3, | ||
| 66 | - GuaranteedStar: 3, | ||
| 67 | - NormalCardNumber: 4, | ||
| 68 | - MinimumGuaranteeCardId: 3, | ||
| 69 | - } | ||
| 70 | - // 非保底卡星级ID i=非保底卡星级ID j=用户分组 | ||
| 71 | - for i := 1; i <= 3; i++ { | ||
| 72 | - for j := 1; j <= 2; j++ { | ||
| 73 | - conf := NormalCardStarSequence{ | ||
| 74 | - Id: i, | ||
| 75 | - Cohort: j, | ||
| 76 | - NormalCardSequenceId: []int{i, i, i, j}, | ||
| 77 | - } | ||
| 78 | - NormalCardStarSequences = append(NormalCardStarSequences, conf) | ||
| 79 | - } | ||
| 80 | - } | ||
| 81 | - // 星级ID对应的卡片 | ||
| 82 | - for i := 1; i <= 3; i++ { | ||
| 83 | - for j := 1; j <= 2; j++ { | ||
| 84 | - conf := CardSequenceConfig{ | ||
| 85 | - Id: i, | ||
| 86 | - Cohort: j, | ||
| 87 | - CardIdList: []int{101, 102, 103, 104, 102, 105, 106, 107, 108, 109}, | ||
| 88 | - } | ||
| 89 | - CardSequenceConfigs = append(CardSequenceConfigs, conf) | ||
| 90 | - } | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | -} | ||
| 94 | - | ||
| 95 | -func DumpConfigs() { | ||
| 96 | - | ||
| 97 | - fmt.Println(ConfigVersion) | ||
| 98 | - fmt.Println(CardConfigs) | ||
| 99 | - fmt.Println(CardholderConfigs) | ||
| 100 | - fmt.Println(NormalCardStarSequences) | ||
| 101 | - fmt.Println(CardSequenceConfigs) | ||
| 102 | -} |