Commit 141bf7314a1450971b0427f1ffd12ffcfc6e2b49
1 parent
b46ab67a
Exists in
master
and in
1 other branch
feat✨:房间排行活动逻辑
Showing
6 changed files
with
66 additions
and
16 deletions
Show diff stats
configs/confroomrank/config.go
| 1 | package confroomrank | 1 | package confroomrank |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "apigame/configs/confbase" | ||
| 4 | "apigame/service-common/svconst" | 5 | "apigame/service-common/svconst" |
| 5 | "apigame/service-common/svmysql" | 6 | "apigame/service-common/svmysql" |
| 6 | "apigame/service-common/svredis" | 7 | "apigame/service-common/svredis" |
| 8 | + "apigame/util/util-lx/lxtime" | ||
| 9 | + "apigame/util/utstring" | ||
| 7 | "fmt" | 10 | "fmt" |
| 8 | ) | 11 | ) |
| 9 | 12 | ||
| @@ -24,6 +27,31 @@ type ActivityConfig struct { | @@ -24,6 +27,31 @@ type ActivityConfig struct { | ||
| 24 | GameId string // 所属游戏ID | 27 | GameId string // 所属游戏ID |
| 25 | } | 28 | } |
| 26 | 29 | ||
| 30 | +func (c *ActivityConfig) GetUid() string { | ||
| 31 | + return utstring.Int64ToString(c.Id) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func (c *ActivityConfig) CheckCurrent() bool { | ||
| 35 | + timeNow := lxtime.NowUninx() | ||
| 36 | + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | ||
| 40 | + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG | ||
| 41 | + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | ||
| 42 | + timeNow := lxtime.NowUninx() | ||
| 43 | + return &confbase.ConfInfo{ | ||
| 44 | + DbMysql: svconst.DbConfig, | ||
| 45 | + TableName: fmt.Sprintf("%s_%s", tableName, suffix), | ||
| 46 | + KeyName: "id", | ||
| 47 | + CurrentQuery: "start_time <= ? AND end_time >= ? AND status = ?", | ||
| 48 | + CurrentArgs: []any{timeNow, timeNow, 1}, | ||
| 49 | + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | ||
| 50 | + CacheCurrent: cacheKey + ":current", | ||
| 51 | + CacheTime: 300, | ||
| 52 | + } | ||
| 53 | +} | ||
| 54 | + | ||
| 27 | func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { | 55 | func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { |
| 28 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG | 56 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG |
| 29 | return &svredis.RedisInfo{ | 57 | return &svredis.RedisInfo{ |
configs/confroomrank/decode.go
| @@ -6,15 +6,16 @@ import ( | @@ -6,15 +6,16 @@ import ( | ||
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | // Decode 解析配置原始数据 | 8 | // Decode 解析配置原始数据 |
| 9 | -func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { | 9 | +func (c *ActivityConfig) Decode(gameId string, rawData any) { |
| 10 | + raw := rawData.(*ActivityConfigRaw) | ||
| 10 | c.GameId = gameId | 11 | c.GameId = gameId |
| 11 | - c.Raw = configRaw | 12 | + c.Raw = raw |
| 12 | 13 | ||
| 13 | - c.Id = configRaw.Id | ||
| 14 | - c.OpenLevel = configRaw.OpenLevel | ||
| 15 | - c.PreviewTime = configRaw.PreviewTime | ||
| 16 | - c.StartTime = configRaw.StartTime | ||
| 17 | - c.EndTime = configRaw.EndTime | 14 | + c.Id = raw.Id |
| 15 | + c.OpenLevel = raw.OpenLevel | ||
| 16 | + c.PreviewTime = raw.PreviewTime | ||
| 17 | + c.StartTime = raw.StartTime | ||
| 18 | + c.EndTime = raw.EndTime | ||
| 18 | 19 | ||
| 19 | c.Robot = make(map[int]RobotConfig) | 20 | c.Robot = make(map[int]RobotConfig) |
| 20 | c.Room = make(map[int]RoomConfig) | 21 | c.Room = make(map[int]RoomConfig) |
| @@ -22,9 +23,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { | @@ -22,9 +23,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { | ||
| 22 | // 解析 机器人 | 23 | // 解析 机器人 |
| 23 | { | 24 | { |
| 24 | configs := make([]RobotConfig, 0) | 25 | configs := make([]RobotConfig, 0) |
| 25 | - err := json.Unmarshal([]byte(configRaw.Robot), &configs) | 26 | + err := json.Unmarshal([]byte(raw.Robot), &configs) |
| 26 | if err != nil { | 27 | if err != nil { |
| 27 | - lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id) | 28 | + lxalilog.Errors(err, raw.Robot, gameId, raw.Id) |
| 28 | return | 29 | return |
| 29 | } | 30 | } |
| 30 | for _, i2 := range configs { | 31 | for _, i2 := range configs { |
| @@ -34,9 +35,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { | @@ -34,9 +35,9 @@ func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { | ||
| 34 | // 解析 房间 | 35 | // 解析 房间 |
| 35 | { | 36 | { |
| 36 | configs := make([]RoomConfig, 0) | 37 | configs := make([]RoomConfig, 0) |
| 37 | - err := json.Unmarshal([]byte(configRaw.Room), &configs) | 38 | + err := json.Unmarshal([]byte(raw.Room), &configs) |
| 38 | if err != nil { | 39 | if err != nil { |
| 39 | - lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id) | 40 | + lxalilog.Errors(err, raw.Room, gameId, raw.Id) |
| 40 | return | 41 | return |
| 41 | } | 42 | } |
| 42 | for _, i2 := range configs { | 43 | for _, i2 := range configs { |
| @@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
| 1 | +package confroomrank | ||
| 2 | + | ||
| 3 | +import "apigame/configs/confbase" | ||
| 4 | + | ||
| 5 | +// GetCurrent 获取 当前配置 | ||
| 6 | +func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { | ||
| 7 | + conf = new(ActivityConfig) | ||
| 8 | + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | ||
| 9 | + | ||
| 10 | + return | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +// GetConfig 获取 配置根据Id | ||
| 14 | +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | ||
| 15 | + conf = new(ActivityConfig) | ||
| 16 | + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) | ||
| 17 | + | ||
| 18 | + return | ||
| 19 | +} |
configs/init.go
| @@ -3,6 +3,7 @@ package configs | @@ -3,6 +3,7 @@ package configs | ||
| 3 | import ( | 3 | import ( |
| 4 | "apigame/configs/confapi" | 4 | "apigame/configs/confapi" |
| 5 | "apigame/configs/confcardholder" | 5 | "apigame/configs/confcardholder" |
| 6 | + "apigame/configs/confroomrank" | ||
| 6 | "apigame/service-common/svconst" | 7 | "apigame/service-common/svconst" |
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| @@ -17,7 +18,7 @@ func Init() bool { | @@ -17,7 +18,7 @@ func Init() bool { | ||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | for _, gameId := range svconst.GameListRoomRank { | 20 | for _, gameId := range svconst.GameListRoomRank { |
| 20 | - _, _ = GetRoomRankConfig(gameId) | 21 | + _, _ = confroomrank.GetCurrent(gameId) |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | return true | 24 | return true |
service-common/svconst/mysql.go
| @@ -17,7 +17,7 @@ const ( | @@ -17,7 +17,7 @@ const ( | ||
| 17 | MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励 | 17 | MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励 |
| 18 | MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励 | 18 | MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励 |
| 19 | 19 | ||
| 20 | - MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity_" // 房间排行活动配置 | ||
| 21 | - MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player_" // 房间排行玩家数据 | ||
| 22 | - MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据 | 20 | + MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity" // 房间排行活动配置 |
| 21 | + MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player" // 房间排行玩家数据 | ||
| 22 | + MYSQL_TABLE_S_ROOMRANK_ROOM = "s_roomrank_room" // 房间排行房间数据 | ||
| 23 | ) | 23 | ) |
service/roomrank/handle.go
| @@ -2,6 +2,7 @@ package roomrank | @@ -2,6 +2,7 @@ package roomrank | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "apigame/configs" | 4 | "apigame/configs" |
| 5 | + "apigame/configs/confroomrank" | ||
| 5 | "apigame/models" | 6 | "apigame/models" |
| 6 | "apigame/service/code-msg" | 7 | "apigame/service/code-msg" |
| 7 | ) | 8 | ) |
| @@ -13,7 +14,7 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | @@ -13,7 +14,7 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | ||
| 13 | gameId := req.GameID | 14 | gameId := req.GameID |
| 14 | 15 | ||
| 15 | // 尝试更新配置 | 16 | // 尝试更新配置 |
| 16 | - config, _ := configs.GetRoomRankConfig(gameId) | 17 | + config, _ := confroomrank.GetCurrent(gameId) |
| 17 | rsp.ActivityId = config.Id | 18 | rsp.ActivityId = config.Id |
| 18 | 19 | ||
| 19 | rsp.Config = config.Client | 20 | rsp.Config = config.Client |