diff --git a/configs-db/confapi/config.go b/configs-db/confapi/config.go deleted file mode 100644 index 5073b22..0000000 --- a/configs-db/confapi/config.go +++ /dev/null @@ -1,48 +0,0 @@ -package confapi - -import ( - "apigame/configs-db/confbase" - "apigame/service-common/svconst" - "fmt" -) - -// ApiGameConfig api游戏配置 -type ApiGameConfig struct { - Raw *Raw -} - -func (c *ApiGameConfig) GetUid() string { - return c.Raw.GameId -} - -func (c *ApiGameConfig) CheckCurrent() bool { - return true -} - -func (c *ApiGameConfig) ConfInfo(suffix string) *confbase.ConfInfo { - tableName := "s_game_config" - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) - return &confbase.ConfInfo{ - DbMysql: svconst.DbApi, - TableName: tableName, - KeyName: "gameid", - CacheKey: cacheKey, - CacheCurrent: cacheKey + ":current", - CacheTime: 300, - } -} - -// Raw 配置原始数据 -type Raw 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"` -} - -// Decode 解析配置原始数据 -func (c *ApiGameConfig) Decode(gameId string, rawData any) { - raw := rawData.(*Raw) - c.Raw = raw -} diff --git a/configs-db/confapi/get.go b/configs-db/confapi/get.go deleted file mode 100644 index 1f13c10..0000000 --- a/configs-db/confapi/get.go +++ /dev/null @@ -1,19 +0,0 @@ -package confapi - -import ( - "apigame/configs-db/confbase" - "errors" -) - -// GetConfig 获取 api游戏配置 -func GetConfig(gameId string) (conf *ApiGameConfig, err error) { - - conf = new(ApiGameConfig) - has := confbase.GetConfig[*ApiGameConfig, Raw](gameId, gameId, conf) - if !has { - err = errors.New("confapi.GetConfig error") - return - } - - return -} diff --git a/configs-db/confbase/external.go b/configs-db/confbase/external.go deleted file mode 100644 index a3568db..0000000 --- a/configs-db/confbase/external.go +++ /dev/null @@ -1,113 +0,0 @@ -package confbase - -import ( - "apigame/util/util-lx/lxalilog" - "apigame/util/zjson" - "apigame/util/zredis" - "fmt" - "runtime/debug" -) - -var CacheState = 1 // 0=关闭 1=打开 - -func SaveCache[T IConfData](gameId string, obj T) { - info := obj.ConfInfo(gameId) - _ = zredis.SetEx(info.CacheKey, zjson.Str(obj), info.CacheTime) -} - -func LoadCache[T IConfData](gameId string, obj T) (has bool) { - if CacheState == 0 { - return false - } - has = true - info := obj.ConfInfo(gameId) - text, err := zredis.Get(info.CacheKey) - if err != nil { - has = false - return - } - err = zjson.Obj(text, &obj) - if err != nil { - fmt.Println(err) - has = false - return - } - return -} - -func LoadData[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { - confRaw := new(T2) - info := obj.ConfInfo(gameId) - db := info.DbMysql - result := db.Table(info.TableName).Where(fmt.Sprintf("%s = ?", info.KeyName), confId).First(confRaw) - - has = result.RowsAffected != 0 - err := result.Error - if err != nil { - lxalilog.Errors(err, "confbase.LoadData error", gameId, confId) - fmt.Printf("%s", debug.Stack()) - return - } - if !has { - return - } - - obj.Decode(gameId, confRaw) - return -} - -func FindDuringTime[T1 IConfData, T2 IConfRawData](obj T1, raw *T2, gameId string) (has bool) { - info := obj.ConfInfo(gameId) - db := info.DbMysql - result := db.Table(info.TableName).Where(info.CurrentQuery, info.CurrentArgs...).First(raw) - has = result.RowsAffected != 0 - return -} - -func GetConfig[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { - has = LoadCache(gameId, obj) - if has { - return - } - has = LoadData[T1, T2](gameId, confId, obj) - if !has { - return - } - SaveCache(gameId, obj) - return -} - -// GetCurrent 获取 当前配置 -func GetCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { - has := false - info := obj.ConfInfo(gameId) - currentKey := info.CacheCurrent - currentId := zredis.GetString(currentKey) - if currentId != "" { - has = GetConfig[T1, T2](gameId, currentId, obj) - if has { - if !obj.CheckCurrent() { - has = false - } - } - } - return has -} - -// FindCurrent 查找 当前配置 -func FindCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { - has := false - info := obj.ConfInfo(gameId) - currentKey := info.CacheCurrent - currentId := zredis.GetString(currentKey) - confRaw := new(T2) - has = FindDuringTime[T1, T2](obj, confRaw, gameId) - if has { - obj.Decode(gameId, confRaw) - SaveCache(gameId, obj) - has = true - currentId = obj.GetUid() - _ = zredis.Set(currentKey, currentId) - } - return has -} diff --git a/configs-db/confbase/interface.go b/configs-db/confbase/interface.go deleted file mode 100644 index 7974c97..0000000 --- a/configs-db/confbase/interface.go +++ /dev/null @@ -1,31 +0,0 @@ -package confbase - -import "gorm.io/gorm" - -// ConfInfo 配置对象信息 -type ConfInfo struct { - DbMysql *gorm.DB - TableName string - KeyName string - CurrentQuery any - CurrentArgs []any - CacheKey string - CacheCurrent string - CacheTime int -} - -// IConfData 配置对象 -type IConfData interface { - // ConfInfo redis存储信息 - ConfInfo(suffix string) *ConfInfo - // Decode 解码 - Decode(gameId string, rawData any) - // GetUid 获取keyID - GetUid() string - // CheckCurrent 判断当前开放 - CheckCurrent() bool -} - -// IConfRawData mysql存储对象 -type IConfRawData interface { -} diff --git a/configs-db/confcardholder/config.go b/configs-db/confcardholder/config.go deleted file mode 100644 index 988c051..0000000 --- a/configs-db/confcardholder/config.go +++ /dev/null @@ -1,153 +0,0 @@ -package confcardholder - -import ( - "apigame/configs-db/confbase" - "apigame/service-common/svconst" - "apigame/util/util-lx/lxtime" - "apigame/util/zconvert" - "fmt" -) - -// ActivityConfig 卡牌活动配置 分析后数据 -type ActivityConfig struct { - Raw *ActivityConfigRaw `json:"-"` - - Id int64 // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - Round int // 轮数 - IconPath string // icon资源路径 - - Awards map[string]string // 奖励配置 - AlbumConfig map[int]AlbumConfig // 卡组配置 - CardConfig map[int]CardConfig // 卡牌配置 - CardholderConfig map[int]OpenCardholderConfig // 卡包开卡规则 - NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 - CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 - StarShopConfig map[int]StarShopConfig // 星星商店配置 - ListSequenceId []int // 用户序列组ID列表 - - Client *ActivityConfigClient - GameId string // 所属游戏ID -} - -func (c *ActivityConfig) GetUid() string { - return zconvert.Int64ToStr(c.Id) -} - -func (c *ActivityConfig) CheckCurrent() bool { - timeNow := lxtime.NowUninx() - return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 -} - -func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { - tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) - timeNow := lxtime.NowUninx() - return &confbase.ConfInfo{ - DbMysql: svconst.DbConfig, - TableName: fmt.Sprintf("%s_%s", tableName, suffix), - KeyName: "id", - CurrentQuery: "status = ? AND start_time <= ? AND end_time >= ?", - CurrentArgs: []any{1, timeNow, timeNow}, - CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), - CacheCurrent: cacheKey + ":current", - CacheTime: 300, - } -} - -// ActivityConfigRaw 卡牌活动配置 原始数据 -type ActivityConfigRaw struct { - Id int64 `gorm:"column:id;primaryKey"` // ID - OpenLevel int // 开启等级 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - Round int // 轮数 - IconPath string // icon资源路径 - - Awards string // 奖励配置 - AlbumConfig string // 卡组配置 - CardConfig string // 卡牌配置 - CardHolderConfig string // 卡包开卡规则 - NormalCardStarSequence string // 卡片星级配置 - CardSequenceConfig string // 卡片星级对应卡牌配置 - StarShopConfig string // 星星商店配置 - - Ver string // 版本号 - Status int // 状态 0=关闭 1=开启 - UpdateTime int64 // 修改时间戳 -} - -// ActivityConfigClient 卡牌活动配置 给客户端数据 -type ActivityConfigClient struct { - Id int64 `form:"id" json:"id"` // ID - Round int `form:"round" json:"round"` // 轮数 - IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 - 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 string `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 int `json:"id"` // ID - CardPackIcon string `json:"img"` // 卡包资源名 - IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 - IsNew int `json:"is_new"` // 是否是新卡包 - GuaranteedStarCardId int `json:"guaranteed_star_card_id"` // 保底卡星级序列ID - NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 - MinimumGuaranteeCardId int `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID - ActivityId int `json:"activity_id"` // 对应活动ID - Star int `json:"star"` // star - Name int `json:"name"` // name -} - -// NormalCardStarConfig 非保底卡星级ID -type NormalCardStarConfig struct { - Id int `json:"id"` // ID - SequenceId int `json:"user_sequence_id"` // 用户序列组ID - Cohort int `json:"cohort"` // 用户分组 - NormalCardSequenceId []int `json:"normal_card_sequence_id"` // 非保底星级序列 -} - -// CardSequenceConfig 星级ID对应的卡片 -type CardSequenceConfig struct { - Id int `json:"id"` // ID - SequenceId int `json:"user_sequence_id"` // 用户序列组ID - Cohort int `json:"cohort"` // 用户分组 - CardIdList []int `json:"card_id_list"` // 卡牌抽取序列 -} - -// StarShopConfig 星星商店配置 -type StarShopConfig struct { - Id int `json:"id"` // ID - NeedStarNumber int `json:"need_star_number"` // 需求星星数 - CardBagIds string `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} -} diff --git a/configs-db/confcardholder/decode.go b/configs-db/confcardholder/decode.go deleted file mode 100644 index 95b1182..0000000 --- a/configs-db/confcardholder/decode.go +++ /dev/null @@ -1,177 +0,0 @@ -package confcardholder - -import ( - "apigame/util/util-lx/lxalilog" - "apigame/util/zslice" - "encoding/json" - "errors" - "fmt" -) - -// Decode 解析配置原始数据 -func (c *ActivityConfig) Decode(gameId string, rawData any) { - raw := rawData.(*ActivityConfigRaw) - c.GameId = gameId - c.Raw = raw - - c.Id = raw.Id - c.OpenLevel = raw.OpenLevel - c.PreviewTime = raw.PreviewTime - c.StartTime = raw.StartTime - c.EndTime = raw.EndTime - c.Round = raw.Round - c.IconPath = raw.IconPath - - c.Awards = make(map[string]string) - c.AlbumConfig = make(map[int]AlbumConfig) - c.CardConfig = make(map[int]CardConfig) - c.CardholderConfig = make(map[int]OpenCardholderConfig) - c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) - c.CardSequenceConfig = make(map[string]CardSequenceConfig) - c.StarShopConfig = make(map[int]StarShopConfig) - // 解析奖励 - { - err := json.Unmarshal([]byte(raw.Awards), &c.Awards) - if err != nil { - lxalilog.Errors(err, raw.Awards, gameId, raw.Id) - return - } - } - // 卡组配置 - { - configs := make([]AlbumConfig, 0) - err := json.Unmarshal([]byte(raw.AlbumConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.AlbumConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.AlbumConfig[i2.SetId] = i2 - } - } - // 卡牌配置 - { - configs := make([]CardConfig, 0) - err := json.Unmarshal([]byte(raw.CardConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.CardConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.CardConfig[i2.Id] = i2 - } - } - // 卡包开卡规则 - { - configs := make([]OpenCardholderConfig, 0) - err := json.Unmarshal([]byte(raw.CardHolderConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.CardHolderConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.CardholderConfig[i2.Id] = i2 - } - } - // 卡片星级配置 - { - configs := make([]NormalCardStarConfig, 0) - err := json.Unmarshal([]byte(raw.NormalCardStarSequence), &configs) - if err != nil { - lxalilog.Errors(err, raw.NormalCardStarSequence, gameId, raw.Id) - return - } - for _, i2 := range configs { - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) - c.NormalCardStarConfig[combineId] = i2 - if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { - c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) - } - } - } - // 卡片星级对应卡牌配置 - { - configs := make([]CardSequenceConfig, 0) - err := json.Unmarshal([]byte(raw.CardSequenceConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.CardSequenceConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) - c.CardSequenceConfig[combineId] = i2 - if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { - c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) - } - } - } - // 星星商店配置 - { - configs := make([]StarShopConfig, 0) - err := json.Unmarshal([]byte(raw.StarShopConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.StarShopConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.StarShopConfig[i2.Id] = i2 - } - } - - c.GenerateConfigClient() -} - -// GenerateConfigClient 生成给客户端的配置 -func (c *ActivityConfig) GenerateConfigClient() { - configClient := &ActivityConfigClient{ - Id: c.Id, - Round: c.Round, - IconPath: c.IconPath, - 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 int) string { - return fmt.Sprintf("%d_%d_%d", id, sequenceId, cohort) -} - -// FindNormalCardStarConfig 查找配置 非保底卡星级ID -func (c *ActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort int) (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 *ActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort int) (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-db/confcardholder/get.go b/configs-db/confcardholder/get.go deleted file mode 100644 index 6b1f161..0000000 --- a/configs-db/confcardholder/get.go +++ /dev/null @@ -1,24 +0,0 @@ -package confcardholder - -import ( - "apigame/configs-db/confbase" -) - -// GetCurrent 获取 当前配置 -func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { - conf = new(ActivityConfig) - has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) - if !has { - conf = new(ActivityConfig) - has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) - } - return -} - -// GetConfig 获取 配置根据Id -func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { - conf = new(ActivityConfig) - has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) - - return -} diff --git a/configs-db/confglobal/config.go b/configs-db/confglobal/config.go deleted file mode 100644 index 6d60780..0000000 --- a/configs-db/confglobal/config.go +++ /dev/null @@ -1,67 +0,0 @@ -package confglobal - -import ( - "apigame/configs-db/confbase" - "apigame/service-common/svconst" - "apigame/util/util-lx/lxalilog" - "encoding/json" - "fmt" -) - -// GlobalConfig 全局配置 -type GlobalConfig struct { - Raw *Raw `json:"-"` - Names []string - Avatars []string - AvatarPath string -} - -func (c *GlobalConfig) GetUid() string { - return c.Raw.GameId -} - -func (c *GlobalConfig) CheckCurrent() bool { - return true -} - -func (c *GlobalConfig) ConfInfo(suffix string) *confbase.ConfInfo { - tableName := "s_game_global_config" - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) - return &confbase.ConfInfo{ - DbMysql: svconst.DbConfig, - TableName: tableName, - KeyName: "gameid", - CacheKey: cacheKey, - CacheCurrent: cacheKey + ":current", - CacheTime: 300, - } -} - -// Raw 配置原始数据 -type Raw struct { - GameId string `gorm:"column:gameid"` - NameConfig string - AvatarConfig string - AvatarPath string -} - -// Decode 解析配置原始数据 -func (c *GlobalConfig) Decode(gameId string, rawData any) { - raw := rawData.(*Raw) - c.Raw = raw - { - err := json.Unmarshal([]byte(raw.NameConfig), &c.Names) - if err != nil { - lxalilog.Errors(err, raw.NameConfig, gameId, raw.GameId) - return - } - } - { - err := json.Unmarshal([]byte(raw.AvatarConfig), &c.Avatars) - if err != nil { - lxalilog.Errors(err, raw.AvatarConfig, gameId, raw.GameId) - return - } - } - c.AvatarPath = raw.AvatarPath -} diff --git a/configs-db/confglobal/get.go b/configs-db/confglobal/get.go deleted file mode 100644 index 0ad90fe..0000000 --- a/configs-db/confglobal/get.go +++ /dev/null @@ -1,19 +0,0 @@ -package confglobal - -import ( - "apigame/configs-db/confbase" - "errors" -) - -// GetConfig 获取 api游戏配置 -func GetConfig(gameId string) (conf *GlobalConfig, err error) { - - conf = new(GlobalConfig) - has := confbase.GetConfig[*GlobalConfig, Raw](gameId, gameId, conf) - if !has { - err = errors.New("confglobal.GetConfig error") - return - } - - return -} diff --git a/configs-db/confroomrank/config.go b/configs-db/confroomrank/config.go deleted file mode 100644 index bf24f63..0000000 --- a/configs-db/confroomrank/config.go +++ /dev/null @@ -1,129 +0,0 @@ -package confroomrank - -import ( - "apigame/configs-db/confbase" - "apigame/service-common/svconst" - "apigame/util/util-lx/lxtime" - "apigame/util/zconvert" - "fmt" -) - -// ActivityConfig 房间排行活动配置 分析后数据 -type ActivityConfig struct { - Raw *ActivityConfigRaw `json:"-"` - - Id int64 // ID - Typ int // 排行榜类型 - OpenLevel int // 开启等级 - OpenScore int64 // 开启积分 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - ReleaseTime string // 结算发奖时间 - - Robot map[int]RobotConfig // 机器人配置 - Room map[int]RoomConfig // 房间配置 - - GameId string // 所属游戏ID -} - -func (c *ActivityConfig) GetUid() string { - return zconvert.Int64ToStr(c.Id) -} - -func (c *ActivityConfig) CheckCurrent() bool { - timeNow := lxtime.NowUninx() - return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 -} - -func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) - timeNow := lxtime.NowUninx() - return &confbase.ConfInfo{ - DbMysql: svconst.DbConfig, - TableName: fmt.Sprintf("%s_%s", tableName, suffix), - KeyName: "id", - CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?", - CurrentArgs: []any{c.Typ, 1, timeNow, timeNow}, - CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), - CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ), - CacheTime: 300, - } -} - -// ActivityConfigRaw 房间排行活动配置 原始数据 -type ActivityConfigRaw struct { - Id int64 `gorm:"column:id;primaryKey"` // ID - Serial int64 // 轮次ID - Typ int // 排行榜类型 - OpenLevel int // 开启等级 - OpenScore int64 // 开启积分 - PreviewTime int64 // 预告时间 - StartTime int64 // 开始时间 - EndTime int64 // 结束时间 - ReleaseTime string // 结算发奖时间 - - BootConfig string // 机器人配置 - RoomConfig string // 房间配置 - - Ver string // 版本号 - Status int // 状态 0=关闭 1=开启 - UpdateTime int64 // 修改时间戳 -} - -// GenerateConfigClient 生成给客户端的配置 -func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { - configClient := &ActivityConfigClient{ - Id: c.Id, - Typ: c.Typ, - Serial: c.Serial, - OpenLevel: c.OpenLevel, - OpenScore: c.OpenScore, - PreviewTime: c.PreviewTime, - StartTime: c.StartTime, - EndTime: c.EndTime, - ReleaseTime: c.ReleaseTime, - Ver: c.Ver, - Status: c.Status, - } - return configClient -} - -// ActivityConfigClient 房间排行活动配置 给客户端数据 -type ActivityConfigClient struct { - Id int64 `form:"id" json:"id"` // ID - Typ int `form:"typ" json:"typ"` // 排行榜类型 - Serial int64 `form:"serial" json:"serial"` // 轮次ID - OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 - OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 - PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 - StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 - EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 - ReleaseTime string `form:"release_time" json:"release_time"` // 结算发奖时间 - Ver string `form:"ver" json:"ver"` // 版本号 - Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启 -} - -// RobotConfig 机器人配置 -type RobotConfig struct { - Id int `json:"id"` // id - MinScore int `json:"min_score"` // 最低分数 - TotalScore int `json:"total_score"` // 总分数 - Range int `json:"range"` // 总分浮动范围(%) -} - -// RoomConfig 房间配置 -type RoomConfig struct { - Id int `json:"id"` // id - Levels []int `json:"level_range"` // 等级范围 - UserClass int `json:"rating"` // 评级 - UserScore []int `json:"score_range"` // 分数范围 - TotalPlayer int `json:"room_user_number"` // 房间总人数 - PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量 - AutoRobot []int `json:"auto_room"` // 自动填充机器人 - InitRobot [][]int `json:"disposition_robots"` // 配置机器人 - Awards map[string]string `json:"rewards"` // 奖励 - SettleScores []int `json:"score_adjest"` // 结算分数调整 - SettleUserType []int `json:"user_type"` // 结算用户类型 -} diff --git a/configs-db/confroomrank/decode.go b/configs-db/confroomrank/decode.go deleted file mode 100644 index e7e4aa4..0000000 --- a/configs-db/confroomrank/decode.go +++ /dev/null @@ -1,50 +0,0 @@ -package confroomrank - -import ( - "apigame/util/util-lx/lxalilog" - "encoding/json" -) - -// Decode 解析配置原始数据 -func (c *ActivityConfig) Decode(gameId string, rawData any) { - raw := rawData.(*ActivityConfigRaw) - c.GameId = gameId - c.Raw = raw - - c.Id = raw.Id - c.Typ = raw.Typ - c.OpenLevel = raw.OpenLevel - c.OpenScore = raw.OpenScore - c.PreviewTime = raw.PreviewTime - c.StartTime = raw.StartTime - c.EndTime = raw.EndTime - c.ReleaseTime = raw.ReleaseTime - - c.Robot = make(map[int]RobotConfig) - c.Room = make(map[int]RoomConfig) - - // 解析 机器人 - { - configs := make([]RobotConfig, 0) - err := json.Unmarshal([]byte(raw.BootConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.Robot[i2.Id] = i2 - } - } - // 解析 房间 - { - configs := make([]RoomConfig, 0) - err := json.Unmarshal([]byte(raw.RoomConfig), &configs) - if err != nil { - lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id) - return - } - for _, i2 := range configs { - c.Room[i2.Id] = i2 - } - } -} diff --git a/configs-db/confroomrank/get.go b/configs-db/confroomrank/get.go deleted file mode 100644 index 29c2388..0000000 --- a/configs-db/confroomrank/get.go +++ /dev/null @@ -1,44 +0,0 @@ -package confroomrank - -import ( - "apigame/configs-db/confbase" - "apigame/util/util-lx/lxalilog" - "apigame/util/util-lx/lxtime" -) - -// GetCurrent 获取 当前配置 -func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { - conf = new(ActivityConfig) - conf.Typ = topType - has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) - if !has { - conf = new(ActivityConfig) - conf.Typ = topType - has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) - } - return -} - -// GetConfig 获取 配置根据Id -func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { - conf = new(ActivityConfig) - has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) - - return -} - -// GetCurrentConfigs 获取当前配置列表 -func GetCurrentConfigs(gameId string) []*ActivityConfigRaw { - obj := new(ActivityConfig) - info := obj.ConfInfo(gameId) - db := info.DbMysql - timeNow := lxtime.NowUninx() - objs := make([]*ActivityConfigRaw, 0) - result := db.Table(info.TableName).Where( - "status = ? AND start_time <= ? AND end_time >= ?", - 1, timeNow, timeNow).Find(&objs) - if result.Error != nil { - lxalilog.Errors(result.Error, "confroomrank.GetCurrentConfigs error", gameId) - } - return objs -} diff --git a/configs-db/init.go b/configs-db/init.go deleted file mode 100644 index 57072c5..0000000 --- a/configs-db/init.go +++ /dev/null @@ -1,29 +0,0 @@ -package configs_db - -import ( - "apigame/configs-db/confapi" - "apigame/configs-db/confcardholder" - "apigame/configs-db/confglobal" - "apigame/service-common/svconst" -) - -func Init() bool { - - for _, gameId := range svconst.GameList { - _, _ = confapi.GetConfig(gameId) - } - - for _, gameId := range svconst.GameList { - _, _ = confglobal.GetConfig(gameId) - } - - for _, gameId := range svconst.GameListCardHolder { - _, _ = confcardholder.GetCurrent(gameId) - } - - //for _, gameId := range svconst.GameListRoomRank { - // _, _ = confroomrank.GetCurrent(gameId) - //} - - return true -} diff --git a/configs/confapi/config.go b/configs/confapi/config.go new file mode 100644 index 0000000..2cbe322 --- /dev/null +++ b/configs/confapi/config.go @@ -0,0 +1,48 @@ +package confapi + +import ( + "apigame/configs/confbase" + "apigame/service-common/svconst" + "fmt" +) + +// ApiGameConfig api游戏配置 +type ApiGameConfig struct { + Raw *Raw +} + +func (c *ApiGameConfig) GetUid() string { + return c.Raw.GameId +} + +func (c *ApiGameConfig) CheckCurrent() bool { + return true +} + +func (c *ApiGameConfig) ConfInfo(suffix string) *confbase.ConfInfo { + tableName := "s_game_config" + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) + return &confbase.ConfInfo{ + DbMysql: svconst.DbApi, + TableName: tableName, + KeyName: "gameid", + CacheKey: cacheKey, + CacheCurrent: cacheKey + ":current", + CacheTime: 300, + } +} + +// Raw 配置原始数据 +type Raw 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"` +} + +// Decode 解析配置原始数据 +func (c *ApiGameConfig) Decode(gameId string, rawData any) { + raw := rawData.(*Raw) + c.Raw = raw +} diff --git a/configs/confapi/get.go b/configs/confapi/get.go new file mode 100644 index 0000000..fcaa1f8 --- /dev/null +++ b/configs/confapi/get.go @@ -0,0 +1,19 @@ +package confapi + +import ( + "apigame/configs/confbase" + "errors" +) + +// GetConfig 获取 api游戏配置 +func GetConfig(gameId string) (conf *ApiGameConfig, err error) { + + conf = new(ApiGameConfig) + has := confbase.GetConfig[*ApiGameConfig, Raw](gameId, gameId, conf) + if !has { + err = errors.New("confapi.GetConfig error") + return + } + + return +} diff --git a/configs/confbase/external.go b/configs/confbase/external.go new file mode 100644 index 0000000..a3568db --- /dev/null +++ b/configs/confbase/external.go @@ -0,0 +1,113 @@ +package confbase + +import ( + "apigame/util/util-lx/lxalilog" + "apigame/util/zjson" + "apigame/util/zredis" + "fmt" + "runtime/debug" +) + +var CacheState = 1 // 0=关闭 1=打开 + +func SaveCache[T IConfData](gameId string, obj T) { + info := obj.ConfInfo(gameId) + _ = zredis.SetEx(info.CacheKey, zjson.Str(obj), info.CacheTime) +} + +func LoadCache[T IConfData](gameId string, obj T) (has bool) { + if CacheState == 0 { + return false + } + has = true + info := obj.ConfInfo(gameId) + text, err := zredis.Get(info.CacheKey) + if err != nil { + has = false + return + } + err = zjson.Obj(text, &obj) + if err != nil { + fmt.Println(err) + has = false + return + } + return +} + +func LoadData[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { + confRaw := new(T2) + info := obj.ConfInfo(gameId) + db := info.DbMysql + result := db.Table(info.TableName).Where(fmt.Sprintf("%s = ?", info.KeyName), confId).First(confRaw) + + has = result.RowsAffected != 0 + err := result.Error + if err != nil { + lxalilog.Errors(err, "confbase.LoadData error", gameId, confId) + fmt.Printf("%s", debug.Stack()) + return + } + if !has { + return + } + + obj.Decode(gameId, confRaw) + return +} + +func FindDuringTime[T1 IConfData, T2 IConfRawData](obj T1, raw *T2, gameId string) (has bool) { + info := obj.ConfInfo(gameId) + db := info.DbMysql + result := db.Table(info.TableName).Where(info.CurrentQuery, info.CurrentArgs...).First(raw) + has = result.RowsAffected != 0 + return +} + +func GetConfig[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { + has = LoadCache(gameId, obj) + if has { + return + } + has = LoadData[T1, T2](gameId, confId, obj) + if !has { + return + } + SaveCache(gameId, obj) + return +} + +// GetCurrent 获取 当前配置 +func GetCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { + has := false + info := obj.ConfInfo(gameId) + currentKey := info.CacheCurrent + currentId := zredis.GetString(currentKey) + if currentId != "" { + has = GetConfig[T1, T2](gameId, currentId, obj) + if has { + if !obj.CheckCurrent() { + has = false + } + } + } + return has +} + +// FindCurrent 查找 当前配置 +func FindCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { + has := false + info := obj.ConfInfo(gameId) + currentKey := info.CacheCurrent + currentId := zredis.GetString(currentKey) + confRaw := new(T2) + has = FindDuringTime[T1, T2](obj, confRaw, gameId) + if has { + obj.Decode(gameId, confRaw) + SaveCache(gameId, obj) + has = true + currentId = obj.GetUid() + _ = zredis.Set(currentKey, currentId) + } + return has +} diff --git a/configs/confbase/interface.go b/configs/confbase/interface.go new file mode 100644 index 0000000..7974c97 --- /dev/null +++ b/configs/confbase/interface.go @@ -0,0 +1,31 @@ +package confbase + +import "gorm.io/gorm" + +// ConfInfo 配置对象信息 +type ConfInfo struct { + DbMysql *gorm.DB + TableName string + KeyName string + CurrentQuery any + CurrentArgs []any + CacheKey string + CacheCurrent string + CacheTime int +} + +// IConfData 配置对象 +type IConfData interface { + // ConfInfo redis存储信息 + ConfInfo(suffix string) *ConfInfo + // Decode 解码 + Decode(gameId string, rawData any) + // GetUid 获取keyID + GetUid() string + // CheckCurrent 判断当前开放 + CheckCurrent() bool +} + +// IConfRawData mysql存储对象 +type IConfRawData interface { +} diff --git a/configs/confcardholder/config.go b/configs/confcardholder/config.go new file mode 100644 index 0000000..a5f262f --- /dev/null +++ b/configs/confcardholder/config.go @@ -0,0 +1,153 @@ +package confcardholder + +import ( + "apigame/configs/confbase" + "apigame/service-common/svconst" + "apigame/util/util-lx/lxtime" + "apigame/util/zconvert" + "fmt" +) + +// ActivityConfig 卡牌活动配置 分析后数据 +type ActivityConfig struct { + Raw *ActivityConfigRaw `json:"-"` + + Id int64 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + Round int // 轮数 + IconPath string // icon资源路径 + + Awards map[string]string // 奖励配置 + AlbumConfig map[int]AlbumConfig // 卡组配置 + CardConfig map[int]CardConfig // 卡牌配置 + CardholderConfig map[int]OpenCardholderConfig // 卡包开卡规则 + NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 + CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 + StarShopConfig map[int]StarShopConfig // 星星商店配置 + ListSequenceId []int // 用户序列组ID列表 + + Client *ActivityConfigClient + GameId string // 所属游戏ID +} + +func (c *ActivityConfig) GetUid() string { + return zconvert.Int64ToStr(c.Id) +} + +func (c *ActivityConfig) CheckCurrent() bool { + timeNow := lxtime.NowUninx() + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 +} + +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) + timeNow := lxtime.NowUninx() + return &confbase.ConfInfo{ + DbMysql: svconst.DbConfig, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), + KeyName: "id", + CurrentQuery: "status = ? AND start_time <= ? AND end_time >= ?", + CurrentArgs: []any{1, timeNow, timeNow}, + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), + CacheCurrent: cacheKey + ":current", + CacheTime: 300, + } +} + +// ActivityConfigRaw 卡牌活动配置 原始数据 +type ActivityConfigRaw struct { + Id int64 `gorm:"column:id;primaryKey"` // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + Round int // 轮数 + IconPath string // icon资源路径 + + Awards string // 奖励配置 + AlbumConfig string // 卡组配置 + CardConfig string // 卡牌配置 + CardHolderConfig string // 卡包开卡规则 + NormalCardStarSequence string // 卡片星级配置 + CardSequenceConfig string // 卡片星级对应卡牌配置 + StarShopConfig string // 星星商店配置 + + Ver string // 版本号 + Status int // 状态 0=关闭 1=开启 + UpdateTime int64 // 修改时间戳 +} + +// ActivityConfigClient 卡牌活动配置 给客户端数据 +type ActivityConfigClient struct { + Id int64 `form:"id" json:"id"` // ID + Round int `form:"round" json:"round"` // 轮数 + IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 + 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 string `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 int `json:"id"` // ID + CardPackIcon string `json:"img"` // 卡包资源名 + IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 + IsNew int `json:"is_new"` // 是否是新卡包 + GuaranteedStarCardId int `json:"guaranteed_star_card_id"` // 保底卡星级序列ID + NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 + MinimumGuaranteeCardId int `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID + ActivityId int `json:"activity_id"` // 对应活动ID + Star int `json:"star"` // star + Name int `json:"name"` // name +} + +// NormalCardStarConfig 非保底卡星级ID +type NormalCardStarConfig struct { + Id int `json:"id"` // ID + SequenceId int `json:"user_sequence_id"` // 用户序列组ID + Cohort int `json:"cohort"` // 用户分组 + NormalCardSequenceId []int `json:"normal_card_sequence_id"` // 非保底星级序列 +} + +// CardSequenceConfig 星级ID对应的卡片 +type CardSequenceConfig struct { + Id int `json:"id"` // ID + SequenceId int `json:"user_sequence_id"` // 用户序列组ID + Cohort int `json:"cohort"` // 用户分组 + CardIdList []int `json:"card_id_list"` // 卡牌抽取序列 +} + +// StarShopConfig 星星商店配置 +type StarShopConfig struct { + Id int `json:"id"` // ID + NeedStarNumber int `json:"need_star_number"` // 需求星星数 + CardBagIds string `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} +} diff --git a/configs/confcardholder/decode.go b/configs/confcardholder/decode.go new file mode 100644 index 0000000..95b1182 --- /dev/null +++ b/configs/confcardholder/decode.go @@ -0,0 +1,177 @@ +package confcardholder + +import ( + "apigame/util/util-lx/lxalilog" + "apigame/util/zslice" + "encoding/json" + "errors" + "fmt" +) + +// Decode 解析配置原始数据 +func (c *ActivityConfig) Decode(gameId string, rawData any) { + raw := rawData.(*ActivityConfigRaw) + c.GameId = gameId + c.Raw = raw + + c.Id = raw.Id + c.OpenLevel = raw.OpenLevel + c.PreviewTime = raw.PreviewTime + c.StartTime = raw.StartTime + c.EndTime = raw.EndTime + c.Round = raw.Round + c.IconPath = raw.IconPath + + c.Awards = make(map[string]string) + c.AlbumConfig = make(map[int]AlbumConfig) + c.CardConfig = make(map[int]CardConfig) + c.CardholderConfig = make(map[int]OpenCardholderConfig) + c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) + c.CardSequenceConfig = make(map[string]CardSequenceConfig) + c.StarShopConfig = make(map[int]StarShopConfig) + // 解析奖励 + { + err := json.Unmarshal([]byte(raw.Awards), &c.Awards) + if err != nil { + lxalilog.Errors(err, raw.Awards, gameId, raw.Id) + return + } + } + // 卡组配置 + { + configs := make([]AlbumConfig, 0) + err := json.Unmarshal([]byte(raw.AlbumConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.AlbumConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.AlbumConfig[i2.SetId] = i2 + } + } + // 卡牌配置 + { + configs := make([]CardConfig, 0) + err := json.Unmarshal([]byte(raw.CardConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.CardConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.CardConfig[i2.Id] = i2 + } + } + // 卡包开卡规则 + { + configs := make([]OpenCardholderConfig, 0) + err := json.Unmarshal([]byte(raw.CardHolderConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.CardHolderConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.CardholderConfig[i2.Id] = i2 + } + } + // 卡片星级配置 + { + configs := make([]NormalCardStarConfig, 0) + err := json.Unmarshal([]byte(raw.NormalCardStarSequence), &configs) + if err != nil { + lxalilog.Errors(err, raw.NormalCardStarSequence, gameId, raw.Id) + return + } + for _, i2 := range configs { + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) + c.NormalCardStarConfig[combineId] = i2 + if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { + c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) + } + } + } + // 卡片星级对应卡牌配置 + { + configs := make([]CardSequenceConfig, 0) + err := json.Unmarshal([]byte(raw.CardSequenceConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.CardSequenceConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) + c.CardSequenceConfig[combineId] = i2 + if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { + c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) + } + } + } + // 星星商店配置 + { + configs := make([]StarShopConfig, 0) + err := json.Unmarshal([]byte(raw.StarShopConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.StarShopConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.StarShopConfig[i2.Id] = i2 + } + } + + c.GenerateConfigClient() +} + +// GenerateConfigClient 生成给客户端的配置 +func (c *ActivityConfig) GenerateConfigClient() { + configClient := &ActivityConfigClient{ + Id: c.Id, + Round: c.Round, + IconPath: c.IconPath, + 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 int) string { + return fmt.Sprintf("%d_%d_%d", id, sequenceId, cohort) +} + +// FindNormalCardStarConfig 查找配置 非保底卡星级ID +func (c *ActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort int) (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 *ActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort int) (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/confcardholder/get.go b/configs/confcardholder/get.go new file mode 100644 index 0000000..cc7efdb --- /dev/null +++ b/configs/confcardholder/get.go @@ -0,0 +1,24 @@ +package confcardholder + +import ( + "apigame/configs/confbase" +) + +// GetCurrent 获取 当前配置 +func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) + if !has { + conf = new(ActivityConfig) + has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) + } + return +} + +// GetConfig 获取 配置根据Id +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) + + return +} diff --git a/configs/confglobal/config.go b/configs/confglobal/config.go new file mode 100644 index 0000000..1ff7805 --- /dev/null +++ b/configs/confglobal/config.go @@ -0,0 +1,67 @@ +package confglobal + +import ( + "apigame/configs/confbase" + "apigame/service-common/svconst" + "apigame/util/util-lx/lxalilog" + "encoding/json" + "fmt" +) + +// GlobalConfig 全局配置 +type GlobalConfig struct { + Raw *Raw `json:"-"` + Names []string + Avatars []string + AvatarPath string +} + +func (c *GlobalConfig) GetUid() string { + return c.Raw.GameId +} + +func (c *GlobalConfig) CheckCurrent() bool { + return true +} + +func (c *GlobalConfig) ConfInfo(suffix string) *confbase.ConfInfo { + tableName := "s_game_global_config" + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) + return &confbase.ConfInfo{ + DbMysql: svconst.DbConfig, + TableName: tableName, + KeyName: "gameid", + CacheKey: cacheKey, + CacheCurrent: cacheKey + ":current", + CacheTime: 300, + } +} + +// Raw 配置原始数据 +type Raw struct { + GameId string `gorm:"column:gameid"` + NameConfig string + AvatarConfig string + AvatarPath string +} + +// Decode 解析配置原始数据 +func (c *GlobalConfig) Decode(gameId string, rawData any) { + raw := rawData.(*Raw) + c.Raw = raw + { + err := json.Unmarshal([]byte(raw.NameConfig), &c.Names) + if err != nil { + lxalilog.Errors(err, raw.NameConfig, gameId, raw.GameId) + return + } + } + { + err := json.Unmarshal([]byte(raw.AvatarConfig), &c.Avatars) + if err != nil { + lxalilog.Errors(err, raw.AvatarConfig, gameId, raw.GameId) + return + } + } + c.AvatarPath = raw.AvatarPath +} diff --git a/configs/confglobal/get.go b/configs/confglobal/get.go new file mode 100644 index 0000000..ca4cfe1 --- /dev/null +++ b/configs/confglobal/get.go @@ -0,0 +1,19 @@ +package confglobal + +import ( + "apigame/configs/confbase" + "errors" +) + +// GetConfig 获取 api游戏配置 +func GetConfig(gameId string) (conf *GlobalConfig, err error) { + + conf = new(GlobalConfig) + has := confbase.GetConfig[*GlobalConfig, Raw](gameId, gameId, conf) + if !has { + err = errors.New("confglobal.GetConfig error") + return + } + + return +} diff --git a/configs/config.go b/configs/config.go deleted file mode 100644 index 8fa1308..0000000 --- a/configs/config.go +++ /dev/null @@ -1,282 +0,0 @@ -// DO NOT EDIT! -// This code is auto generated by go-xlsx-exporter -// VERSION 1.3 -// go-protobuf v1.27.1 - -package configs - -import ( - reflect "reflect" - sync "sync" - - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -/* type ConvertHandler func (field string, value interface{}) interface{} - -type MessageBase struct { - -} - -func (item *MessageBase) GetConvertData(field string, value interface{}) { - -} */ -// Defined in table: data/abtest.xlsx:abtest; -type AbTestCfg struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ID uint32 `protobuf:"varint,1,opt,name=ID,proto3uint32" json:"ID,omitempty"` /** 编号 */ - - Name string `protobuf:"bytes,2,opt,name=Name,proto3string" json:"Name,omitempty"` /** 分组名 */ - - Min uint32 `protobuf:"varint,3,opt,name=Min,proto3uint32" json:"Min,omitempty"` /** ID下限 */ - - Max uint32 `protobuf:"varint,4,opt,name=Max,proto3uint32" json:"Max,omitempty"` /** ID上限 */ - - Condition string `protobuf:"bytes,5,opt,name=Condition,proto3string" json:"Condition,omitempty"` /** 条件 */ - - Config string `protobuf:"bytes,6,opt,name=Config,proto3string" json:"Config,omitempty"` /** 配置 */ - -} - -func (x *AbTestCfg) Reset() { - *x = AbTestCfg{} - if protoimpl.UnsafeEnabled { - mi := &file_config_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AbTestCfg) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AbTestCfg) ProtoMessage() {} - -func (x *AbTestCfg) ProtoReflect() protoreflect.Message { - mi := &file_config_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AbTestCfg.ProtoReflect.Descriptor instead. -func (*AbTestCfg) Descriptor() ([]byte, []int) { - return file_config_proto_rawDescGZIP(), []int{0} -} - -func (x *AbTestCfg) GetID() uint32 { - if x != nil { - return x.ID - } - return 0 -} - -func (x *AbTestCfg) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *AbTestCfg) GetMin() uint32 { - if x != nil { - return x.Min - } - return 0 -} - -func (x *AbTestCfg) GetMax() uint32 { - if x != nil { - return x.Max - } - return 0 -} - -func (x *AbTestCfg) GetCondition() string { - if x != nil { - return x.Condition - } - return "" -} - -func (x *AbTestCfg) GetConfig() string { - if x != nil { - return x.Config - } - return "" -} - - -// Defined in table: data/abtest.xlsx:abtest; -type AbTestCfg_ARRAY struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - - Items []*AbTestCfg `protobuf:"bytes,1,rep,name=Items,proto3*AbTestCfg" json:"Items,omitempty"` - -} - -func (x *AbTestCfg_ARRAY) Reset() { - *x = AbTestCfg_ARRAY{} - if protoimpl.UnsafeEnabled { - mi := &file_config_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AbTestCfg_ARRAY) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AbTestCfg_ARRAY) ProtoMessage() {} - -func (x *AbTestCfg_ARRAY) ProtoReflect() protoreflect.Message { - mi := &file_config_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use AbTestCfg_ARRAY.ProtoReflect.Descriptor instead. -func (*AbTestCfg_ARRAY) Descriptor() ([]byte, []int) { - return file_config_proto_rawDescGZIP(), []int{1} -} - -func (x *AbTestCfg_ARRAY) GetItems() []*AbTestCfg { - if x != nil { - return x.Items - } - return nil -} - - -var File_config_proto protoreflect.FileDescriptor - -var file_config_proto_rawDesc = []byte{ -0x0a,0x0c,0x63,0x6f,0x6e,0x66,0x69,0x67,0x2e,0x70,0x72,0x6f,0x74,0x6f,0x12,0x07, -0x63,0x6f,0x6e,0x66,0x69,0x67,0x73,0x22,0x89,0x01,0x0a,0x09,0x41,0x62,0x54,0x65, -0x73,0x74,0x43,0x66,0x67,0x12,0x0e,0x0a,0x02,0x49,0x44,0x18,0x01,0x20,0x01,0x28, -0x0d,0x52,0x02,0x49,0x44,0x12,0x12,0x0a,0x04,0x4e,0x61,0x6d,0x65,0x18,0x02,0x20, -0x01,0x28,0x09,0x52,0x04,0x4e,0x61,0x6d,0x65,0x12,0x10,0x0a,0x03,0x4d,0x69,0x6e, -0x18,0x03,0x20,0x01,0x28,0x0d,0x52,0x03,0x4d,0x69,0x6e,0x12,0x10,0x0a,0x03,0x4d, -0x61,0x78,0x18,0x04,0x20,0x01,0x28,0x0d,0x52,0x03,0x4d,0x61,0x78,0x12,0x1c,0x0a, -0x09,0x43,0x6f,0x6e,0x64,0x69,0x74,0x69,0x6f,0x6e,0x18,0x05,0x20,0x01,0x28,0x09, -0x52,0x09,0x43,0x6f,0x6e,0x64,0x69,0x74,0x69,0x6f,0x6e,0x12,0x16,0x0a,0x06,0x43, -0x6f,0x6e,0x66,0x69,0x67,0x18,0x06,0x20,0x01,0x28,0x09,0x52,0x06,0x43,0x6f,0x6e, -0x66,0x69,0x67,0x22,0x3b,0x0a,0x0f,0x41,0x62,0x54,0x65,0x73,0x74,0x43,0x66,0x67, -0x5f,0x41,0x52,0x52,0x41,0x59,0x12,0x28,0x0a,0x05,0x49,0x74,0x65,0x6d,0x73,0x18, -0x01,0x20,0x03,0x28,0x0b,0x32,0x12,0x2e,0x63,0x6f,0x6e,0x66,0x69,0x67,0x73,0x2e, -0x41,0x62,0x54,0x65,0x73,0x74,0x43,0x66,0x67,0x52,0x05,0x49,0x74,0x65,0x6d,0x73, -0x62,0x06,0x70,0x72,0x6f,0x74,0x6f,0x33, -} - -var ( - file_config_proto_rawDescOnce sync.Once - file_config_proto_rawDescData = file_config_proto_rawDesc -) - -func file_config_proto_rawDescGZIP() []byte { - file_config_proto_rawDescOnce.Do(func() { - file_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_config_proto_rawDescData) - }) - return file_config_proto_rawDescData -} - -var file_config_proto_enumTypes = make([]protoimpl.EnumInfo, 0) -var file_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_config_proto_goTypes = []interface{}{ - (*AbTestCfg)(nil), // 0: configs.AbTestCfg - (*AbTestCfg_ARRAY)(nil), // 1: configs.AbTestCfg_ARRAY - -} - -var file_config_proto_depIdxs = []int32{ - 0, // 0: configs.AbTestCfg_ARRAY:type_name -> configs.AbTestCfg -1, // [1:1] is the sub-list for method output_type -1, // [1:1] is the sub-list for method input_type -1, // [1:1] is the sub-list for extension type_name -1, // [1:1] is the sub-list for extension extendee -0, // [0:1] is the sub-list for field type_name -} - -func file_config_proto_init() { - if File_config_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AbTestCfg); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - - file_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AbTestCfg_ARRAY); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_config_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_config_proto_goTypes, - DependencyIndexes: file_config_proto_depIdxs, - EnumInfos: file_config_proto_enumTypes, - MessageInfos: file_config_proto_msgTypes, - }.Build() - File_config_proto = out.File - file_config_proto_rawDesc = nil - file_config_proto_goTypes = nil - file_config_proto_depIdxs = nil -} - -func init() { - file_config_proto_init() -} \ No newline at end of file diff --git a/configs/confroomrank/config.go b/configs/confroomrank/config.go new file mode 100644 index 0000000..9514e56 --- /dev/null +++ b/configs/confroomrank/config.go @@ -0,0 +1,129 @@ +package confroomrank + +import ( + "apigame/configs/confbase" + "apigame/service-common/svconst" + "apigame/util/util-lx/lxtime" + "apigame/util/zconvert" + "fmt" +) + +// ActivityConfig 房间排行活动配置 分析后数据 +type ActivityConfig struct { + Raw *ActivityConfigRaw `json:"-"` + + Id int64 // ID + Typ int // 排行榜类型 + OpenLevel int // 开启等级 + OpenScore int64 // 开启积分 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + ReleaseTime string // 结算发奖时间 + + Robot map[int]RobotConfig // 机器人配置 + Room map[int]RoomConfig // 房间配置 + + GameId string // 所属游戏ID +} + +func (c *ActivityConfig) GetUid() string { + return zconvert.Int64ToStr(c.Id) +} + +func (c *ActivityConfig) CheckCurrent() bool { + timeNow := lxtime.NowUninx() + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 +} + +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) + timeNow := lxtime.NowUninx() + return &confbase.ConfInfo{ + DbMysql: svconst.DbConfig, + TableName: fmt.Sprintf("%s_%s", tableName, suffix), + KeyName: "id", + CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?", + CurrentArgs: []any{c.Typ, 1, timeNow, timeNow}, + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), + CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ), + CacheTime: 300, + } +} + +// ActivityConfigRaw 房间排行活动配置 原始数据 +type ActivityConfigRaw struct { + Id int64 `gorm:"column:id;primaryKey"` // ID + Serial int64 // 轮次ID + Typ int // 排行榜类型 + OpenLevel int // 开启等级 + OpenScore int64 // 开启积分 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + ReleaseTime string // 结算发奖时间 + + BootConfig string // 机器人配置 + RoomConfig string // 房间配置 + + Ver string // 版本号 + Status int // 状态 0=关闭 1=开启 + UpdateTime int64 // 修改时间戳 +} + +// GenerateConfigClient 生成给客户端的配置 +func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { + configClient := &ActivityConfigClient{ + Id: c.Id, + Typ: c.Typ, + Serial: c.Serial, + OpenLevel: c.OpenLevel, + OpenScore: c.OpenScore, + PreviewTime: c.PreviewTime, + StartTime: c.StartTime, + EndTime: c.EndTime, + ReleaseTime: c.ReleaseTime, + Ver: c.Ver, + Status: c.Status, + } + return configClient +} + +// ActivityConfigClient 房间排行活动配置 给客户端数据 +type ActivityConfigClient struct { + Id int64 `form:"id" json:"id"` // ID + Typ int `form:"typ" json:"typ"` // 排行榜类型 + Serial int64 `form:"serial" json:"serial"` // 轮次ID + OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 + OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 + PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 + StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 + EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 + ReleaseTime string `form:"release_time" json:"release_time"` // 结算发奖时间 + Ver string `form:"ver" json:"ver"` // 版本号 + Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启 +} + +// RobotConfig 机器人配置 +type RobotConfig struct { + Id int `json:"id"` // id + MinScore int `json:"min_score"` // 最低分数 + TotalScore int `json:"total_score"` // 总分数 + Range int `json:"range"` // 总分浮动范围(%) +} + +// RoomConfig 房间配置 +type RoomConfig struct { + Id int `json:"id"` // id + Levels []int `json:"level_range"` // 等级范围 + UserClass int `json:"rating"` // 评级 + UserScore []int `json:"score_range"` // 分数范围 + TotalPlayer int `json:"room_user_number"` // 房间总人数 + PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量 + AutoRobot []int `json:"auto_room"` // 自动填充机器人 + InitRobot [][]int `json:"disposition_robots"` // 配置机器人 + Awards map[string]string `json:"rewards"` // 奖励 + SettleScores []int `json:"score_adjest"` // 结算分数调整 + SettleUserType []int `json:"user_type"` // 结算用户类型 +} diff --git a/configs/confroomrank/decode.go b/configs/confroomrank/decode.go new file mode 100644 index 0000000..e7e4aa4 --- /dev/null +++ b/configs/confroomrank/decode.go @@ -0,0 +1,50 @@ +package confroomrank + +import ( + "apigame/util/util-lx/lxalilog" + "encoding/json" +) + +// Decode 解析配置原始数据 +func (c *ActivityConfig) Decode(gameId string, rawData any) { + raw := rawData.(*ActivityConfigRaw) + c.GameId = gameId + c.Raw = raw + + c.Id = raw.Id + c.Typ = raw.Typ + c.OpenLevel = raw.OpenLevel + c.OpenScore = raw.OpenScore + c.PreviewTime = raw.PreviewTime + c.StartTime = raw.StartTime + c.EndTime = raw.EndTime + c.ReleaseTime = raw.ReleaseTime + + c.Robot = make(map[int]RobotConfig) + c.Room = make(map[int]RoomConfig) + + // 解析 机器人 + { + configs := make([]RobotConfig, 0) + err := json.Unmarshal([]byte(raw.BootConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.Robot[i2.Id] = i2 + } + } + // 解析 房间 + { + configs := make([]RoomConfig, 0) + err := json.Unmarshal([]byte(raw.RoomConfig), &configs) + if err != nil { + lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id) + return + } + for _, i2 := range configs { + c.Room[i2.Id] = i2 + } + } +} diff --git a/configs/confroomrank/get.go b/configs/confroomrank/get.go new file mode 100644 index 0000000..2171a0c --- /dev/null +++ b/configs/confroomrank/get.go @@ -0,0 +1,44 @@ +package confroomrank + +import ( + "apigame/configs/confbase" + "apigame/util/util-lx/lxalilog" + "apigame/util/util-lx/lxtime" +) + +// GetCurrent 获取 当前配置 +func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + conf.Typ = topType + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) + if !has { + conf = new(ActivityConfig) + conf.Typ = topType + has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) + } + return +} + +// GetConfig 获取 配置根据Id +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { + conf = new(ActivityConfig) + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) + + return +} + +// GetCurrentConfigs 获取当前配置列表 +func GetCurrentConfigs(gameId string) []*ActivityConfigRaw { + obj := new(ActivityConfig) + info := obj.ConfInfo(gameId) + db := info.DbMysql + timeNow := lxtime.NowUninx() + objs := make([]*ActivityConfigRaw, 0) + result := db.Table(info.TableName).Where( + "status = ? AND start_time <= ? AND end_time >= ?", + 1, timeNow, timeNow).Find(&objs) + if result.Error != nil { + lxalilog.Errors(result.Error, "confroomrank.GetCurrentConfigs error", gameId) + } + return objs +} diff --git a/configs/external.go b/configs/external.go deleted file mode 100644 index 1cac80a..0000000 --- a/configs/external.go +++ /dev/null @@ -1,44 +0,0 @@ -package configs - -import ( - "fmt" - "github.com/astaxie/beego" - "reflect" -) - -func Init() bool { - fmt.Println("configs Init") - conf, _ := beego.AppConfig.GetSection("conf") - Initial(conf["path"], "ID") - - //InitExt() - return true -} - -func GetConfig[T any](id string, t T) (obj *T) { - var table = GetTable(t) - dt := table.GetItem(id) - if dt == nil { - return nil - } - obj = dt.(*T) - return -} - -func HasConfig[T any](id string, t T) (has bool) { - var table = GetTable(t) - return table.GetItem(id) != nil -} - -func GetOne[T any](t T) (obj *T) { - var table = GetTable(t) - if len(table.Items()) > 0 { - return table.Items()[0].(*T) - } - return nil -} - -func GetTable[T any](t T) (table *DataTable) { - table = GetDataTable(reflect.TypeOf(t)) - return -} diff --git a/configs/init.go b/configs/init.go new file mode 100644 index 0000000..5d6a4f9 --- /dev/null +++ b/configs/init.go @@ -0,0 +1,29 @@ +package configs + +import ( + "apigame/configs/confapi" + "apigame/configs/confcardholder" + "apigame/configs/confglobal" + "apigame/service-common/svconst" +) + +func Init() bool { + + for _, gameId := range svconst.GameList { + _, _ = confapi.GetConfig(gameId) + } + + for _, gameId := range svconst.GameList { + _, _ = confglobal.GetConfig(gameId) + } + + for _, gameId := range svconst.GameListCardHolder { + _, _ = confcardholder.GetCurrent(gameId) + } + + //for _, gameId := range svconst.GameListRoomRank { + // _, _ = confroomrank.GetCurrent(gameId) + //} + + return true +} diff --git a/configs/reader.go b/configs/reader.go deleted file mode 100644 index aaa7dbc..0000000 --- a/configs/reader.go +++ /dev/null @@ -1,280 +0,0 @@ -package configs - -import ( - "fmt" - "os" - "reflect" - "strings" - - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" -) - -type DataTableMap map[string]IData -type DataItemMap map[string]IData - -type DataArray []interface{} -type DataMap map[string]interface{} - -var ( - DefaultIndexKey = "ID" - BytesFileExt = ".bytes" - - dataDir = "" - dataItemMap = make(DataItemMap, 0) - dataTableMap = make(DataTableMap, 0) -) - -type IFilenameGenerator interface { - GetFilename(typeName string) string -} - -type IData interface { - DataType() reflect.Type -} - -func DataDir() string { - return dataDir -} - -func Initial(dir, defaultKeyName string) { - dataDir = strings.ReplaceAll(dir, "\\", "/") - if strings.LastIndex(dataDir, "/") != len(dataDir)-1 { - dataDir = dataDir + "/" - } - - if defaultKeyName != "" { - DefaultIndexKey = defaultKeyName - } -} - -func RegistDataTable(indexKey string, dataType reflect.Type) { - if _, ok := dataTableMap[dataType.Name()]; !ok { - var t = NewDataTable(indexKey, dataType) - dataTableMap[dataType.Name()] = t - } -} - -func RegistDataTableExt(table IData) { - var dataType = table.DataType() - if _, ok := dataTableMap[dataType.Name()]; !ok { - dataTableMap[dataType.Name()] = table - } -} - -func GetDataItem(dataType reflect.Type) *DataItem { - var dt *DataItem - if item, ok := dataItemMap[dataType.Name()]; !ok { - var t = NewDataItem(dataType) - dataItemMap[dataType.Name()] = t - dt = t - } else { - dt = item.(*DataItem) - } - return dt -} - -func GetDataTable(dataType reflect.Type) *DataTable { - var dt *DataTable - if item, ok := dataTableMap[dataType.Name()]; !ok { - var t = NewDataTable("", dataType) - dataTableMap[dataType.Name()] = t - dt = t - } else { - dt = item.(*DataTable) - } - return dt -} - -func getFullname(dataType reflect.Type) string { - var pkgs = strings.Split(dataType.PkgPath(), "/") - var pkg = pkgs[len(pkgs)-1] - var name = dataType.Name() - return fmt.Sprintf("%s.%s", pkg, name) -} - -type DataItem struct { - dataType reflect.Type - data interface{} - fileGen IFilenameGenerator -} - -func NewDataItem(dataType reflect.Type) *DataItem { - t := new(DataItem) - t.dataType = dataType - t.fileGen = t - return t -} - -func (t *DataItem) DataType() reflect.Type { - return t.dataType -} - -func (t *DataItem) Item() interface{} { - t.load() - return t.data -} - -func (t *DataItem) Clear() { - t.data = nil -} - -func (t *DataItem) GetFilename(typeName string) string { - return fmt.Sprintf("%s%s%s", dataDir, strings.ToLower(typeName), BytesFileExt) -} - -func (t *DataItem) load() { - if t.data != nil { - return - } - - var filename = t.fileGen.GetFilename(t.dataType.Name()) - if ok, _ := PathExists(filename); !ok { - fmt.Printf("can not find data file %s", filename) - return - } - - fullName := getFullname(t.dataType) - msgName := protoreflect.FullName(fullName) - msgType, err := protoregistry.GlobalTypes.FindMessageByName(msgName) - if err != nil { - fmt.Printf("can not find proto message named %v, %v", fullName, err) - return - } - message := msgType.New().Interface() - - bytes, err := os.ReadFile(filename) - if err != nil { - fmt.Printf("read bytes file failed, %v", err) - return - } - - err = proto.Unmarshal(bytes, message) - if err != nil { - fmt.Printf("proto unmarshal failed, %v", err) - return - } - - t.data = message -} - -type DataTable struct { - indexKey string - dataType reflect.Type - data DataArray - dataMap DataMap - fileGen IFilenameGenerator -} - -func NewDataTable(indexKey string, dataType reflect.Type) *DataTable { - if indexKey == "" { - indexKey = DefaultIndexKey - } - - t := new(DataTable) - t.indexKey = indexKey - t.dataType = dataType - t.fileGen = t - return t -} - -func (t *DataTable) DataType() reflect.Type { - return t.dataType -} - -func (t *DataTable) Items() DataArray { - if t.data == nil { - t.load() - } - return t.data -} - -func (t *DataTable) ItemsMap() DataMap { - if t.data == nil { - t.load() - } - t.itemsAsMap() - return t.dataMap -} - -func (t *DataTable) GetItem(id string) interface{} { - var dataMap = t.ItemsMap() - if dt, ok := dataMap[id]; ok { - return dt - } - return nil -} - -func (t *DataTable) Clear() { - t.data = nil - t.dataMap = nil -} - -func (t *DataTable) GetFilename(typeName string) string { - return fmt.Sprintf("%s%s%s", dataDir, strings.ToLower(typeName), BytesFileExt) -} - -func (t *DataTable) load() { - if t.data != nil { - return - } - - var filename = t.fileGen.GetFilename(t.dataType.Name()) - if ok, _ := PathExists(filename); !ok { - fmt.Printf("can not find data file %s", filename) - return - } - - fullName := getFullname(t.dataType) + "_ARRAY" - msgName := protoreflect.FullName(fullName) - msgType, err := protoregistry.GlobalTypes.FindMessageByName(msgName) - if err != nil { - fmt.Printf("can not find proto message named %v, %v", fullName, err) - return - } - message := msgType.New().Interface() - - bytes, err := os.ReadFile(filename) - if err != nil { - fmt.Printf("read bytes file failed, %v", err) - return - } - - err = proto.Unmarshal(bytes, message) - if err != nil { - fmt.Printf("proto unmarshal failed, %v", err) - return - } - - var value = reflect.ValueOf(message) - var elm = value.Elem() - if elm.Kind() != reflect.Struct { - fmt.Printf("type %s kind error", fullName) - return - } - - t.data = make(DataArray, 0) - var items = elm.FieldByName("Items").Interface() - if reflect.TypeOf(items).Kind() == reflect.Slice { - s := reflect.ValueOf(items) - for i := 0; i < s.Len(); i++ { - ele := s.Index(i) - t.data = append(t.data, ele.Interface()) - } - } -} - -func (t *DataTable) itemsAsMap() { - if t.dataMap != nil { - return - } - t.dataMap = make(DataMap) - - for _, item := range t.data { - var value = reflect.ValueOf(item) - var elm = value.Elem() - var idx = elm.FieldByName(t.indexKey).Interface() - t.dataMap[fmt.Sprintf("%v", idx)] = item - } -} diff --git a/configs/utils.go b/configs/utils.go deleted file mode 100644 index f2276b1..0000000 --- a/configs/utils.go +++ /dev/null @@ -1,14 +0,0 @@ -package configs - -import "os" - -func PathExists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return false, err -} diff --git a/controllers/admin.go b/controllers/admin.go index b211881..4503648 100644 --- a/controllers/admin.go +++ b/controllers/admin.go @@ -1,7 +1,7 @@ package controllers import ( - "apigame/configs-db/confbase" + "apigame/configs/confbase" "apigame/models" "apigame/service/code-msg" ) diff --git a/controllers/demo.go b/controllers/demo.go index 4ccbf96..be7c36b 100644 --- a/controllers/demo.go +++ b/controllers/demo.go @@ -1,7 +1,7 @@ package controllers import ( - "apigame/configs-db/confcardholder" + "apigame/configs/confcardholder" "apigame/models" "apigame/service/code-msg" "encoding/json" diff --git a/main.go b/main.go index 1315038..36b27a0 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "apigame/configs" - "apigame/configs-db" _ "apigame/routers" "apigame/service" "apigame/service-common/svconst" @@ -66,10 +65,6 @@ func Init() bool { // //_ = config.InitLxLimit() - if !configs_db.Init() { - return false - } - if !configs.Init() { return false } diff --git a/middleware/sign/index.go b/middleware/sign/index.go index a9c9b3f..f0ab408 100644 --- a/middleware/sign/index.go +++ b/middleware/sign/index.go @@ -1,7 +1,7 @@ package sign import ( - "apigame/configs-db/confapi" + "apigame/configs/confapi" "apigame/middleware/sdk" "apigame/service/code-msg" "apigame/util/util-lx/lxalilog" diff --git a/service-common/svcommon/simulate.go b/service-common/svcommon/simulate.go index 5a9b900..3b6187e 100644 --- a/service-common/svcommon/simulate.go +++ b/service-common/svcommon/simulate.go @@ -1,7 +1,7 @@ package svcommon import ( - "apigame/configs-db/confglobal" + "apigame/configs/confglobal" "apigame/util/zmisc" "math/rand" ) diff --git a/service/cardholder/handle.go b/service/cardholder/handle.go index b8761cf..9bf0f74 100644 --- a/service/cardholder/handle.go +++ b/service/cardholder/handle.go @@ -1,14 +1,13 @@ package cardholder import ( - "apigame/configs-db/confcardholder" + "apigame/configs/confcardholder" "apigame/models" "apigame/service-common/svmysql" "apigame/service/code-msg" "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" "apigame/util/zslice" - "fmt" ) // HandleGetConfig 活动配置 @@ -357,10 +356,6 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m rsp.AutoExchangeHolder = player.Details.AutoExchangeHolderIds rsp.NewCards = player.Details.AutoExchangeNewCards - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.LastStarCount) - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.AutoExchangeHolder) - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.NewCards) - player.Details.LastStarCount = 0 player.Details.AutoExchangeHolderIds = make([]int, 0) player.Details.AutoExchangeNewCards = make([][]int, 0) diff --git a/service/cardholder/logic.go b/service/cardholder/logic.go index beb6c63..3498d42 100644 --- a/service/cardholder/logic.go +++ b/service/cardholder/logic.go @@ -1,7 +1,7 @@ package cardholder import ( - "apigame/configs-db/confcardholder" + "apigame/configs/confcardholder" "apigame/models" "apigame/service-common/svmysql" "apigame/service/code-msg" diff --git a/service/cardholder/player.go b/service/cardholder/player.go index 366e9cb..d7b00a4 100644 --- a/service/cardholder/player.go +++ b/service/cardholder/player.go @@ -1,7 +1,7 @@ package cardholder import ( - "apigame/configs-db/confcardholder" + "apigame/configs/confcardholder" "apigame/service-common/svmysql" "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" diff --git a/service/roomrank/handle.go b/service/roomrank/handle.go index f2a35aa..04b8325 100644 --- a/service/roomrank/handle.go +++ b/service/roomrank/handle.go @@ -1,7 +1,7 @@ package roomrank import ( - "apigame/configs-db/confroomrank" + "apigame/configs/confroomrank" "apigame/models" "apigame/service-common/svcommon" "apigame/service/code-msg" diff --git a/service/roomrank/logic.go b/service/roomrank/logic.go index 2a38e27..6821bd0 100644 --- a/service/roomrank/logic.go +++ b/service/roomrank/logic.go @@ -1,7 +1,7 @@ package roomrank import ( - "apigame/configs-db/confroomrank" + "apigame/configs/confroomrank" "apigame/service-common/svconst" "apigame/util/util-lx/lxtime" "apigame/util/zconvert" diff --git a/service/roomrank/player.go b/service/roomrank/player.go index 88fe401..3f346fb 100644 --- a/service/roomrank/player.go +++ b/service/roomrank/player.go @@ -1,7 +1,7 @@ package roomrank import ( - "apigame/configs-db/confroomrank" + "apigame/configs/confroomrank" "apigame/models" "apigame/service-common/svcommon" "apigame/service-common/svmysql" diff --git a/service/roomrank/room.go b/service/roomrank/room.go index 611c916..c243915 100644 --- a/service/roomrank/room.go +++ b/service/roomrank/room.go @@ -1,7 +1,7 @@ package roomrank import ( - "apigame/configs-db/confroomrank" + "apigame/configs/confroomrank" "apigame/service-common/svcommon" "apigame/service-common/svmysql" "apigame/util/util-lx/lxalilog" -- libgit2 0.21.0