config.go
4.76 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
package confroomrank
import (
"apigame/configs-db/confbase"
"apigame/service-common/svconst"
"apigame/util/util-lx/lxtime"
"apigame/util/zconvert"
"fmt"
)
// ActivityConfig 房间排行活动配置 分析后数据
type ActivityConfig struct {
Raw *ActivityConfigRaw `json:"-"`
Id int64 // ID
Typ int // 排行榜类型
OpenLevel int // 开启等级
OpenScore int64 // 开启积分
PreviewTime int64 // 预告时间
StartTime int64 // 开始时间
EndTime int64 // 结束时间
ReleaseTime string // 结算发奖时间
Robot map[int]RobotConfig // 机器人配置
Room map[int]RoomConfig // 房间配置
GameId string // 所属游戏ID
}
func (c *ActivityConfig) GetUid() string {
return zconvert.Int64ToStr(c.Id)
}
func (c *ActivityConfig) CheckCurrent() bool {
timeNow := lxtime.NowUninx()
return timeNow >= c.StartTime && timeNow <= c.EndTime && c.Raw.Status == 1
}
func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo {
tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG
cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix)
timeNow := lxtime.NowUninx()
return &confbase.ConfInfo{
DbMysql: svconst.DbConfig,
TableName: fmt.Sprintf("%s_%s", tableName, suffix),
KeyName: "id",
CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?",
CurrentArgs: []any{c.Typ, 1, timeNow, timeNow},
CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id),
CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ),
CacheTime: 300,
}
}
// ActivityConfigRaw 房间排行活动配置 原始数据
type ActivityConfigRaw struct {
Id int64 `gorm:"column:id;primaryKey"` // ID
Serial int64 // 轮次ID
Typ int // 排行榜类型
OpenLevel int // 开启等级
OpenScore int64 // 开启积分
PreviewTime int64 // 预告时间
StartTime int64 // 开始时间
EndTime int64 // 结束时间
ReleaseTime string // 结算发奖时间
BootConfig string // 机器人配置
RoomConfig string // 房间配置
Ver string // 版本号
Status int // 状态 0=关闭 1=开启
UpdateTime int64 // 修改时间戳
}
// GenerateConfigClient 生成给客户端的配置
func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient {
configClient := &ActivityConfigClient{
Id: c.Id,
Typ: c.Typ,
Serial: c.Serial,
OpenLevel: c.OpenLevel,
OpenScore: c.OpenScore,
PreviewTime: c.PreviewTime,
StartTime: c.StartTime,
EndTime: c.EndTime,
ReleaseTime: c.ReleaseTime,
Ver: c.Ver,
Status: c.Status,
}
return configClient
}
// ActivityConfigClient 房间排行活动配置 给客户端数据
type ActivityConfigClient struct {
Id int64 `form:"id" json:"id"` // ID
Typ int `form:"typ" json:"typ"` // 排行榜类型
Serial int64 `form:"serial" json:"serial"` // 轮次ID
OpenLevel int `form:"open_level" json:"open_level"` // 开启等级
OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分
PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间
StartTime int64 `form:"start_time" json:"start_time"` // 开始时间
EndTime int64 `form:"end_time" json:"end_time"` // 结束时间
ReleaseTime string `form:"release_time" json:"release_time"` // 结算发奖时间
Ver string `form:"ver" json:"ver"` // 版本号
Status int `form:"status" json:"status"` // 状态 0=关闭 1=开启
}
// RobotConfig 机器人配置
type RobotConfig struct {
Id int `json:"id"` // id
MinScore int `json:"min_score"` // 最低分数
TotalScore int `json:"total_score"` // 总分数
Range int `json:"range"` // 总分浮动范围(%)
}
// RoomConfig 房间配置
type RoomConfig struct {
Id int `json:"id"` // id
Levels []int `json:"level_range"` // 等级范围
UserClass int `json:"rating"` // 评级
UserScore []int `json:"score_range"` // 分数范围
TotalPlayer int `json:"room_user_number"` // 房间总人数
PlayerTypeCount [][]int `json:"user_type_number"` // 玩家类型数量
AutoRobot []int `json:"auto_room"` // 自动填充机器人
InitRobot [][]int `json:"disposition_robots"` // 配置机器人
Awards map[string]string `json:"rewards"` // 奖励
SettleScores []int `json:"score_adjest"` // 结算分数调整
SettleUserType []int `json:"user_type"` // 结算用户类型
}