diff --git a/configs/conf-roomrank-decode.go b/configs/conf-roomrank-decode.go deleted file mode 100644 index 38fb0fd..0000000 --- a/configs/conf-roomrank-decode.go +++ /dev/null @@ -1,55 +0,0 @@ -package configs - -import ( - "apigame/util/util-lx/lxalilog" - "encoding/json" -) - -// Decode 解析配置原始数据 -func (c *RoomRankConfig) Decode(gameId string, configRaw *RoomRankConfigRaw) { - c.GameId = gameId - c.Raw = configRaw - - c.Id = configRaw.Id - c.OpenLevel = configRaw.OpenLevel - c.PreviewTime = configRaw.PreviewTime - c.StartTime = configRaw.StartTime - c.EndTime = configRaw.EndTime - - c.Robot = make(map[int]RoomRankRobotConfig) - c.Room = make(map[int]RoomRankRoomConfig) - - // 解析 机器人 - { - configs := make([]RoomRankRobotConfig, 0) - err := json.Unmarshal([]byte(configRaw.Robot), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.Robot[i2.Id] = i2 - } - } - // 解析 房间 - { - configs := make([]RoomRankRoomConfig, 0) - err := json.Unmarshal([]byte(configRaw.Room), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.Room[i2.Id] = i2 - } - } - c.GenerateConfigClient() -} - -// GenerateConfigClient 生成给客户端的配置 -func (c *RoomRankConfig) GenerateConfigClient() { - configClient := &RoomRankConfigClient{ - Id: c.Id, - } - c.Client = configClient -} diff --git a/configs/conf-roomrank.go b/configs/conf-roomrank.go deleted file mode 100644 index 7b60401..0000000 --- a/configs/conf-roomrank.go +++ /dev/null @@ -1,85 +0,0 @@ -package configs - -import ( - "apigame/service-common/svconst" - "apigame/service-common/svmysql" - "apigame/service-common/svredis" - "fmt" -) - -// RoomRankConfig 房间排行活动配置 分析后数据 -type RoomRankConfig struct { - Raw *RoomRankConfigRaw `json:"-"` - - Id int64 // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - - Robot map[int]RoomRankRobotConfig // 机器人配置 - Room map[int]RoomRankRoomConfig // 房间配置 - - Client *RoomRankConfigClient - GameId string // 所属游戏ID -} - -func (c *RoomRankConfig) RedisInfo(suffix string) *svredis.RedisInfo { - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG - return &svredis.RedisInfo{ - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), - CacheTime: 300, - } -} - -// RoomRankConfigRaw 房间排行活动配置 原始数据 -type RoomRankConfigRaw struct { - Id int64 `gorm:"column:id;primaryKey"` // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - - Robot string // 机器人配置 - Room string // 房间配置 - - Ver string // 版本号 - Status int // 状态 0=关闭 1=开启 - UpdateTime int64 // 修改时间戳 -} - -func (c *RoomRankConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG - return &svmysql.MysqlInfo{ - DbMysql: svconst.DbConfig.Where("status = ?", 1), - TableName: tableName + suffix, - } -} - -// RoomRankConfigClient 房间排行活动配置 给客户端数据 -type RoomRankConfigClient struct { - Id int64 `form:"id" json:"id"` // ID -} - -// RoomRankRobotConfig 机器人配置 -type RoomRankRobotConfig struct { - Id int `json:"id"` // id - MinScore int `json:"min_score"` // 最低分数 - TotalScore int `json:"total_score"` // 总分数 - TotalRate int `json:"total_rate"` // 总分浮动范围(%) -} - -// RoomRankRoomConfig 房间配置 -type RoomRankRoomConfig struct { - Id int `json:"id"` // id - Levels []int `json:"levels"` // 等级范围 - UserClass int `json:"user_class"` // 评级 - UserScore []int `json:"user_score"` // 分数范围 - TotalPlayer int `json:"total_player"` // 房间总人数 - PlayerTypeCount [][]int `json:"player_type_count"` // 玩家类型数量 - AutoRobot []int `json:"auto_robot"` // 自动填充机器人 - InitRobot [][]int `json:"init_robot"` // 配置机器人 - Awards []string `json:"awards"` // 奖励 - SettleScores []int `json:"settle_scores"` // 结算分数调整 - SettleUserType []int `json:"settle_user_type"` // 结算用户类型 -} diff --git a/configs/confcardholder/config.go b/configs/confcardholder/config.go index ec69ba2..37ec487 100644 --- a/configs/confcardholder/config.go +++ b/configs/confcardholder/config.go @@ -30,7 +30,7 @@ type ActivityConfig struct { CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 StarShopConfig map[int]StarShopConfig // 星星商店配置 - Client *CardActivityConfigClient + Client *ActivityConfigClient GameId string // 所属游戏ID } @@ -98,8 +98,8 @@ func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { } } -// CardActivityConfigClient 卡牌活动配置 给客户端数据 -type CardActivityConfigClient struct { +// ActivityConfigClient 卡牌活动配置 给客户端数据 +type ActivityConfigClient struct { Id int64 `form:"id" json:"id"` // ID IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 diff --git a/configs/confcardholder/decode.go b/configs/confcardholder/decode.go index 742bf2d..16d2984 100644 --- a/configs/confcardholder/decode.go +++ b/configs/confcardholder/decode.go @@ -119,7 +119,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { // GenerateConfigClient 生成给客户端的配置 func (c *ActivityConfig) GenerateConfigClient() { - configClient := &CardActivityConfigClient{ + configClient := &ActivityConfigClient{ Id: c.Id, IconPath: c.IconPath, RoundAwards: c.Awards, diff --git a/configs/confroomrank/config.go b/configs/confroomrank/config.go new file mode 100644 index 0000000..d7cb1fb --- /dev/null +++ b/configs/confroomrank/config.go @@ -0,0 +1,85 @@ +package confroomrank + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "fmt" +) + +// ActivityConfig 房间排行活动配置 分析后数据 +type ActivityConfig struct { + Raw *ActivityConfigRaw `json:"-"` + + Id int64 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + + Robot map[int]RobotConfig // 机器人配置 + Room map[int]RoomConfig // 房间配置 + + Client *ActivityConfigClient + GameId string // 所属游戏ID +} + +func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + return &svredis.RedisInfo{ + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), + CacheTime: 300, + } +} + +// ActivityConfigRaw 房间排行活动配置 原始数据 +type ActivityConfigRaw struct { + Id int64 `gorm:"column:id;primaryKey"` // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + + Robot string // 机器人配置 + Room string // 房间配置 + + Ver string // 版本号 + Status int // 状态 0=关闭 1=开启 + UpdateTime int64 // 修改时间戳 +} + +func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbConfig.Where("status = ?", 1), + TableName: tableName + suffix, + } +} + +// ActivityConfigClient 房间排行活动配置 给客户端数据 +type ActivityConfigClient struct { + Id int64 `form:"id" json:"id"` // ID +} + +// RobotConfig 机器人配置 +type RobotConfig struct { + Id int `json:"id"` // id + MinScore int `json:"min_score"` // 最低分数 + TotalScore int `json:"total_score"` // 总分数 + TotalRate int `json:"total_rate"` // 总分浮动范围(%) +} + +// RoomConfig 房间配置 +type RoomConfig struct { + Id int `json:"id"` // id + Levels []int `json:"levels"` // 等级范围 + UserClass int `json:"user_class"` // 评级 + UserScore []int `json:"user_score"` // 分数范围 + TotalPlayer int `json:"total_player"` // 房间总人数 + PlayerTypeCount [][]int `json:"player_type_count"` // 玩家类型数量 + AutoRobot []int `json:"auto_robot"` // 自动填充机器人 + InitRobot [][]int `json:"init_robot"` // 配置机器人 + Awards []string `json:"awards"` // 奖励 + SettleScores []int `json:"settle_scores"` // 结算分数调整 + SettleUserType []int `json:"settle_user_type"` // 结算用户类型 +} diff --git a/configs/confroomrank/decode.go b/configs/confroomrank/decode.go new file mode 100644 index 0000000..9150561 --- /dev/null +++ b/configs/confroomrank/decode.go @@ -0,0 +1,55 @@ +package confroomrank + +import ( + "apigame/util/util-lx/lxalilog" + "encoding/json" +) + +// Decode 解析配置原始数据 +func (c *ActivityConfig) Decode(gameId string, configRaw *ActivityConfigRaw) { + c.GameId = gameId + c.Raw = configRaw + + c.Id = configRaw.Id + c.OpenLevel = configRaw.OpenLevel + c.PreviewTime = configRaw.PreviewTime + c.StartTime = configRaw.StartTime + c.EndTime = configRaw.EndTime + + c.Robot = make(map[int]RobotConfig) + c.Room = make(map[int]RoomConfig) + + // 解析 机器人 + { + configs := make([]RobotConfig, 0) + err := json.Unmarshal([]byte(configRaw.Robot), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.Robot[i2.Id] = i2 + } + } + // 解析 房间 + { + configs := make([]RoomConfig, 0) + err := json.Unmarshal([]byte(configRaw.Room), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.Room[i2.Id] = i2 + } + } + c.GenerateConfigClient() +} + +// GenerateConfigClient 生成给客户端的配置 +func (c *ActivityConfig) GenerateConfigClient() { + configClient := &ActivityConfigClient{ + Id: c.Id, + } + c.Client = configClient +} diff --git a/configs/registry.go b/configs/registry.go index 730410e..a763a73 100644 --- a/configs/registry.go +++ b/configs/registry.go @@ -1,6 +1,7 @@ package configs import ( + "apigame/configs/confroomrank" "apigame/service-common/svmysql" "apigame/service-common/svredis" "apigame/util/util-lx/lxalilog" @@ -8,15 +9,15 @@ import ( ) // GetRoomRankConfig 获取 房间排行活动配置 -func GetRoomRankConfig(gameId string) (conf *RoomRankConfig, has bool) { +func GetRoomRankConfig(gameId string) (conf *confroomrank.ActivityConfig, has bool) { var err error - conf = new(RoomRankConfig) + conf = new(confroomrank.ActivityConfig) has = svredis.LoadData(gameId, conf) if has { fmt.Println("dwjw GetRoomRankConfig use cache") return } - confRaw := new(RoomRankConfigRaw) + confRaw := new(confroomrank.ActivityConfigRaw) has, err = svmysql.First(confRaw, gameId) if err != nil { lxalilog.Errors(err, "configs.GetRoomRankConfig error", gameId) diff --git a/controllers/demo.go b/controllers/demo.go index 2714992..ea8b8ec 100644 --- a/controllers/demo.go +++ b/controllers/demo.go @@ -1,7 +1,7 @@ package controllers import ( - "apigame/configs" + "apigame/configs/confroomrank" "apigame/models" "apigame/service/code-msg" "apigame/util/util-lx/lxalilog" @@ -27,20 +27,20 @@ func (c *DemoController) Demo() { lxalilog.Errors("DemoController.demo") { - list := make([]configs.RoomRankRobotConfig, 0) - list = append(list, configs.RoomRankRobotConfig{ + list := make([]confroomrank.RobotConfig, 0) + list = append(list, confroomrank.RobotConfig{ Id: 1, MinScore: 10, TotalScore: 30, TotalRate: 10, }) - list = append(list, configs.RoomRankRobotConfig{ + list = append(list, confroomrank.RobotConfig{ Id: 2, MinScore: 20, TotalScore: 50, TotalRate: 6, }) - list = append(list, configs.RoomRankRobotConfig{ + list = append(list, confroomrank.RobotConfig{ Id: 3, MinScore: 50, TotalScore: 200, @@ -49,9 +49,9 @@ func (c *DemoController) Demo() { fmt.Println(zjson.Str(list)) } { - list := make([]configs.RoomRankRoomConfig, 0) + list := make([]confroomrank.RoomConfig, 0) { - room := configs.RoomRankRoomConfig{} + room := confroomrank.RoomConfig{} room.Id = 1 room.Levels = []int{1, 9999} room.UserClass = 0 diff --git a/service/roomrank/player.go b/service/roomrank/player.go index 7c4c6b0..306704c 100644 --- a/service/roomrank/player.go +++ b/service/roomrank/player.go @@ -1,7 +1,7 @@ package roomrank import ( - "apigame/configs" + "apigame/configs/confroomrank" "apigame/models" "apigame/service-common/svmysql" "apigame/util/util-lx/lxalilog" @@ -36,7 +36,7 @@ func LoadPlayer(gameId string, playerUid int64) (d *DataRoomRankPlayer) { } // GetInfo 活动信息 -func GetInfo(player *DataRoomRankPlayer, conf *configs.RoomRankConfig) models.RoomRankInfo { +func GetInfo(player *DataRoomRankPlayer, conf *confroomrank.ActivityConfig) models.RoomRankInfo { info := models.RoomRankInfo{} return info } -- libgit2 0.21.0