Commit 89074b8412da2baf750d01967d2b746a76b423c3
1 parent
23dc082b
Exists in
master
feat✨:配置框架重构回滚
Showing
42 changed files
with
914 additions
and
1544 deletions
Show diff stats
configs-db/confapi/config.go
| ... | ... | @@ -1,48 +0,0 @@ |
| 1 | -package confapi | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "apigame/service-common/svconst" | |
| 6 | - "fmt" | |
| 7 | -) | |
| 8 | - | |
| 9 | -// ApiGameConfig api游戏配置 | |
| 10 | -type ApiGameConfig struct { | |
| 11 | - Raw *Raw | |
| 12 | -} | |
| 13 | - | |
| 14 | -func (c *ApiGameConfig) GetUid() string { | |
| 15 | - return c.Raw.GameId | |
| 16 | -} | |
| 17 | - | |
| 18 | -func (c *ApiGameConfig) CheckCurrent() bool { | |
| 19 | - return true | |
| 20 | -} | |
| 21 | - | |
| 22 | -func (c *ApiGameConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 23 | - tableName := "s_game_config" | |
| 24 | - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 25 | - return &confbase.ConfInfo{ | |
| 26 | - DbMysql: svconst.DbApi, | |
| 27 | - TableName: tableName, | |
| 28 | - KeyName: "gameid", | |
| 29 | - CacheKey: cacheKey, | |
| 30 | - CacheCurrent: cacheKey + ":current", | |
| 31 | - CacheTime: 300, | |
| 32 | - } | |
| 33 | -} | |
| 34 | - | |
| 35 | -// Raw 配置原始数据 | |
| 36 | -type Raw struct { | |
| 37 | - AppId string `gorm:"column:appid"` | |
| 38 | - GameId string `gorm:"column:gameid"` | |
| 39 | - Secret string `gorm:"column:secret"` | |
| 40 | - AppKey string `gorm:"column:appkey"` | |
| 41 | - Name string `gorm:"column:name"` | |
| 42 | -} | |
| 43 | - | |
| 44 | -// Decode 解析配置原始数据 | |
| 45 | -func (c *ApiGameConfig) Decode(gameId string, rawData any) { | |
| 46 | - raw := rawData.(*Raw) | |
| 47 | - c.Raw = raw | |
| 48 | -} |
configs-db/confapi/get.go
| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | -package confapi | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "errors" | |
| 6 | -) | |
| 7 | - | |
| 8 | -// GetConfig 获取 api游戏配置 | |
| 9 | -func GetConfig(gameId string) (conf *ApiGameConfig, err error) { | |
| 10 | - | |
| 11 | - conf = new(ApiGameConfig) | |
| 12 | - has := confbase.GetConfig[*ApiGameConfig, Raw](gameId, gameId, conf) | |
| 13 | - if !has { | |
| 14 | - err = errors.New("confapi.GetConfig error") | |
| 15 | - return | |
| 16 | - } | |
| 17 | - | |
| 18 | - return | |
| 19 | -} |
configs-db/confbase/external.go
| ... | ... | @@ -1,113 +0,0 @@ |
| 1 | -package confbase | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/util/util-lx/lxalilog" | |
| 5 | - "apigame/util/zjson" | |
| 6 | - "apigame/util/zredis" | |
| 7 | - "fmt" | |
| 8 | - "runtime/debug" | |
| 9 | -) | |
| 10 | - | |
| 11 | -var CacheState = 1 // 0=关闭 1=打开 | |
| 12 | - | |
| 13 | -func SaveCache[T IConfData](gameId string, obj T) { | |
| 14 | - info := obj.ConfInfo(gameId) | |
| 15 | - _ = zredis.SetEx(info.CacheKey, zjson.Str(obj), info.CacheTime) | |
| 16 | -} | |
| 17 | - | |
| 18 | -func LoadCache[T IConfData](gameId string, obj T) (has bool) { | |
| 19 | - if CacheState == 0 { | |
| 20 | - return false | |
| 21 | - } | |
| 22 | - has = true | |
| 23 | - info := obj.ConfInfo(gameId) | |
| 24 | - text, err := zredis.Get(info.CacheKey) | |
| 25 | - if err != nil { | |
| 26 | - has = false | |
| 27 | - return | |
| 28 | - } | |
| 29 | - err = zjson.Obj(text, &obj) | |
| 30 | - if err != nil { | |
| 31 | - fmt.Println(err) | |
| 32 | - has = false | |
| 33 | - return | |
| 34 | - } | |
| 35 | - return | |
| 36 | -} | |
| 37 | - | |
| 38 | -func LoadData[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { | |
| 39 | - confRaw := new(T2) | |
| 40 | - info := obj.ConfInfo(gameId) | |
| 41 | - db := info.DbMysql | |
| 42 | - result := db.Table(info.TableName).Where(fmt.Sprintf("%s = ?", info.KeyName), confId).First(confRaw) | |
| 43 | - | |
| 44 | - has = result.RowsAffected != 0 | |
| 45 | - err := result.Error | |
| 46 | - if err != nil { | |
| 47 | - lxalilog.Errors(err, "confbase.LoadData error", gameId, confId) | |
| 48 | - fmt.Printf("%s", debug.Stack()) | |
| 49 | - return | |
| 50 | - } | |
| 51 | - if !has { | |
| 52 | - return | |
| 53 | - } | |
| 54 | - | |
| 55 | - obj.Decode(gameId, confRaw) | |
| 56 | - return | |
| 57 | -} | |
| 58 | - | |
| 59 | -func FindDuringTime[T1 IConfData, T2 IConfRawData](obj T1, raw *T2, gameId string) (has bool) { | |
| 60 | - info := obj.ConfInfo(gameId) | |
| 61 | - db := info.DbMysql | |
| 62 | - result := db.Table(info.TableName).Where(info.CurrentQuery, info.CurrentArgs...).First(raw) | |
| 63 | - has = result.RowsAffected != 0 | |
| 64 | - return | |
| 65 | -} | |
| 66 | - | |
| 67 | -func GetConfig[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { | |
| 68 | - has = LoadCache(gameId, obj) | |
| 69 | - if has { | |
| 70 | - return | |
| 71 | - } | |
| 72 | - has = LoadData[T1, T2](gameId, confId, obj) | |
| 73 | - if !has { | |
| 74 | - return | |
| 75 | - } | |
| 76 | - SaveCache(gameId, obj) | |
| 77 | - return | |
| 78 | -} | |
| 79 | - | |
| 80 | -// GetCurrent 获取 当前配置 | |
| 81 | -func GetCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { | |
| 82 | - has := false | |
| 83 | - info := obj.ConfInfo(gameId) | |
| 84 | - currentKey := info.CacheCurrent | |
| 85 | - currentId := zredis.GetString(currentKey) | |
| 86 | - if currentId != "" { | |
| 87 | - has = GetConfig[T1, T2](gameId, currentId, obj) | |
| 88 | - if has { | |
| 89 | - if !obj.CheckCurrent() { | |
| 90 | - has = false | |
| 91 | - } | |
| 92 | - } | |
| 93 | - } | |
| 94 | - return has | |
| 95 | -} | |
| 96 | - | |
| 97 | -// FindCurrent 查找 当前配置 | |
| 98 | -func FindCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { | |
| 99 | - has := false | |
| 100 | - info := obj.ConfInfo(gameId) | |
| 101 | - currentKey := info.CacheCurrent | |
| 102 | - currentId := zredis.GetString(currentKey) | |
| 103 | - confRaw := new(T2) | |
| 104 | - has = FindDuringTime[T1, T2](obj, confRaw, gameId) | |
| 105 | - if has { | |
| 106 | - obj.Decode(gameId, confRaw) | |
| 107 | - SaveCache(gameId, obj) | |
| 108 | - has = true | |
| 109 | - currentId = obj.GetUid() | |
| 110 | - _ = zredis.Set(currentKey, currentId) | |
| 111 | - } | |
| 112 | - return has | |
| 113 | -} |
configs-db/confbase/interface.go
| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | -package confbase | |
| 2 | - | |
| 3 | -import "gorm.io/gorm" | |
| 4 | - | |
| 5 | -// ConfInfo 配置对象信息 | |
| 6 | -type ConfInfo struct { | |
| 7 | - DbMysql *gorm.DB | |
| 8 | - TableName string | |
| 9 | - KeyName string | |
| 10 | - CurrentQuery any | |
| 11 | - CurrentArgs []any | |
| 12 | - CacheKey string | |
| 13 | - CacheCurrent string | |
| 14 | - CacheTime int | |
| 15 | -} | |
| 16 | - | |
| 17 | -// IConfData 配置对象 | |
| 18 | -type IConfData interface { | |
| 19 | - // ConfInfo redis存储信息 | |
| 20 | - ConfInfo(suffix string) *ConfInfo | |
| 21 | - // Decode 解码 | |
| 22 | - Decode(gameId string, rawData any) | |
| 23 | - // GetUid 获取keyID | |
| 24 | - GetUid() string | |
| 25 | - // CheckCurrent 判断当前开放 | |
| 26 | - CheckCurrent() bool | |
| 27 | -} | |
| 28 | - | |
| 29 | -// IConfRawData mysql存储对象 | |
| 30 | -type IConfRawData interface { | |
| 31 | -} |
configs-db/confcardholder/config.go
| ... | ... | @@ -1,153 +0,0 @@ |
| 1 | -package confcardholder | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "apigame/service-common/svconst" | |
| 6 | - "apigame/util/util-lx/lxtime" | |
| 7 | - "apigame/util/zconvert" | |
| 8 | - "fmt" | |
| 9 | -) | |
| 10 | - | |
| 11 | -// ActivityConfig 卡牌活动配置 分析后数据 | |
| 12 | -type ActivityConfig struct { | |
| 13 | - Raw *ActivityConfigRaw `json:"-"` | |
| 14 | - | |
| 15 | - Id int64 // ID | |
| 16 | - OpenLevel int // 开启等级 | |
| 17 | - PreviewTime int64 // 预告时间 | |
| 18 | - StartTime int64 // 开始时间 | |
| 19 | - EndTime int64 // 结束时间 | |
| 20 | - Round int // 轮数 | |
| 21 | - IconPath string // icon资源路径 | |
| 22 | - | |
| 23 | - Awards map[string]string // 奖励配置 | |
| 24 | - AlbumConfig map[int]AlbumConfig // 卡组配置 | |
| 25 | - CardConfig map[int]CardConfig // 卡牌配置 | |
| 26 | - CardholderConfig map[int]OpenCardholderConfig // 卡包开卡规则 | |
| 27 | - NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 | |
| 28 | - CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 | |
| 29 | - StarShopConfig map[int]StarShopConfig // 星星商店配置 | |
| 30 | - ListSequenceId []int // 用户序列组ID列表 | |
| 31 | - | |
| 32 | - Client *ActivityConfigClient | |
| 33 | - GameId string // 所属游戏ID | |
| 34 | -} | |
| 35 | - | |
| 36 | -func (c *ActivityConfig) GetUid() string { | |
| 37 | - return zconvert.Int64ToStr(c.Id) | |
| 38 | -} | |
| 39 | - | |
| 40 | -func (c *ActivityConfig) CheckCurrent() bool { | |
| 41 | - timeNow := lxtime.NowUninx() | |
| 42 | - return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 | |
| 43 | -} | |
| 44 | - | |
| 45 | -func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 46 | - tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG | |
| 47 | - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 48 | - timeNow := lxtime.NowUninx() | |
| 49 | - return &confbase.ConfInfo{ | |
| 50 | - DbMysql: svconst.DbConfig, | |
| 51 | - TableName: fmt.Sprintf("%s_%s", tableName, suffix), | |
| 52 | - KeyName: "id", | |
| 53 | - CurrentQuery: "status = ? AND start_time <= ? AND end_time >= ?", | |
| 54 | - CurrentArgs: []any{1, timeNow, timeNow}, | |
| 55 | - CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | |
| 56 | - CacheCurrent: cacheKey + ":current", | |
| 57 | - CacheTime: 300, | |
| 58 | - } | |
| 59 | -} | |
| 60 | - | |
| 61 | -// ActivityConfigRaw 卡牌活动配置 原始数据 | |
| 62 | -type ActivityConfigRaw struct { | |
| 63 | - Id int64 `gorm:"column:id;primaryKey"` // ID | |
| 64 | - OpenLevel int // 开启等级 | |
| 65 | - PreviewTime int64 // 预告时间 | |
| 66 | - StartTime int64 // 开始时间 | |
| 67 | - EndTime int64 // 结束时间 | |
| 68 | - Round int // 轮数 | |
| 69 | - IconPath string // icon资源路径 | |
| 70 | - | |
| 71 | - Awards string // 奖励配置 | |
| 72 | - AlbumConfig string // 卡组配置 | |
| 73 | - CardConfig string // 卡牌配置 | |
| 74 | - CardHolderConfig string // 卡包开卡规则 | |
| 75 | - NormalCardStarSequence string // 卡片星级配置 | |
| 76 | - CardSequenceConfig string // 卡片星级对应卡牌配置 | |
| 77 | - StarShopConfig string // 星星商店配置 | |
| 78 | - | |
| 79 | - Ver string // 版本号 | |
| 80 | - Status int // 状态 0=关闭 1=开启 | |
| 81 | - UpdateTime int64 // 修改时间戳 | |
| 82 | -} | |
| 83 | - | |
| 84 | -// ActivityConfigClient 卡牌活动配置 给客户端数据 | |
| 85 | -type ActivityConfigClient struct { | |
| 86 | - Id int64 `form:"id" json:"id"` // ID | |
| 87 | - Round int `form:"round" json:"round"` // 轮数 | |
| 88 | - IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 | |
| 89 | - RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 | |
| 90 | - Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置 | |
| 91 | - Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置 | |
| 92 | - Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则 | |
| 93 | - StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置 | |
| 94 | -} | |
| 95 | - | |
| 96 | -// AlbumConfig 卡组表 | |
| 97 | -type AlbumConfig struct { | |
| 98 | - SetId int `json:"set_id"` // 卡组名 | |
| 99 | - Name int `json:"name"` // 卡组图片 | |
| 100 | - Icon string `json:"icon"` // 卡组id | |
| 101 | - Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次 | |
| 102 | - StartTime int64 `json:"start_time"` // 开始时间 | |
| 103 | - EndTime int64 `json:"end_time"` // 结束时间 | |
| 104 | -} | |
| 105 | - | |
| 106 | -// CardConfig 卡牌表 | |
| 107 | -type CardConfig struct { | |
| 108 | - Id int `json:"id"` // ID | |
| 109 | - Name int `json:"name"` // 卡牌名字 | |
| 110 | - Icon string `json:"icon"` // 卡牌图标 | |
| 111 | - Desc int `json:"desc"` // 卡牌描述 | |
| 112 | - SetId int `json:"album_setid"` // 卡组id | |
| 113 | - Star int `json:"star"` // 星级 | |
| 114 | - IsGold int `json:"is_gold"` // 是否是金卡 | |
| 115 | - IsSend int `json:"is_send"` // 卡片是否可赠送 | |
| 116 | -} | |
| 117 | - | |
| 118 | -// OpenCardholderConfig 卡包开卡规则表 | |
| 119 | -type OpenCardholderConfig struct { | |
| 120 | - Id int `json:"id"` // ID | |
| 121 | - CardPackIcon string `json:"img"` // 卡包资源名 | |
| 122 | - IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 | |
| 123 | - IsNew int `json:"is_new"` // 是否是新卡包 | |
| 124 | - GuaranteedStarCardId int `json:"guaranteed_star_card_id"` // 保底卡星级序列ID | |
| 125 | - NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 | |
| 126 | - MinimumGuaranteeCardId int `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID | |
| 127 | - ActivityId int `json:"activity_id"` // 对应活动ID | |
| 128 | - Star int `json:"star"` // star | |
| 129 | - Name int `json:"name"` // name | |
| 130 | -} | |
| 131 | - | |
| 132 | -// NormalCardStarConfig 非保底卡星级ID | |
| 133 | -type NormalCardStarConfig struct { | |
| 134 | - Id int `json:"id"` // ID | |
| 135 | - SequenceId int `json:"user_sequence_id"` // 用户序列组ID | |
| 136 | - Cohort int `json:"cohort"` // 用户分组 | |
| 137 | - NormalCardSequenceId []int `json:"normal_card_sequence_id"` // 非保底星级序列 | |
| 138 | -} | |
| 139 | - | |
| 140 | -// CardSequenceConfig 星级ID对应的卡片 | |
| 141 | -type CardSequenceConfig struct { | |
| 142 | - Id int `json:"id"` // ID | |
| 143 | - SequenceId int `json:"user_sequence_id"` // 用户序列组ID | |
| 144 | - Cohort int `json:"cohort"` // 用户分组 | |
| 145 | - CardIdList []int `json:"card_id_list"` // 卡牌抽取序列 | |
| 146 | -} | |
| 147 | - | |
| 148 | -// StarShopConfig 星星商店配置 | |
| 149 | -type StarShopConfig struct { | |
| 150 | - Id int `json:"id"` // ID | |
| 151 | - NeedStarNumber int `json:"need_star_number"` // 需求星星数 | |
| 152 | - CardBagIds string `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} | |
| 153 | -} |
configs-db/confcardholder/decode.go
| ... | ... | @@ -1,177 +0,0 @@ |
| 1 | -package confcardholder | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/util/util-lx/lxalilog" | |
| 5 | - "apigame/util/zslice" | |
| 6 | - "encoding/json" | |
| 7 | - "errors" | |
| 8 | - "fmt" | |
| 9 | -) | |
| 10 | - | |
| 11 | -// Decode 解析配置原始数据 | |
| 12 | -func (c *ActivityConfig) Decode(gameId string, rawData any) { | |
| 13 | - raw := rawData.(*ActivityConfigRaw) | |
| 14 | - c.GameId = gameId | |
| 15 | - c.Raw = raw | |
| 16 | - | |
| 17 | - c.Id = raw.Id | |
| 18 | - c.OpenLevel = raw.OpenLevel | |
| 19 | - c.PreviewTime = raw.PreviewTime | |
| 20 | - c.StartTime = raw.StartTime | |
| 21 | - c.EndTime = raw.EndTime | |
| 22 | - c.Round = raw.Round | |
| 23 | - c.IconPath = raw.IconPath | |
| 24 | - | |
| 25 | - c.Awards = make(map[string]string) | |
| 26 | - c.AlbumConfig = make(map[int]AlbumConfig) | |
| 27 | - c.CardConfig = make(map[int]CardConfig) | |
| 28 | - c.CardholderConfig = make(map[int]OpenCardholderConfig) | |
| 29 | - c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) | |
| 30 | - c.CardSequenceConfig = make(map[string]CardSequenceConfig) | |
| 31 | - c.StarShopConfig = make(map[int]StarShopConfig) | |
| 32 | - // 解析奖励 | |
| 33 | - { | |
| 34 | - err := json.Unmarshal([]byte(raw.Awards), &c.Awards) | |
| 35 | - if err != nil { | |
| 36 | - lxalilog.Errors(err, raw.Awards, gameId, raw.Id) | |
| 37 | - return | |
| 38 | - } | |
| 39 | - } | |
| 40 | - // 卡组配置 | |
| 41 | - { | |
| 42 | - configs := make([]AlbumConfig, 0) | |
| 43 | - err := json.Unmarshal([]byte(raw.AlbumConfig), &configs) | |
| 44 | - if err != nil { | |
| 45 | - lxalilog.Errors(err, raw.AlbumConfig, gameId, raw.Id) | |
| 46 | - return | |
| 47 | - } | |
| 48 | - for _, i2 := range configs { | |
| 49 | - c.AlbumConfig[i2.SetId] = i2 | |
| 50 | - } | |
| 51 | - } | |
| 52 | - // 卡牌配置 | |
| 53 | - { | |
| 54 | - configs := make([]CardConfig, 0) | |
| 55 | - err := json.Unmarshal([]byte(raw.CardConfig), &configs) | |
| 56 | - if err != nil { | |
| 57 | - lxalilog.Errors(err, raw.CardConfig, gameId, raw.Id) | |
| 58 | - return | |
| 59 | - } | |
| 60 | - for _, i2 := range configs { | |
| 61 | - c.CardConfig[i2.Id] = i2 | |
| 62 | - } | |
| 63 | - } | |
| 64 | - // 卡包开卡规则 | |
| 65 | - { | |
| 66 | - configs := make([]OpenCardholderConfig, 0) | |
| 67 | - err := json.Unmarshal([]byte(raw.CardHolderConfig), &configs) | |
| 68 | - if err != nil { | |
| 69 | - lxalilog.Errors(err, raw.CardHolderConfig, gameId, raw.Id) | |
| 70 | - return | |
| 71 | - } | |
| 72 | - for _, i2 := range configs { | |
| 73 | - c.CardholderConfig[i2.Id] = i2 | |
| 74 | - } | |
| 75 | - } | |
| 76 | - // 卡片星级配置 | |
| 77 | - { | |
| 78 | - configs := make([]NormalCardStarConfig, 0) | |
| 79 | - err := json.Unmarshal([]byte(raw.NormalCardStarSequence), &configs) | |
| 80 | - if err != nil { | |
| 81 | - lxalilog.Errors(err, raw.NormalCardStarSequence, gameId, raw.Id) | |
| 82 | - return | |
| 83 | - } | |
| 84 | - for _, i2 := range configs { | |
| 85 | - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) | |
| 86 | - c.NormalCardStarConfig[combineId] = i2 | |
| 87 | - if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { | |
| 88 | - c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) | |
| 89 | - } | |
| 90 | - } | |
| 91 | - } | |
| 92 | - // 卡片星级对应卡牌配置 | |
| 93 | - { | |
| 94 | - configs := make([]CardSequenceConfig, 0) | |
| 95 | - err := json.Unmarshal([]byte(raw.CardSequenceConfig), &configs) | |
| 96 | - if err != nil { | |
| 97 | - lxalilog.Errors(err, raw.CardSequenceConfig, gameId, raw.Id) | |
| 98 | - return | |
| 99 | - } | |
| 100 | - for _, i2 := range configs { | |
| 101 | - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) | |
| 102 | - c.CardSequenceConfig[combineId] = i2 | |
| 103 | - if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { | |
| 104 | - c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) | |
| 105 | - } | |
| 106 | - } | |
| 107 | - } | |
| 108 | - // 星星商店配置 | |
| 109 | - { | |
| 110 | - configs := make([]StarShopConfig, 0) | |
| 111 | - err := json.Unmarshal([]byte(raw.StarShopConfig), &configs) | |
| 112 | - if err != nil { | |
| 113 | - lxalilog.Errors(err, raw.StarShopConfig, gameId, raw.Id) | |
| 114 | - return | |
| 115 | - } | |
| 116 | - for _, i2 := range configs { | |
| 117 | - c.StarShopConfig[i2.Id] = i2 | |
| 118 | - } | |
| 119 | - } | |
| 120 | - | |
| 121 | - c.GenerateConfigClient() | |
| 122 | -} | |
| 123 | - | |
| 124 | -// GenerateConfigClient 生成给客户端的配置 | |
| 125 | -func (c *ActivityConfig) GenerateConfigClient() { | |
| 126 | - configClient := &ActivityConfigClient{ | |
| 127 | - Id: c.Id, | |
| 128 | - Round: c.Round, | |
| 129 | - IconPath: c.IconPath, | |
| 130 | - RoundAwards: c.Awards, | |
| 131 | - Albums: make([]AlbumConfig, 0), | |
| 132 | - Cards: make([]CardConfig, 0), | |
| 133 | - Holders: make([]OpenCardholderConfig, 0), | |
| 134 | - StarShop: make([]StarShopConfig, 0), | |
| 135 | - } | |
| 136 | - for _, i2 := range c.AlbumConfig { | |
| 137 | - configClient.Albums = append(configClient.Albums, i2) | |
| 138 | - } | |
| 139 | - for _, i2 := range c.CardConfig { | |
| 140 | - configClient.Cards = append(configClient.Cards, i2) | |
| 141 | - } | |
| 142 | - for _, i2 := range c.CardholderConfig { | |
| 143 | - configClient.Holders = append(configClient.Holders, i2) | |
| 144 | - } | |
| 145 | - for _, i2 := range c.StarShopConfig { | |
| 146 | - configClient.StarShop = append(configClient.StarShop, i2) | |
| 147 | - } | |
| 148 | - c.Client = configClient | |
| 149 | -} | |
| 150 | - | |
| 151 | -// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组 | |
| 152 | -func CombineIdSequenceIdCohort(id, sequenceId, cohort int) string { | |
| 153 | - return fmt.Sprintf("%d_%d_%d", id, sequenceId, cohort) | |
| 154 | -} | |
| 155 | - | |
| 156 | -// FindNormalCardStarConfig 查找配置 非保底卡星级ID | |
| 157 | -func (c *ActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort int) (conf NormalCardStarConfig, has bool) { | |
| 158 | - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) | |
| 159 | - conf, has = c.NormalCardStarConfig[combineId] | |
| 160 | - if !has { | |
| 161 | - lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort) | |
| 162 | - } | |
| 163 | - return | |
| 164 | -} | |
| 165 | - | |
| 166 | -// FindCardSequenceConfig 查找配置 星级ID对应的卡片 | |
| 167 | -func (c *ActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort int) (conf CardSequenceConfig, has bool) { | |
| 168 | - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) | |
| 169 | - conf, has = c.CardSequenceConfig[combineId] | |
| 170 | - if !has { | |
| 171 | - lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort) | |
| 172 | - fmt.Println(id) | |
| 173 | - fmt.Println(sequenceId) | |
| 174 | - fmt.Println(cohort) | |
| 175 | - } | |
| 176 | - return | |
| 177 | -} |
configs-db/confcardholder/get.go
| ... | ... | @@ -1,24 +0,0 @@ |
| 1 | -package confcardholder | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | -) | |
| 6 | - | |
| 7 | -// GetCurrent 获取 当前配置 | |
| 8 | -func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { | |
| 9 | - conf = new(ActivityConfig) | |
| 10 | - has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 11 | - if !has { | |
| 12 | - conf = new(ActivityConfig) | |
| 13 | - has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 14 | - } | |
| 15 | - return | |
| 16 | -} | |
| 17 | - | |
| 18 | -// GetConfig 获取 配置根据Id | |
| 19 | -func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | |
| 20 | - conf = new(ActivityConfig) | |
| 21 | - has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) | |
| 22 | - | |
| 23 | - return | |
| 24 | -} |
configs-db/confglobal/config.go
| ... | ... | @@ -1,67 +0,0 @@ |
| 1 | -package confglobal | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "apigame/service-common/svconst" | |
| 6 | - "apigame/util/util-lx/lxalilog" | |
| 7 | - "encoding/json" | |
| 8 | - "fmt" | |
| 9 | -) | |
| 10 | - | |
| 11 | -// GlobalConfig 全局配置 | |
| 12 | -type GlobalConfig struct { | |
| 13 | - Raw *Raw `json:"-"` | |
| 14 | - Names []string | |
| 15 | - Avatars []string | |
| 16 | - AvatarPath string | |
| 17 | -} | |
| 18 | - | |
| 19 | -func (c *GlobalConfig) GetUid() string { | |
| 20 | - return c.Raw.GameId | |
| 21 | -} | |
| 22 | - | |
| 23 | -func (c *GlobalConfig) CheckCurrent() bool { | |
| 24 | - return true | |
| 25 | -} | |
| 26 | - | |
| 27 | -func (c *GlobalConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 28 | - tableName := "s_game_global_config" | |
| 29 | - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 30 | - return &confbase.ConfInfo{ | |
| 31 | - DbMysql: svconst.DbConfig, | |
| 32 | - TableName: tableName, | |
| 33 | - KeyName: "gameid", | |
| 34 | - CacheKey: cacheKey, | |
| 35 | - CacheCurrent: cacheKey + ":current", | |
| 36 | - CacheTime: 300, | |
| 37 | - } | |
| 38 | -} | |
| 39 | - | |
| 40 | -// Raw 配置原始数据 | |
| 41 | -type Raw struct { | |
| 42 | - GameId string `gorm:"column:gameid"` | |
| 43 | - NameConfig string | |
| 44 | - AvatarConfig string | |
| 45 | - AvatarPath string | |
| 46 | -} | |
| 47 | - | |
| 48 | -// Decode 解析配置原始数据 | |
| 49 | -func (c *GlobalConfig) Decode(gameId string, rawData any) { | |
| 50 | - raw := rawData.(*Raw) | |
| 51 | - c.Raw = raw | |
| 52 | - { | |
| 53 | - err := json.Unmarshal([]byte(raw.NameConfig), &c.Names) | |
| 54 | - if err != nil { | |
| 55 | - lxalilog.Errors(err, raw.NameConfig, gameId, raw.GameId) | |
| 56 | - return | |
| 57 | - } | |
| 58 | - } | |
| 59 | - { | |
| 60 | - err := json.Unmarshal([]byte(raw.AvatarConfig), &c.Avatars) | |
| 61 | - if err != nil { | |
| 62 | - lxalilog.Errors(err, raw.AvatarConfig, gameId, raw.GameId) | |
| 63 | - return | |
| 64 | - } | |
| 65 | - } | |
| 66 | - c.AvatarPath = raw.AvatarPath | |
| 67 | -} |
configs-db/confglobal/get.go
| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | -package confglobal | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "errors" | |
| 6 | -) | |
| 7 | - | |
| 8 | -// GetConfig 获取 api游戏配置 | |
| 9 | -func GetConfig(gameId string) (conf *GlobalConfig, err error) { | |
| 10 | - | |
| 11 | - conf = new(GlobalConfig) | |
| 12 | - has := confbase.GetConfig[*GlobalConfig, Raw](gameId, gameId, conf) | |
| 13 | - if !has { | |
| 14 | - err = errors.New("confglobal.GetConfig error") | |
| 15 | - return | |
| 16 | - } | |
| 17 | - | |
| 18 | - return | |
| 19 | -} |
configs-db/confroomrank/config.go
| ... | ... | @@ -1,129 +0,0 @@ |
| 1 | -package confroomrank | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "apigame/service-common/svconst" | |
| 6 | - "apigame/util/util-lx/lxtime" | |
| 7 | - "apigame/util/zconvert" | |
| 8 | - "fmt" | |
| 9 | -) | |
| 10 | - | |
| 11 | -// ActivityConfig 房间排行活动配置 分析后数据 | |
| 12 | -type ActivityConfig struct { | |
| 13 | - Raw *ActivityConfigRaw `json:"-"` | |
| 14 | - | |
| 15 | - Id int64 // ID | |
| 16 | - Typ int // 排行榜类型 | |
| 17 | - OpenLevel int // 开启等级 | |
| 18 | - OpenScore int64 // 开启积分 | |
| 19 | - PreviewTime int64 // 预告时间 | |
| 20 | - StartTime int64 // 开始时间 | |
| 21 | - EndTime int64 // 结束时间 | |
| 22 | - ReleaseTime string // 结算发奖时间 | |
| 23 | - | |
| 24 | - Robot map[int]RobotConfig // 机器人配置 | |
| 25 | - Room map[int]RoomConfig // 房间配置 | |
| 26 | - | |
| 27 | - GameId string // 所属游戏ID | |
| 28 | -} | |
| 29 | - | |
| 30 | -func (c *ActivityConfig) GetUid() string { | |
| 31 | - return zconvert.Int64ToStr(c.Id) | |
| 32 | -} | |
| 33 | - | |
| 34 | -func (c *ActivityConfig) CheckCurrent() bool { | |
| 35 | - timeNow := lxtime.NowUninx() | |
| 36 | - return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 | |
| 37 | -} | |
| 38 | - | |
| 39 | -func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 40 | - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG | |
| 41 | - cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 42 | - timeNow := lxtime.NowUninx() | |
| 43 | - return &confbase.ConfInfo{ | |
| 44 | - DbMysql: svconst.DbConfig, | |
| 45 | - TableName: fmt.Sprintf("%s_%s", tableName, suffix), | |
| 46 | - KeyName: "id", | |
| 47 | - CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?", | |
| 48 | - CurrentArgs: []any{c.Typ, 1, timeNow, timeNow}, | |
| 49 | - CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | |
| 50 | - CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ), | |
| 51 | - CacheTime: 300, | |
| 52 | - } | |
| 53 | -} | |
| 54 | - | |
| 55 | -// ActivityConfigRaw 房间排行活动配置 原始数据 | |
| 56 | -type ActivityConfigRaw struct { | |
| 57 | - Id int64 `gorm:"column:id;primaryKey"` // ID | |
| 58 | - Serial int64 // 轮次ID | |
| 59 | - Typ int // 排行榜类型 | |
| 60 | - OpenLevel int // 开启等级 | |
| 61 | - OpenScore int64 // 开启积分 | |
| 62 | - PreviewTime int64 // 预告时间 | |
| 63 | - StartTime int64 // 开始时间 | |
| 64 | - EndTime int64 // 结束时间 | |
| 65 | - ReleaseTime string // 结算发奖时间 | |
| 66 | - | |
| 67 | - BootConfig string // 机器人配置 | |
| 68 | - RoomConfig string // 房间配置 | |
| 69 | - | |
| 70 | - Ver string // 版本号 | |
| 71 | - Status int // 状态 0=关闭 1=开启 | |
| 72 | - UpdateTime int64 // 修改时间戳 | |
| 73 | -} | |
| 74 | - | |
| 75 | -// GenerateConfigClient 生成给客户端的配置 | |
| 76 | -func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { | |
| 77 | - configClient := &ActivityConfigClient{ | |
| 78 | - Id: c.Id, | |
| 79 | - Typ: c.Typ, | |
| 80 | - Serial: c.Serial, | |
| 81 | - OpenLevel: c.OpenLevel, | |
| 82 | - OpenScore: c.OpenScore, | |
| 83 | - PreviewTime: c.PreviewTime, | |
| 84 | - StartTime: c.StartTime, | |
| 85 | - EndTime: c.EndTime, | |
| 86 | - ReleaseTime: c.ReleaseTime, | |
| 87 | - Ver: c.Ver, | |
| 88 | - Status: c.Status, | |
| 89 | - } | |
| 90 | - return configClient | |
| 91 | -} | |
| 92 | - | |
| 93 | -// ActivityConfigClient 房间排行活动配置 给客户端数据 | |
| 94 | -type ActivityConfigClient struct { | |
| 95 | - Id int64 `form:"id" json:"id"` // ID | |
| 96 | - Typ int `form:"typ" json:"typ"` // 排行榜类型 | |
| 97 | - Serial int64 `form:"serial" json:"serial"` // 轮次ID | |
| 98 | - OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 | |
| 99 | - OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 | |
| 100 | - PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 | |
| 101 | - StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 | |
| 102 | - EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 | |
| 103 | - ReleaseTime string `form:"release_time" json:"release_time"` // 结算发奖时间 | |
| 104 | - Ver string `form:"ver" json:"ver"` // 版本号 | |
| 105 | - Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启 | |
| 106 | -} | |
| 107 | - | |
| 108 | -// RobotConfig 机器人配置 | |
| 109 | -type RobotConfig struct { | |
| 110 | - Id int `json:"id"` // id | |
| 111 | - MinScore int `json:"min_score"` // 最低分数 | |
| 112 | - TotalScore int `json:"total_score"` // 总分数 | |
| 113 | - Range int `json:"range"` // 总分浮动范围(%) | |
| 114 | -} | |
| 115 | - | |
| 116 | -// RoomConfig 房间配置 | |
| 117 | -type RoomConfig struct { | |
| 118 | - Id int `json:"id"` // id | |
| 119 | - Levels []int `json:"level_range"` // 等级范围 | |
| 120 | - UserClass int `json:"rating"` // 评级 | |
| 121 | - UserScore []int `json:"score_range"` // 分数范围 | |
| 122 | - TotalPlayer int `json:"room_user_number"` // 房间总人数 | |
| 123 | - PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量 | |
| 124 | - AutoRobot []int `json:"auto_room"` // 自动填充机器人 | |
| 125 | - InitRobot [][]int `json:"disposition_robots"` // 配置机器人 | |
| 126 | - Awards map[string]string `json:"rewards"` // 奖励 | |
| 127 | - SettleScores []int `json:"score_adjest"` // 结算分数调整 | |
| 128 | - SettleUserType []int `json:"user_type"` // 结算用户类型 | |
| 129 | -} |
configs-db/confroomrank/decode.go
| ... | ... | @@ -1,50 +0,0 @@ |
| 1 | -package confroomrank | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/util/util-lx/lxalilog" | |
| 5 | - "encoding/json" | |
| 6 | -) | |
| 7 | - | |
| 8 | -// Decode 解析配置原始数据 | |
| 9 | -func (c *ActivityConfig) Decode(gameId string, rawData any) { | |
| 10 | - raw := rawData.(*ActivityConfigRaw) | |
| 11 | - c.GameId = gameId | |
| 12 | - c.Raw = raw | |
| 13 | - | |
| 14 | - c.Id = raw.Id | |
| 15 | - c.Typ = raw.Typ | |
| 16 | - c.OpenLevel = raw.OpenLevel | |
| 17 | - c.OpenScore = raw.OpenScore | |
| 18 | - c.PreviewTime = raw.PreviewTime | |
| 19 | - c.StartTime = raw.StartTime | |
| 20 | - c.EndTime = raw.EndTime | |
| 21 | - c.ReleaseTime = raw.ReleaseTime | |
| 22 | - | |
| 23 | - c.Robot = make(map[int]RobotConfig) | |
| 24 | - c.Room = make(map[int]RoomConfig) | |
| 25 | - | |
| 26 | - // 解析 机器人 | |
| 27 | - { | |
| 28 | - configs := make([]RobotConfig, 0) | |
| 29 | - err := json.Unmarshal([]byte(raw.BootConfig), &configs) | |
| 30 | - if err != nil { | |
| 31 | - lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id) | |
| 32 | - return | |
| 33 | - } | |
| 34 | - for _, i2 := range configs { | |
| 35 | - c.Robot[i2.Id] = i2 | |
| 36 | - } | |
| 37 | - } | |
| 38 | - // 解析 房间 | |
| 39 | - { | |
| 40 | - configs := make([]RoomConfig, 0) | |
| 41 | - err := json.Unmarshal([]byte(raw.RoomConfig), &configs) | |
| 42 | - if err != nil { | |
| 43 | - lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id) | |
| 44 | - return | |
| 45 | - } | |
| 46 | - for _, i2 := range configs { | |
| 47 | - c.Room[i2.Id] = i2 | |
| 48 | - } | |
| 49 | - } | |
| 50 | -} |
configs-db/confroomrank/get.go
| ... | ... | @@ -1,44 +0,0 @@ |
| 1 | -package confroomrank | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confbase" | |
| 5 | - "apigame/util/util-lx/lxalilog" | |
| 6 | - "apigame/util/util-lx/lxtime" | |
| 7 | -) | |
| 8 | - | |
| 9 | -// GetCurrent 获取 当前配置 | |
| 10 | -func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { | |
| 11 | - conf = new(ActivityConfig) | |
| 12 | - conf.Typ = topType | |
| 13 | - has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 14 | - if !has { | |
| 15 | - conf = new(ActivityConfig) | |
| 16 | - conf.Typ = topType | |
| 17 | - has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 18 | - } | |
| 19 | - return | |
| 20 | -} | |
| 21 | - | |
| 22 | -// GetConfig 获取 配置根据Id | |
| 23 | -func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | |
| 24 | - conf = new(ActivityConfig) | |
| 25 | - has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) | |
| 26 | - | |
| 27 | - return | |
| 28 | -} | |
| 29 | - | |
| 30 | -// GetCurrentConfigs 获取当前配置列表 | |
| 31 | -func GetCurrentConfigs(gameId string) []*ActivityConfigRaw { | |
| 32 | - obj := new(ActivityConfig) | |
| 33 | - info := obj.ConfInfo(gameId) | |
| 34 | - db := info.DbMysql | |
| 35 | - timeNow := lxtime.NowUninx() | |
| 36 | - objs := make([]*ActivityConfigRaw, 0) | |
| 37 | - result := db.Table(info.TableName).Where( | |
| 38 | - "status = ? AND start_time <= ? AND end_time >= ?", | |
| 39 | - 1, timeNow, timeNow).Find(&objs) | |
| 40 | - if result.Error != nil { | |
| 41 | - lxalilog.Errors(result.Error, "confroomrank.GetCurrentConfigs error", gameId) | |
| 42 | - } | |
| 43 | - return objs | |
| 44 | -} |
configs-db/init.go
| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | -package configs_db | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "apigame/configs-db/confapi" | |
| 5 | - "apigame/configs-db/confcardholder" | |
| 6 | - "apigame/configs-db/confglobal" | |
| 7 | - "apigame/service-common/svconst" | |
| 8 | -) | |
| 9 | - | |
| 10 | -func Init() bool { | |
| 11 | - | |
| 12 | - for _, gameId := range svconst.GameList { | |
| 13 | - _, _ = confapi.GetConfig(gameId) | |
| 14 | - } | |
| 15 | - | |
| 16 | - for _, gameId := range svconst.GameList { | |
| 17 | - _, _ = confglobal.GetConfig(gameId) | |
| 18 | - } | |
| 19 | - | |
| 20 | - for _, gameId := range svconst.GameListCardHolder { | |
| 21 | - _, _ = confcardholder.GetCurrent(gameId) | |
| 22 | - } | |
| 23 | - | |
| 24 | - //for _, gameId := range svconst.GameListRoomRank { | |
| 25 | - // _, _ = confroomrank.GetCurrent(gameId) | |
| 26 | - //} | |
| 27 | - | |
| 28 | - return true | |
| 29 | -} |
| ... | ... | @@ -0,0 +1,48 @@ |
| 1 | +package confapi | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "apigame/service-common/svconst" | |
| 6 | + "fmt" | |
| 7 | +) | |
| 8 | + | |
| 9 | +// ApiGameConfig api游戏配置 | |
| 10 | +type ApiGameConfig struct { | |
| 11 | + Raw *Raw | |
| 12 | +} | |
| 13 | + | |
| 14 | +func (c *ApiGameConfig) GetUid() string { | |
| 15 | + return c.Raw.GameId | |
| 16 | +} | |
| 17 | + | |
| 18 | +func (c *ApiGameConfig) CheckCurrent() bool { | |
| 19 | + return true | |
| 20 | +} | |
| 21 | + | |
| 22 | +func (c *ApiGameConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 23 | + tableName := "s_game_config" | |
| 24 | + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 25 | + return &confbase.ConfInfo{ | |
| 26 | + DbMysql: svconst.DbApi, | |
| 27 | + TableName: tableName, | |
| 28 | + KeyName: "gameid", | |
| 29 | + CacheKey: cacheKey, | |
| 30 | + CacheCurrent: cacheKey + ":current", | |
| 31 | + CacheTime: 300, | |
| 32 | + } | |
| 33 | +} | |
| 34 | + | |
| 35 | +// Raw 配置原始数据 | |
| 36 | +type Raw struct { | |
| 37 | + AppId string `gorm:"column:appid"` | |
| 38 | + GameId string `gorm:"column:gameid"` | |
| 39 | + Secret string `gorm:"column:secret"` | |
| 40 | + AppKey string `gorm:"column:appkey"` | |
| 41 | + Name string `gorm:"column:name"` | |
| 42 | +} | |
| 43 | + | |
| 44 | +// Decode 解析配置原始数据 | |
| 45 | +func (c *ApiGameConfig) Decode(gameId string, rawData any) { | |
| 46 | + raw := rawData.(*Raw) | |
| 47 | + c.Raw = raw | |
| 48 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +package confapi | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "errors" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// GetConfig 获取 api游戏配置 | |
| 9 | +func GetConfig(gameId string) (conf *ApiGameConfig, err error) { | |
| 10 | + | |
| 11 | + conf = new(ApiGameConfig) | |
| 12 | + has := confbase.GetConfig[*ApiGameConfig, Raw](gameId, gameId, conf) | |
| 13 | + if !has { | |
| 14 | + err = errors.New("confapi.GetConfig error") | |
| 15 | + return | |
| 16 | + } | |
| 17 | + | |
| 18 | + return | |
| 19 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,113 @@ |
| 1 | +package confbase | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/util/util-lx/lxalilog" | |
| 5 | + "apigame/util/zjson" | |
| 6 | + "apigame/util/zredis" | |
| 7 | + "fmt" | |
| 8 | + "runtime/debug" | |
| 9 | +) | |
| 10 | + | |
| 11 | +var CacheState = 1 // 0=关闭 1=打开 | |
| 12 | + | |
| 13 | +func SaveCache[T IConfData](gameId string, obj T) { | |
| 14 | + info := obj.ConfInfo(gameId) | |
| 15 | + _ = zredis.SetEx(info.CacheKey, zjson.Str(obj), info.CacheTime) | |
| 16 | +} | |
| 17 | + | |
| 18 | +func LoadCache[T IConfData](gameId string, obj T) (has bool) { | |
| 19 | + if CacheState == 0 { | |
| 20 | + return false | |
| 21 | + } | |
| 22 | + has = true | |
| 23 | + info := obj.ConfInfo(gameId) | |
| 24 | + text, err := zredis.Get(info.CacheKey) | |
| 25 | + if err != nil { | |
| 26 | + has = false | |
| 27 | + return | |
| 28 | + } | |
| 29 | + err = zjson.Obj(text, &obj) | |
| 30 | + if err != nil { | |
| 31 | + fmt.Println(err) | |
| 32 | + has = false | |
| 33 | + return | |
| 34 | + } | |
| 35 | + return | |
| 36 | +} | |
| 37 | + | |
| 38 | +func LoadData[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { | |
| 39 | + confRaw := new(T2) | |
| 40 | + info := obj.ConfInfo(gameId) | |
| 41 | + db := info.DbMysql | |
| 42 | + result := db.Table(info.TableName).Where(fmt.Sprintf("%s = ?", info.KeyName), confId).First(confRaw) | |
| 43 | + | |
| 44 | + has = result.RowsAffected != 0 | |
| 45 | + err := result.Error | |
| 46 | + if err != nil { | |
| 47 | + lxalilog.Errors(err, "confbase.LoadData error", gameId, confId) | |
| 48 | + fmt.Printf("%s", debug.Stack()) | |
| 49 | + return | |
| 50 | + } | |
| 51 | + if !has { | |
| 52 | + return | |
| 53 | + } | |
| 54 | + | |
| 55 | + obj.Decode(gameId, confRaw) | |
| 56 | + return | |
| 57 | +} | |
| 58 | + | |
| 59 | +func FindDuringTime[T1 IConfData, T2 IConfRawData](obj T1, raw *T2, gameId string) (has bool) { | |
| 60 | + info := obj.ConfInfo(gameId) | |
| 61 | + db := info.DbMysql | |
| 62 | + result := db.Table(info.TableName).Where(info.CurrentQuery, info.CurrentArgs...).First(raw) | |
| 63 | + has = result.RowsAffected != 0 | |
| 64 | + return | |
| 65 | +} | |
| 66 | + | |
| 67 | +func GetConfig[T1 IConfData, T2 IConfRawData](gameId string, confId any, obj T1) (has bool) { | |
| 68 | + has = LoadCache(gameId, obj) | |
| 69 | + if has { | |
| 70 | + return | |
| 71 | + } | |
| 72 | + has = LoadData[T1, T2](gameId, confId, obj) | |
| 73 | + if !has { | |
| 74 | + return | |
| 75 | + } | |
| 76 | + SaveCache(gameId, obj) | |
| 77 | + return | |
| 78 | +} | |
| 79 | + | |
| 80 | +// GetCurrent 获取 当前配置 | |
| 81 | +func GetCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { | |
| 82 | + has := false | |
| 83 | + info := obj.ConfInfo(gameId) | |
| 84 | + currentKey := info.CacheCurrent | |
| 85 | + currentId := zredis.GetString(currentKey) | |
| 86 | + if currentId != "" { | |
| 87 | + has = GetConfig[T1, T2](gameId, currentId, obj) | |
| 88 | + if has { | |
| 89 | + if !obj.CheckCurrent() { | |
| 90 | + has = false | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| 94 | + return has | |
| 95 | +} | |
| 96 | + | |
| 97 | +// FindCurrent 查找 当前配置 | |
| 98 | +func FindCurrent[T1 IConfData, T2 IConfRawData](gameId string, obj T1) bool { | |
| 99 | + has := false | |
| 100 | + info := obj.ConfInfo(gameId) | |
| 101 | + currentKey := info.CacheCurrent | |
| 102 | + currentId := zredis.GetString(currentKey) | |
| 103 | + confRaw := new(T2) | |
| 104 | + has = FindDuringTime[T1, T2](obj, confRaw, gameId) | |
| 105 | + if has { | |
| 106 | + obj.Decode(gameId, confRaw) | |
| 107 | + SaveCache(gameId, obj) | |
| 108 | + has = true | |
| 109 | + currentId = obj.GetUid() | |
| 110 | + _ = zredis.Set(currentKey, currentId) | |
| 111 | + } | |
| 112 | + return has | |
| 113 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +package confbase | |
| 2 | + | |
| 3 | +import "gorm.io/gorm" | |
| 4 | + | |
| 5 | +// ConfInfo 配置对象信息 | |
| 6 | +type ConfInfo struct { | |
| 7 | + DbMysql *gorm.DB | |
| 8 | + TableName string | |
| 9 | + KeyName string | |
| 10 | + CurrentQuery any | |
| 11 | + CurrentArgs []any | |
| 12 | + CacheKey string | |
| 13 | + CacheCurrent string | |
| 14 | + CacheTime int | |
| 15 | +} | |
| 16 | + | |
| 17 | +// IConfData 配置对象 | |
| 18 | +type IConfData interface { | |
| 19 | + // ConfInfo redis存储信息 | |
| 20 | + ConfInfo(suffix string) *ConfInfo | |
| 21 | + // Decode 解码 | |
| 22 | + Decode(gameId string, rawData any) | |
| 23 | + // GetUid 获取keyID | |
| 24 | + GetUid() string | |
| 25 | + // CheckCurrent 判断当前开放 | |
| 26 | + CheckCurrent() bool | |
| 27 | +} | |
| 28 | + | |
| 29 | +// IConfRawData mysql存储对象 | |
| 30 | +type IConfRawData interface { | |
| 31 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,153 @@ |
| 1 | +package confcardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "apigame/service-common/svconst" | |
| 6 | + "apigame/util/util-lx/lxtime" | |
| 7 | + "apigame/util/zconvert" | |
| 8 | + "fmt" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// ActivityConfig 卡牌活动配置 分析后数据 | |
| 12 | +type ActivityConfig struct { | |
| 13 | + Raw *ActivityConfigRaw `json:"-"` | |
| 14 | + | |
| 15 | + Id int64 // ID | |
| 16 | + OpenLevel int // 开启等级 | |
| 17 | + PreviewTime int64 // 预告时间 | |
| 18 | + StartTime int64 // 开始时间 | |
| 19 | + EndTime int64 // 结束时间 | |
| 20 | + Round int // 轮数 | |
| 21 | + IconPath string // icon资源路径 | |
| 22 | + | |
| 23 | + Awards map[string]string // 奖励配置 | |
| 24 | + AlbumConfig map[int]AlbumConfig // 卡组配置 | |
| 25 | + CardConfig map[int]CardConfig // 卡牌配置 | |
| 26 | + CardholderConfig map[int]OpenCardholderConfig // 卡包开卡规则 | |
| 27 | + NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 | |
| 28 | + CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 | |
| 29 | + StarShopConfig map[int]StarShopConfig // 星星商店配置 | |
| 30 | + ListSequenceId []int // 用户序列组ID列表 | |
| 31 | + | |
| 32 | + Client *ActivityConfigClient | |
| 33 | + GameId string // 所属游戏ID | |
| 34 | +} | |
| 35 | + | |
| 36 | +func (c *ActivityConfig) GetUid() string { | |
| 37 | + return zconvert.Int64ToStr(c.Id) | |
| 38 | +} | |
| 39 | + | |
| 40 | +func (c *ActivityConfig) CheckCurrent() bool { | |
| 41 | + timeNow := lxtime.NowUninx() | |
| 42 | + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 | |
| 43 | +} | |
| 44 | + | |
| 45 | +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 46 | + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG | |
| 47 | + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 48 | + timeNow := lxtime.NowUninx() | |
| 49 | + return &confbase.ConfInfo{ | |
| 50 | + DbMysql: svconst.DbConfig, | |
| 51 | + TableName: fmt.Sprintf("%s_%s", tableName, suffix), | |
| 52 | + KeyName: "id", | |
| 53 | + CurrentQuery: "status = ? AND start_time <= ? AND end_time >= ?", | |
| 54 | + CurrentArgs: []any{1, timeNow, timeNow}, | |
| 55 | + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | |
| 56 | + CacheCurrent: cacheKey + ":current", | |
| 57 | + CacheTime: 300, | |
| 58 | + } | |
| 59 | +} | |
| 60 | + | |
| 61 | +// ActivityConfigRaw 卡牌活动配置 原始数据 | |
| 62 | +type ActivityConfigRaw struct { | |
| 63 | + Id int64 `gorm:"column:id;primaryKey"` // ID | |
| 64 | + OpenLevel int // 开启等级 | |
| 65 | + PreviewTime int64 // 预告时间 | |
| 66 | + StartTime int64 // 开始时间 | |
| 67 | + EndTime int64 // 结束时间 | |
| 68 | + Round int // 轮数 | |
| 69 | + IconPath string // icon资源路径 | |
| 70 | + | |
| 71 | + Awards string // 奖励配置 | |
| 72 | + AlbumConfig string // 卡组配置 | |
| 73 | + CardConfig string // 卡牌配置 | |
| 74 | + CardHolderConfig string // 卡包开卡规则 | |
| 75 | + NormalCardStarSequence string // 卡片星级配置 | |
| 76 | + CardSequenceConfig string // 卡片星级对应卡牌配置 | |
| 77 | + StarShopConfig string // 星星商店配置 | |
| 78 | + | |
| 79 | + Ver string // 版本号 | |
| 80 | + Status int // 状态 0=关闭 1=开启 | |
| 81 | + UpdateTime int64 // 修改时间戳 | |
| 82 | +} | |
| 83 | + | |
| 84 | +// ActivityConfigClient 卡牌活动配置 给客户端数据 | |
| 85 | +type ActivityConfigClient struct { | |
| 86 | + Id int64 `form:"id" json:"id"` // ID | |
| 87 | + Round int `form:"round" json:"round"` // 轮数 | |
| 88 | + IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 | |
| 89 | + RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 | |
| 90 | + Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置 | |
| 91 | + Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置 | |
| 92 | + Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则 | |
| 93 | + StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置 | |
| 94 | +} | |
| 95 | + | |
| 96 | +// AlbumConfig 卡组表 | |
| 97 | +type AlbumConfig struct { | |
| 98 | + SetId int `json:"set_id"` // 卡组名 | |
| 99 | + Name int `json:"name"` // 卡组图片 | |
| 100 | + Icon string `json:"icon"` // 卡组id | |
| 101 | + Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次 | |
| 102 | + StartTime int64 `json:"start_time"` // 开始时间 | |
| 103 | + EndTime int64 `json:"end_time"` // 结束时间 | |
| 104 | +} | |
| 105 | + | |
| 106 | +// CardConfig 卡牌表 | |
| 107 | +type CardConfig struct { | |
| 108 | + Id int `json:"id"` // ID | |
| 109 | + Name int `json:"name"` // 卡牌名字 | |
| 110 | + Icon string `json:"icon"` // 卡牌图标 | |
| 111 | + Desc int `json:"desc"` // 卡牌描述 | |
| 112 | + SetId int `json:"album_setid"` // 卡组id | |
| 113 | + Star int `json:"star"` // 星级 | |
| 114 | + IsGold int `json:"is_gold"` // 是否是金卡 | |
| 115 | + IsSend int `json:"is_send"` // 卡片是否可赠送 | |
| 116 | +} | |
| 117 | + | |
| 118 | +// OpenCardholderConfig 卡包开卡规则表 | |
| 119 | +type OpenCardholderConfig struct { | |
| 120 | + Id int `json:"id"` // ID | |
| 121 | + CardPackIcon string `json:"img"` // 卡包资源名 | |
| 122 | + IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包 | |
| 123 | + IsNew int `json:"is_new"` // 是否是新卡包 | |
| 124 | + GuaranteedStarCardId int `json:"guaranteed_star_card_id"` // 保底卡星级序列ID | |
| 125 | + NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量 | |
| 126 | + MinimumGuaranteeCardId int `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID | |
| 127 | + ActivityId int `json:"activity_id"` // 对应活动ID | |
| 128 | + Star int `json:"star"` // star | |
| 129 | + Name int `json:"name"` // name | |
| 130 | +} | |
| 131 | + | |
| 132 | +// NormalCardStarConfig 非保底卡星级ID | |
| 133 | +type NormalCardStarConfig struct { | |
| 134 | + Id int `json:"id"` // ID | |
| 135 | + SequenceId int `json:"user_sequence_id"` // 用户序列组ID | |
| 136 | + Cohort int `json:"cohort"` // 用户分组 | |
| 137 | + NormalCardSequenceId []int `json:"normal_card_sequence_id"` // 非保底星级序列 | |
| 138 | +} | |
| 139 | + | |
| 140 | +// CardSequenceConfig 星级ID对应的卡片 | |
| 141 | +type CardSequenceConfig struct { | |
| 142 | + Id int `json:"id"` // ID | |
| 143 | + SequenceId int `json:"user_sequence_id"` // 用户序列组ID | |
| 144 | + Cohort int `json:"cohort"` // 用户分组 | |
| 145 | + CardIdList []int `json:"card_id_list"` // 卡牌抽取序列 | |
| 146 | +} | |
| 147 | + | |
| 148 | +// StarShopConfig 星星商店配置 | |
| 149 | +type StarShopConfig struct { | |
| 150 | + Id int `json:"id"` // ID | |
| 151 | + NeedStarNumber int `json:"need_star_number"` // 需求星星数 | |
| 152 | + CardBagIds string `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量} | |
| 153 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,177 @@ |
| 1 | +package confcardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/util/util-lx/lxalilog" | |
| 5 | + "apigame/util/zslice" | |
| 6 | + "encoding/json" | |
| 7 | + "errors" | |
| 8 | + "fmt" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// Decode 解析配置原始数据 | |
| 12 | +func (c *ActivityConfig) Decode(gameId string, rawData any) { | |
| 13 | + raw := rawData.(*ActivityConfigRaw) | |
| 14 | + c.GameId = gameId | |
| 15 | + c.Raw = raw | |
| 16 | + | |
| 17 | + c.Id = raw.Id | |
| 18 | + c.OpenLevel = raw.OpenLevel | |
| 19 | + c.PreviewTime = raw.PreviewTime | |
| 20 | + c.StartTime = raw.StartTime | |
| 21 | + c.EndTime = raw.EndTime | |
| 22 | + c.Round = raw.Round | |
| 23 | + c.IconPath = raw.IconPath | |
| 24 | + | |
| 25 | + c.Awards = make(map[string]string) | |
| 26 | + c.AlbumConfig = make(map[int]AlbumConfig) | |
| 27 | + c.CardConfig = make(map[int]CardConfig) | |
| 28 | + c.CardholderConfig = make(map[int]OpenCardholderConfig) | |
| 29 | + c.NormalCardStarConfig = make(map[string]NormalCardStarConfig) | |
| 30 | + c.CardSequenceConfig = make(map[string]CardSequenceConfig) | |
| 31 | + c.StarShopConfig = make(map[int]StarShopConfig) | |
| 32 | + // 解析奖励 | |
| 33 | + { | |
| 34 | + err := json.Unmarshal([]byte(raw.Awards), &c.Awards) | |
| 35 | + if err != nil { | |
| 36 | + lxalilog.Errors(err, raw.Awards, gameId, raw.Id) | |
| 37 | + return | |
| 38 | + } | |
| 39 | + } | |
| 40 | + // 卡组配置 | |
| 41 | + { | |
| 42 | + configs := make([]AlbumConfig, 0) | |
| 43 | + err := json.Unmarshal([]byte(raw.AlbumConfig), &configs) | |
| 44 | + if err != nil { | |
| 45 | + lxalilog.Errors(err, raw.AlbumConfig, gameId, raw.Id) | |
| 46 | + return | |
| 47 | + } | |
| 48 | + for _, i2 := range configs { | |
| 49 | + c.AlbumConfig[i2.SetId] = i2 | |
| 50 | + } | |
| 51 | + } | |
| 52 | + // 卡牌配置 | |
| 53 | + { | |
| 54 | + configs := make([]CardConfig, 0) | |
| 55 | + err := json.Unmarshal([]byte(raw.CardConfig), &configs) | |
| 56 | + if err != nil { | |
| 57 | + lxalilog.Errors(err, raw.CardConfig, gameId, raw.Id) | |
| 58 | + return | |
| 59 | + } | |
| 60 | + for _, i2 := range configs { | |
| 61 | + c.CardConfig[i2.Id] = i2 | |
| 62 | + } | |
| 63 | + } | |
| 64 | + // 卡包开卡规则 | |
| 65 | + { | |
| 66 | + configs := make([]OpenCardholderConfig, 0) | |
| 67 | + err := json.Unmarshal([]byte(raw.CardHolderConfig), &configs) | |
| 68 | + if err != nil { | |
| 69 | + lxalilog.Errors(err, raw.CardHolderConfig, gameId, raw.Id) | |
| 70 | + return | |
| 71 | + } | |
| 72 | + for _, i2 := range configs { | |
| 73 | + c.CardholderConfig[i2.Id] = i2 | |
| 74 | + } | |
| 75 | + } | |
| 76 | + // 卡片星级配置 | |
| 77 | + { | |
| 78 | + configs := make([]NormalCardStarConfig, 0) | |
| 79 | + err := json.Unmarshal([]byte(raw.NormalCardStarSequence), &configs) | |
| 80 | + if err != nil { | |
| 81 | + lxalilog.Errors(err, raw.NormalCardStarSequence, gameId, raw.Id) | |
| 82 | + return | |
| 83 | + } | |
| 84 | + for _, i2 := range configs { | |
| 85 | + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) | |
| 86 | + c.NormalCardStarConfig[combineId] = i2 | |
| 87 | + if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { | |
| 88 | + c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | + // 卡片星级对应卡牌配置 | |
| 93 | + { | |
| 94 | + configs := make([]CardSequenceConfig, 0) | |
| 95 | + err := json.Unmarshal([]byte(raw.CardSequenceConfig), &configs) | |
| 96 | + if err != nil { | |
| 97 | + lxalilog.Errors(err, raw.CardSequenceConfig, gameId, raw.Id) | |
| 98 | + return | |
| 99 | + } | |
| 100 | + for _, i2 := range configs { | |
| 101 | + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort) | |
| 102 | + c.CardSequenceConfig[combineId] = i2 | |
| 103 | + if !zslice.Contains(c.ListSequenceId, i2.SequenceId) { | |
| 104 | + c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId) | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } | |
| 108 | + // 星星商店配置 | |
| 109 | + { | |
| 110 | + configs := make([]StarShopConfig, 0) | |
| 111 | + err := json.Unmarshal([]byte(raw.StarShopConfig), &configs) | |
| 112 | + if err != nil { | |
| 113 | + lxalilog.Errors(err, raw.StarShopConfig, gameId, raw.Id) | |
| 114 | + return | |
| 115 | + } | |
| 116 | + for _, i2 := range configs { | |
| 117 | + c.StarShopConfig[i2.Id] = i2 | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 121 | + c.GenerateConfigClient() | |
| 122 | +} | |
| 123 | + | |
| 124 | +// GenerateConfigClient 生成给客户端的配置 | |
| 125 | +func (c *ActivityConfig) GenerateConfigClient() { | |
| 126 | + configClient := &ActivityConfigClient{ | |
| 127 | + Id: c.Id, | |
| 128 | + Round: c.Round, | |
| 129 | + IconPath: c.IconPath, | |
| 130 | + RoundAwards: c.Awards, | |
| 131 | + Albums: make([]AlbumConfig, 0), | |
| 132 | + Cards: make([]CardConfig, 0), | |
| 133 | + Holders: make([]OpenCardholderConfig, 0), | |
| 134 | + StarShop: make([]StarShopConfig, 0), | |
| 135 | + } | |
| 136 | + for _, i2 := range c.AlbumConfig { | |
| 137 | + configClient.Albums = append(configClient.Albums, i2) | |
| 138 | + } | |
| 139 | + for _, i2 := range c.CardConfig { | |
| 140 | + configClient.Cards = append(configClient.Cards, i2) | |
| 141 | + } | |
| 142 | + for _, i2 := range c.CardholderConfig { | |
| 143 | + configClient.Holders = append(configClient.Holders, i2) | |
| 144 | + } | |
| 145 | + for _, i2 := range c.StarShopConfig { | |
| 146 | + configClient.StarShop = append(configClient.StarShop, i2) | |
| 147 | + } | |
| 148 | + c.Client = configClient | |
| 149 | +} | |
| 150 | + | |
| 151 | +// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组 | |
| 152 | +func CombineIdSequenceIdCohort(id, sequenceId, cohort int) string { | |
| 153 | + return fmt.Sprintf("%d_%d_%d", id, sequenceId, cohort) | |
| 154 | +} | |
| 155 | + | |
| 156 | +// FindNormalCardStarConfig 查找配置 非保底卡星级ID | |
| 157 | +func (c *ActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort int) (conf NormalCardStarConfig, has bool) { | |
| 158 | + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) | |
| 159 | + conf, has = c.NormalCardStarConfig[combineId] | |
| 160 | + if !has { | |
| 161 | + lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort) | |
| 162 | + } | |
| 163 | + return | |
| 164 | +} | |
| 165 | + | |
| 166 | +// FindCardSequenceConfig 查找配置 星级ID对应的卡片 | |
| 167 | +func (c *ActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort int) (conf CardSequenceConfig, has bool) { | |
| 168 | + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort) | |
| 169 | + conf, has = c.CardSequenceConfig[combineId] | |
| 170 | + if !has { | |
| 171 | + lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort) | |
| 172 | + fmt.Println(id) | |
| 173 | + fmt.Println(sequenceId) | |
| 174 | + fmt.Println(cohort) | |
| 175 | + } | |
| 176 | + return | |
| 177 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | +package confcardholder | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | +) | |
| 6 | + | |
| 7 | +// GetCurrent 获取 当前配置 | |
| 8 | +func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { | |
| 9 | + conf = new(ActivityConfig) | |
| 10 | + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 11 | + if !has { | |
| 12 | + conf = new(ActivityConfig) | |
| 13 | + has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 14 | + } | |
| 15 | + return | |
| 16 | +} | |
| 17 | + | |
| 18 | +// GetConfig 获取 配置根据Id | |
| 19 | +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | |
| 20 | + conf = new(ActivityConfig) | |
| 21 | + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) | |
| 22 | + | |
| 23 | + return | |
| 24 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,67 @@ |
| 1 | +package confglobal | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "apigame/service-common/svconst" | |
| 6 | + "apigame/util/util-lx/lxalilog" | |
| 7 | + "encoding/json" | |
| 8 | + "fmt" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// GlobalConfig 全局配置 | |
| 12 | +type GlobalConfig struct { | |
| 13 | + Raw *Raw `json:"-"` | |
| 14 | + Names []string | |
| 15 | + Avatars []string | |
| 16 | + AvatarPath string | |
| 17 | +} | |
| 18 | + | |
| 19 | +func (c *GlobalConfig) GetUid() string { | |
| 20 | + return c.Raw.GameId | |
| 21 | +} | |
| 22 | + | |
| 23 | +func (c *GlobalConfig) CheckCurrent() bool { | |
| 24 | + return true | |
| 25 | +} | |
| 26 | + | |
| 27 | +func (c *GlobalConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 28 | + tableName := "s_game_global_config" | |
| 29 | + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 30 | + return &confbase.ConfInfo{ | |
| 31 | + DbMysql: svconst.DbConfig, | |
| 32 | + TableName: tableName, | |
| 33 | + KeyName: "gameid", | |
| 34 | + CacheKey: cacheKey, | |
| 35 | + CacheCurrent: cacheKey + ":current", | |
| 36 | + CacheTime: 300, | |
| 37 | + } | |
| 38 | +} | |
| 39 | + | |
| 40 | +// Raw 配置原始数据 | |
| 41 | +type Raw struct { | |
| 42 | + GameId string `gorm:"column:gameid"` | |
| 43 | + NameConfig string | |
| 44 | + AvatarConfig string | |
| 45 | + AvatarPath string | |
| 46 | +} | |
| 47 | + | |
| 48 | +// Decode 解析配置原始数据 | |
| 49 | +func (c *GlobalConfig) Decode(gameId string, rawData any) { | |
| 50 | + raw := rawData.(*Raw) | |
| 51 | + c.Raw = raw | |
| 52 | + { | |
| 53 | + err := json.Unmarshal([]byte(raw.NameConfig), &c.Names) | |
| 54 | + if err != nil { | |
| 55 | + lxalilog.Errors(err, raw.NameConfig, gameId, raw.GameId) | |
| 56 | + return | |
| 57 | + } | |
| 58 | + } | |
| 59 | + { | |
| 60 | + err := json.Unmarshal([]byte(raw.AvatarConfig), &c.Avatars) | |
| 61 | + if err != nil { | |
| 62 | + lxalilog.Errors(err, raw.AvatarConfig, gameId, raw.GameId) | |
| 63 | + return | |
| 64 | + } | |
| 65 | + } | |
| 66 | + c.AvatarPath = raw.AvatarPath | |
| 67 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +package confglobal | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "errors" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// GetConfig 获取 api游戏配置 | |
| 9 | +func GetConfig(gameId string) (conf *GlobalConfig, err error) { | |
| 10 | + | |
| 11 | + conf = new(GlobalConfig) | |
| 12 | + has := confbase.GetConfig[*GlobalConfig, Raw](gameId, gameId, conf) | |
| 13 | + if !has { | |
| 14 | + err = errors.New("confglobal.GetConfig error") | |
| 15 | + return | |
| 16 | + } | |
| 17 | + | |
| 18 | + return | |
| 19 | +} | ... | ... |
configs/config.go
| ... | ... | @@ -1,282 +0,0 @@ |
| 1 | -// DO NOT EDIT! | |
| 2 | -// This code is auto generated by go-xlsx-exporter | |
| 3 | -// VERSION 1.3 | |
| 4 | -// go-protobuf v1.27.1 | |
| 5 | - | |
| 6 | -package configs | |
| 7 | - | |
| 8 | -import ( | |
| 9 | - reflect "reflect" | |
| 10 | - sync "sync" | |
| 11 | - | |
| 12 | - protoreflect "google.golang.org/protobuf/reflect/protoreflect" | |
| 13 | - protoimpl "google.golang.org/protobuf/runtime/protoimpl" | |
| 14 | -) | |
| 15 | - | |
| 16 | -const ( | |
| 17 | - // Verify that this generated code is sufficiently up-to-date. | |
| 18 | - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) | |
| 19 | - // Verify that runtime/protoimpl is sufficiently up-to-date. | |
| 20 | - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) | |
| 21 | -) | |
| 22 | - | |
| 23 | -/* type ConvertHandler func (field string, value interface{}) interface{} | |
| 24 | - | |
| 25 | -type MessageBase struct { | |
| 26 | - | |
| 27 | -} | |
| 28 | - | |
| 29 | -func (item *MessageBase) GetConvertData(field string, value interface{}) { | |
| 30 | - | |
| 31 | -} */ | |
| 32 | -// Defined in table: data/abtest.xlsx:abtest; | |
| 33 | -type AbTestCfg struct { | |
| 34 | - state protoimpl.MessageState | |
| 35 | - sizeCache protoimpl.SizeCache | |
| 36 | - unknownFields protoimpl.UnknownFields | |
| 37 | - | |
| 38 | - ID uint32 `protobuf:"varint,1,opt,name=ID,proto3uint32" json:"ID,omitempty"` /** 编号 */ | |
| 39 | - | |
| 40 | - Name string `protobuf:"bytes,2,opt,name=Name,proto3string" json:"Name,omitempty"` /** 分组名 */ | |
| 41 | - | |
| 42 | - Min uint32 `protobuf:"varint,3,opt,name=Min,proto3uint32" json:"Min,omitempty"` /** ID下限 */ | |
| 43 | - | |
| 44 | - Max uint32 `protobuf:"varint,4,opt,name=Max,proto3uint32" json:"Max,omitempty"` /** ID上限 */ | |
| 45 | - | |
| 46 | - Condition string `protobuf:"bytes,5,opt,name=Condition,proto3string" json:"Condition,omitempty"` /** 条件 */ | |
| 47 | - | |
| 48 | - Config string `protobuf:"bytes,6,opt,name=Config,proto3string" json:"Config,omitempty"` /** 配置 */ | |
| 49 | - | |
| 50 | -} | |
| 51 | - | |
| 52 | -func (x *AbTestCfg) Reset() { | |
| 53 | - *x = AbTestCfg{} | |
| 54 | - if protoimpl.UnsafeEnabled { | |
| 55 | - mi := &file_config_proto_msgTypes[0] | |
| 56 | - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) | |
| 57 | - ms.StoreMessageInfo(mi) | |
| 58 | - } | |
| 59 | -} | |
| 60 | - | |
| 61 | -func (x *AbTestCfg) String() string { | |
| 62 | - return protoimpl.X.MessageStringOf(x) | |
| 63 | -} | |
| 64 | - | |
| 65 | -func (*AbTestCfg) ProtoMessage() {} | |
| 66 | - | |
| 67 | -func (x *AbTestCfg) ProtoReflect() protoreflect.Message { | |
| 68 | - mi := &file_config_proto_msgTypes[0] | |
| 69 | - if protoimpl.UnsafeEnabled && x != nil { | |
| 70 | - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) | |
| 71 | - if ms.LoadMessageInfo() == nil { | |
| 72 | - ms.StoreMessageInfo(mi) | |
| 73 | - } | |
| 74 | - return ms | |
| 75 | - } | |
| 76 | - return mi.MessageOf(x) | |
| 77 | -} | |
| 78 | - | |
| 79 | -// Deprecated: Use AbTestCfg.ProtoReflect.Descriptor instead. | |
| 80 | -func (*AbTestCfg) Descriptor() ([]byte, []int) { | |
| 81 | - return file_config_proto_rawDescGZIP(), []int{0} | |
| 82 | -} | |
| 83 | - | |
| 84 | -func (x *AbTestCfg) GetID() uint32 { | |
| 85 | - if x != nil { | |
| 86 | - return x.ID | |
| 87 | - } | |
| 88 | - return 0 | |
| 89 | -} | |
| 90 | - | |
| 91 | -func (x *AbTestCfg) GetName() string { | |
| 92 | - if x != nil { | |
| 93 | - return x.Name | |
| 94 | - } | |
| 95 | - return "" | |
| 96 | -} | |
| 97 | - | |
| 98 | -func (x *AbTestCfg) GetMin() uint32 { | |
| 99 | - if x != nil { | |
| 100 | - return x.Min | |
| 101 | - } | |
| 102 | - return 0 | |
| 103 | -} | |
| 104 | - | |
| 105 | -func (x *AbTestCfg) GetMax() uint32 { | |
| 106 | - if x != nil { | |
| 107 | - return x.Max | |
| 108 | - } | |
| 109 | - return 0 | |
| 110 | -} | |
| 111 | - | |
| 112 | -func (x *AbTestCfg) GetCondition() string { | |
| 113 | - if x != nil { | |
| 114 | - return x.Condition | |
| 115 | - } | |
| 116 | - return "" | |
| 117 | -} | |
| 118 | - | |
| 119 | -func (x *AbTestCfg) GetConfig() string { | |
| 120 | - if x != nil { | |
| 121 | - return x.Config | |
| 122 | - } | |
| 123 | - return "" | |
| 124 | -} | |
| 125 | - | |
| 126 | - | |
| 127 | -// Defined in table: data/abtest.xlsx:abtest; | |
| 128 | -type AbTestCfg_ARRAY struct { | |
| 129 | - state protoimpl.MessageState | |
| 130 | - sizeCache protoimpl.SizeCache | |
| 131 | - unknownFields protoimpl.UnknownFields | |
| 132 | - | |
| 133 | - | |
| 134 | - Items []*AbTestCfg `protobuf:"bytes,1,rep,name=Items,proto3*AbTestCfg" json:"Items,omitempty"` | |
| 135 | - | |
| 136 | -} | |
| 137 | - | |
| 138 | -func (x *AbTestCfg_ARRAY) Reset() { | |
| 139 | - *x = AbTestCfg_ARRAY{} | |
| 140 | - if protoimpl.UnsafeEnabled { | |
| 141 | - mi := &file_config_proto_msgTypes[1] | |
| 142 | - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) | |
| 143 | - ms.StoreMessageInfo(mi) | |
| 144 | - } | |
| 145 | -} | |
| 146 | - | |
| 147 | -func (x *AbTestCfg_ARRAY) String() string { | |
| 148 | - return protoimpl.X.MessageStringOf(x) | |
| 149 | -} | |
| 150 | - | |
| 151 | -func (*AbTestCfg_ARRAY) ProtoMessage() {} | |
| 152 | - | |
| 153 | -func (x *AbTestCfg_ARRAY) ProtoReflect() protoreflect.Message { | |
| 154 | - mi := &file_config_proto_msgTypes[1] | |
| 155 | - if protoimpl.UnsafeEnabled && x != nil { | |
| 156 | - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) | |
| 157 | - if ms.LoadMessageInfo() == nil { | |
| 158 | - ms.StoreMessageInfo(mi) | |
| 159 | - } | |
| 160 | - return ms | |
| 161 | - } | |
| 162 | - return mi.MessageOf(x) | |
| 163 | -} | |
| 164 | - | |
| 165 | -// Deprecated: Use AbTestCfg_ARRAY.ProtoReflect.Descriptor instead. | |
| 166 | -func (*AbTestCfg_ARRAY) Descriptor() ([]byte, []int) { | |
| 167 | - return file_config_proto_rawDescGZIP(), []int{1} | |
| 168 | -} | |
| 169 | - | |
| 170 | -func (x *AbTestCfg_ARRAY) GetItems() []*AbTestCfg { | |
| 171 | - if x != nil { | |
| 172 | - return x.Items | |
| 173 | - } | |
| 174 | - return nil | |
| 175 | -} | |
| 176 | - | |
| 177 | - | |
| 178 | -var File_config_proto protoreflect.FileDescriptor | |
| 179 | - | |
| 180 | -var file_config_proto_rawDesc = []byte{ | |
| 181 | -0x0a,0x0c,0x63,0x6f,0x6e,0x66,0x69,0x67,0x2e,0x70,0x72,0x6f,0x74,0x6f,0x12,0x07, | |
| 182 | -0x63,0x6f,0x6e,0x66,0x69,0x67,0x73,0x22,0x89,0x01,0x0a,0x09,0x41,0x62,0x54,0x65, | |
| 183 | -0x73,0x74,0x43,0x66,0x67,0x12,0x0e,0x0a,0x02,0x49,0x44,0x18,0x01,0x20,0x01,0x28, | |
| 184 | -0x0d,0x52,0x02,0x49,0x44,0x12,0x12,0x0a,0x04,0x4e,0x61,0x6d,0x65,0x18,0x02,0x20, | |
| 185 | -0x01,0x28,0x09,0x52,0x04,0x4e,0x61,0x6d,0x65,0x12,0x10,0x0a,0x03,0x4d,0x69,0x6e, | |
| 186 | -0x18,0x03,0x20,0x01,0x28,0x0d,0x52,0x03,0x4d,0x69,0x6e,0x12,0x10,0x0a,0x03,0x4d, | |
| 187 | -0x61,0x78,0x18,0x04,0x20,0x01,0x28,0x0d,0x52,0x03,0x4d,0x61,0x78,0x12,0x1c,0x0a, | |
| 188 | -0x09,0x43,0x6f,0x6e,0x64,0x69,0x74,0x69,0x6f,0x6e,0x18,0x05,0x20,0x01,0x28,0x09, | |
| 189 | -0x52,0x09,0x43,0x6f,0x6e,0x64,0x69,0x74,0x69,0x6f,0x6e,0x12,0x16,0x0a,0x06,0x43, | |
| 190 | -0x6f,0x6e,0x66,0x69,0x67,0x18,0x06,0x20,0x01,0x28,0x09,0x52,0x06,0x43,0x6f,0x6e, | |
| 191 | -0x66,0x69,0x67,0x22,0x3b,0x0a,0x0f,0x41,0x62,0x54,0x65,0x73,0x74,0x43,0x66,0x67, | |
| 192 | -0x5f,0x41,0x52,0x52,0x41,0x59,0x12,0x28,0x0a,0x05,0x49,0x74,0x65,0x6d,0x73,0x18, | |
| 193 | -0x01,0x20,0x03,0x28,0x0b,0x32,0x12,0x2e,0x63,0x6f,0x6e,0x66,0x69,0x67,0x73,0x2e, | |
| 194 | -0x41,0x62,0x54,0x65,0x73,0x74,0x43,0x66,0x67,0x52,0x05,0x49,0x74,0x65,0x6d,0x73, | |
| 195 | -0x62,0x06,0x70,0x72,0x6f,0x74,0x6f,0x33, | |
| 196 | -} | |
| 197 | - | |
| 198 | -var ( | |
| 199 | - file_config_proto_rawDescOnce sync.Once | |
| 200 | - file_config_proto_rawDescData = file_config_proto_rawDesc | |
| 201 | -) | |
| 202 | - | |
| 203 | -func file_config_proto_rawDescGZIP() []byte { | |
| 204 | - file_config_proto_rawDescOnce.Do(func() { | |
| 205 | - file_config_proto_rawDescData = protoimpl.X.CompressGZIP(file_config_proto_rawDescData) | |
| 206 | - }) | |
| 207 | - return file_config_proto_rawDescData | |
| 208 | -} | |
| 209 | - | |
| 210 | -var file_config_proto_enumTypes = make([]protoimpl.EnumInfo, 0) | |
| 211 | -var file_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2) | |
| 212 | -var file_config_proto_goTypes = []interface{}{ | |
| 213 | - (*AbTestCfg)(nil), // 0: configs.AbTestCfg | |
| 214 | - (*AbTestCfg_ARRAY)(nil), // 1: configs.AbTestCfg_ARRAY | |
| 215 | - | |
| 216 | -} | |
| 217 | - | |
| 218 | -var file_config_proto_depIdxs = []int32{ | |
| 219 | - 0, // 0: configs.AbTestCfg_ARRAY:type_name -> configs.AbTestCfg | |
| 220 | -1, // [1:1] is the sub-list for method output_type | |
| 221 | -1, // [1:1] is the sub-list for method input_type | |
| 222 | -1, // [1:1] is the sub-list for extension type_name | |
| 223 | -1, // [1:1] is the sub-list for extension extendee | |
| 224 | -0, // [0:1] is the sub-list for field type_name | |
| 225 | -} | |
| 226 | - | |
| 227 | -func file_config_proto_init() { | |
| 228 | - if File_config_proto != nil { | |
| 229 | - return | |
| 230 | - } | |
| 231 | - if !protoimpl.UnsafeEnabled { | |
| 232 | - file_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { | |
| 233 | - switch v := v.(*AbTestCfg); i { | |
| 234 | - case 0: | |
| 235 | - return &v.state | |
| 236 | - case 1: | |
| 237 | - return &v.sizeCache | |
| 238 | - case 2: | |
| 239 | - return &v.unknownFields | |
| 240 | - default: | |
| 241 | - return nil | |
| 242 | - } | |
| 243 | - } | |
| 244 | - | |
| 245 | - file_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { | |
| 246 | - switch v := v.(*AbTestCfg_ARRAY); i { | |
| 247 | - case 0: | |
| 248 | - return &v.state | |
| 249 | - case 1: | |
| 250 | - return &v.sizeCache | |
| 251 | - case 2: | |
| 252 | - return &v.unknownFields | |
| 253 | - default: | |
| 254 | - return nil | |
| 255 | - } | |
| 256 | - } | |
| 257 | - | |
| 258 | - } | |
| 259 | - type x struct{} | |
| 260 | - out := protoimpl.TypeBuilder{ | |
| 261 | - File: protoimpl.DescBuilder{ | |
| 262 | - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), | |
| 263 | - RawDescriptor: file_config_proto_rawDesc, | |
| 264 | - NumEnums: 0, | |
| 265 | - NumMessages: 2, | |
| 266 | - NumExtensions: 0, | |
| 267 | - NumServices: 0, | |
| 268 | - }, | |
| 269 | - GoTypes: file_config_proto_goTypes, | |
| 270 | - DependencyIndexes: file_config_proto_depIdxs, | |
| 271 | - EnumInfos: file_config_proto_enumTypes, | |
| 272 | - MessageInfos: file_config_proto_msgTypes, | |
| 273 | - }.Build() | |
| 274 | - File_config_proto = out.File | |
| 275 | - file_config_proto_rawDesc = nil | |
| 276 | - file_config_proto_goTypes = nil | |
| 277 | - file_config_proto_depIdxs = nil | |
| 278 | -} | |
| 279 | - | |
| 280 | -func init() { | |
| 281 | - file_config_proto_init() | |
| 282 | -} | |
| 283 | 0 | \ No newline at end of file |
| ... | ... | @@ -0,0 +1,129 @@ |
| 1 | +package confroomrank | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "apigame/service-common/svconst" | |
| 6 | + "apigame/util/util-lx/lxtime" | |
| 7 | + "apigame/util/zconvert" | |
| 8 | + "fmt" | |
| 9 | +) | |
| 10 | + | |
| 11 | +// ActivityConfig 房间排行活动配置 分析后数据 | |
| 12 | +type ActivityConfig struct { | |
| 13 | + Raw *ActivityConfigRaw `json:"-"` | |
| 14 | + | |
| 15 | + Id int64 // ID | |
| 16 | + Typ int // 排行榜类型 | |
| 17 | + OpenLevel int // 开启等级 | |
| 18 | + OpenScore int64 // 开启积分 | |
| 19 | + PreviewTime int64 // 预告时间 | |
| 20 | + StartTime int64 // 开始时间 | |
| 21 | + EndTime int64 // 结束时间 | |
| 22 | + ReleaseTime string // 结算发奖时间 | |
| 23 | + | |
| 24 | + Robot map[int]RobotConfig // 机器人配置 | |
| 25 | + Room map[int]RoomConfig // 房间配置 | |
| 26 | + | |
| 27 | + GameId string // 所属游戏ID | |
| 28 | +} | |
| 29 | + | |
| 30 | +func (c *ActivityConfig) GetUid() string { | |
| 31 | + return zconvert.Int64ToStr(c.Id) | |
| 32 | +} | |
| 33 | + | |
| 34 | +func (c *ActivityConfig) CheckCurrent() bool { | |
| 35 | + timeNow := lxtime.NowUninx() | |
| 36 | + return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1 | |
| 37 | +} | |
| 38 | + | |
| 39 | +func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | |
| 40 | + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG | |
| 41 | + cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) | |
| 42 | + timeNow := lxtime.NowUninx() | |
| 43 | + return &confbase.ConfInfo{ | |
| 44 | + DbMysql: svconst.DbConfig, | |
| 45 | + TableName: fmt.Sprintf("%s_%s", tableName, suffix), | |
| 46 | + KeyName: "id", | |
| 47 | + CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?", | |
| 48 | + CurrentArgs: []any{c.Typ, 1, timeNow, timeNow}, | |
| 49 | + CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | |
| 50 | + CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ), | |
| 51 | + CacheTime: 300, | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ActivityConfigRaw 房间排行活动配置 原始数据 | |
| 56 | +type ActivityConfigRaw struct { | |
| 57 | + Id int64 `gorm:"column:id;primaryKey"` // ID | |
| 58 | + Serial int64 // 轮次ID | |
| 59 | + Typ int // 排行榜类型 | |
| 60 | + OpenLevel int // 开启等级 | |
| 61 | + OpenScore int64 // 开启积分 | |
| 62 | + PreviewTime int64 // 预告时间 | |
| 63 | + StartTime int64 // 开始时间 | |
| 64 | + EndTime int64 // 结束时间 | |
| 65 | + ReleaseTime string // 结算发奖时间 | |
| 66 | + | |
| 67 | + BootConfig string // 机器人配置 | |
| 68 | + RoomConfig string // 房间配置 | |
| 69 | + | |
| 70 | + Ver string // 版本号 | |
| 71 | + Status int // 状态 0=关闭 1=开启 | |
| 72 | + UpdateTime int64 // 修改时间戳 | |
| 73 | +} | |
| 74 | + | |
| 75 | +// GenerateConfigClient 生成给客户端的配置 | |
| 76 | +func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { | |
| 77 | + configClient := &ActivityConfigClient{ | |
| 78 | + Id: c.Id, | |
| 79 | + Typ: c.Typ, | |
| 80 | + Serial: c.Serial, | |
| 81 | + OpenLevel: c.OpenLevel, | |
| 82 | + OpenScore: c.OpenScore, | |
| 83 | + PreviewTime: c.PreviewTime, | |
| 84 | + StartTime: c.StartTime, | |
| 85 | + EndTime: c.EndTime, | |
| 86 | + ReleaseTime: c.ReleaseTime, | |
| 87 | + Ver: c.Ver, | |
| 88 | + Status: c.Status, | |
| 89 | + } | |
| 90 | + return configClient | |
| 91 | +} | |
| 92 | + | |
| 93 | +// ActivityConfigClient 房间排行活动配置 给客户端数据 | |
| 94 | +type ActivityConfigClient struct { | |
| 95 | + Id int64 `form:"id" json:"id"` // ID | |
| 96 | + Typ int `form:"typ" json:"typ"` // 排行榜类型 | |
| 97 | + Serial int64 `form:"serial" json:"serial"` // 轮次ID | |
| 98 | + OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 | |
| 99 | + OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 | |
| 100 | + PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 | |
| 101 | + StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 | |
| 102 | + EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 | |
| 103 | + ReleaseTime string `form:"release_time" json:"release_time"` // 结算发奖时间 | |
| 104 | + Ver string `form:"ver" json:"ver"` // 版本号 | |
| 105 | + Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启 | |
| 106 | +} | |
| 107 | + | |
| 108 | +// RobotConfig 机器人配置 | |
| 109 | +type RobotConfig struct { | |
| 110 | + Id int `json:"id"` // id | |
| 111 | + MinScore int `json:"min_score"` // 最低分数 | |
| 112 | + TotalScore int `json:"total_score"` // 总分数 | |
| 113 | + Range int `json:"range"` // 总分浮动范围(%) | |
| 114 | +} | |
| 115 | + | |
| 116 | +// RoomConfig 房间配置 | |
| 117 | +type RoomConfig struct { | |
| 118 | + Id int `json:"id"` // id | |
| 119 | + Levels []int `json:"level_range"` // 等级范围 | |
| 120 | + UserClass int `json:"rating"` // 评级 | |
| 121 | + UserScore []int `json:"score_range"` // 分数范围 | |
| 122 | + TotalPlayer int `json:"room_user_number"` // 房间总人数 | |
| 123 | + PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量 | |
| 124 | + AutoRobot []int `json:"auto_room"` // 自动填充机器人 | |
| 125 | + InitRobot [][]int `json:"disposition_robots"` // 配置机器人 | |
| 126 | + Awards map[string]string `json:"rewards"` // 奖励 | |
| 127 | + SettleScores []int `json:"score_adjest"` // 结算分数调整 | |
| 128 | + SettleUserType []int `json:"user_type"` // 结算用户类型 | |
| 129 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | +package confroomrank | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/util/util-lx/lxalilog" | |
| 5 | + "encoding/json" | |
| 6 | +) | |
| 7 | + | |
| 8 | +// Decode 解析配置原始数据 | |
| 9 | +func (c *ActivityConfig) Decode(gameId string, rawData any) { | |
| 10 | + raw := rawData.(*ActivityConfigRaw) | |
| 11 | + c.GameId = gameId | |
| 12 | + c.Raw = raw | |
| 13 | + | |
| 14 | + c.Id = raw.Id | |
| 15 | + c.Typ = raw.Typ | |
| 16 | + c.OpenLevel = raw.OpenLevel | |
| 17 | + c.OpenScore = raw.OpenScore | |
| 18 | + c.PreviewTime = raw.PreviewTime | |
| 19 | + c.StartTime = raw.StartTime | |
| 20 | + c.EndTime = raw.EndTime | |
| 21 | + c.ReleaseTime = raw.ReleaseTime | |
| 22 | + | |
| 23 | + c.Robot = make(map[int]RobotConfig) | |
| 24 | + c.Room = make(map[int]RoomConfig) | |
| 25 | + | |
| 26 | + // 解析 机器人 | |
| 27 | + { | |
| 28 | + configs := make([]RobotConfig, 0) | |
| 29 | + err := json.Unmarshal([]byte(raw.BootConfig), &configs) | |
| 30 | + if err != nil { | |
| 31 | + lxalilog.Errors(err, raw.BootConfig, gameId, raw.Id) | |
| 32 | + return | |
| 33 | + } | |
| 34 | + for _, i2 := range configs { | |
| 35 | + c.Robot[i2.Id] = i2 | |
| 36 | + } | |
| 37 | + } | |
| 38 | + // 解析 房间 | |
| 39 | + { | |
| 40 | + configs := make([]RoomConfig, 0) | |
| 41 | + err := json.Unmarshal([]byte(raw.RoomConfig), &configs) | |
| 42 | + if err != nil { | |
| 43 | + lxalilog.Errors(err, raw.RoomConfig, gameId, raw.Id) | |
| 44 | + return | |
| 45 | + } | |
| 46 | + for _, i2 := range configs { | |
| 47 | + c.Room[i2.Id] = i2 | |
| 48 | + } | |
| 49 | + } | |
| 50 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | +package confroomrank | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confbase" | |
| 5 | + "apigame/util/util-lx/lxalilog" | |
| 6 | + "apigame/util/util-lx/lxtime" | |
| 7 | +) | |
| 8 | + | |
| 9 | +// GetCurrent 获取 当前配置 | |
| 10 | +func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { | |
| 11 | + conf = new(ActivityConfig) | |
| 12 | + conf.Typ = topType | |
| 13 | + has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 14 | + if !has { | |
| 15 | + conf = new(ActivityConfig) | |
| 16 | + conf.Typ = topType | |
| 17 | + has = confbase.FindCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | |
| 18 | + } | |
| 19 | + return | |
| 20 | +} | |
| 21 | + | |
| 22 | +// GetConfig 获取 配置根据Id | |
| 23 | +func GetConfig(gameId string, confId int64) (conf *ActivityConfig, has bool) { | |
| 24 | + conf = new(ActivityConfig) | |
| 25 | + has = confbase.GetConfig[*ActivityConfig, ActivityConfigRaw](gameId, confId, conf) | |
| 26 | + | |
| 27 | + return | |
| 28 | +} | |
| 29 | + | |
| 30 | +// GetCurrentConfigs 获取当前配置列表 | |
| 31 | +func GetCurrentConfigs(gameId string) []*ActivityConfigRaw { | |
| 32 | + obj := new(ActivityConfig) | |
| 33 | + info := obj.ConfInfo(gameId) | |
| 34 | + db := info.DbMysql | |
| 35 | + timeNow := lxtime.NowUninx() | |
| 36 | + objs := make([]*ActivityConfigRaw, 0) | |
| 37 | + result := db.Table(info.TableName).Where( | |
| 38 | + "status = ? AND start_time <= ? AND end_time >= ?", | |
| 39 | + 1, timeNow, timeNow).Find(&objs) | |
| 40 | + if result.Error != nil { | |
| 41 | + lxalilog.Errors(result.Error, "confroomrank.GetCurrentConfigs error", gameId) | |
| 42 | + } | |
| 43 | + return objs | |
| 44 | +} | ... | ... |
configs/external.go
| ... | ... | @@ -1,44 +0,0 @@ |
| 1 | -package configs | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "fmt" | |
| 5 | - "github.com/astaxie/beego" | |
| 6 | - "reflect" | |
| 7 | -) | |
| 8 | - | |
| 9 | -func Init() bool { | |
| 10 | - fmt.Println("configs Init") | |
| 11 | - conf, _ := beego.AppConfig.GetSection("conf") | |
| 12 | - Initial(conf["path"], "ID") | |
| 13 | - | |
| 14 | - //InitExt() | |
| 15 | - return true | |
| 16 | -} | |
| 17 | - | |
| 18 | -func GetConfig[T any](id string, t T) (obj *T) { | |
| 19 | - var table = GetTable(t) | |
| 20 | - dt := table.GetItem(id) | |
| 21 | - if dt == nil { | |
| 22 | - return nil | |
| 23 | - } | |
| 24 | - obj = dt.(*T) | |
| 25 | - return | |
| 26 | -} | |
| 27 | - | |
| 28 | -func HasConfig[T any](id string, t T) (has bool) { | |
| 29 | - var table = GetTable(t) | |
| 30 | - return table.GetItem(id) != nil | |
| 31 | -} | |
| 32 | - | |
| 33 | -func GetOne[T any](t T) (obj *T) { | |
| 34 | - var table = GetTable(t) | |
| 35 | - if len(table.Items()) > 0 { | |
| 36 | - return table.Items()[0].(*T) | |
| 37 | - } | |
| 38 | - return nil | |
| 39 | -} | |
| 40 | - | |
| 41 | -func GetTable[T any](t T) (table *DataTable) { | |
| 42 | - table = GetDataTable(reflect.TypeOf(t)) | |
| 43 | - return | |
| 44 | -} |
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package configs | |
| 2 | + | |
| 3 | +import ( | |
| 4 | + "apigame/configs/confapi" | |
| 5 | + "apigame/configs/confcardholder" | |
| 6 | + "apigame/configs/confglobal" | |
| 7 | + "apigame/service-common/svconst" | |
| 8 | +) | |
| 9 | + | |
| 10 | +func Init() bool { | |
| 11 | + | |
| 12 | + for _, gameId := range svconst.GameList { | |
| 13 | + _, _ = confapi.GetConfig(gameId) | |
| 14 | + } | |
| 15 | + | |
| 16 | + for _, gameId := range svconst.GameList { | |
| 17 | + _, _ = confglobal.GetConfig(gameId) | |
| 18 | + } | |
| 19 | + | |
| 20 | + for _, gameId := range svconst.GameListCardHolder { | |
| 21 | + _, _ = confcardholder.GetCurrent(gameId) | |
| 22 | + } | |
| 23 | + | |
| 24 | + //for _, gameId := range svconst.GameListRoomRank { | |
| 25 | + // _, _ = confroomrank.GetCurrent(gameId) | |
| 26 | + //} | |
| 27 | + | |
| 28 | + return true | |
| 29 | +} | ... | ... |
configs/reader.go
| ... | ... | @@ -1,280 +0,0 @@ |
| 1 | -package configs | |
| 2 | - | |
| 3 | -import ( | |
| 4 | - "fmt" | |
| 5 | - "os" | |
| 6 | - "reflect" | |
| 7 | - "strings" | |
| 8 | - | |
| 9 | - "google.golang.org/protobuf/proto" | |
| 10 | - "google.golang.org/protobuf/reflect/protoreflect" | |
| 11 | - "google.golang.org/protobuf/reflect/protoregistry" | |
| 12 | -) | |
| 13 | - | |
| 14 | -type DataTableMap map[string]IData | |
| 15 | -type DataItemMap map[string]IData | |
| 16 | - | |
| 17 | -type DataArray []interface{} | |
| 18 | -type DataMap map[string]interface{} | |
| 19 | - | |
| 20 | -var ( | |
| 21 | - DefaultIndexKey = "ID" | |
| 22 | - BytesFileExt = ".bytes" | |
| 23 | - | |
| 24 | - dataDir = "" | |
| 25 | - dataItemMap = make(DataItemMap, 0) | |
| 26 | - dataTableMap = make(DataTableMap, 0) | |
| 27 | -) | |
| 28 | - | |
| 29 | -type IFilenameGenerator interface { | |
| 30 | - GetFilename(typeName string) string | |
| 31 | -} | |
| 32 | - | |
| 33 | -type IData interface { | |
| 34 | - DataType() reflect.Type | |
| 35 | -} | |
| 36 | - | |
| 37 | -func DataDir() string { | |
| 38 | - return dataDir | |
| 39 | -} | |
| 40 | - | |
| 41 | -func Initial(dir, defaultKeyName string) { | |
| 42 | - dataDir = strings.ReplaceAll(dir, "\\", "/") | |
| 43 | - if strings.LastIndex(dataDir, "/") != len(dataDir)-1 { | |
| 44 | - dataDir = dataDir + "/" | |
| 45 | - } | |
| 46 | - | |
| 47 | - if defaultKeyName != "" { | |
| 48 | - DefaultIndexKey = defaultKeyName | |
| 49 | - } | |
| 50 | -} | |
| 51 | - | |
| 52 | -func RegistDataTable(indexKey string, dataType reflect.Type) { | |
| 53 | - if _, ok := dataTableMap[dataType.Name()]; !ok { | |
| 54 | - var t = NewDataTable(indexKey, dataType) | |
| 55 | - dataTableMap[dataType.Name()] = t | |
| 56 | - } | |
| 57 | -} | |
| 58 | - | |
| 59 | -func RegistDataTableExt(table IData) { | |
| 60 | - var dataType = table.DataType() | |
| 61 | - if _, ok := dataTableMap[dataType.Name()]; !ok { | |
| 62 | - dataTableMap[dataType.Name()] = table | |
| 63 | - } | |
| 64 | -} | |
| 65 | - | |
| 66 | -func GetDataItem(dataType reflect.Type) *DataItem { | |
| 67 | - var dt *DataItem | |
| 68 | - if item, ok := dataItemMap[dataType.Name()]; !ok { | |
| 69 | - var t = NewDataItem(dataType) | |
| 70 | - dataItemMap[dataType.Name()] = t | |
| 71 | - dt = t | |
| 72 | - } else { | |
| 73 | - dt = item.(*DataItem) | |
| 74 | - } | |
| 75 | - return dt | |
| 76 | -} | |
| 77 | - | |
| 78 | -func GetDataTable(dataType reflect.Type) *DataTable { | |
| 79 | - var dt *DataTable | |
| 80 | - if item, ok := dataTableMap[dataType.Name()]; !ok { | |
| 81 | - var t = NewDataTable("", dataType) | |
| 82 | - dataTableMap[dataType.Name()] = t | |
| 83 | - dt = t | |
| 84 | - } else { | |
| 85 | - dt = item.(*DataTable) | |
| 86 | - } | |
| 87 | - return dt | |
| 88 | -} | |
| 89 | - | |
| 90 | -func getFullname(dataType reflect.Type) string { | |
| 91 | - var pkgs = strings.Split(dataType.PkgPath(), "/") | |
| 92 | - var pkg = pkgs[len(pkgs)-1] | |
| 93 | - var name = dataType.Name() | |
| 94 | - return fmt.Sprintf("%s.%s", pkg, name) | |
| 95 | -} | |
| 96 | - | |
| 97 | -type DataItem struct { | |
| 98 | - dataType reflect.Type | |
| 99 | - data interface{} | |
| 100 | - fileGen IFilenameGenerator | |
| 101 | -} | |
| 102 | - | |
| 103 | -func NewDataItem(dataType reflect.Type) *DataItem { | |
| 104 | - t := new(DataItem) | |
| 105 | - t.dataType = dataType | |
| 106 | - t.fileGen = t | |
| 107 | - return t | |
| 108 | -} | |
| 109 | - | |
| 110 | -func (t *DataItem) DataType() reflect.Type { | |
| 111 | - return t.dataType | |
| 112 | -} | |
| 113 | - | |
| 114 | -func (t *DataItem) Item() interface{} { | |
| 115 | - t.load() | |
| 116 | - return t.data | |
| 117 | -} | |
| 118 | - | |
| 119 | -func (t *DataItem) Clear() { | |
| 120 | - t.data = nil | |
| 121 | -} | |
| 122 | - | |
| 123 | -func (t *DataItem) GetFilename(typeName string) string { | |
| 124 | - return fmt.Sprintf("%s%s%s", dataDir, strings.ToLower(typeName), BytesFileExt) | |
| 125 | -} | |
| 126 | - | |
| 127 | -func (t *DataItem) load() { | |
| 128 | - if t.data != nil { | |
| 129 | - return | |
| 130 | - } | |
| 131 | - | |
| 132 | - var filename = t.fileGen.GetFilename(t.dataType.Name()) | |
| 133 | - if ok, _ := PathExists(filename); !ok { | |
| 134 | - fmt.Printf("can not find data file %s", filename) | |
| 135 | - return | |
| 136 | - } | |
| 137 | - | |
| 138 | - fullName := getFullname(t.dataType) | |
| 139 | - msgName := protoreflect.FullName(fullName) | |
| 140 | - msgType, err := protoregistry.GlobalTypes.FindMessageByName(msgName) | |
| 141 | - if err != nil { | |
| 142 | - fmt.Printf("can not find proto message named %v, %v", fullName, err) | |
| 143 | - return | |
| 144 | - } | |
| 145 | - message := msgType.New().Interface() | |
| 146 | - | |
| 147 | - bytes, err := os.ReadFile(filename) | |
| 148 | - if err != nil { | |
| 149 | - fmt.Printf("read bytes file failed, %v", err) | |
| 150 | - return | |
| 151 | - } | |
| 152 | - | |
| 153 | - err = proto.Unmarshal(bytes, message) | |
| 154 | - if err != nil { | |
| 155 | - fmt.Printf("proto unmarshal failed, %v", err) | |
| 156 | - return | |
| 157 | - } | |
| 158 | - | |
| 159 | - t.data = message | |
| 160 | -} | |
| 161 | - | |
| 162 | -type DataTable struct { | |
| 163 | - indexKey string | |
| 164 | - dataType reflect.Type | |
| 165 | - data DataArray | |
| 166 | - dataMap DataMap | |
| 167 | - fileGen IFilenameGenerator | |
| 168 | -} | |
| 169 | - | |
| 170 | -func NewDataTable(indexKey string, dataType reflect.Type) *DataTable { | |
| 171 | - if indexKey == "" { | |
| 172 | - indexKey = DefaultIndexKey | |
| 173 | - } | |
| 174 | - | |
| 175 | - t := new(DataTable) | |
| 176 | - t.indexKey = indexKey | |
| 177 | - t.dataType = dataType | |
| 178 | - t.fileGen = t | |
| 179 | - return t | |
| 180 | -} | |
| 181 | - | |
| 182 | -func (t *DataTable) DataType() reflect.Type { | |
| 183 | - return t.dataType | |
| 184 | -} | |
| 185 | - | |
| 186 | -func (t *DataTable) Items() DataArray { | |
| 187 | - if t.data == nil { | |
| 188 | - t.load() | |
| 189 | - } | |
| 190 | - return t.data | |
| 191 | -} | |
| 192 | - | |
| 193 | -func (t *DataTable) ItemsMap() DataMap { | |
| 194 | - if t.data == nil { | |
| 195 | - t.load() | |
| 196 | - } | |
| 197 | - t.itemsAsMap() | |
| 198 | - return t.dataMap | |
| 199 | -} | |
| 200 | - | |
| 201 | -func (t *DataTable) GetItem(id string) interface{} { | |
| 202 | - var dataMap = t.ItemsMap() | |
| 203 | - if dt, ok := dataMap[id]; ok { | |
| 204 | - return dt | |
| 205 | - } | |
| 206 | - return nil | |
| 207 | -} | |
| 208 | - | |
| 209 | -func (t *DataTable) Clear() { | |
| 210 | - t.data = nil | |
| 211 | - t.dataMap = nil | |
| 212 | -} | |
| 213 | - | |
| 214 | -func (t *DataTable) GetFilename(typeName string) string { | |
| 215 | - return fmt.Sprintf("%s%s%s", dataDir, strings.ToLower(typeName), BytesFileExt) | |
| 216 | -} | |
| 217 | - | |
| 218 | -func (t *DataTable) load() { | |
| 219 | - if t.data != nil { | |
| 220 | - return | |
| 221 | - } | |
| 222 | - | |
| 223 | - var filename = t.fileGen.GetFilename(t.dataType.Name()) | |
| 224 | - if ok, _ := PathExists(filename); !ok { | |
| 225 | - fmt.Printf("can not find data file %s", filename) | |
| 226 | - return | |
| 227 | - } | |
| 228 | - | |
| 229 | - fullName := getFullname(t.dataType) + "_ARRAY" | |
| 230 | - msgName := protoreflect.FullName(fullName) | |
| 231 | - msgType, err := protoregistry.GlobalTypes.FindMessageByName(msgName) | |
| 232 | - if err != nil { | |
| 233 | - fmt.Printf("can not find proto message named %v, %v", fullName, err) | |
| 234 | - return | |
| 235 | - } | |
| 236 | - message := msgType.New().Interface() | |
| 237 | - | |
| 238 | - bytes, err := os.ReadFile(filename) | |
| 239 | - if err != nil { | |
| 240 | - fmt.Printf("read bytes file failed, %v", err) | |
| 241 | - return | |
| 242 | - } | |
| 243 | - | |
| 244 | - err = proto.Unmarshal(bytes, message) | |
| 245 | - if err != nil { | |
| 246 | - fmt.Printf("proto unmarshal failed, %v", err) | |
| 247 | - return | |
| 248 | - } | |
| 249 | - | |
| 250 | - var value = reflect.ValueOf(message) | |
| 251 | - var elm = value.Elem() | |
| 252 | - if elm.Kind() != reflect.Struct { | |
| 253 | - fmt.Printf("type %s kind error", fullName) | |
| 254 | - return | |
| 255 | - } | |
| 256 | - | |
| 257 | - t.data = make(DataArray, 0) | |
| 258 | - var items = elm.FieldByName("Items").Interface() | |
| 259 | - if reflect.TypeOf(items).Kind() == reflect.Slice { | |
| 260 | - s := reflect.ValueOf(items) | |
| 261 | - for i := 0; i < s.Len(); i++ { | |
| 262 | - ele := s.Index(i) | |
| 263 | - t.data = append(t.data, ele.Interface()) | |
| 264 | - } | |
| 265 | - } | |
| 266 | -} | |
| 267 | - | |
| 268 | -func (t *DataTable) itemsAsMap() { | |
| 269 | - if t.dataMap != nil { | |
| 270 | - return | |
| 271 | - } | |
| 272 | - t.dataMap = make(DataMap) | |
| 273 | - | |
| 274 | - for _, item := range t.data { | |
| 275 | - var value = reflect.ValueOf(item) | |
| 276 | - var elm = value.Elem() | |
| 277 | - var idx = elm.FieldByName(t.indexKey).Interface() | |
| 278 | - t.dataMap[fmt.Sprintf("%v", idx)] = item | |
| 279 | - } | |
| 280 | -} |
configs/utils.go
controllers/admin.go
controllers/demo.go
main.go
| ... | ... | @@ -2,7 +2,6 @@ package main |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 4 | "apigame/configs" |
| 5 | - "apigame/configs-db" | |
| 6 | 5 | _ "apigame/routers" |
| 7 | 6 | "apigame/service" |
| 8 | 7 | "apigame/service-common/svconst" |
| ... | ... | @@ -66,10 +65,6 @@ func Init() bool { |
| 66 | 65 | // |
| 67 | 66 | //_ = config.InitLxLimit() |
| 68 | 67 | |
| 69 | - if !configs_db.Init() { | |
| 70 | - return false | |
| 71 | - } | |
| 72 | - | |
| 73 | 68 | if !configs.Init() { |
| 74 | 69 | return false |
| 75 | 70 | } | ... | ... |
middleware/sign/index.go
service-common/svcommon/simulate.go
service/cardholder/handle.go
| 1 | 1 | package cardholder |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | - "apigame/configs-db/confcardholder" | |
| 4 | + "apigame/configs/confcardholder" | |
| 5 | 5 | "apigame/models" |
| 6 | 6 | "apigame/service-common/svmysql" |
| 7 | 7 | "apigame/service/code-msg" |
| 8 | 8 | "apigame/util/util-lx/lxalilog" |
| 9 | 9 | "apigame/util/util-lx/lxtime" |
| 10 | 10 | "apigame/util/zslice" |
| 11 | - "fmt" | |
| 12 | 11 | ) |
| 13 | 12 | |
| 14 | 13 | // HandleGetConfig 活动配置 |
| ... | ... | @@ -357,10 +356,6 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m |
| 357 | 356 | rsp.AutoExchangeHolder = player.Details.AutoExchangeHolderIds |
| 358 | 357 | rsp.NewCards = player.Details.AutoExchangeNewCards |
| 359 | 358 | |
| 360 | - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.LastStarCount) | |
| 361 | - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.AutoExchangeHolder) | |
| 362 | - fmt.Println("HandleAutoExchangeInfo rsp.LastStarCount", rsp.NewCards) | |
| 363 | - | |
| 364 | 359 | player.Details.LastStarCount = 0 |
| 365 | 360 | player.Details.AutoExchangeHolderIds = make([]int, 0) |
| 366 | 361 | player.Details.AutoExchangeNewCards = make([][]int, 0) | ... | ... |
service/cardholder/logic.go
service/cardholder/player.go
service/roomrank/handle.go
service/roomrank/logic.go
service/roomrank/player.go