Commit 3dd95caa9eb3bf8ca51e1b8bd4d4422a5f1f444d
1 parent
2799b096
Exists in
master
and in
1 other branch
feat✨:房间排行榜改为支持多个排行榜
Showing
5 changed files
with
52 additions
and
32 deletions
Show diff stats
configs/confroomrank/config.go
| @@ -23,7 +23,6 @@ type ActivityConfig struct { | @@ -23,7 +23,6 @@ type ActivityConfig struct { | ||
| 23 | Robot map[int]RobotConfig // 机器人配置 | 23 | Robot map[int]RobotConfig // 机器人配置 |
| 24 | Room map[int]RoomConfig // 房间配置 | 24 | Room map[int]RoomConfig // 房间配置 |
| 25 | 25 | ||
| 26 | - Client *ActivityConfigClient | ||
| 27 | GameId string // 所属游戏ID | 26 | GameId string // 所属游戏ID |
| 28 | } | 27 | } |
| 29 | 28 | ||
| @@ -55,6 +54,7 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | @@ -55,6 +54,7 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | ||
| 55 | // ActivityConfigRaw 房间排行活动配置 原始数据 | 54 | // ActivityConfigRaw 房间排行活动配置 原始数据 |
| 56 | type ActivityConfigRaw struct { | 55 | type ActivityConfigRaw struct { |
| 57 | Id int64 `gorm:"column:id;primaryKey"` // ID | 56 | Id int64 `gorm:"column:id;primaryKey"` // ID |
| 57 | + Typ int // 排行榜类型 | ||
| 58 | OpenLevel int // 开启等级 | 58 | OpenLevel int // 开启等级 |
| 59 | PreviewTime int64 // 预告时间 | 59 | PreviewTime int64 // 预告时间 |
| 60 | StartTime int64 // 开始时间 | 60 | StartTime int64 // 开始时间 |
| @@ -69,9 +69,33 @@ type ActivityConfigRaw struct { | @@ -69,9 +69,33 @@ type ActivityConfigRaw struct { | ||
| 69 | UpdateTime int64 // 修改时间戳 | 69 | UpdateTime int64 // 修改时间戳 |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | +// GenerateConfigClient 生成给客户端的配置 | ||
| 73 | +func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { | ||
| 74 | + configClient := &ActivityConfigClient{ | ||
| 75 | + Id: c.Id, | ||
| 76 | + Typ: c.Typ, | ||
| 77 | + OpenLevel: c.OpenLevel, | ||
| 78 | + PreviewTime: c.PreviewTime, | ||
| 79 | + StartTime: c.StartTime, | ||
| 80 | + EndTime: c.EndTime, | ||
| 81 | + ReleaseTime: c.ReleaseTime, | ||
| 82 | + Ver: c.Ver, | ||
| 83 | + Status: c.Status, | ||
| 84 | + } | ||
| 85 | + return configClient | ||
| 86 | +} | ||
| 87 | + | ||
| 72 | // ActivityConfigClient 房间排行活动配置 给客户端数据 | 88 | // ActivityConfigClient 房间排行活动配置 给客户端数据 |
| 73 | type ActivityConfigClient struct { | 89 | type ActivityConfigClient struct { |
| 74 | - Id int64 `form:"id" json:"id"` // ID | 90 | + Id int64 `form:"id" json:"id"` // ID |
| 91 | + Typ int `form:"typ" json:"typ"` // 排行榜类型 | ||
| 92 | + OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 | ||
| 93 | + PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 | ||
| 94 | + StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 | ||
| 95 | + EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 | ||
| 96 | + ReleaseTime int64 `form:"release_time" json:"release_time"` // 结算发奖时间 | ||
| 97 | + Ver string `form:"ver" json:"ver"` // 版本号 | ||
| 98 | + Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启 | ||
| 75 | } | 99 | } |
| 76 | 100 | ||
| 77 | // RobotConfig 机器人配置 | 101 | // RobotConfig 机器人配置 |
configs/confroomrank/decode.go
| @@ -12,6 +12,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | @@ -12,6 +12,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | ||
| 12 | c.Raw = raw | 12 | c.Raw = raw |
| 13 | 13 | ||
| 14 | c.Id = raw.Id | 14 | c.Id = raw.Id |
| 15 | + c.Typ = raw.Typ | ||
| 15 | c.OpenLevel = raw.OpenLevel | 16 | c.OpenLevel = raw.OpenLevel |
| 16 | c.PreviewTime = raw.PreviewTime | 17 | c.PreviewTime = raw.PreviewTime |
| 17 | c.StartTime = raw.StartTime | 18 | c.StartTime = raw.StartTime |
| @@ -45,13 +46,4 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | @@ -45,13 +46,4 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | ||
| 45 | c.Room[i2.Id] = i2 | 46 | c.Room[i2.Id] = i2 |
| 46 | } | 47 | } |
| 47 | } | 48 | } |
| 48 | - c.GenerateConfigClient() | ||
| 49 | -} | ||
| 50 | - | ||
| 51 | -// GenerateConfigClient 生成给客户端的配置 | ||
| 52 | -func (c *ActivityConfig) GenerateConfigClient() { | ||
| 53 | - configClient := &ActivityConfigClient{ | ||
| 54 | - Id: c.Id, | ||
| 55 | - } | ||
| 56 | - c.Client = configClient | ||
| 57 | } | 49 | } |
configs/confroomrank/get.go
| 1 | package confroomrank | 1 | package confroomrank |
| 2 | 2 | ||
| 3 | -import "apigame/configs/confbase" | 3 | +import ( |
| 4 | + "apigame/configs/confbase" | ||
| 5 | + "apigame/util/util-lx/lxalilog" | ||
| 6 | + "apigame/util/util-lx/lxtime" | ||
| 7 | +) | ||
| 4 | 8 | ||
| 5 | // GetCurrent 获取 当前配置 | 9 | // GetCurrent 获取 当前配置 |
| 6 | func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { | 10 | func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { |
| @@ -18,3 +22,19 @@ func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | @@ -18,3 +22,19 @@ func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | ||
| 18 | 22 | ||
| 19 | return | 23 | return |
| 20 | } | 24 | } |
| 25 | + | ||
| 26 | +// GetCurrentConfigs 获取当前配置列表 | ||
| 27 | +func GetCurrentConfigs(gameId string) []*ActivityConfigRaw { | ||
| 28 | + obj := new(ActivityConfig) | ||
| 29 | + info := obj.ConfInfo(gameId) | ||
| 30 | + db := info.DbMysql | ||
| 31 | + timeNow := lxtime.NowUninx() | ||
| 32 | + objs := make([]*ActivityConfigRaw, 0) | ||
| 33 | + result := db.Table(info.TableName).Where( | ||
| 34 | + "status = ? AND start_time <= ? AND end_time >= ?", | ||
| 35 | + 1, timeNow, timeNow).Find(&objs) | ||
| 36 | + if result.Error != nil { | ||
| 37 | + lxalilog.Errors(result.Error, "confroomrank.GetCurrentConfigs error", gameId) | ||
| 38 | + } | ||
| 39 | + return objs | ||
| 40 | +} |
models/roomrank.go
| @@ -8,13 +8,7 @@ type ReqRoomRankGetConfig struct { | @@ -8,13 +8,7 @@ type ReqRoomRankGetConfig struct { | ||
| 8 | 8 | ||
| 9 | // RspRoomRankGetConfig 返回 活动配置 | 9 | // RspRoomRankGetConfig 返回 活动配置 |
| 10 | type RspRoomRankGetConfig struct { | 10 | type RspRoomRankGetConfig struct { |
| 11 | - ActivityId int64 `form:"activity_id" json:"activity_id"` // 活动配置 0=无活动 | ||
| 12 | - PrepareTime int64 `form:"prepare_time" json:"prepare_time"` // 活动预告时间 | ||
| 13 | - StartTime int64 `form:"start_time" json:"start_time"` // 活动开始时间 | ||
| 14 | - EndTime int64 `form:"end_time" json:"end_time"` // 活动结束时间 | ||
| 15 | - ReleaseTime int64 `form:"release_time" json:"release_time"` // 结算发奖时间 | ||
| 16 | - OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 | ||
| 17 | - Config any `form:"config" json:"config"` // 活动配置对象 | 11 | + Config []any `form:"config" json:"config"` // 活动配置列表 |
| 18 | } | 12 | } |
| 19 | 13 | ||
| 20 | // RoomRankTopNode 排行玩家 | 14 | // RoomRankTopNode 排行玩家 |
service/roomrank/handle.go
| @@ -14,20 +14,10 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | @@ -14,20 +14,10 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | ||
| 14 | gameId := req.GameID | 14 | gameId := req.GameID |
| 15 | 15 | ||
| 16 | // 尝试更新配置 | 16 | // 尝试更新配置 |
| 17 | - config, hasConfig := confroomrank.GetCurrent(gameId, 1) | ||
| 18 | - if !hasConfig { | ||
| 19 | - code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR | ||
| 20 | - return | 17 | + configs := confroomrank.GetCurrentConfigs(gameId) |
| 18 | + for _, config := range configs { | ||
| 19 | + rsp.Config = append(rsp.Config, config.GenerateConfigClient()) | ||
| 21 | } | 20 | } |
| 22 | - rsp.ActivityId = config.Id | ||
| 23 | - rsp.PrepareTime = config.PreviewTime | ||
| 24 | - rsp.StartTime = config.StartTime | ||
| 25 | - rsp.EndTime = config.EndTime | ||
| 26 | - rsp.ReleaseTime = config.ReleaseTime | ||
| 27 | - rsp.OpenLevel = config.OpenLevel | ||
| 28 | - | ||
| 29 | - rsp.Config = config.Client | ||
| 30 | - | ||
| 31 | return | 21 | return |
| 32 | } | 22 | } |
| 33 | 23 |