Commit b46ab67a709dc7974372bb251c7ea0a978ba6306

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

feat✨:房间排行活动逻辑

configs/conf-roomrank-decode.go
@@ -1,55 +0,0 @@ @@ -1,55 +0,0 @@
1 -package configs  
2 -  
3 -import (  
4 - "apigame/util/util-lx/lxalilog"  
5 - "encoding/json"  
6 -)  
7 -  
8 -// Decode 解析配置原始数据  
9 -func (c *RoomRankConfig) Decode(gameId string, configRaw *RoomRankConfigRaw) {  
10 - c.GameId = gameId  
11 - c.Raw = configRaw  
12 -  
13 - c.Id = configRaw.Id  
14 - c.OpenLevel = configRaw.OpenLevel  
15 - c.PreviewTime = configRaw.PreviewTime  
16 - c.StartTime = configRaw.StartTime  
17 - c.EndTime = configRaw.EndTime  
18 -  
19 - c.Robot = make(map[int]RoomRankRobotConfig)  
20 - c.Room = make(map[int]RoomRankRoomConfig)  
21 -  
22 - // 解析 机器人  
23 - {  
24 - configs := make([]RoomRankRobotConfig, 0)  
25 - err := json.Unmarshal([]byte(configRaw.Robot), &configs)  
26 - if err != nil {  
27 - lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id)  
28 - return  
29 - }  
30 - for _, i2 := range configs {  
31 - c.Robot[i2.Id] = i2  
32 - }  
33 - }  
34 - // 解析 房间  
35 - {  
36 - configs := make([]RoomRankRoomConfig, 0)  
37 - err := json.Unmarshal([]byte(configRaw.Room), &configs)  
38 - if err != nil {  
39 - lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id)  
40 - return  
41 - }  
42 - for _, i2 := range configs {  
43 - c.Room[i2.Id] = i2  
44 - }  
45 - }  
46 - c.GenerateConfigClient()  
47 -}  
48 -  
49 -// GenerateConfigClient 生成给客户端的配置  
50 -func (c *RoomRankConfig) GenerateConfigClient() {  
51 - configClient := &RoomRankConfigClient{  
52 - Id: c.Id,  
53 - }  
54 - c.Client = configClient  
55 -}  
configs/conf-roomrank.go
@@ -1,85 +0,0 @@ @@ -1,85 +0,0 @@
1 -package configs  
2 -  
3 -import (  
4 - "apigame/service-common/svconst"  
5 - "apigame/service-common/svmysql"  
6 - "apigame/service-common/svredis"  
7 - "fmt"  
8 -)  
9 -  
10 -// RoomRankConfig 房间排行活动配置 分析后数据  
11 -type RoomRankConfig struct {  
12 - Raw *RoomRankConfigRaw `json:"-"`  
13 -  
14 - Id int64 // ID  
15 - OpenLevel int // 开启等级  
16 - PreviewTime int64 // 预告时间  
17 - StartTime int64 // 开始时间  
18 - EndTime int64 // 结束时间  
19 -  
20 - Robot map[int]RoomRankRobotConfig // 机器人配置  
21 - Room map[int]RoomRankRoomConfig // 房间配置  
22 -  
23 - Client *RoomRankConfigClient  
24 - GameId string // 所属游戏ID  
25 -}  
26 -  
27 -func (c *RoomRankConfig) RedisInfo(suffix string) *svredis.RedisInfo {  
28 - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG  
29 - return &svredis.RedisInfo{  
30 - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix),  
31 - CacheTime: 300,  
32 - }  
33 -}  
34 -  
35 -// RoomRankConfigRaw 房间排行活动配置 原始数据  
36 -type RoomRankConfigRaw struct {  
37 - Id int64 `gorm:"column:id;primaryKey"` // ID  
38 - OpenLevel int // 开启等级  
39 - PreviewTime int64 // 预告时间  
40 - StartTime int64 // 开始时间  
41 - EndTime int64 // 结束时间  
42 -  
43 - Robot string // 机器人配置  
44 - Room string // 房间配置  
45 -  
46 - Ver string // 版本号  
47 - Status int // 状态 0=关闭 1=开启  
48 - UpdateTime int64 // 修改时间戳  
49 -}  
50 -  
51 -func (c *RoomRankConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo {  
52 - tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG  
53 - return &svmysql.MysqlInfo{  
54 - DbMysql: svconst.DbConfig.Where("status = ?", 1),  
55 - TableName: tableName + suffix,  
56 - }  
57 -}  
58 -  
59 -// RoomRankConfigClient 房间排行活动配置 给客户端数据  
60 -type RoomRankConfigClient struct {  
61 - Id int64 `form:"id" json:"id"` // ID  
62 -}  
63 -  
64 -// RoomRankRobotConfig 机器人配置  
65 -type RoomRankRobotConfig struct {  
66 - Id int `json:"id"` // id  
67 - MinScore int `json:"min_score"` // 最低分数  
68 - TotalScore int `json:"total_score"` // 总分数  
69 - TotalRate int `json:"total_rate"` // 总分浮动范围(%)  
70 -}  
71 -  
72 -// RoomRankRoomConfig 房间配置  
73 -type RoomRankRoomConfig struct {  
74 - Id int `json:"id"` // id  
75 - Levels []int `json:"levels"` // 等级范围  
76 - UserClass int `json:"user_class"` // 评级  
77 - UserScore []int `json:"user_score"` // 分数范围  
78 - TotalPlayer int `json:"total_player"` // 房间总人数  
79 - PlayerTypeCount [][]int `json:"player_type_count"` // 玩家类型数量  
80 - AutoRobot []int `json:"auto_robot"` // 自动填充机器人  
81 - InitRobot [][]int `json:"init_robot"` // 配置机器人  
82 - Awards []string `json:"awards"` // 奖励  
83 - SettleScores []int `json:"settle_scores"` // 结算分数调整  
84 - SettleUserType []int `json:"settle_user_type"` // 结算用户类型  
85 -}  
configs/confcardholder/config.go
@@ -30,7 +30,7 @@ type ActivityConfig struct { @@ -30,7 +30,7 @@ type ActivityConfig struct {
30 CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置 30 CardSequenceConfig map[string]CardSequenceConfig // k=ID_用户序列_用户分组 卡片星级对应卡牌配置
31 StarShopConfig map[int]StarShopConfig // 星星商店配置 31 StarShopConfig map[int]StarShopConfig // 星星商店配置
32 32
33 - Client *CardActivityConfigClient 33 + Client *ActivityConfigClient
34 GameId string // 所属游戏ID 34 GameId string // 所属游戏ID
35 } 35 }
36 36
@@ -98,8 +98,8 @@ func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo { @@ -98,8 +98,8 @@ func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo {
98 } 98 }
99 } 99 }
100 100
101 -// CardActivityConfigClient 卡牌活动配置 给客户端数据  
102 -type CardActivityConfigClient struct { 101 +// ActivityConfigClient 卡牌活动配置 给客户端数据
  102 +type ActivityConfigClient struct {
103 Id int64 `form:"id" json:"id"` // ID 103 Id int64 `form:"id" json:"id"` // ID
104 IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径 104 IconPath string `form:"icon_path" json:"icon_path"` // icon资源路径
105 RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置 105 RoundAwards map[string]string `form:"round_awards" json:"round_awards"` // 轮次奖励配置
configs/confcardholder/decode.go
@@ -119,7 +119,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { @@ -119,7 +119,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) {
119 119
120 // GenerateConfigClient 生成给客户端的配置 120 // GenerateConfigClient 生成给客户端的配置
121 func (c *ActivityConfig) GenerateConfigClient() { 121 func (c *ActivityConfig) GenerateConfigClient() {
122 - configClient := &CardActivityConfigClient{ 122 + configClient := &ActivityConfigClient{
123 Id: c.Id, 123 Id: c.Id,
124 IconPath: c.IconPath, 124 IconPath: c.IconPath,
125 RoundAwards: c.Awards, 125 RoundAwards: c.Awards,
configs/confroomrank/config.go 0 → 100644
@@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
  1 +package confroomrank
  2 +
  3 +import (
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
  6 + "apigame/service-common/svredis"
  7 + "fmt"
  8 +)
  9 +
  10 +// ActivityConfig 房间排行活动配置 分析后数据
  11 +type ActivityConfig struct {
  12 + Raw *ActivityConfigRaw `json:"-"`
  13 +
  14 + Id int64 // ID
  15 + OpenLevel int // 开启等级
  16 + PreviewTime int64 // 预告时间
  17 + StartTime int64 // 开始时间
  18 + EndTime int64 // 结束时间
  19 +
  20 + Robot map[int]RobotConfig // 机器人配置
  21 + Room map[int]RoomConfig // 房间配置
  22 +
  23 + Client *ActivityConfigClient
  24 + GameId string // 所属游戏ID
  25 +}
  26 +
  27 +func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo {
  28 + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG
  29 + return &svredis.RedisInfo{
  30 + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix),
  31 + CacheTime: 300,
  32 + }
  33 +}
  34 +
  35 +// ActivityConfigRaw 房间排行活动配置 原始数据
  36 +type ActivityConfigRaw struct {
  37 + Id int64 `gorm:"column:id;primaryKey"` // ID
  38 + OpenLevel int // 开启等级
  39 + PreviewTime int64 // 预告时间
  40 + StartTime int64 // 开始时间
  41 + EndTime int64 // 结束时间
  42 +
  43 + Robot string // 机器人配置
  44 + Room string // 房间配置
  45 +
  46 + Ver string // 版本号
  47 + Status int // 状态 0=关闭 1=开启
  48 + UpdateTime int64 // 修改时间戳
  49 +}
  50 +
  51 +func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo {
  52 + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG
  53 + return &svmysql.MysqlInfo{
  54 + DbMysql: svconst.DbConfig.Where("status = ?", 1),
  55 + TableName: tableName + suffix,
  56 + }
  57 +}
  58 +
  59 +// ActivityConfigClient 房间排行活动配置 给客户端数据
  60 +type ActivityConfigClient struct {
  61 + Id int64 `form:"id" json:"id"` // ID
  62 +}
  63 +
  64 +// RobotConfig 机器人配置
  65 +type RobotConfig struct {
  66 + Id int `json:"id"` // id
  67 + MinScore int `json:"min_score"` // 最低分数
  68 + TotalScore int `json:"total_score"` // 总分数
  69 + TotalRate int `json:"total_rate"` // 总分浮动范围(%)
  70 +}
  71 +
  72 +// RoomConfig 房间配置
  73 +type RoomConfig struct {
  74 + Id int `json:"id"` // id
  75 + Levels []int `json:"levels"` // 等级范围
  76 + UserClass int `json:"user_class"` // 评级
  77 + UserScore []int `json:"user_score"` // 分数范围
  78 + TotalPlayer int `json:"total_player"` // 房间总人数
  79 + PlayerTypeCount [][]int `json:"player_type_count"` // 玩家类型数量
  80 + AutoRobot []int `json:"auto_robot"` // 自动填充机器人
  81 + InitRobot [][]int `json:"init_robot"` // 配置机器人
  82 + Awards []string `json:"awards"` // 奖励
  83 + SettleScores []int `json:"settle_scores"` // 结算分数调整
  84 + SettleUserType []int `json:"settle_user_type"` // 结算用户类型
  85 +}
configs/confroomrank/decode.go 0 → 100644
@@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
  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, configRaw *ActivityConfigRaw) {
  10 + c.GameId = gameId
  11 + c.Raw = configRaw
  12 +
  13 + c.Id = configRaw.Id
  14 + c.OpenLevel = configRaw.OpenLevel
  15 + c.PreviewTime = configRaw.PreviewTime
  16 + c.StartTime = configRaw.StartTime
  17 + c.EndTime = configRaw.EndTime
  18 +
  19 + c.Robot = make(map[int]RobotConfig)
  20 + c.Room = make(map[int]RoomConfig)
  21 +
  22 + // 解析 机器人
  23 + {
  24 + configs := make([]RobotConfig, 0)
  25 + err := json.Unmarshal([]byte(configRaw.Robot), &configs)
  26 + if err != nil {
  27 + lxalilog.Errors(err, configRaw.Robot, gameId, configRaw.Id)
  28 + return
  29 + }
  30 + for _, i2 := range configs {
  31 + c.Robot[i2.Id] = i2
  32 + }
  33 + }
  34 + // 解析 房间
  35 + {
  36 + configs := make([]RoomConfig, 0)
  37 + err := json.Unmarshal([]byte(configRaw.Room), &configs)
  38 + if err != nil {
  39 + lxalilog.Errors(err, configRaw.Room, gameId, configRaw.Id)
  40 + return
  41 + }
  42 + for _, i2 := range configs {
  43 + c.Room[i2.Id] = i2
  44 + }
  45 + }
  46 + c.GenerateConfigClient()
  47 +}
  48 +
  49 +// GenerateConfigClient 生成给客户端的配置
  50 +func (c *ActivityConfig) GenerateConfigClient() {
  51 + configClient := &ActivityConfigClient{
  52 + Id: c.Id,
  53 + }
  54 + c.Client = configClient
  55 +}
configs/registry.go
1 package configs 1 package configs
2 2
3 import ( 3 import (
  4 + "apigame/configs/confroomrank"
4 "apigame/service-common/svmysql" 5 "apigame/service-common/svmysql"
5 "apigame/service-common/svredis" 6 "apigame/service-common/svredis"
6 "apigame/util/util-lx/lxalilog" 7 "apigame/util/util-lx/lxalilog"
@@ -8,15 +9,15 @@ import ( @@ -8,15 +9,15 @@ import (
8 ) 9 )
9 10
10 // GetRoomRankConfig 获取 房间排行活动配置 11 // GetRoomRankConfig 获取 房间排行活动配置
11 -func GetRoomRankConfig(gameId string) (conf *RoomRankConfig, has bool) { 12 +func GetRoomRankConfig(gameId string) (conf *confroomrank.ActivityConfig, has bool) {
12 var err error 13 var err error
13 - conf = new(RoomRankConfig) 14 + conf = new(confroomrank.ActivityConfig)
14 has = svredis.LoadData(gameId, conf) 15 has = svredis.LoadData(gameId, conf)
15 if has { 16 if has {
16 fmt.Println("dwjw GetRoomRankConfig use cache") 17 fmt.Println("dwjw GetRoomRankConfig use cache")
17 return 18 return
18 } 19 }
19 - confRaw := new(RoomRankConfigRaw) 20 + confRaw := new(confroomrank.ActivityConfigRaw)
20 has, err = svmysql.First(confRaw, gameId) 21 has, err = svmysql.First(confRaw, gameId)
21 if err != nil { 22 if err != nil {
22 lxalilog.Errors(err, "configs.GetRoomRankConfig error", gameId) 23 lxalilog.Errors(err, "configs.GetRoomRankConfig error", gameId)
controllers/demo.go
1 package controllers 1 package controllers
2 2
3 import ( 3 import (
4 - "apigame/configs" 4 + "apigame/configs/confroomrank"
5 "apigame/models" 5 "apigame/models"
6 "apigame/service/code-msg" 6 "apigame/service/code-msg"
7 "apigame/util/util-lx/lxalilog" 7 "apigame/util/util-lx/lxalilog"
@@ -27,20 +27,20 @@ func (c *DemoController) Demo() { @@ -27,20 +27,20 @@ func (c *DemoController) Demo() {
27 lxalilog.Errors("DemoController.demo") 27 lxalilog.Errors("DemoController.demo")
28 28
29 { 29 {
30 - list := make([]configs.RoomRankRobotConfig, 0)  
31 - list = append(list, configs.RoomRankRobotConfig{ 30 + list := make([]confroomrank.RobotConfig, 0)
  31 + list = append(list, confroomrank.RobotConfig{
32 Id: 1, 32 Id: 1,
33 MinScore: 10, 33 MinScore: 10,
34 TotalScore: 30, 34 TotalScore: 30,
35 TotalRate: 10, 35 TotalRate: 10,
36 }) 36 })
37 - list = append(list, configs.RoomRankRobotConfig{ 37 + list = append(list, confroomrank.RobotConfig{
38 Id: 2, 38 Id: 2,
39 MinScore: 20, 39 MinScore: 20,
40 TotalScore: 50, 40 TotalScore: 50,
41 TotalRate: 6, 41 TotalRate: 6,
42 }) 42 })
43 - list = append(list, configs.RoomRankRobotConfig{ 43 + list = append(list, confroomrank.RobotConfig{
44 Id: 3, 44 Id: 3,
45 MinScore: 50, 45 MinScore: 50,
46 TotalScore: 200, 46 TotalScore: 200,
@@ -49,9 +49,9 @@ func (c *DemoController) Demo() { @@ -49,9 +49,9 @@ func (c *DemoController) Demo() {
49 fmt.Println(zjson.Str(list)) 49 fmt.Println(zjson.Str(list))
50 } 50 }
51 { 51 {
52 - list := make([]configs.RoomRankRoomConfig, 0) 52 + list := make([]confroomrank.RoomConfig, 0)
53 { 53 {
54 - room := configs.RoomRankRoomConfig{} 54 + room := confroomrank.RoomConfig{}
55 room.Id = 1 55 room.Id = 1
56 room.Levels = []int{1, 9999} 56 room.Levels = []int{1, 9999}
57 room.UserClass = 0 57 room.UserClass = 0
service/roomrank/player.go
1 package roomrank 1 package roomrank
2 2
3 import ( 3 import (
4 - "apigame/configs" 4 + "apigame/configs/confroomrank"
5 "apigame/models" 5 "apigame/models"
6 "apigame/service-common/svmysql" 6 "apigame/service-common/svmysql"
7 "apigame/util/util-lx/lxalilog" 7 "apigame/util/util-lx/lxalilog"
@@ -36,7 +36,7 @@ func LoadPlayer(gameId string, playerUid int64) (d *DataRoomRankPlayer) { @@ -36,7 +36,7 @@ func LoadPlayer(gameId string, playerUid int64) (d *DataRoomRankPlayer) {
36 } 36 }
37 37
38 // GetInfo 活动信息 38 // GetInfo 活动信息
39 -func GetInfo(player *DataRoomRankPlayer, conf *configs.RoomRankConfig) models.RoomRankInfo { 39 +func GetInfo(player *DataRoomRankPlayer, conf *confroomrank.ActivityConfig) models.RoomRankInfo {
40 info := models.RoomRankInfo{} 40 info := models.RoomRankInfo{}
41 return info 41 return info
42 } 42 }