Commit 533fde9cfe493b4a3ba18c367a87efa04d183f2c
1 parent
ddbeaaa1
Exists in
master
and in
1 other branch
feat✨:通用的获取随机名字和头像的接口
Showing
5 changed files
with
77 additions
and
3 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | +package controllers | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/models" | |
| 5 | + "apigame/service-common/svcommon" | |
| 6 | + "apigame/service/code-msg" | |
| 7 | + "github.com/samber/lo" | |
| 8 | +) | |
| 9 | + | |
| 10 | +// CommonController 绑定控制器 | |
| 11 | +type CommonController struct { | |
| 12 | + BaseController | |
| 13 | +} | |
| 14 | + | |
| 15 | +// GetName 获取随机名字 | |
| 16 | +func (c *CommonController) GetName() { | |
| 17 | + req := new(models.ReqCommonGetName) | |
| 18 | + if !c.GetPostData(req) { | |
| 19 | + return | |
| 20 | + } | |
| 21 | + rsp := models.RspCommonGetName{} | |
| 22 | + count := lo.Clamp(req.Count, 1, 100) | |
| 23 | + for i := 0; i < count; i++ { | |
| 24 | + rsp.Values = append(rsp.Values, svcommon.GetName(req.GameID)) | |
| 25 | + } | |
| 26 | + | |
| 27 | + c.RetRspCodeData(code_msg.RECODE_OK, rsp) | |
| 28 | +} | |
| 29 | + | |
| 30 | +// GetAvatar 获取随机头像 | |
| 31 | +func (c *CommonController) GetAvatar() { | |
| 32 | + req := new(models.ReqCommonGetAvatar) | |
| 33 | + if !c.GetPostData(req) { | |
| 34 | + return | |
| 35 | + } | |
| 36 | + rsp := models.RspCommonGetAvatar{} | |
| 37 | + count := lo.Clamp(req.Count, 1, 100) | |
| 38 | + for i := 0; i < count; i++ { | |
| 39 | + rsp.Values = append(rsp.Values, svcommon.GetAvatar(req.GameID)) | |
| 40 | + } | |
| 41 | + | |
| 42 | + c.RetRspCodeData(code_msg.RECODE_OK, rsp) | |
| 43 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +package models | |
| 2 | + | |
| 3 | +// ReqCommonGetName 请求 | |
| 4 | +type ReqCommonGetName struct { | |
| 5 | + BaseLoginInfo | |
| 6 | + BaseSign | |
| 7 | + Count int `form:"count" json:"count"` // 请求数量 | |
| 8 | +} | |
| 9 | + | |
| 10 | +// RspCommonGetName 返回 | |
| 11 | +type RspCommonGetName struct { | |
| 12 | + Values []string `form:"values" json:"values"` // 结果列表 | |
| 13 | +} | |
| 14 | + | |
| 15 | +// ReqCommonGetAvatar 请求 | |
| 16 | +type ReqCommonGetAvatar struct { | |
| 17 | + BaseLoginInfo | |
| 18 | + BaseSign | |
| 19 | + Count int `form:"count" json:"count"` // 请求数量 | |
| 20 | +} | |
| 21 | + | |
| 22 | +// RspCommonGetAvatar 返回 | |
| 23 | +type RspCommonGetAvatar struct { | |
| 24 | + Values []string `form:"values" json:"values"` // 结果列表 | |
| 25 | +} | ... | ... |
routers/router.go
| ... | ... | @@ -10,6 +10,12 @@ func init() { |
| 10 | 10 | |
| 11 | 11 | prefix := "/3ad7e4ab95ae2249" |
| 12 | 12 | |
| 13 | + // 通用 | |
| 14 | + // 获取随机名字 | |
| 15 | + beego.Router(prefix+"/common/getname", &controllers.CommonController{}, "post:GetName") | |
| 16 | + // 获取随机头像 | |
| 17 | + beego.Router(prefix+"/common/getavatar", &controllers.CommonController{}, "post:GetAvatar") | |
| 18 | + | |
| 13 | 19 | // 卡包卡牌活动 |
| 14 | 20 | // 活动配置 |
| 15 | 21 | beego.Router(prefix+"/cardholder/getconfig", &controllers.CardHolderController{}, "post:GetConfig") | ... | ... |
service-common/svcommon/simulate.go
| ... | ... | @@ -17,8 +17,8 @@ func GetName(gameId string) string { |
| 17 | 17 | return "李四" |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -// GetIcon 随机模拟玩家头像 | |
| 21 | -func GetIcon(gameId string) string { | |
| 20 | +// GetAvatar 随机模拟玩家头像 | |
| 21 | +func GetAvatar(gameId string) string { | |
| 22 | 22 | config, err := confglobal.GetConfig(gameId) |
| 23 | 23 | if err == nil { |
| 24 | 24 | count := len(config.Avatars) | ... | ... |
service/roomrank/player.go
| ... | ... | @@ -42,7 +42,7 @@ func NewRoomRobot(gameId string, robotConfigId int, userType int) *RoomPlayer { |
| 42 | 42 | d := &RoomPlayer{ |
| 43 | 43 | Uid: rand.Int63(), |
| 44 | 44 | Name: svcommon.GetName(gameId), |
| 45 | - Icon: svcommon.GetIcon(gameId), | |
| 45 | + Icon: svcommon.GetAvatar(gameId), | |
| 46 | 46 | Score: 0, |
| 47 | 47 | JoinTime: lxtime.NowUninx(), |
| 48 | 48 | UserType: userType, | ... | ... |