From 271b3b29efb583573599558d12a2149db47e564c Mon Sep 17 00:00:00 2001 From: 王家文 Date: Thu, 18 Apr 2024 11:23:04 +0800 Subject: [PATCH] feat✨:房间排行活动配置 --- configs/conf-api.go | 33 +++++++++++++++++++++++++++++++++ configs/conf-cardholder-decode.go | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configs/conf-cardholder.go | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configs/conf-roomrank-decode.go | 43 +++++++++++++++++++++++++++++++++++++++++++ configs/conf-roomrank.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configs/feat-api.go | 33 --------------------------------- configs/feat-cardholder-decode.go | 169 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- configs/feat-cardholder.go | 135 --------------------------------------------------------------------------------------------------------------------------------------- configs/feat-roomrank-decode.go | 20 -------------------- configs/feat-roomrank.go | 51 --------------------------------------------------- configs/registry.go | 1 + controllers/demo.go | 26 ++++++++++++++++++++++---- service-common/svconst/mysql.go | 10 +++++----- service/cardholder/dto-game.go | 3 ++- service/cardholder/dto-record.go | 7 ++++--- service/cardholder/logic.go | 4 ++-- util/utjson/json.go | 8 -------- 17 files changed, 486 insertions(+), 431 deletions(-) create mode 100644 configs/conf-api.go create mode 100644 configs/conf-cardholder-decode.go create mode 100644 configs/conf-cardholder.go create mode 100644 configs/conf-roomrank-decode.go create mode 100644 configs/conf-roomrank.go delete mode 100644 configs/feat-api.go delete mode 100644 configs/feat-cardholder-decode.go delete mode 100644 configs/feat-cardholder.go delete mode 100644 configs/feat-roomrank-decode.go delete mode 100644 configs/feat-roomrank.go delete mode 100644 util/utjson/json.go diff --git a/configs/conf-api.go b/configs/conf-api.go new file mode 100644 index 0000000..3f33dfe --- /dev/null +++ b/configs/conf-api.go @@ -0,0 +1,33 @@ +package configs + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "fmt" +) + +// ApiGameConfig api游戏配置 +type ApiGameConfig struct { + AppId string `gorm:"column:appid"` + GameId string `gorm:"column:gameid"` + Secret string `gorm:"column:secret"` + AppKey string `gorm:"column:appkey"` + Name string `gorm:"column:name"` +} + +func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo { + tableName := "s_game_config" + return &svredis.RedisInfo{ + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), + CacheTime: 300, + } +} + +func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo { + tableName := "s_game_config" + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbApi.Where("gameid = ?", suffix), + TableName: tableName, + } +} diff --git a/configs/conf-cardholder-decode.go b/configs/conf-cardholder-decode.go new file mode 100644 index 0000000..085dd00 --- /dev/null +++ b/configs/conf-cardholder-decode.go @@ -0,0 +1,169 @@ +package configs + +import ( + "apigame/util/util-lx/lxalilog" + "encoding/json" + "errors" + "fmt" + "strings" +) + +// Decode 解析配置原始数据 +func (c *CardActivityConfig) Decode(gameId string, configRaw *CardActivityConfigRaw) { + 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.Round = configRaw.Round + + c.Awards = make(map[string]string) + c.AlbumConfig = make(map[int]AlbumConfig) + c.CardConfig = make(map[int]CardConfig) + c.CardholderConfig = make(map[string]OpenCardholderConfig) + c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) + c.CardSequenceConfig = make(map[string]CardSequenceConfig) + c.StarShopConfig = make(map[int]StarShopConfig) + // 解析奖励 + { + err := json.Unmarshal([]byte(configRaw.Awards), &c.Awards) + if err != nil { + lxalilog.Errors(err, configRaw.Awards, gameId, configRaw.Id) + return + } + } + // 卡组配置 + { + configs := make([]AlbumConfig, 0) + err := json.Unmarshal([]byte(configRaw.AlbumConfig), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.AlbumConfig, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.AlbumConfig[i2.SetId] = i2 + } + } + // 卡牌配置 + { + configs := make([]CardConfig, 0) + err := json.Unmarshal([]byte(configRaw.CardConfig), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.CardConfig, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.CardConfig[i2.Id] = i2 + } + } + // 卡包开卡规则 + { + configs := make([]OpenCardholderConfig, 0) + err := json.Unmarshal([]byte(configRaw.CardHolderConfig), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.CardHolderConfig, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.CardholderConfig[i2.Id] = i2 + } + } + // 卡片星级配置 + { + configs := make([]NormalCardStarConfig, 0) + err := json.Unmarshal([]byte(configRaw.NormalCardStarSequence), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.NormalCardStarSequence, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",") + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) + c.NormalCardStarConfig[combineId] = i2 + } + } + // 卡片星级对应卡牌配置 + { + configs := make([]CardSequenceConfig, 0) + err := json.Unmarshal([]byte(configRaw.CardSequenceConfig), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.CardSequenceConfig, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + i2.CardIdLists = strings.Split(i2.CardIdList, ",") + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) + c.CardSequenceConfig[combineId] = i2 + } + } + // 星星商店配置 + { + configs := make([]StarShopConfig, 0) + err := json.Unmarshal([]byte(configRaw.StarShopConfig), &configs) + if err != nil { + lxalilog.Errors(err, configRaw.StarShopConfig, gameId, configRaw.Id) + return + } + for _, i2 := range configs { + c.StarShopConfig[i2.Id] = i2 + } + } + + c.GenerateConfigClient() +} + +// GenerateConfigClient 生成给客户端的配置 +func (c *CardActivityConfig) GenerateConfigClient() { + configClient := &CardActivityConfigClient{ + Id: c.Id, + RoundAwards: c.Awards, + Albums: make([]AlbumConfig, 0), + Cards: make([]CardConfig, 0), + Holders: make([]OpenCardholderConfig, 0), + StarShop: make([]StarShopConfig, 0), + } + for _, i2 := range c.AlbumConfig { + configClient.Albums = append(configClient.Albums, i2) + } + for _, i2 := range c.CardConfig { + configClient.Cards = append(configClient.Cards, i2) + } + for _, i2 := range c.CardholderConfig { + configClient.Holders = append(configClient.Holders, i2) + } + for _, i2 := range c.StarShopConfig { + configClient.StarShop = append(configClient.StarShop, i2) + } + c.Client = configClient +} + +// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组 +func CombineIdSequenceIdCohort(id, sequenceId, cohort string) string { + return fmt.Sprintf("%s_%s_%s", id, sequenceId, cohort) +} + +// FindNormalCardStarConfig 查找配置 非保底卡星级ID +func (c *CardActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort string) (conf NormalCardStarConfig, has bool) { + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) + conf, has = c.NormalCardStarConfig[combineId] + if !has { + lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort) + } + return +} + +// FindCardSequenceConfig 查找配置 星级ID对应的卡片 +func (c *CardActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) { + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) + conf, has = c.CardSequenceConfig[combineId] + if !has { + lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort) + fmt.Println(id) + fmt.Println(sequenceId) + fmt.Println(cohort) + } + return +} diff --git a/configs/conf-cardholder.go b/configs/conf-cardholder.go new file mode 100644 index 0000000..783b487 --- /dev/null +++ b/configs/conf-cardholder.go @@ -0,0 +1,137 @@ +package configs + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "fmt" +) + +// CardActivityConfig 卡牌活动配置 分析后数据 +type CardActivityConfig struct { + Raw *CardActivityConfigRaw `json:"-"` + + Id int64 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + Round int // 轮数 + + Awards map[string]string // 奖励配置 + AlbumConfig map[int]AlbumConfig // 卡组配置 + CardConfig map[int]CardConfig // 卡牌配置 + CardholderConfig map[string]OpenCardholderConfig // 卡包开卡规则 + NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 + CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 + StarShopConfig map[int]StarShopConfig // 星星商店配置 + + Client *CardActivityConfigClient + GameId string // 所属游戏ID +} + +func (c *CardActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG + return &svredis.RedisInfo{ + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), + CacheTime: 300, + } +} + +// CardActivityConfigRaw 卡牌活动配置 原始数据 +type CardActivityConfigRaw struct { + Id int64 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + Round int // 轮数 + + Awards string `json:"-"` // 奖励配置 + AlbumConfig string `json:"-"` // 卡组配置 + CardConfig string `json:"-"` // 卡牌配置 + CardHolderConfig string `json:"-"` // 卡包开卡规则 + NormalCardStarSequence string `json:"-"` // 卡片星级配置 + CardSequenceConfig string `json:"-"` // 卡片星级对应卡牌配置 + StarShopConfig string `json:"-"` // 星星商店配置 + + Ver string // 版本号 + Status int // 状态 0=关闭 1=开启 + UpdateTime int64 // 修改时间戳 +} + +func (c *CardActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbConfig.Where("status = ?", 1), + TableName: fmt.Sprintf("%s_%s", tableName, suffix), + } +} + +// CardActivityConfigClient 卡牌活动配置 给客户端数据 +type CardActivityConfigClient struct { + Id int64 `form:"id" json:"id"` // ID + RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 + Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置 + Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置 + Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则 + StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置 +} + +// AlbumConfig 卡组表 +type AlbumConfig struct { + SetId int `json:"set_id"` // 卡组名 + Name int `json:"name"` // 卡组图片 + Icon string `json:"icon"` // 卡组id + Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次 + StartTime int64 `json:"start_time"` // 开始时间 + EndTime int64 `json:"end_time"` // 结束时间 +} + +// CardConfig 卡牌表 +type CardConfig struct { + Id int `json:"id"` // ID + Name int `json:"name"` // 卡牌名字 + Icon int `json:"icon"` // 卡牌图标 + Desc int `json:"desc"` // 卡牌描述 + SetId int `json:"album_setid"` // 卡组id + Star int `json:"star"` // 星级 + IsGold int `json:"is_gold"` // 是否是金卡 + IsSend int `json:"is_send"` // 卡片是否可赠送 +} + +// OpenCardholderConfig 卡包开卡规则表 +type OpenCardholderConfig struct { + Id string `json:"id"` // ID + IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 + IsNew int `json:"is_new"` // 是否是新卡包 + GuaranteedStarCardId string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID + NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 + MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID + ActivityId int `json:"activity_id"` // 对应活动ID +} + +// NormalCardStarConfig 非保底卡星级ID +type NormalCardStarConfig struct { + Id string `json:"id"` // ID + SequenceId string `json:"user_sequence_id"` // 用户序列组ID + Cohort string `json:"cohort"` // 用户分组 + NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列 + NormalCardSequenceIds []string `json:"normal_card_sequence_ids"` // 非保底星级序列 +} + +// CardSequenceConfig 星级ID对应的卡片 +type CardSequenceConfig struct { + Id string `json:"id"` // ID + SequenceId string `json:"user_sequence_id"` // 用户序列组ID + Cohort string `json:"cohort"` // 用户分组 + CardIdList string `json:"card_id_list"` // 卡牌抽取序列 + CardIdLists []string `json:"card_id_lists"` // 卡牌抽取序列 +} + +// StarShopConfig 星星商店配置 +type StarShopConfig struct { + Id int `json:"id"` // ID + NeedStarNumber int `json:"need_star_number"` // 需求星星数 + CardBagIds []int `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} +} diff --git a/configs/conf-roomrank-decode.go b/configs/conf-roomrank-decode.go new file mode 100644 index 0000000..a96bb7a --- /dev/null +++ b/configs/conf-roomrank-decode.go @@ -0,0 +1,43 @@ +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) + + // 解析机器人 + { + 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 + } + } + + 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 new file mode 100644 index 0000000..08bd587 --- /dev/null +++ b/configs/conf-roomrank.go @@ -0,0 +1,68 @@ +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 // 机器人配置 + + 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 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + + Robot string `json:"-"` // 机器人配置 + + 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"` // 总分浮动范围(%) +} diff --git a/configs/feat-api.go b/configs/feat-api.go deleted file mode 100644 index 3f33dfe..0000000 --- a/configs/feat-api.go +++ /dev/null @@ -1,33 +0,0 @@ -package configs - -import ( - "apigame/service-common/svconst" - "apigame/service-common/svmysql" - "apigame/service-common/svredis" - "fmt" -) - -// ApiGameConfig api游戏配置 -type ApiGameConfig struct { - AppId string `gorm:"column:appid"` - GameId string `gorm:"column:gameid"` - Secret string `gorm:"column:secret"` - AppKey string `gorm:"column:appkey"` - Name string `gorm:"column:name"` -} - -func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo { - tableName := "s_game_config" - return &svredis.RedisInfo{ - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), - CacheTime: 300, - } -} - -func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo { - tableName := "s_game_config" - return &svmysql.MysqlInfo{ - DbMysql: svconst.DbApi.Where("gameid = ?", suffix), - TableName: tableName, - } -} diff --git a/configs/feat-cardholder-decode.go b/configs/feat-cardholder-decode.go deleted file mode 100644 index 085dd00..0000000 --- a/configs/feat-cardholder-decode.go +++ /dev/null @@ -1,169 +0,0 @@ -package configs - -import ( - "apigame/util/util-lx/lxalilog" - "encoding/json" - "errors" - "fmt" - "strings" -) - -// Decode 解析配置原始数据 -func (c *CardActivityConfig) Decode(gameId string, configRaw *CardActivityConfigRaw) { - 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.Round = configRaw.Round - - c.Awards = make(map[string]string) - c.AlbumConfig = make(map[int]AlbumConfig) - c.CardConfig = make(map[int]CardConfig) - c.CardholderConfig = make(map[string]OpenCardholderConfig) - c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) - c.CardSequenceConfig = make(map[string]CardSequenceConfig) - c.StarShopConfig = make(map[int]StarShopConfig) - // 解析奖励 - { - err := json.Unmarshal([]byte(configRaw.Awards), &c.Awards) - if err != nil { - lxalilog.Errors(err, configRaw.Awards, gameId, configRaw.Id) - return - } - } - // 卡组配置 - { - configs := make([]AlbumConfig, 0) - err := json.Unmarshal([]byte(configRaw.AlbumConfig), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.AlbumConfig, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.AlbumConfig[i2.SetId] = i2 - } - } - // 卡牌配置 - { - configs := make([]CardConfig, 0) - err := json.Unmarshal([]byte(configRaw.CardConfig), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.CardConfig, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.CardConfig[i2.Id] = i2 - } - } - // 卡包开卡规则 - { - configs := make([]OpenCardholderConfig, 0) - err := json.Unmarshal([]byte(configRaw.CardHolderConfig), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.CardHolderConfig, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.CardholderConfig[i2.Id] = i2 - } - } - // 卡片星级配置 - { - configs := make([]NormalCardStarConfig, 0) - err := json.Unmarshal([]byte(configRaw.NormalCardStarSequence), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.NormalCardStarSequence, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",") - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) - c.NormalCardStarConfig[combineId] = i2 - } - } - // 卡片星级对应卡牌配置 - { - configs := make([]CardSequenceConfig, 0) - err := json.Unmarshal([]byte(configRaw.CardSequenceConfig), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.CardSequenceConfig, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - i2.CardIdLists = strings.Split(i2.CardIdList, ",") - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) - c.CardSequenceConfig[combineId] = i2 - } - } - // 星星商店配置 - { - configs := make([]StarShopConfig, 0) - err := json.Unmarshal([]byte(configRaw.StarShopConfig), &configs) - if err != nil { - lxalilog.Errors(err, configRaw.StarShopConfig, gameId, configRaw.Id) - return - } - for _, i2 := range configs { - c.StarShopConfig[i2.Id] = i2 - } - } - - c.GenerateConfigClient() -} - -// GenerateConfigClient 生成给客户端的配置 -func (c *CardActivityConfig) GenerateConfigClient() { - configClient := &CardActivityConfigClient{ - Id: c.Id, - RoundAwards: c.Awards, - Albums: make([]AlbumConfig, 0), - Cards: make([]CardConfig, 0), - Holders: make([]OpenCardholderConfig, 0), - StarShop: make([]StarShopConfig, 0), - } - for _, i2 := range c.AlbumConfig { - configClient.Albums = append(configClient.Albums, i2) - } - for _, i2 := range c.CardConfig { - configClient.Cards = append(configClient.Cards, i2) - } - for _, i2 := range c.CardholderConfig { - configClient.Holders = append(configClient.Holders, i2) - } - for _, i2 := range c.StarShopConfig { - configClient.StarShop = append(configClient.StarShop, i2) - } - c.Client = configClient -} - -// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组 -func CombineIdSequenceIdCohort(id, sequenceId, cohort string) string { - return fmt.Sprintf("%s_%s_%s", id, sequenceId, cohort) -} - -// FindNormalCardStarConfig 查找配置 非保底卡星级ID -func (c *CardActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort string) (conf NormalCardStarConfig, has bool) { - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) - conf, has = c.NormalCardStarConfig[combineId] - if !has { - lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort) - } - return -} - -// FindCardSequenceConfig 查找配置 星级ID对应的卡片 -func (c *CardActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) { - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) - conf, has = c.CardSequenceConfig[combineId] - if !has { - lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort) - fmt.Println(id) - fmt.Println(sequenceId) - fmt.Println(cohort) - } - return -} diff --git a/configs/feat-cardholder.go b/configs/feat-cardholder.go deleted file mode 100644 index 1a238f7..0000000 --- a/configs/feat-cardholder.go +++ /dev/null @@ -1,135 +0,0 @@ -package configs - -import ( - "apigame/service-common/svconst" - "apigame/service-common/svmysql" - "apigame/service-common/svredis" - "fmt" -) - -// CardActivityConfig 卡牌活动配置 分析后数据 -type CardActivityConfig struct { - Raw *CardActivityConfigRaw `json:"-"` - - Id int64 // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - Round int // 轮数 - - Awards map[string]string // 奖励配置 - AlbumConfig map[int]AlbumConfig // 卡组配置 - CardConfig map[int]CardConfig // 卡牌配置 - CardholderConfig map[string]OpenCardholderConfig // 卡包开卡规则 - NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 - CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 - StarShopConfig map[int]StarShopConfig // 星星商店配置 - - Client *CardActivityConfigClient - GameId string // 所属游戏ID -} - -func (c *CardActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo { - tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG - return &svredis.RedisInfo{ - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), - CacheTime: 300, - } -} - -// CardActivityConfigRaw 卡牌活动配置 原始数据 -type CardActivityConfigRaw struct { - Id int64 // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - Round int // 轮数 - Awards string `json:"-"` // 奖励配置 - AlbumConfig string `json:"-"` // 卡组配置 - CardConfig string `json:"-"` // 卡牌配置 - CardHolderConfig string `json:"-"` // 卡包开卡规则 - NormalCardStarSequence string `json:"-"` // 卡片星级配置 - CardSequenceConfig string `json:"-"` // 卡片星级对应卡牌配置 - StarShopConfig string `json:"-"` // 星星商店配置 - Ver string // 版本号 - Status int // 状态 0=关闭 1=开启 - UpdateTime int64 // 修改时间戳 -} - -func (c *CardActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { - tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG - return &svmysql.MysqlInfo{ - DbMysql: svconst.DbConfig.Where("status = ?", 1), - TableName: tableName + suffix, - } -} - -// CardActivityConfigClient 卡牌活动配置 给客户端数据 -type CardActivityConfigClient struct { - Id int64 `form:"id" json:"id"` // ID - RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 - Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置 - Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置 - Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则 - StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置 -} - -// AlbumConfig 卡组表 -type AlbumConfig struct { - SetId int `json:"set_id"` // 卡组名 - Name int `json:"name"` // 卡组图片 - Icon string `json:"icon"` // 卡组id - Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次 - StartTime int64 `json:"start_time"` // 开始时间 - EndTime int64 `json:"end_time"` // 结束时间 -} - -// CardConfig 卡牌表 -type CardConfig struct { - Id int `json:"id"` // ID - Name int `json:"name"` // 卡牌名字 - Icon int `json:"icon"` // 卡牌图标 - Desc int `json:"desc"` // 卡牌描述 - SetId int `json:"album_setid"` // 卡组id - Star int `json:"star"` // 星级 - IsGold int `json:"is_gold"` // 是否是金卡 - IsSend int `json:"is_send"` // 卡片是否可赠送 -} - -// OpenCardholderConfig 卡包开卡规则表 -type OpenCardholderConfig struct { - Id string `json:"id"` // ID - IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 - IsNew int `json:"is_new"` // 是否是新卡包 - GuaranteedStarCardId string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID - NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 - MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID - ActivityId int `json:"activity_id"` // 对应活动ID -} - -// NormalCardStarConfig 非保底卡星级ID -type NormalCardStarConfig struct { - Id string `json:"id"` // ID - SequenceId string `json:"user_sequence_id"` // 用户序列组ID - Cohort string `json:"cohort"` // 用户分组 - NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列 - NormalCardSequenceIds []string `json:"normal_card_sequence_ids"` // 非保底星级序列 -} - -// CardSequenceConfig 星级ID对应的卡片 -type CardSequenceConfig struct { - Id string `json:"id"` // ID - SequenceId string `json:"user_sequence_id"` // 用户序列组ID - Cohort string `json:"cohort"` // 用户分组 - CardIdList string `json:"card_id_list"` // 卡牌抽取序列 - CardIdLists []string `json:"card_id_lists"` // 卡牌抽取序列 -} - -// StarShopConfig 星星商店配置 -type StarShopConfig struct { - Id int `json:"id"` // ID - NeedStarNumber int `json:"need_star_number"` // 需求星星数 - CardBagIds []int `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} -} diff --git a/configs/feat-roomrank-decode.go b/configs/feat-roomrank-decode.go deleted file mode 100644 index ab1e058..0000000 --- a/configs/feat-roomrank-decode.go +++ /dev/null @@ -1,20 +0,0 @@ -package configs - -// Decode 解析配置原始数据 -func (c *RoomRankConfig) Decode(gameId string, configRaw *RoomRankConfigRaw) { - c.GameId = gameId - c.Raw = configRaw - - c.Id = configRaw.Id - // 解析奖励 - - c.GenerateConfigClient() -} - -// GenerateConfigClient 生成给客户端的配置 -func (c *RoomRankConfig) GenerateConfigClient() { - configClient := &RoomRankConfigClient{ - Id: c.Id, - } - c.Client = configClient -} diff --git a/configs/feat-roomrank.go b/configs/feat-roomrank.go deleted file mode 100644 index d933560..0000000 --- a/configs/feat-roomrank.go +++ /dev/null @@ -1,51 +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 - - 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 // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - 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 -} diff --git a/configs/registry.go b/configs/registry.go index ed8c303..90149a7 100644 --- a/configs/registry.go +++ b/configs/registry.go @@ -79,6 +79,7 @@ func GetRoomRankConfig(gameId string) (conf *RoomRankConfig, has bool) { conf.Decode(gameId, confRaw) fmt.Println("dwjw GetRoomRankConfig save cache") + fmt.Println("dwjw🐸", conf.Robot) svredis.SaveData(gameId, conf) return diff --git a/controllers/demo.go b/controllers/demo.go index e095649..ec8c978 100644 --- a/controllers/demo.go +++ b/controllers/demo.go @@ -1,9 +1,10 @@ package controllers import ( + "apigame/configs" "apigame/models" "apigame/service/code-msg" - "apigame/service/roomrank" + "apigame/util/zjson" "fmt" ) @@ -23,9 +24,26 @@ func (c *DemoController) Demo() { fmt.Println("DemoController.demo") { - room := &roomrank.DataRoomRankRoom{Uid: req.UID, ActivityId: 1} - roomrank.SaveRoom(req.GameID, room) - fmt.Println(room.Id) + list := make([]configs.RoomRankRobotConfig, 0) + list = append(list, configs.RoomRankRobotConfig{ + Id: 1, + MinScore: 10, + TotalScore: 30, + TotalRate: 10, + }) + list = append(list, configs.RoomRankRobotConfig{ + Id: 2, + MinScore: 20, + TotalScore: 50, + TotalRate: 6, + }) + list = append(list, configs.RoomRankRobotConfig{ + Id: 3, + MinScore: 50, + TotalScore: 200, + TotalRate: 5, + }) + fmt.Println(zjson.Str(list)) } c.RetRspCodeData(code_msg.RECODE_OK, rsp) diff --git a/service-common/svconst/mysql.go b/service-common/svconst/mysql.go index 4e3a2bc..1bebedc 100644 --- a/service-common/svconst/mysql.go +++ b/service-common/svconst/mysql.go @@ -11,11 +11,11 @@ const ( MYSQL_MERGECONFIG = "merge_config" MYSQL_DEFAULT_QUERY_MAXCOUNT = 100 - MYSQL_TABLE_S_CARDHOLDER_CONFIG = "s_card_activity_" // 开卡包活动配置 - MYSQL_TABLE_S_CARDHOLDER_DATA = "s_cardholder_data_" // 开卡包活动数据 - MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN = "s_cardholder_record_open_" // 开卡包活动日志开卡包 - MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum_" // 开卡包活动日志领取卡组奖励 - MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround_" // 开卡包活动日志领取轮次奖励 + MYSQL_TABLE_S_CARDHOLDER_CONFIG = "s_card_activity" // 开卡包活动配置 + MYSQL_TABLE_S_CARDHOLDER_DATA = "s_cardholder_data" // 开卡包活动数据 + MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN = "s_cardholder_record_open" // 开卡包活动日志开卡包 + MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum" // 开卡包活动日志领取卡组奖励 + MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround" // 开卡包活动日志领取轮次奖励 MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity_" // 房间排行活动配置 MYSQL_TABLE_S_ROOMRANK_PLAYER = "s_roomrank_player_" // 房间排行玩家数据 diff --git a/service/cardholder/dto-game.go b/service/cardholder/dto-game.go index 1db795d..e3bc1e7 100644 --- a/service/cardholder/dto-game.go +++ b/service/cardholder/dto-game.go @@ -6,6 +6,7 @@ import ( "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" "encoding/json" + "fmt" ) // DataCardHolder 卡牌活动持久数据 @@ -24,7 +25,7 @@ func (d *DataCardHolder) MysqlInfo(suffix string) *svmysql.MysqlInfo { tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_DATA return &svmysql.MysqlInfo{ DbMysql: svconst.DbCommon, - TableName: tableName + suffix, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), } } diff --git a/service/cardholder/dto-record.go b/service/cardholder/dto-record.go index c8efb61..e21d792 100644 --- a/service/cardholder/dto-record.go +++ b/service/cardholder/dto-record.go @@ -4,6 +4,7 @@ import ( "apigame/service-common/svconst" "apigame/service-common/svmysql" "apigame/util/util-lx/lxtime" + "fmt" ) // RecordCardHolderBase 开卡包活动日志公共 @@ -43,7 +44,7 @@ func (d *RecordCardHolderOpen) MysqlInfo(suffix string) *svmysql.MysqlInfo { tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN return &svmysql.MysqlInfo{ DbMysql: svconst.DbCommon, - TableName: tableName + suffix, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), } } @@ -68,7 +69,7 @@ func (d *RecordCardHolderRewardAlbum) MysqlInfo(suffix string) *svmysql.MysqlInf tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM return &svmysql.MysqlInfo{ DbMysql: svconst.DbCommon, - TableName: tableName + suffix, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), } } @@ -91,7 +92,7 @@ func (d *RecordCardHolderRewardRound) MysqlInfo(suffix string) *svmysql.MysqlInf tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND return &svmysql.MysqlInfo{ DbMysql: svconst.DbCommon, - TableName: tableName + suffix, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), } } diff --git a/service/cardholder/logic.go b/service/cardholder/logic.go index 6d76aab..cd5c7fa 100644 --- a/service/cardholder/logic.go +++ b/service/cardholder/logic.go @@ -7,9 +7,9 @@ import ( "apigame/service/code-msg" "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" - "apigame/util/utjson" "apigame/util/utslice" "apigame/util/utstring" + "apigame/util/zjson" "github.com/samber/lo" "sort" "strconv" @@ -197,7 +197,7 @@ func DoOpen(gameId string, { recordBase := NewRecordCardHolderBase(player.Uid, sequenceId, cohort, config.Id, player.Details.Round) _ = svmysql.Create(NewRecordCardHolderOpen(recordBase, - openMode, utstring.StringToInt(confCardholder.Id), utjson.JsonString(newCards)), + openMode, utstring.StringToInt(confCardholder.Id), zjson.Str(newCards)), gameId) } diff --git a/util/utjson/json.go b/util/utjson/json.go deleted file mode 100644 index 0c4156e..0000000 --- a/util/utjson/json.go +++ /dev/null @@ -1,8 +0,0 @@ -package utjson - -import "encoding/json" - -func JsonString(o any) string { - bs, _ := json.Marshal(o) - return string(bs) -} -- libgit2 0.21.0