Commit ea63197a1bb80f31d9d7ff200b45f6c8aeb96cca

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

feat:解析配置数据

main.go
... ... @@ -4,14 +4,14 @@ import (
4 4 "apigame/models"
5 5 _ "apigame/routers"
6 6 ht_draw "apigame/service/ht-cardholder"
7   - "fmt"
8 7 "github.com/astaxie/beego"
  8 + "github.com/astaxie/beego/logs"
9 9 "github.com/astaxie/beego/plugins/cors"
10 10 )
11 11  
12 12 func main() {
13   - fmt.Println("apigame")
14   - //fmt.Println("😊🐸😺")
  13 + logs.Info("apigame")
  14 + //logs.Info("😊🐸😺")
15 15  
16 16 //解决跨域问题
17 17 beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
... ...
service/ht-cardholder/config-registry.go 0 → 100644
... ... @@ -0,0 +1,122 @@
  1 +package ht_cardholder
  2 +
  3 +import (
  4 + "apigame/lx-util/lxalilog"
  5 + "apigame/service/constd"
  6 + "encoding/json"
  7 + "github.com/astaxie/beego/logs"
  8 +)
  9 +
  10 +var (
  11 + configGameId = "10128"
  12 + configTable = constd.MYSQL_TABLE_ACTIVITY_S_CARD_ACTIVITY + configGameId
  13 + Registry RegistryConfigs // 卡牌活动配置
  14 +
  15 + CardConfigs = make(map[int]CardConfig) // 卡牌表
  16 + CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表
  17 + NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID
  18 + CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片
  19 +)
  20 +
  21 +// RegistryConfigs 卡牌活动配置
  22 +type RegistryConfigs struct {
  23 + CardActivityConfigRaws map[int64]CardActivityConfigRaw // 活动配置列表 原始数据
  24 + CardActivityConfig map[int64]CardActivityConfig // 活动配置列表 分析后数据
  25 +}
  26 +
  27 +func NewRegistryConfigs() {
  28 + Registry = RegistryConfigs{
  29 + CardActivityConfigRaws: make(map[int64]CardActivityConfigRaw),
  30 + CardActivityConfig: make(map[int64]CardActivityConfig),
  31 + }
  32 +}
  33 +
  34 +// Decode 解析配置原始数据
  35 +func (r RegistryConfigs) Decode(confRaw CardActivityConfigRaw) {
  36 + conf := CardActivityConfig{
  37 + Raw: confRaw,
  38 + Id: confRaw.Id,
  39 + Awards: make(map[string]string),
  40 + AlbumConfig: make(map[string]AlbumConfig),
  41 + CardConfig: make(map[int]CardConfig),
  42 + CardholderConfig: make(map[string]CardholderConfig),
  43 + NormalCardStarSequence: make([]NormalCardStarSequence, 0),
  44 + CardSequenceConfig: make([]CardSequenceConfig, 0),
  45 + }
  46 + // 解析奖励
  47 + {
  48 + err := json.Unmarshal([]byte(confRaw.Awards), &conf.Awards)
  49 + if err != nil {
  50 + lxalilog.Errors(err, confRaw.Awards, configGameId, confRaw.Id)
  51 + return
  52 + }
  53 + }
  54 + // 卡组配置
  55 + {
  56 + configs := make([]AlbumConfig, 0)
  57 + err := json.Unmarshal([]byte(confRaw.AlbumConfig), &configs)
  58 + if err != nil {
  59 + lxalilog.Errors(err, confRaw.AlbumConfig, configGameId, confRaw.Id)
  60 + return
  61 + }
  62 + for _, i2 := range configs {
  63 + conf.AlbumConfig[i2.SetId] = i2
  64 + }
  65 + }
  66 + // 卡牌配置
  67 + {
  68 + configs := make([]CardConfig, 0)
  69 + err := json.Unmarshal([]byte(confRaw.CardConfig), &configs)
  70 + if err != nil {
  71 + lxalilog.Errors(err, confRaw.CardConfig, configGameId, confRaw.Id)
  72 + return
  73 + }
  74 + for _, i2 := range configs {
  75 + conf.CardConfig[i2.Id] = i2
  76 + }
  77 + }
  78 + // 卡包开卡规则
  79 + {
  80 + configs := make([]CardholderConfig, 0)
  81 + err := json.Unmarshal([]byte(confRaw.CardHolderConfig), &configs)
  82 + if err != nil {
  83 + lxalilog.Errors(err, confRaw.CardHolderConfig, configGameId, confRaw.Id)
  84 + return
  85 + }
  86 + for _, i2 := range configs {
  87 + conf.CardholderConfig[i2.Id] = i2
  88 + }
  89 + }
  90 + // 卡片星级配置
  91 + {
  92 + configs := make([]NormalCardStarSequence, 0)
  93 + err := json.Unmarshal([]byte(confRaw.NormalCardStarSequence), &configs)
  94 + if err != nil {
  95 + lxalilog.Errors(err, confRaw.NormalCardStarSequence, configGameId, confRaw.Id)
  96 + return
  97 + }
  98 + for _, i2 := range configs {
  99 + conf.NormalCardStarSequence = append(conf.NormalCardStarSequence, i2)
  100 + }
  101 + }
  102 + // 卡片星级对应卡牌配置
  103 + {
  104 + configs := make([]CardSequenceConfig, 0)
  105 + err := json.Unmarshal([]byte(confRaw.CardSequenceConfig), &configs)
  106 + if err != nil {
  107 + lxalilog.Errors(err, confRaw.CardSequenceConfig, configGameId, confRaw.Id)
  108 + return
  109 + }
  110 + for _, i2 := range configs {
  111 + conf.CardSequenceConfig = append(conf.CardSequenceConfig, i2)
  112 + }
  113 + }
  114 +
  115 + r.CardActivityConfig[conf.Id] = conf
  116 + logs.Debug(conf.Awards)
  117 + logs.Debug(conf.AlbumConfig)
  118 + logs.Debug(conf.CardConfig)
  119 + logs.Debug(conf.CardholderConfig)
  120 + logs.Debug("🐸", conf.NormalCardStarSequence)
  121 + logs.Debug("🐸", conf.CardSequenceConfig)
  122 +}
... ...
service/ht-cardholder/config.go
1 1 package ht_cardholder
2 2  
3   -// CardActivityConfigs 卡牌活动配置
4   -type CardActivityConfigs struct {
5   - CardActivityConfigs map[int64]CardActivityConfig // 活动配置列表
6   -}
7   -
8 3 // CardActivityUpdateConfig 卡牌活动更新配置
9 4 type CardActivityUpdateConfig struct {
10 5 Id int64 `json:"id"` // ID
11 6 UpdateTime int64 `json:"update_time"` // 修改时间戳
12 7 }
13 8  
14   -// CardActivityConfig 卡牌活动配置
  9 +// CardActivityConfig 卡牌活动配置 分析后数据
15 10 type CardActivityConfig struct {
  11 + Raw CardActivityConfigRaw
  12 + Id int64 // ID
  13 + Awards map[string]string // 奖励配置
  14 + AlbumConfig map[string]AlbumConfig // 卡组配置
  15 + CardConfig map[int]CardConfig // 卡牌配置
  16 + CardholderConfig map[string]CardholderConfig // 卡包开卡规则
  17 + NormalCardStarSequence []NormalCardStarSequence // 卡片星级配置
  18 + CardSequenceConfig []CardSequenceConfig // 卡片星级对应卡牌配置
  19 +}
  20 +
  21 +// CardActivityConfigRaw 卡牌活动配置 原始数据
  22 +type CardActivityConfigRaw struct {
16 23 Id int64 `json:"id"` // ID
17 24 OpenLevel int `json:"open_level"` // 开启等级
18 25 PreviewTime int64 `json:"preview_time"` // 预告时间
... ... @@ -29,35 +36,44 @@ type CardActivityConfig struct {
29 36 UpdateTime int64 `json:"update_time"` // 修改时间戳
30 37 }
31 38  
  39 +// AlbumConfig 卡组表
  40 +type AlbumConfig struct {
  41 + SetId string `json:"set_id"` // 卡组id
  42 + Rewards string `json:"rewards"` // 集齐奖励
  43 + StartTime int64 `json:"start_time"` // 开始时间
  44 + EndTime int64 `json:"end_time"` // 结束时间
  45 +}
  46 +
32 47 // CardConfig 卡牌表
33 48 type CardConfig struct {
34   - Id int `json:"id"` // ID
35   - GroupId int `json:"groupid"` // 卡组id
36   - IsGoldCard int `json:"isgoldcard"` // 是否是金卡
37   - Star int `json:"star"` // 星级
  49 + Id int `json:"id"` // ID
  50 + SetId string `json:"album_setid"` // 卡组id
  51 + IsGold int `json:"is_gold"` // 是否是金卡
  52 + Star int `json:"star"` // 星级
38 53 }
39 54  
40 55 // CardholderConfig 卡包开卡规则表
41 56 type CardholderConfig struct {
42   - Id int `json:"id"` // ID
43   - GuaranteedStar int `json:"guaranteedstar"` // 保底卡星级序列ID
44   - IsGoldCardholder int `json:"isgoldcardholder"` // 是否是金卡包
45   - IsNew int `json:"isnew"` // 是否是新卡包
46   - NormalCardNumber int `json:"normalcardnumber"` // 非保底卡数量
47   - MinimumGuaranteeCardId int `json:"minimumguaranteecardid"` // 非保底卡牌序列ID
  57 + Id string `json:"id"` // ID
  58 + GuaranteedStar string `json:"guaranteed_star_card_id"` // 保底卡星级序列ID
  59 + IsGoldCardholder int `json:"isgoldcardholder"` // 是否是金卡包
  60 + IsNew int `json:"isnew"` // 是否是新卡包
  61 + NormalCardNumber int `json:"normal_card_number"` // 非保底卡数量
  62 + MinimumGuaranteeCardId string `json:"minimum_guarantee_card_id"` // 非保底卡牌序列ID
48 63 }
49 64  
50 65 // NormalCardStarSequence 非保底卡星级ID
51 66 type NormalCardStarSequence struct {
52   - Id int `json:"id"` // ID
53   - Cohort int `json:"cohort"` // 用户分组
54   - StarSequenceId int `json:"starsequenceid"` // 用户序列组ID
55   - NormalCardSequenceId []int `json:"normalcardsequenceid"` // 非保底星级序列
  67 + Id string `json:"id"` // ID
  68 + SequenceId string `json:"user_sequence_id"` // 用户序列组ID
  69 + Cohort string `json:"cohort"` // 用户分组
  70 + NormalCardSequenceId string `json:"normal_card_sequence_id"` // 非保底星级序列
56 71 }
57 72  
58 73 // CardSequenceConfig 星级ID对应的卡片
59 74 type CardSequenceConfig struct {
60   - Id int `json:"id"` // SequenceId 用户序列组ID
61   - Cohort int `json:"cohort"` // 用户分组
62   - CardIdList []int `json:"cardidlist"` // 卡牌抽取序列
  75 + Id string `json:"id"` // SequenceId 用户序列组ID
  76 + SequenceId string `json:"user_sequence_id"` // 用户序列组ID
  77 + Cohort string `json:"cohort"` // 用户分组
  78 + CardIdList string `json:"card_id_list"` // 卡牌抽取序列
63 79 }
... ...
service/ht-cardholder/configs.go
... ... @@ -2,30 +2,16 @@ package ht_cardholder
2 2  
3 3 import (
4 4 "apigame/api-util/umysql"
  5 + "apigame/lx-util/lxalilog"
5 6 "apigame/service/constd"
6 7 "fmt"
7   -)
8   -
9   -var configTable = constd.MYSQL_TABLE_ACTIVITY_S_CARD_ACTIVITY + "10128"
10   -
11   -var (
12   - Registry CardActivityConfigs // 卡牌活动配置
13   -
14   - CardConfigs = make(map[int]CardConfig) // 卡牌表
15   - CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表
16   - NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID
17   - CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片
  8 + "github.com/astaxie/beego/logs"
18 9 )
19 10  
20 11 // Init 初始化
21 12 func Init() {
22 13  
23   - Registry = CardActivityConfigs{
24   - CardActivityConfigs: make(map[int64]CardActivityConfig),
25   - }
26   -
27   - // todo 装填虚拟数据
28   - //UseSimulateConfigs()
  14 + NewRegistryConfigs()
29 15  
30 16 TryUpdateConfigs()
31 17  
... ... @@ -46,7 +32,7 @@ func LoadConfigs() {
46 32 sql := fmt.Sprintf("select id,update_time from %s", configTable)
47 33 err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf)
48 34 if err != nil {
49   - // todo 记录错误日志
  35 + lxalilog.Errors(err, sql, configGameId)
50 36 return
51 37 }
52 38 for _, config := range conf {
... ... @@ -55,15 +41,16 @@ func LoadConfigs() {
55 41 fmt.Println(configsUpdate)
56 42 }
57 43 // 如果条目不存在 从活动列表中删除
58   - for k, _ := range Registry.CardActivityConfigs {
  44 + for k, _ := range Registry.CardActivityConfigRaws {
59 45 _, ok := configsUpdate[k]
60 46 if !ok {
61   - delete(Registry.CardActivityConfigs, k)
  47 + delete(Registry.CardActivityConfigRaws, k)
  48 + delete(Registry.CardActivityConfig, k)
62 49 }
63 50 }
64 51 for k, confUpdate := range configsUpdate {
65 52 needUpdate := false
66   - confOld, ok := Registry.CardActivityConfigs[k]
  53 + confOld, ok := Registry.CardActivityConfigRaws[k]
67 54 // 如果条目不存在 或者 修改时间不一致 需要更新
68 55 if !ok {
69 56 needUpdate = true
... ... @@ -74,79 +61,17 @@ func LoadConfigs() {
74 61 }
75 62 // 更新数据
76 63 if needUpdate {
77   - fmt.Println("__________________尝试更新活动条目ID:", k)
78   - confNew := CardActivityConfig{}
  64 + logs.Debug("__________________尝试更新活动条目ID:", k)
  65 + confNew := CardActivityConfigRaw{}
79 66 sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTable, k)
80 67 err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew)
81 68 if err != nil {
82   - // todo 记录错误日志
  69 + lxalilog.Errors(err, sql, configGameId, k)
83 70 continue
84 71 }
85   - fmt.Println("__________________更新活动条目ID:", confNew.Id)
86   - Registry.CardActivityConfigs[confNew.Id] = confNew
87   - }
88   - }
89   -
90   -}
91   -
92   -// UseSimulateConfigs 装填虚拟数据
93   -func UseSimulateConfigs() {
94   -
95   - // 卡牌表 i=卡组ID j=卡牌顺序
96   - for i := 1; i <= 9; i++ {
97   - for j := 1; j <= 9; j++ {
98   - conf := CardConfig{
99   - Id: i*100 + j,
100   - GroupId: i,
101   - IsGoldCard: 0,
102   - Star: 1,
103   - }
104   - if j == 9 {
105   - conf.IsGoldCard = 1
106   - conf.Star = 2
107   - }
108   - CardConfigs[conf.Id] = conf
109   - }
110   - }
111   - // 卡包开卡规则表
112   - CardholderConfigs[1] = CardholderConfig{
113   - Id: 1,
114   - GuaranteedStar: 1,
115   - NormalCardNumber: 2,
116   - MinimumGuaranteeCardId: 1,
117   - }
118   - CardholderConfigs[2] = CardholderConfig{
119   - Id: 2,
120   - GuaranteedStar: 2,
121   - NormalCardNumber: 3,
122   - MinimumGuaranteeCardId: 2,
123   - }
124   - CardholderConfigs[3] = CardholderConfig{
125   - Id: 3,
126   - GuaranteedStar: 3,
127   - NormalCardNumber: 4,
128   - MinimumGuaranteeCardId: 3,
129   - }
130   - // 非保底卡星级ID i=非保底卡星级ID j=用户分组
131   - for i := 1; i <= 3; i++ {
132   - for j := 1; j <= 2; j++ {
133   - conf := NormalCardStarSequence{
134   - Id: i,
135   - Cohort: j,
136   - NormalCardSequenceId: []int{i, i, i, j},
137   - }
138   - NormalCardStarSequences = append(NormalCardStarSequences, conf)
139   - }
140   - }
141   - // 星级ID对应的卡片
142   - for i := 1; i <= 3; i++ {
143   - for j := 1; j <= 2; j++ {
144   - conf := CardSequenceConfig{
145   - Id: i,
146   - Cohort: j,
147   - CardIdList: []int{101, 102, 103, 104, 102, 105, 106, 107, 108, 109},
148   - }
149   - CardSequenceConfigs = append(CardSequenceConfigs, conf)
  72 + logs.Debug("__________________更新活动条目ID:", confNew.Id)
  73 + Registry.CardActivityConfigRaws[confNew.Id] = confNew
  74 + Registry.Decode(confNew)
150 75 }
151 76 }
152 77  
... ...