Commit 29e2ebdcd43f77c732075639dd7b5a4f07966031

Authored by 王家文
1 parent 9a13710f
Exists in master and in 1 other branch dev-wjw

refactor♻️:redis对象和mysql对象持久化和读取

configs/feat-cardholder-decode.go 0 → 100644
@@ -0,0 +1,169 @@ @@ -0,0 +1,169 @@
  1 +package configs
  2 +
  3 +import (
  4 + "apigame/util/util-lx/lxalilog"
  5 + "encoding/json"
  6 + "errors"
  7 + "fmt"
  8 + "strings"
  9 +)
  10 +
  11 +// Decode 解析配置原始数据
  12 +func (c *CardActivityConfig) Decode(gameId string, configRaw *CardActivityConfigRaw) {
  13 + c.GameId = gameId
  14 + c.Raw = configRaw
  15 +
  16 + c.Id = configRaw.Id
  17 + c.OpenLevel = configRaw.OpenLevel
  18 + c.PreviewTime = configRaw.PreviewTime
  19 + c.StartTime = configRaw.StartTime
  20 + c.EndTime = configRaw.EndTime
  21 + c.Round = configRaw.Round
  22 +
  23 + c.Awards = make(map[string]string)
  24 + c.AlbumConfig = make(map[int]AlbumConfig)
  25 + c.CardConfig = make(map[int]CardConfig)
  26 + c.CardholderConfig = make(map[string]OpenCardholderConfig)
  27 + c.NormalCardStarConfig = make(map[string]NormalCardStarConfig)
  28 + c.CardSequenceConfig = make(map[string]CardSequenceConfig)
  29 + c.StarShopConfig = make(map[int]StarShopConfig)
  30 + // 解析奖励
  31 + {
  32 + err := json.Unmarshal([]byte(configRaw.Awards), &c.Awards)
  33 + if err != nil {
  34 + lxalilog.Errors(err, configRaw.Awards, gameId, configRaw.Id)
  35 + return
  36 + }
  37 + }
  38 + // 卡组配置
  39 + {
  40 + configs := make([]AlbumConfig, 0)
  41 + err := json.Unmarshal([]byte(configRaw.AlbumConfig), &configs)
  42 + if err != nil {
  43 + lxalilog.Errors(err, configRaw.AlbumConfig, gameId, configRaw.Id)
  44 + return
  45 + }
  46 + for _, i2 := range configs {
  47 + c.AlbumConfig[i2.SetId] = i2
  48 + }
  49 + }
  50 + // 卡牌配置
  51 + {
  52 + configs := make([]CardConfig, 0)
  53 + err := json.Unmarshal([]byte(configRaw.CardConfig), &configs)
  54 + if err != nil {
  55 + lxalilog.Errors(err, configRaw.CardConfig, gameId, configRaw.Id)
  56 + return
  57 + }
  58 + for _, i2 := range configs {
  59 + c.CardConfig[i2.Id] = i2
  60 + }
  61 + }
  62 + // 卡包开卡规则
  63 + {
  64 + configs := make([]OpenCardholderConfig, 0)
  65 + err := json.Unmarshal([]byte(configRaw.CardHolderConfig), &configs)
  66 + if err != nil {
  67 + lxalilog.Errors(err, configRaw.CardHolderConfig, gameId, configRaw.Id)
  68 + return
  69 + }
  70 + for _, i2 := range configs {
  71 + c.CardholderConfig[i2.Id] = i2
  72 + }
  73 + }
  74 + // 卡片星级配置
  75 + {
  76 + configs := make([]NormalCardStarConfig, 0)
  77 + err := json.Unmarshal([]byte(configRaw.NormalCardStarSequence), &configs)
  78 + if err != nil {
  79 + lxalilog.Errors(err, configRaw.NormalCardStarSequence, gameId, configRaw.Id)
  80 + return
  81 + }
  82 + for _, i2 := range configs {
  83 + i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",")
  84 + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)
  85 + c.NormalCardStarConfig[combineId] = i2
  86 + }
  87 + }
  88 + // 卡片星级对应卡牌配置
  89 + {
  90 + configs := make([]CardSequenceConfig, 0)
  91 + err := json.Unmarshal([]byte(configRaw.CardSequenceConfig), &configs)
  92 + if err != nil {
  93 + lxalilog.Errors(err, configRaw.CardSequenceConfig, gameId, configRaw.Id)
  94 + return
  95 + }
  96 + for _, i2 := range configs {
  97 + i2.CardIdLists = strings.Split(i2.CardIdList, ",")
  98 + combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)
  99 + c.CardSequenceConfig[combineId] = i2
  100 + }
  101 + }
  102 + // 星星商店配置
  103 + {
  104 + configs := make([]StarShopConfig, 0)
  105 + err := json.Unmarshal([]byte(configRaw.StarShopConfig), &configs)
  106 + if err != nil {
  107 + lxalilog.Errors(err, configRaw.StarShopConfig, gameId, configRaw.Id)
  108 + return
  109 + }
  110 + for _, i2 := range configs {
  111 + c.StarShopConfig[i2.Id] = i2
  112 + }
  113 + }
  114 +
  115 + c.GenerateConfigClient()
  116 +}
  117 +
  118 +// GenerateConfigClient 生成给客户端的配置
  119 +func (c *CardActivityConfig) GenerateConfigClient() {
  120 + configClient := &CardActivityConfigClient{
  121 + Id: c.Id,
  122 + RoundAwards: c.Awards,
  123 + Albums: make([]AlbumConfig, 0),
  124 + Cards: make([]CardConfig, 0),
  125 + Holders: make([]OpenCardholderConfig, 0),
  126 + StarShop: make([]StarShopConfig, 0),
  127 + }
  128 + for _, i2 := range c.AlbumConfig {
  129 + configClient.Albums = append(configClient.Albums, i2)
  130 + }
  131 + for _, i2 := range c.CardConfig {
  132 + configClient.Cards = append(configClient.Cards, i2)
  133 + }
  134 + for _, i2 := range c.CardholderConfig {
  135 + configClient.Holders = append(configClient.Holders, i2)
  136 + }
  137 + for _, i2 := range c.StarShopConfig {
  138 + configClient.StarShop = append(configClient.StarShop, i2)
  139 + }
  140 + c.Client = configClient
  141 +}
  142 +
  143 +// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组
  144 +func CombineIdSequenceIdCohort(id, sequenceId, cohort string) string {
  145 + return fmt.Sprintf("%s_%s_%s", id, sequenceId, cohort)
  146 +}
  147 +
  148 +// FindNormalCardStarConfig 查找配置 非保底卡星级ID
  149 +func (c *CardActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort string) (conf NormalCardStarConfig, has bool) {
  150 + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
  151 + conf, has = c.NormalCardStarConfig[combineId]
  152 + if !has {
  153 + lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort)
  154 + }
  155 + return
  156 +}
  157 +
  158 +// FindCardSequenceConfig 查找配置 星级ID对应的卡片
  159 +func (c *CardActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) {
  160 + combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
  161 + conf, has = c.CardSequenceConfig[combineId]
  162 + if !has {
  163 + lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort)
  164 + fmt.Println(id)
  165 + fmt.Println(sequenceId)
  166 + fmt.Println(cohort)
  167 + }
  168 + return
  169 +}
