configs.go
3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package ht_cardholder
import (
"apigame/api-util/umysql"
"apigame/service/constd"
"fmt"
)
var configTable = constd.MYSQL_TABLE_ACTIVITY_S_CARD_ACTIVITY + "10128"
var (
Registry CardActivityConfigs // 卡牌活动配置
CardConfigs = make(map[int]CardConfig) // 卡牌表
CardholderConfigs = make(map[int]CardholderConfig) // 卡包开卡规则表
NormalCardStarSequences = make([]NormalCardStarSequence, 0) // 非保底卡星级ID
CardSequenceConfigs = make([]CardSequenceConfig, 0) // 星级ID对应的卡片
)
// Init 初始化
func Init() {
Registry = CardActivityConfigs{
CardActivityConfigs: make(map[int64]CardActivityConfig),
}
// todo 装填虚拟数据
//UseSimulateConfigs()
TryUpdateConfigs()
//DumpConfigs()
}
// TryUpdateConfigs 尝试更新配置表
func TryUpdateConfigs() {
LoadConfigs()
}
// LoadConfigs 读取mysql配置
func LoadConfigs() {
// 读取最后修改时间
configsUpdate := make(map[int64]CardActivityUpdateConfig)
{
conf := make([]CardActivityUpdateConfig, 0)
sql := fmt.Sprintf("select id,update_time from %s", configTable)
err := umysql.FindSql(constd.MYSQL_MERGECONFIG, sql, &conf)
if err != nil {
// todo 记录错误日志
return
}
for _, config := range conf {
configsUpdate[config.Id] = config
}
fmt.Println(configsUpdate)
}
// 如果条目不存在 从活动列表中删除
for k, _ := range Registry.CardActivityConfigs {
_, ok := configsUpdate[k]
if !ok {
delete(Registry.CardActivityConfigs, k)
}
}
for k, confUpdate := range configsUpdate {
needUpdate := false
confOld, ok := Registry.CardActivityConfigs[k]
// 如果条目不存在 或者 修改时间不一致 需要更新
if !ok {
needUpdate = true
} else {
if confOld.UpdateTime != confUpdate.UpdateTime {
needUpdate = true
}
}
// 更新数据
if needUpdate {
fmt.Println("__________________尝试更新活动条目ID:", k)
confNew := CardActivityConfig{}
sql := fmt.Sprintf("select * from %s where id=%d limit 1", configTable, k)
err := umysql.FindOneSql(constd.MYSQL_MERGECONFIG, sql, &confNew)
if err != nil {
// todo 记录错误日志
continue
}
fmt.Println("__________________更新活动条目ID:", confNew.Id)
Registry.CardActivityConfigs[confNew.Id] = confNew
}
}
}
// UseSimulateConfigs 装填虚拟数据
func UseSimulateConfigs() {
// 卡牌表 i=卡组ID j=卡牌顺序
for i := 1; i <= 9; i++ {
for j := 1; j <= 9; j++ {
conf := CardConfig{
Id: i*100 + j,
GroupId: i,
IsGoldCard: 0,
Star: 1,
}
if j == 9 {
conf.IsGoldCard = 1
conf.Star = 2
}
CardConfigs[conf.Id] = conf
}
}
// 卡包开卡规则表
CardholderConfigs[1] = CardholderConfig{
Id: 1,
GuaranteedStar: 1,
NormalCardNumber: 2,
MinimumGuaranteeCardId: 1,
}
CardholderConfigs[2] = CardholderConfig{
Id: 2,
GuaranteedStar: 2,
NormalCardNumber: 3,
MinimumGuaranteeCardId: 2,
}
CardholderConfigs[3] = CardholderConfig{
Id: 3,
GuaranteedStar: 3,
NormalCardNumber: 4,
MinimumGuaranteeCardId: 3,
}
// 非保底卡星级ID i=非保底卡星级ID j=用户分组
for i := 1; i <= 3; i++ {
for j := 1; j <= 2; j++ {
conf := NormalCardStarSequence{
Id: i,
Cohort: j,
NormalCardSequenceId: []int{i, i, i, j},
}
NormalCardStarSequences = append(NormalCardStarSequences, conf)
}
}
// 星级ID对应的卡片
for i := 1; i <= 3; i++ {
for j := 1; j <= 2; j++ {
conf := CardSequenceConfig{
Id: i,
Cohort: j,
CardIdList: []int{101, 102, 103, 104, 102, 105, 106, 107, 108, 109},
}
CardSequenceConfigs = append(CardSequenceConfigs, conf)
}
}
}
func DumpConfigs() {
fmt.Println(CardConfigs)
fmt.Println(CardholderConfigs)
fmt.Println(NormalCardStarSequences)
fmt.Println(CardSequenceConfigs)
}