configs/feat-cardholder.go
@@ -3,17 +3,23 @@ package configs @@ -3,17 +3,23 @@ package configs
3 import ( 3 import (
4 "apigame/common/svconst" 4 "apigame/common/svconst"
5 "apigame/common/svdto" 5 "apigame/common/svdto"
  6 + "apigame/common/svmysql"
  7 + "apigame/common/svredis"
6 "apigame/service/constd" 8 "apigame/service/constd"
7 - "apigame/util/utdto"  
8 "fmt" 9 "fmt"
9 ) 10 )
10 11
11 // CardActivityConfig 卡牌活动配置 分析后数据 12 // CardActivityConfig 卡牌活动配置 分析后数据
12 type CardActivityConfig struct { 13 type CardActivityConfig struct {
13 - Raw *CardActivityConfigRaw  
14 - Client *CardActivityConfigClient  
15 - GameId string // 所属游戏ID  
16 - Id int64 // ID 14 + Raw *CardActivityConfigRaw `json:"-"`
  15 +
  16 + Id int64 // ID
  17 + OpenLevel int // 开启等级
  18 + PreviewTime int64 // 预告时间
  19 + StartTime int64 // 开始时间
  20 + EndTime int64 // 结束时间
  21 + Round int // 轮数
  22 +
17 Awards map[string]string // 奖励配置 23 Awards map[string]string // 奖励配置
18 AlbumConfig map[int]AlbumConfig // 卡组配置 24 AlbumConfig map[int]AlbumConfig // 卡组配置
19 CardConfig map[int]CardConfig // 卡牌配置 25 CardConfig map[int]CardConfig // 卡牌配置
@@ -21,15 +27,14 @@ type CardActivityConfig struct { @@ -21,15 +27,14 @@ type CardActivityConfig struct {
21 NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置 27 NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置
22 CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 28 CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置
23 StarShopConfig map[int]StarShopConfig // 星星商店配置 29 StarShopConfig map[int]StarShopConfig // 星星商店配置
24 -}  
25 30
26 -func (c *CardActivityConfigRaw) TableName() string { return utdto.MYSQL_TABLE_TEMPLATE } 31 + Client *CardActivityConfigClient
  32 + GameId string // 所属游戏ID
  33 +}
27 34
28 -func (c *CardActivityConfigRaw) GetRule(gameId string) *svdto.DtoRule { 35 +func (c *CardActivityConfig) RedisInfo(gameId string) *svredis.RedisInfo {
29 tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG 36 tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG
30 - return &svdto.DtoRule{  
31 - DbMysql: svconst.DbConfig,  
32 - TableName: tableName + gameId, 37 + return &svredis.RedisInfo{
33 CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId), 38 CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId),
34 CacheTime: 300, 39 CacheTime: 300,
35 } 40 }
@@ -55,6 +60,14 @@ type CardActivityConfigRaw struct { @@ -55,6 +60,14 @@ type CardActivityConfigRaw struct {
55 UpdateTime int64 // 修改时间戳 60 UpdateTime int64 // 修改时间戳
56 } 61 }
57 62
  63 +func (c *CardActivityConfigRaw) MysqlInfo(gameId string) *svmysql.MysqlInfo {
  64 + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG
  65 + return &svmysql.MysqlInfo{
  66 + DbMysql: svconst.DbConfig.Where("status = ?", 1),
  67 + TableName: tableName + gameId,
  68 + }
  69 +}
  70 +
58 // CardActivityConfigClient 卡牌活动配置 给客户端数据 71 // CardActivityConfigClient 卡牌活动配置 给客户端数据
59 type CardActivityConfigClient struct { 72 type CardActivityConfigClient struct {
60 Id int64 `form:"id" json:"id"` // ID 73 Id int64 `form:"id" json:"id"` // ID
@@ -100,11 +113,11 @@ type OpenCardholderConfig struct { @@ -100,11 +113,11 @@ type OpenCardholderConfig struct {
100 113
101 // NormalCardStarConfig 非保底卡星级ID 114 // NormalCardStarConfig 非保底卡星级ID
102 type NormalCardStarConfig struct { 115 type NormalCardStarConfig struct {
103 - Id string `json:"id"` // ID  
104 - SequenceId string `json:"user_sequence_id"` // 用户序列组ID  
105 - Cohort string `json:"cohort"` // 用户分组  
106 - NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列  
107 - NormalCardSequenceIds []string `json:"-"` // 非保底星级序列 116 + Id string `json:"id"` // ID
  117 + SequenceId string `json:"user_sequence_id"` // 用户序列组ID
  118 + Cohort string `json:"cohort"` // 用户分组
  119 + NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列
  120 + NormalCardSequenceIds []string `json:"normal_card_sequence_ids"` // 非保底星级序列
108 } 121 }
109 122
110 // CardSequenceConfig 星级ID对应的卡片 123 // CardSequenceConfig 星级ID对应的卡片
@@ -113,7 +126,7 @@ type CardSequenceConfig struct { @@ -113,7 +126,7 @@ type CardSequenceConfig struct {
113 SequenceId string `json:"user_sequence_id"` // 用户序列组ID 126 SequenceId string `json:"user_sequence_id"` // 用户序列组ID
114 Cohort string `json:"cohort"` // 用户分组 127 Cohort string `json:"cohort"` // 用户分组
115 CardIdList string `json:"card_id_list"` // 卡牌抽取序列 128 CardIdList string `json:"card_id_list"` // 卡牌抽取序列
116 - CardIdLists []string `json:"-"` // 卡牌抽取序列 129 + CardIdLists []string `json:"card_id_lists"` // 卡牌抽取序列
117 } 130 }
118 131
119 // StarShopConfig 星星商店配置 132 // StarShopConfig 星星商店配置
configs/init.go
@@ -3,28 +3,9 @@ package configs @@ -3,28 +3,9 @@ package configs
3 func Init() bool { 3 func Init() bool {
4 4
5 gameId := "10149" 5 gameId := "10149"
6 - ////{  
7 - //// conf := &ApiGameConfig{AppId: "dsadsads", GameId: gameId, Name: "Name"}  
8 - //// CacheSave(gameId, conf)  
9 - ////}  
10 - //{  
11 - // conf, has := CacheLoad(gameId, &ApiGameConfig{})  
12 - // fmt.Println("dwjw🐸", conf, has)  
13 - //}  
14 6
15 - //{  
16 - // conf := &CardActivityConfigRaw{}  
17 - // rule := conf.GetRule(gameId)  
18 - // db := rule.DbMysql.Where("status = ?", 1)  
19 - // has, err := svdto.First(db, conf, gameId)  
20 - // fmt.Println("dwjw🐸", conf, has, err)  
21 - //}  
22 -  
23 - //for _, gameId := range svconst.GameListCardHolder {  
24 - // LoadConfig(gameId)  
25 - //}  
26 -  
27 - _, _ = GetApiGame(gameId) 7 + _, _ = GetApiGameConfig(gameId)
  8 + _, _ = GetCardActivityConfig(gameId)
28 9
29 return true 10 return true
30 } 11 }
configs/registry.go
@@ -6,20 +6,48 @@ import ( @@ -6,20 +6,48 @@ import (
6 "fmt" 6 "fmt"
7 ) 7 )
8 8
9 -// GetApiGame 获取 api游戏配置  
10 -func GetApiGame(gameId string) (conf *ApiGameConfig, err error) { 9 +// GetApiGameConfig 获取 api游戏配置
  10 +func GetApiGameConfig(gameId string) (conf *ApiGameConfig, err error) {
11 conf = new(ApiGameConfig) 11 conf = new(ApiGameConfig)
12 has := svredis.LoadData(gameId, conf) 12 has := svredis.LoadData(gameId, conf)
13 if has { 13 if has {
14 - fmt.Println("dwjw GetApiGame use cache") 14 + fmt.Println("dwjw GetApiGameConfig use cache")
15 return 15 return
16 } 16 }
17 has, err = svmysql.First(conf, gameId) 17 has, err = svmysql.First(conf, gameId)
18 if err != nil { 18 if err != nil {
19 return 19 return
20 } 20 }
  21 + if !has {
  22 + return
  23 + }
  24 + fmt.Println("dwjw GetApiGameConfig save cache")
  25 + svredis.SaveData(gameId, conf)
  26 +
  27 + return
  28 +}
  29 +
  30 +// GetCardActivityConfig 获取 卡牌活动配置
  31 +func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) {
  32 + var err error
  33 + conf = new(CardActivityConfig)
  34 + has = svredis.LoadData(gameId, conf)
  35 + if has {
  36 + fmt.Println("dwjw GetCardActivityConfig use cache")
  37 + return
  38 + }
  39 + confRaw := new(CardActivityConfigRaw)
  40 + has, err = svmysql.First(confRaw, gameId)
  41 + if err != nil {
  42 + return
  43 + }
  44 + if !has {
  45 + return
  46 + }
  47 +
  48 + conf.Decode(gameId, confRaw)
21 49
22 - fmt.Println("dwjw GetApiGame save cache") 50 + fmt.Println("dwjw GetCardActivityConfig save cache")
23 svredis.SaveData(gameId, conf) 51 svredis.SaveData(gameId, conf)
24 52
25 return 53 return
middleware/sign/index.go
@@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf @@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
223 223
224 gameid := newdata["gameid"].(string) 224 gameid := newdata["gameid"].(string)
225 225
226 - gameconfig, err = configs.GetApiGame(gameid) 226 + gameconfig, err = configs.GetApiGameConfig(gameid)
227 if err != nil { 227 if err != nil {
228 lxalilog.Errors(err) 228 lxalilog.Errors(err)
229 return 229 return
service/cardholder/config-client.go
@@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
1 -package cardholder  
2 -  
3 -// CardActivityConfigClient 卡牌活动配置 给客户端数据  
4 -type CardActivityConfigClient struct {  
5 - Id int64 `form:"id" json:"id"` // ID  
6 - RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置  
7 - Albums []AlbumConfig `form:"albums" json:"albums"` // 卡组配置  
8 - Cards []CardConfig `form:"cards" json:"cards"` // 卡牌配置  
9 - Holders []OpenCardholderConfig `form:"holders" json:"holders"` // 卡包开卡规则  
10 - StarShop []StarShopConfig `form:"star_shop" json:"star_shop"` // 星星商店配置  
11 -}  
service/cardholder/config-load.go
@@ -1,77 +0,0 @@ @@ -1,77 +0,0 @@
1 -package cardholder  
2 -  
3 -import (  
4 - "apigame/common/svconst"  
5 -)  
6 -  
7 -// Init1 初始化  
8 -func Init1() {  
9 -  
10 - NewConfigs()  
11 -  
12 - TryUpdateConfigs()  
13 -}  
14 -  
15 -// TryUpdateConfigs 尝试更新配置表  
16 -func TryUpdateConfigs() {  
17 - LoadConfigs()  
18 -}  
19 -  
20 -// LoadConfigs 读取mysql配置  
21 -func LoadConfigs() {  
22 - for _, gameId := range svconst.GameListCardHolder {  
23 - LoadConfig(gameId)  
24 - }  
25 -}  
26 -  
27 -// TryUpdateConfig 尝试更新配置表  
28 -func TryUpdateConfig(gameId string) (config *CardActivityConfig, has bool) {  
29 - LoadConfig(gameId)  
30 - return GetConfig(gameId)  
31 -}  
32 -  
33 -// LoadConfig 读取mysql配置  
34 -func LoadConfig(gameId string) {  
35 - //// 找到当前开放的活动  
36 - //configOpen := CardActivityUpdateConfig{Id: 0}  
37 - //{  
38 - // conf := make([]CardActivityUpdateConfig, 0)  
39 - // _, err := svdto.Find(&conf, new(CardActivityUpdateConfig), gameId)  
40 - // if err != nil {  
41 - // return  
42 - // }  
43 - // for _, config := range conf {  
44 - // if config.Status != 0 {  
45 - // configOpen = config  
46 - // continue  
47 - // }  
48 - // }  
49 - // fmt.Println(configOpen)  
50 - //}  
51 - //// 没有开放的活动  
52 - //if configOpen.Id == 0 {  
53 - // return  
54 - //}  
55 - //// 判断是否需要更新  
56 - //needUpdate := false  
57 - //configOld, hasConfigOld := GetConfig(gameId)  
58 - //if hasConfigOld {  
59 - // if configOpen.Id != configOld.Raw.Id || configOpen.UpdateTime != configOld.Raw.UpdateTime {  
60 - // needUpdate = true  
61 - // }  
62 - //} else {  
63 - // needUpdate = true  
64 - //}  
65 - //// 更新数据  
66 - //if needUpdate {  
67 - // confNew := &CardActivityConfigRaw{}  
68 - // hasConfNew, err := svdto.First(confNew, gameId)  
69 - // if err != nil {  
70 - // return  
71 - // }  
72 - // if !hasConfNew {  
73 - // return  
74 - // }  
75 - // ConfigDecode(gameId, confNew)  
76 - //}  
77 -}  
service/cardholder/config-registry.go
@@ -1,175 +0,0 @@ @@ -1,175 +0,0 @@
1 -package cardholder  
2 -  
3 -import (  
4 - "apigame/util/util-lx/lxalilog"  
5 - "encoding/json"  
6 - "errors"  
7 - "fmt"  
8 - "strings"  
9 -)  
10 -  
11 -var (  
12 - _Configs map[string]*CardActivityConfig // 配置列表 k=GameId v=配置  
13 -)  
14 -  
15 -func NewConfigs() {  
16 - _Configs = make(map[string]*CardActivityConfig)  
17 -}  
18 -  
19 -func GetConfig(gameId string) (config *CardActivityConfig, has bool) {  
20 - config, has = _Configs[gameId]  
21 - return  
22 -}  
23 -  
24 -// ConfigDecode 解析配置原始数据  
25 -func ConfigDecode(gameId string, configRaw *CardActivityConfigRaw) {  
26 - Config := &CardActivityConfig{  
27 - Raw: configRaw,  
28 - GameId: gameId,  
29 - Id: configRaw.Id,  
30 - Awards: make(map[string]string),  
31 - AlbumConfig: make(map[int]AlbumConfig),  
32 - CardConfig: make(map[int]CardConfig),  
33 - CardholderConfig: make(map[string]OpenCardholderConfig),  
34 - NormalCardStarConfig: make(map[string]NormalCardStarConfig),  
35 - CardSequenceConfig: make(map[string]CardSequenceConfig),  
36 - StarShopConfig: make(map[int]StarShopConfig),  
37 - }  
38 - // 解析奖励  
39 - {  
40 - err := json.Unmarshal([]byte(configRaw.Awards), &Config.Awards)  
41 - if err != nil {  
42 - lxalilog.Errors(err, configRaw.Awards, gameId, configRaw.Id)  
43 - return  
44 - }  
45 - }  
46 - // 卡组配置  
47 - {  
48 - configs := make([]AlbumConfig, 0)  
49 - err := json.Unmarshal([]byte(configRaw.AlbumConfig), &configs)  
50 - if err != nil {  
51 - lxalilog.Errors(err, configRaw.AlbumConfig, gameId, configRaw.Id)  
52 - return  
53 - }  
54 - for _, i2 := range configs {  
55 - Config.AlbumConfig[i2.SetId] = i2  
56 - }  
57 - }  
58 - // 卡牌配置  
59 - {  
60 - configs := make([]CardConfig, 0)  
61 - err := json.Unmarshal([]byte(configRaw.CardConfig), &configs)  
62 - if err != nil {  
63 - lxalilog.Errors(err, configRaw.CardConfig, gameId, configRaw.Id)  
64 - return  
65 - }  
66 - for _, i2 := range configs {  
67 - Config.CardConfig[i2.Id] = i2  
68 - }  
69 - }  
70 - // 卡包开卡规则  
71 - {  
72 - configs := make([]OpenCardholderConfig, 0)  
73 - err := json.Unmarshal([]byte(configRaw.CardHolderConfig), &configs)  
74 - if err != nil {  
75 - lxalilog.Errors(err, configRaw.CardHolderConfig, gameId, configRaw.Id)  
76 - return  
77 - }  
78 - for _, i2 := range configs {  
79 - Config.CardholderConfig[i2.Id] = i2  
80 - }  
81 - }  
82 - // 卡片星级配置  
83 - {  
84 - configs := make([]NormalCardStarConfig, 0)  
85 - err := json.Unmarshal([]byte(configRaw.NormalCardStarSequence), &configs)  
86 - if err != nil {  
87 - lxalilog.Errors(err, configRaw.NormalCardStarSequence, gameId, configRaw.Id)  
88 - return  
89 - }  
90 - for _, i2 := range configs {  
91 - i2.NormalCardSequenceIds = strings.Split(i2.NormalCardSequenceId, ",")  
92 - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)  
93 - Config.NormalCardStarConfig[combineId] = i2  
94 - }  
95 - }  
96 - // 卡片星级对应卡牌配置  
97 - {  
98 - configs := make([]CardSequenceConfig, 0)  
99 - err := json.Unmarshal([]byte(configRaw.CardSequenceConfig), &configs)  
100 - if err != nil {  
101 - lxalilog.Errors(err, configRaw.CardSequenceConfig, gameId, configRaw.Id)  
102 - return  
103 - }  
104 - for _, i2 := range configs {  
105 - i2.CardIdLists = strings.Split(i2.CardIdList, ",")  
106 - combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)  
107 - Config.CardSequenceConfig[combineId] = i2  
108 - }  
109 - }  
110 - // 星星商店配置  
111 - {  
112 - configs := make([]StarShopConfig, 0)  
113 - err := json.Unmarshal([]byte(configRaw.StarShopConfig), &configs)  
114 - if err != nil {  
115 - lxalilog.Errors(err, configRaw.StarShopConfig, gameId, configRaw.Id)  
116 - return  
117 - }  
118 - for _, i2 := range configs {  
119 - Config.StarShopConfig[i2.Id] = i2  
120 - }  
121 - }  
122 - _Configs[gameId] = Config  
123 -  
124 - GenerateConfigClient(Config)  
125 -}  
126 -  
127 -// GenerateConfigClient 生成给客户端的配置  
128 -func GenerateConfigClient(config *CardActivityConfig) {  
129 - configClient := &CardActivityConfigClient{  
130 - Id: config.Id,  
131 - RoundAwards: config.Awards,  
132 - Albums: make([]AlbumConfig, 0),  
133 - Cards: make([]CardConfig, 0),  
134 - Holders: make([]OpenCardholderConfig, 0),  
135 - StarShop: make([]StarShopConfig, 0),  
136 - }  
137 - for _, i2 := range config.AlbumConfig {  
138 - configClient.Albums = append(configClient.Albums, i2)  
139 - }  
140 - for _, i2 := range config.CardConfig {  
141 - configClient.Cards = append(configClient.Cards, i2)  
142 - }  
143 - for _, i2 := range config.CardholderConfig {  
144 - configClient.Holders = append(configClient.Holders, i2)  
145 - }  
146 - for _, i2 := range config.StarShopConfig {  
147 - configClient.StarShop = append(configClient.StarShop, i2)  
148 - }  
149 - config.Client = configClient  
150 -}  
151 -  
152 -// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组  
153 -func CombineIdSequenceIdCohort(id, sequenceId, cohort string) string {  
154 - return fmt.Sprintf("%s_%s_%s", id, sequenceId, cohort)  
155 -}  
156 -  
157 -// FindNormalCardStarConfig 查找配置 非保底卡星级ID  
158 -func (c *CardActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort string) (conf NormalCardStarConfig, has bool) {  
159 - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)  
160 - conf, has = c.NormalCardStarConfig[combineId]  
161 - if !has {  
162 - lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort)  
163 - }  
164 - return  
165 -}  
166 -  
167 -// FindCardSequenceConfig 查找配置 星级ID对应的卡片  
168 -func (c *CardActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort string) (conf CardSequenceConfig, has bool) {  
169 - combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)  
170 - conf, has = c.CardSequenceConfig[combineId]  
171 - if !has {  
172 - lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort)  
173 - }  
174 - return  
175 -}  
service/cardholder/config.go
@@ -1,122 +0,0 @@ @@ -1,122 +0,0 @@
1 -package cardholder  
2 -  
3 -import (  
4 - "apigame/service/constd"  
5 - "apigame/util/utdto"  
6 -)  
7 -  
8 -// CardActivityUpdateConfig 卡牌活动更新配置  
9 -type CardActivityUpdateConfig struct {  
10 - Id int64 // ID  
11 - Status int // 状态 0=关闭 1=开启  
12 - UpdateTime int64 // 修改时间戳  
13 -}  
14 -  
15 -func (d *CardActivityUpdateConfig) TableName() string {  
16 - return utdto.MYSQL_TABLE_TEMPLATE  
17 -}  
18 -  
19 -func (d *CardActivityUpdateConfig) GetTableName(gameId string) string {  
20 - return constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG + gameId  
21 -}  
22 -  
23 -// CardActivityConfig 卡牌活动配置 分析后数据  
24 -type CardActivityConfig struct {  
25 - Raw *CardActivityConfigRaw  
26 - Client *CardActivityConfigClient  
27 - GameId string // 所属游戏ID  
28 - Id int64 // ID  
29 - Awards map[string]string // 奖励配置  
30 - AlbumConfig map[int]AlbumConfig // 卡组配置  
31 - CardConfig map[int]CardConfig // 卡牌配置  
32 - CardholderConfig map[string]OpenCardholderConfig // 卡包开卡规则  
33 - NormalCardStarConfig map[string]NormalCardStarConfig // k=ID_用户序列_用户分组 卡片星级配置  
34 - CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置  
35 - StarShopConfig map[int]StarShopConfig // 星星商店配置  
36 -}  
37 -  
38 -// CardActivityConfigRaw 卡牌活动配置 原始数据  
39 -type CardActivityConfigRaw struct {  
40 - Id int64 // ID  
41 - OpenLevel int // 开启等级  
42 - PreviewTime int64 // 预告时间  
43 - StartTime int64 // 开始时间  
44 - EndTime int64 // 结束时间  
45 - Round int // 轮数  
46 - Awards string `json:"-"` // 奖励配置  
47 - AlbumConfig string `json:"-"` // 卡组配置  
48 - CardConfig string `json:"-"` // 卡牌配置  
49 - CardHolderConfig string `json:"-"` // 卡包开卡规则  
50 - NormalCardStarSequence string `json:"-"` // 卡片星级配置  
51 - CardSequenceConfig string `json:"-"` // 卡片星级对应卡牌配置  
52 - StarShopConfig string `json:"-"` // 星星商店配置  
53 - Ver string // 版本号  
54 - Status int // 状态 0=关闭 1=开启  
55 - UpdateTime int64 // 修改时间戳  
56 -}  
57 -  
58 -func (d *CardActivityConfigRaw) TableName() string {  
59 - return utdto.MYSQL_TABLE_TEMPLATE  
60 -}  
61 -  
62 -func (d *CardActivityConfigRaw) GetTableName(gameId string) string {  
63 - return constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG + gameId  
64 -}  
65 -  
66 -// AlbumConfig 卡组表  
67 -type AlbumConfig struct {  
68 - SetId int `json:"set_id"` // 卡组名  
69 - Name int `json:"name"` // 卡组图片  
70 - Icon string `json:"icon"` // 卡组id  
71 - Rewards map[string]string `json:"rewards"` // 集齐奖励 k=轮次  
72 - StartTime int64 `json:"start_time"` // 开始时间  
73 - EndTime int64 `json:"end_time"` // 结束时间  
74 -}  
75 -  
76 -// CardConfig 卡牌表  
77 -type CardConfig struct {  
78 - Id int `json:"id"` // ID  
79 - Name int `json:"name"` // 卡牌名字  
80 - Icon int `json:"icon"` // 卡牌图标  
81 - Desc int `json:"desc"` // 卡牌描述  
82 - SetId int `json:"album_setid"` // 卡组id  
83 - Star int `json:"star"` // 星级  
84 - IsGold int `json:"is_gold"` // 是否是金卡  
85 - IsSend int `json:"is_send"` // 卡片是否可赠送  
86 -}  
87 -  
88 -// OpenCardholderConfig 卡包开卡规则表  
89 -type OpenCardholderConfig struct {  
90 - Id string `json:"id"` // ID  
91 - IsGoldCardholder int `json:"is_gold_card_holder"` // 是否是金卡包  
92 - IsNew int `json:"is_new"` // 是否是新卡包  
93 - GuaranteedStarCardId string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID  
94 - NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量  
95 - MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID  
96 - ActivityId int `json:"activity_id"` // 对应活动ID  
97 -}  
98 -  
99 -// NormalCardStarConfig 非保底卡星级ID  
100 -type NormalCardStarConfig struct {  
101 - Id string `json:"id"` // ID  
102 - SequenceId string `json:"user_sequence_id"` // 用户序列组ID  
103 - Cohort string `json:"cohort"` // 用户分组  
104 - NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列  
105 - NormalCardSequenceIds []string `json:"-"` // 非保底星级序列  
106 -}  
107 -  
108 -// CardSequenceConfig 星级ID对应的卡片  
109 -type CardSequenceConfig struct {  
110 - Id string `json:"id"` // ID  
111 - SequenceId string `json:"user_sequence_id"` // 用户序列组ID  
112 - Cohort string `json:"cohort"` // 用户分组  
113 - CardIdList string `json:"card_id_list"` // 卡牌抽取序列  
114 - CardIdLists []string `json:"-"` // 卡牌抽取序列  
115 -}  
116 -  
117 -// StarShopConfig 星星商店配置  
118 -type StarShopConfig struct {  
119 - Id int `json:"id"` // ID  
120 - NeedStarNumber int `json:"need_star_number"` // 需求星星数  
121 - CardBagIds []int `json:"card_bag_ids"` // 可换取的卡包ID {卡包类型,卡包ID,卡包数量}  
122 -}  
service/cardholder/handle.go
1 package cardholder 1 package cardholder
2 2
3 import ( 3 import (
  4 + "apigame/configs"
4 "apigame/models" 5 "apigame/models"
5 "apigame/service/constd" 6 "apigame/service/constd"
6 "apigame/util/util-lx/lxalilog" 7 "apigame/util/util-lx/lxalilog"
@@ -15,12 +16,12 @@ func HandleGetConfig(req *models.ReqCardHolderGetConfig) (code string, rsp model @@ -15,12 +16,12 @@ func HandleGetConfig(req *models.ReqCardHolderGetConfig) (code string, rsp model
15 code = constd.RECODE_OK 16 code = constd.RECODE_OK
16 17
17 // 尝试更新配置 18 // 尝试更新配置
18 - config, _ := TryUpdateConfig(req.GameID) 19 + config, _ := configs.GetCardActivityConfig(req.GameID)
19 rsp.ActivityId = config.Id 20 rsp.ActivityId = config.Id
20 - rsp.PrepareTime = config.Raw.PreviewTime  
21 - rsp.StartTime = config.Raw.StartTime  
22 - rsp.EndTime = config.Raw.EndTime  
23 - rsp.OpenLevel = config.Raw.OpenLevel 21 + rsp.PrepareTime = config.PreviewTime
  22 + rsp.StartTime = config.StartTime
  23 + rsp.EndTime = config.EndTime
  24 + rsp.OpenLevel = config.OpenLevel
24 25
25 rsp.Config = config.Client 26 rsp.Config = config.Client
26 27
@@ -33,7 +34,7 @@ func HandleInfo(req *models.ReqCardHolderInfo) (code string, rsp models.RspCardH @@ -33,7 +34,7 @@ func HandleInfo(req *models.ReqCardHolderInfo) (code string, rsp models.RspCardH
33 code = constd.RECODE_OK 34 code = constd.RECODE_OK
34 35
35 // 尝试更新配置 36 // 尝试更新配置
36 - config, hasConfig := TryUpdateConfig(req.GameID) 37 + config, hasConfig := configs.GetCardActivityConfig(req.GameID)
37 if !hasConfig { 38 if !hasConfig {
38 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR 39 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
39 return 40 return
@@ -41,7 +42,7 @@ func HandleInfo(req *models.ReqCardHolderInfo) (code string, rsp models.RspCardH @@ -41,7 +42,7 @@ func HandleInfo(req *models.ReqCardHolderInfo) (code string, rsp models.RspCardH
41 42
42 // 判断预告时间 43 // 判断预告时间
43 sec := lxtime.NowUninx() 44 sec := lxtime.NowUninx()
44 - if sec < config.Raw.StartTime { 45 + if sec < config.StartTime {
45 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR 46 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
46 return 47 return
47 } 48 }
@@ -63,7 +64,7 @@ func HandleOpen(req *models.ReqCardHolderOpen) (code string, rsp models.RspCardH @@ -63,7 +64,7 @@ func HandleOpen(req *models.ReqCardHolderOpen) (code string, rsp models.RspCardH
63 code = constd.RECODE_OK 64 code = constd.RECODE_OK
64 65
65 // 尝试更新配置 66 // 尝试更新配置
66 - config, hasConfig := TryUpdateConfig(req.GameID) 67 + config, hasConfig := configs.GetCardActivityConfig(req.GameID)
67 if !hasConfig { 68 if !hasConfig {
68 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR 69 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
69 return 70 return
@@ -138,7 +139,7 @@ func HandleShopExchange(req *models.ReqStarShopExchange) (code string, rsp model @@ -138,7 +139,7 @@ func HandleShopExchange(req *models.ReqStarShopExchange) (code string, rsp model
138 code = constd.RECODE_OK 139 code = constd.RECODE_OK
139 140
140 // 尝试更新配置 141 // 尝试更新配置
141 - config, hasConfig := TryUpdateConfig(req.GameID) 142 + config, hasConfig := configs.GetCardActivityConfig(req.GameID)
142 if !hasConfig { 143 if !hasConfig {
143 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR 144 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
144 return 145 return
@@ -244,7 +245,7 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m @@ -244,7 +245,7 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m
244 code = constd.RECODE_OK 245 code = constd.RECODE_OK
245 246
246 // 尝试更新配置 247 // 尝试更新配置
247 - config, hasConfig := TryUpdateConfig(req.GameID) 248 + config, hasConfig := configs.GetCardActivityConfig(req.GameID)
248 if !hasConfig { 249 if !hasConfig {
249 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR 250 code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
250 return 251 return
service/cardholder/logic.go
@@ -2,6 +2,7 @@ package cardholder @@ -2,6 +2,7 @@ package cardholder
2 2
3 import ( 3 import (
4 "apigame/common/svdto" 4 "apigame/common/svdto"
  5 + "apigame/configs"
5 "apigame/models" 6 "apigame/models"
6 "apigame/service/constd" 7 "apigame/service/constd"
7 "apigame/util/util-lx/lxalilog" 8 "apigame/util/util-lx/lxalilog"
@@ -38,7 +39,7 @@ func _LoadData(gameId string, uid int64) (d *CardHolderData) { @@ -38,7 +39,7 @@ func _LoadData(gameId string, uid int64) (d *CardHolderData) {
38 } 39 }
39 40
40 // LoadData 获取数据 外部接口 41 // LoadData 获取数据 外部接口
41 -func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *CardHolderData) { 42 +func LoadData(gameId string, uid int64, config *configs.CardActivityConfig) (d *CardHolderData) {
42 configId := config.Id 43 configId := config.Id
43 d = _LoadData(gameId, uid) 44 d = _LoadData(gameId, uid)
44 // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新 45 // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新
@@ -61,23 +62,23 @@ func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *CardHold @@ -61,23 +62,23 @@ func LoadData(gameId string, uid int64, config *CardActivityConfig) (d *CardHold
61 } 62 }
62 63
63 // CheckStatus 判断活动是否开启 64 // CheckStatus 判断活动是否开启
64 -func CheckStatus(conf *CardActivityConfig) string { 65 +func CheckStatus(conf *configs.CardActivityConfig) string {
65 sec := lxtime.NowUninx() 66 sec := lxtime.NowUninx()
66 if conf.Id == 0 { 67 if conf.Id == 0 {
67 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR 68 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
68 } 69 }
69 - if sec < conf.Raw.StartTime { 70 + if sec < conf.StartTime {
70 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR 71 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
71 } 72 }
72 - if sec > conf.Raw.EndTime { 73 + if sec > conf.EndTime {
73 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR 74 return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR
74 } 75 }
75 return constd.RECODE_OK 76 return constd.RECODE_OK
76 } 77 }
77 78
78 // CheckGameData 检查游戏数据 轮次等 79 // CheckGameData 检查游戏数据 轮次等
79 -func CheckGameData(d *CardHolderData, conf *CardActivityConfig) string {  
80 - if d.Details.Round > conf.Raw.Round { 80 +func CheckGameData(d *CardHolderData, conf *configs.CardActivityConfig) string {
  81 + if d.Details.Round > conf.Round {
81 return constd.RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR 82 return constd.RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR
82 } 83 }
83 return constd.RECODE_OK 84 return constd.RECODE_OK
@@ -119,7 +120,7 @@ func GetListFromArray(array []string, scale, count int) []string { @@ -119,7 +120,7 @@ func GetListFromArray(array []string, scale, count int) []string {
119 } 120 }
120 121
121 // GetNewCard 按顺序查找数目最少的一张卡抽取 122 // GetNewCard 按顺序查找数目最少的一张卡抽取
122 -func GetNewCard(gameData *CardHolderData, conf *CardActivityConfig) int { 123 +func GetNewCard(gameData *CardHolderData, conf *configs.CardActivityConfig) int {
123 if len(conf.CardConfig) < 1 { 124 if len(conf.CardConfig) < 1 {
124 return 0 125 return 0
125 } 126 }
@@ -136,7 +137,7 @@ func GetNewCard(gameData *CardHolderData, conf *CardActivityConfig) int { @@ -136,7 +137,7 @@ func GetNewCard(gameData *CardHolderData, conf *CardActivityConfig) int {
136 } 137 }
137 138
138 // CheckAlbumFinish 判断卡组是否已集齐 139 // CheckAlbumFinish 判断卡组是否已集齐
139 -func CheckAlbumFinish(albumId int, gameData *CardHolderData, config *CardActivityConfig) bool { 140 +func CheckAlbumFinish(albumId int, gameData *CardHolderData, config *configs.CardActivityConfig) bool {
140 for _, conf := range config.CardConfig { 141 for _, conf := range config.CardConfig {
141 if conf.SetId == albumId { 142 if conf.SetId == albumId {
142 count := gameData.Details.Cards[conf.Id] 143 count := gameData.Details.Cards[conf.Id]
@@ -149,7 +150,7 @@ func CheckAlbumFinish(albumId int, gameData *CardHolderData, config *CardActivit @@ -149,7 +150,7 @@ func CheckAlbumFinish(albumId int, gameData *CardHolderData, config *CardActivit
149 } 150 }
150 151
151 // CheckRoundFinish 判断轮次是否已集齐(所有卡组集齐) 152 // CheckRoundFinish 判断轮次是否已集齐(所有卡组集齐)
152 -func CheckRoundFinish(gameData *CardHolderData, config *CardActivityConfig) bool { 153 +func CheckRoundFinish(gameData *CardHolderData, config *configs.CardActivityConfig) bool {
153 for _, conf := range config.AlbumConfig { 154 for _, conf := range config.AlbumConfig {
154 count := gameData.Details.Album[conf.SetId] 155 count := gameData.Details.Album[conf.SetId]
155 if count < 1 { 156 if count < 1 {
@@ -167,7 +168,7 @@ func HandleNextRound(gameData *CardHolderData) { @@ -167,7 +168,7 @@ func HandleNextRound(gameData *CardHolderData) {
167 } 168 }
168 169
169 // GetInfo 玩家卡牌活动信息 170 // GetInfo 玩家卡牌活动信息
170 -func GetInfo(gameData *CardHolderData, conf *CardActivityConfig) models.CardHolderInfo { 171 +func GetInfo(gameData *CardHolderData, conf *configs.CardActivityConfig) models.CardHolderInfo {
171 info := models.CardHolderInfo{ 172 info := models.CardHolderInfo{
172 Cards: make(map[int]int), 173 Cards: make(map[int]int),
173 Album: make(map[int]int), 174 Album: make(map[int]int),
@@ -188,8 +189,8 @@ func GetInfo(gameData *CardHolderData, conf *CardActivityConfig) models.CardHold @@ -188,8 +189,8 @@ func GetInfo(gameData *CardHolderData, conf *CardActivityConfig) models.CardHold
188 // openMode:开包类型0客户端驱动1星星商店购买2剩余星星兑换 189 // openMode:开包类型0客户端驱动1星星商店购买2剩余星星兑换
189 func DoOpen(gameId string, 190 func DoOpen(gameId string,
190 gameData *CardHolderData, 191 gameData *CardHolderData,
191 - config *CardActivityConfig,  
192 - confCardholder OpenCardholderConfig, 192 + config *configs.CardActivityConfig,
  193 + confCardholder configs.OpenCardholderConfig,
193 sequenceId, cohort string, 194 sequenceId, cohort string,
194 openMode int) (newCards []int) { 195 openMode int) (newCards []int) {
195 196
@@ -205,7 +206,7 @@ func DoOpen(gameId string, @@ -205,7 +206,7 @@ func DoOpen(gameId string,
205 getCardFunc := func(cardConfigId string) { 206 getCardFunc := func(cardConfigId string) {
206 confCardSequence, hasCardSequence := config.FindCardSequenceConfig(cardConfigId, sequenceId, cohort) 207 confCardSequence, hasCardSequence := config.FindCardSequenceConfig(cardConfigId, sequenceId, cohort)
207 if hasCardSequence { 208 if hasCardSequence {
208 - combineId := CombineIdSequenceIdCohort(cardConfigId, sequenceId, cohort) 209 + combineId := configs.CombineIdSequenceIdCohort(cardConfigId, sequenceId, cohort)
209 scale := gameData.Details.CardSequenceScales[combineId] 210 scale := gameData.Details.CardSequenceScales[combineId]
210 cardId := GetOneFromArray(confCardSequence.CardIdLists, scale) 211 cardId := GetOneFromArray(confCardSequence.CardIdLists, scale)
211 cardIdInt := utstring.StringToInt(cardId) 212 cardIdInt := utstring.StringToInt(cardId)
@@ -226,7 +227,7 @@ func DoOpen(gameId string, @@ -226,7 +227,7 @@ func DoOpen(gameId string,
226 count := confCardholder.NormalCardNumber 227 count := confCardholder.NormalCardNumber
227 confNormalCardStar, hasNormalCardStar := config.FindNormalCardStarConfig(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort) 228 confNormalCardStar, hasNormalCardStar := config.FindNormalCardStarConfig(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort)
228 if hasNormalCardStar { 229 if hasNormalCardStar {
229 - combineIdStar := CombineIdSequenceIdCohort(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort) 230 + combineIdStar := configs.CombineIdSequenceIdCohort(confCardholder.MinimumGuaranteeCardId, sequenceId, cohort)
230 scaleStar := gameData.Details.StarSequenceScales[combineIdStar] 231 scaleStar := gameData.Details.StarSequenceScales[combineIdStar]
231 starIds := GetListFromArray(confNormalCardStar.NormalCardSequenceIds, scaleStar, count) 232 starIds := GetListFromArray(confNormalCardStar.NormalCardSequenceIds, scaleStar, count)
232 // 增加星级刻度 233 // 增加星级刻度
@@ -251,7 +252,7 @@ func DoOpen(gameId string, @@ -251,7 +252,7 @@ func DoOpen(gameId string,
251 // DoOpenCheckAward 封装的新卡判断是否出发卡组和轮次奖励的逻辑 252 // DoOpenCheckAward 封装的新卡判断是否出发卡组和轮次奖励的逻辑
252 func DoOpenCheckAward(gameId string, 253 func DoOpenCheckAward(gameId string,
253 gameData *CardHolderData, 254 gameData *CardHolderData,
254 - config *CardActivityConfig, 255 + config *configs.CardActivityConfig,
255 sequenceId, cohort string, 256 sequenceId, cohort string,
256 newCards []int, 257 newCards []int,
257 openMode int) (awardAlbum map[int]string, awardRound string) { 258 openMode int) (awardAlbum map[int]string, awardRound string) {
@@ -312,7 +313,7 @@ func DoOpenCheckAward(gameId string, @@ -312,7 +313,7 @@ func DoOpenCheckAward(gameId string,
312 } 313 }
313 314
314 // CalculateStarCount 计算星星点数 315 // CalculateStarCount 计算星星点数
315 -func CalculateStarCount(gameData *CardHolderData, config *CardActivityConfig) { 316 +func CalculateStarCount(gameData *CardHolderData, config *configs.CardActivityConfig) {
316 starCount := 0 317 starCount := 0
317 for cardId, cardCount := range gameData.Details.Cards { 318 for cardId, cardCount := range gameData.Details.Cards {
318 if cardCount <= 1 { 319 if cardCount <= 1 {
@@ -334,7 +335,7 @@ func CalculateStarCount(gameData *CardHolderData, config *CardActivityConfig) { @@ -334,7 +335,7 @@ func CalculateStarCount(gameData *CardHolderData, config *CardActivityConfig) {
334 } 335 }
335 336
336 // GetStarCardList 按照规则扣除星星数找到需要扣除的卡牌列表 337 // GetStarCardList 按照规则扣除星星数找到需要扣除的卡牌列表
337 -func GetStarCardList(gameData *CardHolderData, config *CardActivityConfig, needStar int) (enough bool, cardList map[int]int) { 338 +func GetStarCardList(gameData *CardHolderData, config *configs.CardActivityConfig, needStar int) (enough bool, cardList map[int]int) {
338 enough = false 339 enough = false
339 cardList = make(map[int]int) 340 cardList = make(map[int]int)
340 starAmount := 0 341 starAmount := 0
@@ -403,10 +404,10 @@ func GetStarCardList(gameData *CardHolderData, config *CardActivityConfig, needS @@ -403,10 +404,10 @@ func GetStarCardList(gameData *CardHolderData, config *CardActivityConfig, needS
403 } 404 }
404 405
405 // NextActivityAutoExchange 活动切换时自动兑换卡包 406 // NextActivityAutoExchange 活动切换时自动兑换卡包
406 -func NextActivityAutoExchange(gameId string, gameData *CardHolderData, config *CardActivityConfig) { 407 +func NextActivityAutoExchange(gameId string, gameData *CardHolderData, config *configs.CardActivityConfig) {
407 starCount := gameData.Details.LastStarCount 408 starCount := gameData.Details.LastStarCount
408 // 把星星的配置按照需要的星星数降序排列 409 // 把星星的配置按照需要的星星数降序排列
409 - list := lo.Values[int, StarShopConfig](config.StarShopConfig) 410 + list := lo.Values[int, configs.StarShopConfig](config.StarShopConfig)
410 sort.Slice(list, func(i, j int) bool { 411 sort.Slice(list, func(i, j int) bool {
411 return list[i].NeedStarNumber < list[j].NeedStarNumber 412 return list[i].NeedStarNumber < list[j].NeedStarNumber
412 }) 413 })
util/utdto/base.go
1 package utdto 1 package utdto
2 2
3 import ( 3 import (
4 - "fmt"  
5 "gorm.io/gorm" 4 "gorm.io/gorm"
6 "strings" 5 "strings"
7 ) 6 )
@@ -33,7 +32,6 @@ func Save(db *gorm.DB, value any, tableName string) *gorm.DB { @@ -33,7 +32,6 @@ func Save(db *gorm.DB, value any, tableName string) *gorm.DB {
33 func First(db *gorm.DB, value any, tableName string) *gorm.DB { 32 func First(db *gorm.DB, value any, tableName string) *gorm.DB {
34 stmt := db.Session(&gorm.Session{DryRun: true}).First(value).Statement 33 stmt := db.Session(&gorm.Session{DryRun: true}).First(value).Statement
35 stmtSQL := stmt.SQL.String() 34 stmtSQL := stmt.SQL.String()
36 - fmt.Println("dwjw🐷 stmt.Table", stmt.Table)  
37 sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1) 35 sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
38 return db.Raw(sql, stmt.Vars...).Scan(value) 36 return db.Raw(sql, stmt.Vars...).Scan(value)
39 } 37 }