Commit 60c545c8f58459d712d56444f780aabe07ce2fa8
1 parent
b3c9207e
Exists in
master
and in
1 other branch
feat✨:房间排行榜改为支持多个排行榜
Showing
12 changed files
with
65 additions
and
48 deletions
Show diff stats
configs/confcardholder/config.go
| @@ -49,8 +49,8 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | @@ -49,8 +49,8 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | ||
| 49 | DbMysql: svconst.DbConfig, | 49 | DbMysql: svconst.DbConfig, |
| 50 | TableName: fmt.Sprintf("%s_%s", tableName, suffix), | 50 | TableName: fmt.Sprintf("%s_%s", tableName, suffix), |
| 51 | KeyName: "id", | 51 | KeyName: "id", |
| 52 | - CurrentQuery: "start_time <= ? AND end_time >= ? AND status = ?", | ||
| 53 | - CurrentArgs: []any{timeNow, timeNow, 1}, | 52 | + CurrentQuery: "status = ? AND start_time <= ? AND end_time >= ?", |
| 53 | + CurrentArgs: []any{1, timeNow, timeNow}, | ||
| 54 | CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | 54 | CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), |
| 55 | CacheCurrent: cacheKey + ":current", | 55 | CacheCurrent: cacheKey + ":current", |
| 56 | CacheTime: 300, | 56 | CacheTime: 300, |
configs/confroomrank/config.go
| @@ -13,6 +13,7 @@ type ActivityConfig struct { | @@ -13,6 +13,7 @@ type ActivityConfig struct { | ||
| 13 | Raw *ActivityConfigRaw `json:"-"` | 13 | Raw *ActivityConfigRaw `json:"-"` |
| 14 | 14 | ||
| 15 | Id int64 // ID | 15 | Id int64 // ID |
| 16 | + Typ int // 排行榜类型 | ||
| 16 | OpenLevel int // 开启等级 | 17 | OpenLevel int // 开启等级 |
| 17 | PreviewTime int64 // 预告时间 | 18 | PreviewTime int64 // 预告时间 |
| 18 | StartTime int64 // 开始时间 | 19 | StartTime int64 // 开始时间 |
| @@ -43,10 +44,10 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | @@ -43,10 +44,10 @@ func (c *ActivityConfig) ConfInfo(suffix string) *confbase.ConfInfo { | ||
| 43 | DbMysql: svconst.DbConfig, | 44 | DbMysql: svconst.DbConfig, |
| 44 | TableName: fmt.Sprintf("%s_%s", tableName, suffix), | 45 | TableName: fmt.Sprintf("%s_%s", tableName, suffix), |
| 45 | KeyName: "id", | 46 | KeyName: "id", |
| 46 | - CurrentQuery: "start_time <= ? AND end_time >= ? AND status = ?", | ||
| 47 | - CurrentArgs: []any{timeNow, timeNow, 1}, | 47 | + CurrentQuery: "typ = ? AND status = ? AND start_time <= ? AND end_time >= ?", |
| 48 | + CurrentArgs: []any{c.Typ, 1, timeNow, timeNow}, | ||
| 48 | CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), | 49 | CacheKey: fmt.Sprintf("%s:%d", cacheKey, c.Id), |
| 49 | - CacheCurrent: cacheKey + ":current", | 50 | + CacheCurrent: fmt.Sprintf("%s:%d:current", cacheKey, c.Typ), |
| 50 | CacheTime: 300, | 51 | CacheTime: 300, |
| 51 | } | 52 | } |
| 52 | } | 53 | } |
configs/confroomrank/get.go
| @@ -3,8 +3,9 @@ package confroomrank | @@ -3,8 +3,9 @@ package confroomrank | ||
| 3 | import "apigame/configs/confbase" | 3 | import "apigame/configs/confbase" |
| 4 | 4 | ||
| 5 | // GetCurrent 获取 当前配置 | 5 | // GetCurrent 获取 当前配置 |
| 6 | -func GetCurrent(gameId string) (conf *ActivityConfig, has bool) { | 6 | +func GetCurrent(gameId string, topType int) (conf *ActivityConfig, has bool) { |
| 7 | conf = new(ActivityConfig) | 7 | conf = new(ActivityConfig) |
| 8 | + conf.Typ = topType | ||
| 8 | has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) | 9 | has = confbase.GetCurrent[*ActivityConfig, ActivityConfigRaw](gameId, conf) |
| 9 | 10 | ||
| 10 | return | 11 | return |
configs/init.go
| @@ -4,7 +4,6 @@ import ( | @@ -4,7 +4,6 @@ import ( | ||
| 4 | "apigame/configs/confapi" | 4 | "apigame/configs/confapi" |
| 5 | "apigame/configs/confcardholder" | 5 | "apigame/configs/confcardholder" |
| 6 | "apigame/configs/confglobal" | 6 | "apigame/configs/confglobal" |
| 7 | - "apigame/configs/confroomrank" | ||
| 8 | "apigame/service-common/svconst" | 7 | "apigame/service-common/svconst" |
| 9 | ) | 8 | ) |
| 10 | 9 | ||
| @@ -22,9 +21,9 @@ func Init() bool { | @@ -22,9 +21,9 @@ func Init() bool { | ||
| 22 | _, _ = confcardholder.GetCurrent(gameId) | 21 | _, _ = confcardholder.GetCurrent(gameId) |
| 23 | } | 22 | } |
| 24 | 23 | ||
| 25 | - for _, gameId := range svconst.GameListRoomRank { | ||
| 26 | - _, _ = confroomrank.GetCurrent(gameId) | ||
| 27 | - } | 24 | + //for _, gameId := range svconst.GameListRoomRank { |
| 25 | + // _, _ = confroomrank.GetCurrent(gameId) | ||
| 26 | + //} | ||
| 28 | 27 | ||
| 29 | return true | 28 | return true |
| 30 | } | 29 | } |
models/roomrank.go
| @@ -44,6 +44,7 @@ type RoomRankInfo struct { | @@ -44,6 +44,7 @@ type RoomRankInfo struct { | ||
| 44 | type ReqRoomRankInfo struct { | 44 | type ReqRoomRankInfo struct { |
| 45 | BaseLoginInfo | 45 | BaseLoginInfo |
| 46 | BaseSign | 46 | BaseSign |
| 47 | + TopType int `form:"top_type" json:"top_type"` // 排行榜类型 | ||
| 47 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 | 48 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 |
| 48 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 | 49 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 |
| 49 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 | 50 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 |
| @@ -58,6 +59,7 @@ type RspRoomRankInfo struct { | @@ -58,6 +59,7 @@ type RspRoomRankInfo struct { | ||
| 58 | type ReqRoomRankGetSettleAward struct { | 59 | type ReqRoomRankGetSettleAward struct { |
| 59 | BaseLoginInfo | 60 | BaseLoginInfo |
| 60 | BaseSign | 61 | BaseSign |
| 62 | + TopType int `form:"top_type" json:"top_type"` // 排行榜类型 | ||
| 61 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 | 63 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 |
| 62 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 | 64 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 |
| 63 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 | 65 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 |
| @@ -75,6 +77,7 @@ type RspRoomRankGetSettleAward struct { | @@ -75,6 +77,7 @@ type RspRoomRankGetSettleAward struct { | ||
| 75 | type ReqRoomRankAddScore struct { | 77 | type ReqRoomRankAddScore struct { |
| 76 | BaseLoginInfo | 78 | BaseLoginInfo |
| 77 | BaseSign | 79 | BaseSign |
| 80 | + TopType int `form:"top_type" json:"top_type"` // 排行榜类型 | ||
| 78 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 | 81 | PlayerLevel int `form:"player_level" json:"player_level"` // 玩家等级 |
| 79 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 | 82 | PlayerName string `form:"player_name" json:"player_name"` // 玩家名字 |
| 80 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 | 83 | PlayerIcon string `form:"player_icon" json:"player_icon"` // 玩家头像 |
service/init.go
| @@ -4,7 +4,6 @@ import ( | @@ -4,7 +4,6 @@ import ( | ||
| 4 | "apigame/service-common/svconst" | 4 | "apigame/service-common/svconst" |
| 5 | "apigame/service-common/svmysql" | 5 | "apigame/service-common/svmysql" |
| 6 | "apigame/service/cardholder" | 6 | "apigame/service/cardholder" |
| 7 | - "apigame/service/roomrank" | ||
| 8 | ) | 7 | ) |
| 9 | 8 | ||
| 10 | func Init() { | 9 | func Init() { |
| @@ -17,11 +16,5 @@ func Init() { | @@ -17,11 +16,5 @@ func Init() { | ||
| 17 | svmysql.InitTable(new(cardholder.RecordRewardAlbum), gameId, true) | 16 | svmysql.InitTable(new(cardholder.RecordRewardAlbum), gameId, true) |
| 18 | svmysql.InitTable(new(cardholder.RecordRewardRound), gameId, true) | 17 | svmysql.InitTable(new(cardholder.RecordRewardRound), gameId, true) |
| 19 | } | 18 | } |
| 20 | - // 房间排行 | ||
| 21 | - for _, gameId := range svconst.GameListRoomRank { | ||
| 22 | - svmysql.InitTable(new(roomrank.Player), gameId, true) | ||
| 23 | - svmysql.InitTable(new(roomrank.RecordGetSettleAward), gameId, true) | ||
| 24 | - svmysql.InitTable(new(roomrank.RecordAddScore), gameId, true) | ||
| 25 | - } | ||
| 26 | 19 | ||
| 27 | } | 20 | } |
service/roomrank/dto-player.go
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | // Player 房间排行持久数据 | 10 | // Player 房间排行持久数据 |
| 11 | type Player struct { | 11 | type Player struct { |
| 12 | Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` | 12 | Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` |
| 13 | + TopType int `gorm:"comment:排行榜类型"` | ||
| 13 | Name string `gorm:"-"` // 玩家名字 | 14 | Name string `gorm:"-"` // 玩家名字 |
| 14 | Icon string `gorm:"-"` // 玩家头像 | 15 | Icon string `gorm:"-"` // 玩家头像 |
| 15 | ActivityId int64 `gorm:"comment:活动ID"` | 16 | ActivityId int64 `gorm:"comment:活动ID"` |
| @@ -34,19 +35,21 @@ func (d *Player) MysqlInfo(suffix string) *svmysql.MysqlInfo { | @@ -34,19 +35,21 @@ func (d *Player) MysqlInfo(suffix string) *svmysql.MysqlInfo { | ||
| 34 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_PLAYER | 35 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_PLAYER |
| 35 | return &svmysql.MysqlInfo{ | 36 | return &svmysql.MysqlInfo{ |
| 36 | DbMysql: svconst.DbCommon, | 37 | DbMysql: svconst.DbCommon, |
| 37 | - TableName: fmt.Sprintf("%s_%s", tableName, suffix), | 38 | + TableName: fmt.Sprintf("%s_%s_%d", tableName, suffix, d.TopType), |
| 38 | } | 39 | } |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | -func NewPlayer(uid int64) *Player { | 42 | +func NewPlayer(uid int64, topType int) *Player { |
| 42 | d := &Player{ | 43 | d := &Player{ |
| 43 | - Uid: uid, | 44 | + Uid: uid, |
| 45 | + TopType: topType, | ||
| 44 | } | 46 | } |
| 45 | return d | 47 | return d |
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | -func (d *Player) Init(uid int64) { | 50 | +func (d *Player) Init(uid int64, topType int) { |
| 49 | d.Uid = uid | 51 | d.Uid = uid |
| 52 | + d.TopType = topType | ||
| 50 | d.CreateTime = lxtime.NowUninx() | 53 | d.CreateTime = lxtime.NowUninx() |
| 51 | } | 54 | } |
| 52 | 55 |
service/roomrank/dto-record.go
| @@ -10,17 +10,19 @@ import ( | @@ -10,17 +10,19 @@ import ( | ||
| 10 | // RecordBase 日志公共 | 10 | // RecordBase 日志公共 |
| 11 | type RecordBase struct { | 11 | type RecordBase struct { |
| 12 | Id int64 `gorm:"primaryKey;comment:日志ID"` | 12 | Id int64 `gorm:"primaryKey;comment:日志ID"` |
| 13 | + TopType int `gorm:"comment:排行榜类型"` | ||
| 13 | Uid int64 `gorm:"comment:玩家唯一ID"` | 14 | Uid int64 `gorm:"comment:玩家唯一ID"` |
| 14 | ActivityId int64 `gorm:"comment:当前活动ID"` | 15 | ActivityId int64 `gorm:"comment:当前活动ID"` |
| 15 | CreateTime int64 `gorm:"comment:创建时间戳"` | 16 | CreateTime int64 `gorm:"comment:创建时间戳"` |
| 16 | UpdateTime int64 `gorm:"comment:修改时间戳"` | 17 | UpdateTime int64 `gorm:"comment:修改时间戳"` |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | -func NewRecordBase(uid int64, activityId int64) RecordBase { | 20 | +func NewRecordBase(uid int64, topType int, activityId int64) RecordBase { |
| 20 | secNow := lxtime.NowUninx() | 21 | secNow := lxtime.NowUninx() |
| 21 | return RecordBase{ | 22 | return RecordBase{ |
| 22 | CreateTime: secNow, | 23 | CreateTime: secNow, |
| 23 | UpdateTime: secNow, | 24 | UpdateTime: secNow, |
| 25 | + TopType: topType, | ||
| 24 | Uid: uid, | 26 | Uid: uid, |
| 25 | ActivityId: activityId, | 27 | ActivityId: activityId, |
| 26 | } | 28 | } |
| @@ -36,7 +38,7 @@ func (d *RecordGetSettleAward) MysqlInfo(suffix string) *svmysql.MysqlInfo { | @@ -36,7 +38,7 @@ func (d *RecordGetSettleAward) MysqlInfo(suffix string) *svmysql.MysqlInfo { | ||
| 36 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_RECORD_SETTLEAWARD | 38 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_RECORD_SETTLEAWARD |
| 37 | return &svmysql.MysqlInfo{ | 39 | return &svmysql.MysqlInfo{ |
| 38 | DbMysql: svconst.DbCommon, | 40 | DbMysql: svconst.DbCommon, |
| 39 | - TableName: fmt.Sprintf("%s_%s", tableName, suffix), | 41 | + TableName: fmt.Sprintf("%s_%s_%d", tableName, suffix, d.TopType), |
| 40 | } | 42 | } |
| 41 | } | 43 | } |
| 42 | 44 | ||
| @@ -60,7 +62,7 @@ func (d *RecordAddScore) MysqlInfo(suffix string) *svmysql.MysqlInfo { | @@ -60,7 +62,7 @@ func (d *RecordAddScore) MysqlInfo(suffix string) *svmysql.MysqlInfo { | ||
| 60 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_RECORD_ADDSCORE | 62 | tableName := svconst.MYSQL_TABLE_S_ROOMRANK_RECORD_ADDSCORE |
| 61 | return &svmysql.MysqlInfo{ | 63 | return &svmysql.MysqlInfo{ |
| 62 | DbMysql: svconst.DbCommon, | 64 | DbMysql: svconst.DbCommon, |
| 63 | - TableName: fmt.Sprintf("%s_%s", tableName, suffix), | 65 | + TableName: fmt.Sprintf("%s_%s_%d", tableName, suffix, d.TopType), |
| 64 | } | 66 | } |
| 65 | } | 67 | } |
| 66 | 68 |
service/roomrank/handle.go
| @@ -3,7 +3,6 @@ package roomrank | @@ -3,7 +3,6 @@ package roomrank | ||
| 3 | import ( | 3 | import ( |
| 4 | "apigame/configs/confroomrank" | 4 | "apigame/configs/confroomrank" |
| 5 | "apigame/models" | 5 | "apigame/models" |
| 6 | - "apigame/service-common/svmysql" | ||
| 7 | "apigame/service/code-msg" | 6 | "apigame/service/code-msg" |
| 8 | "apigame/util/zredislock" | 7 | "apigame/util/zredislock" |
| 9 | ) | 8 | ) |
| @@ -15,7 +14,7 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | @@ -15,7 +14,7 @@ func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models. | ||
| 15 | gameId := req.GameID | 14 | gameId := req.GameID |
| 16 | 15 | ||
| 17 | // 尝试更新配置 | 16 | // 尝试更新配置 |
| 18 | - config, hasConfig := confroomrank.GetCurrent(gameId) | 17 | + config, hasConfig := confroomrank.GetCurrent(gameId, 1) |
| 19 | if !hasConfig { | 18 | if !hasConfig { |
| 20 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR | 19 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR |
| 21 | return | 20 | return |
| @@ -41,7 +40,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | @@ -41,7 +40,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | ||
| 41 | playerLevel := req.PlayerLevel | 40 | playerLevel := req.PlayerLevel |
| 42 | 41 | ||
| 43 | // 尝试更新配置 | 42 | // 尝试更新配置 |
| 44 | - config, hasConfig := confroomrank.GetCurrent(gameId) | 43 | + config, hasConfig := confroomrank.GetCurrent(gameId, req.TopType) |
| 45 | if !hasConfig { | 44 | if !hasConfig { |
| 46 | config = new(confroomrank.ActivityConfig) | 45 | config = new(confroomrank.ActivityConfig) |
| 47 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR | 46 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR |
| @@ -49,7 +48,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | @@ -49,7 +48,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | ||
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | // 读取游戏数据 | 50 | // 读取游戏数据 |
| 52 | - player := LoadPlayer(gameId, playerUid) | 51 | + player := LoadPlayer(gameId, playerUid, req.TopType) |
| 53 | player.Name = req.PlayerName | 52 | player.Name = req.PlayerName |
| 54 | player.Icon = req.PlayerIcon | 53 | player.Icon = req.PlayerIcon |
| 55 | 54 | ||
| @@ -103,7 +102,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | @@ -103,7 +102,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | ||
| 103 | playerUid := req.UID | 102 | playerUid := req.UID |
| 104 | 103 | ||
| 105 | // 尝试更新配置 | 104 | // 尝试更新配置 |
| 106 | - config, hasConfig := confroomrank.GetCurrent(gameId) | 105 | + config, hasConfig := confroomrank.GetCurrent(gameId, req.TopType) |
| 107 | if !hasConfig { | 106 | if !hasConfig { |
| 108 | config = new(confroomrank.ActivityConfig) | 107 | config = new(confroomrank.ActivityConfig) |
| 109 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR | 108 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR |
| @@ -111,7 +110,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | @@ -111,7 +110,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | ||
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | // 读取游戏数据 | 112 | // 读取游戏数据 |
| 114 | - player := LoadPlayer(gameId, playerUid) | 113 | + player := LoadPlayer(gameId, playerUid, req.TopType) |
| 115 | player.Name = req.PlayerName | 114 | player.Name = req.PlayerName |
| 116 | player.Icon = req.PlayerIcon | 115 | player.Icon = req.PlayerIcon |
| 117 | 116 | ||
| @@ -144,10 +143,8 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | @@ -144,10 +143,8 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | ||
| 144 | SavePlayer(gameId, player) | 143 | SavePlayer(gameId, player) |
| 145 | 144 | ||
| 146 | // 记录日志 | 145 | // 记录日志 |
| 147 | - recordBase := NewRecordBase(player.Uid, oldActivityId) | ||
| 148 | - _ = svmysql.Create(NewRecordGetSettleAward(recordBase, | ||
| 149 | - rsp.AwardText), | ||
| 150 | - gameId) | 146 | + recordBase := NewRecordBase(player.Uid, req.TopType, oldActivityId) |
| 147 | + SaveRecordGetSettleAward(gameId, NewRecordGetSettleAward(recordBase, rsp.AwardText)) | ||
| 151 | 148 | ||
| 152 | return | 149 | return |
| 153 | } | 150 | } |
| @@ -161,7 +158,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -161,7 +158,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 161 | playerLevel := req.PlayerLevel | 158 | playerLevel := req.PlayerLevel |
| 162 | 159 | ||
| 163 | // 尝试更新配置 | 160 | // 尝试更新配置 |
| 164 | - config, hasConfig := confroomrank.GetCurrent(gameId) | 161 | + config, hasConfig := confroomrank.GetCurrent(gameId, req.TopType) |
| 165 | if !hasConfig { | 162 | if !hasConfig { |
| 166 | config = new(confroomrank.ActivityConfig) | 163 | config = new(confroomrank.ActivityConfig) |
| 167 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR | 164 | code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR |
| @@ -169,7 +166,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -169,7 +166,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 169 | } | 166 | } |
| 170 | 167 | ||
| 171 | // 读取游戏数据 | 168 | // 读取游戏数据 |
| 172 | - player := LoadPlayer(gameId, playerUid) | 169 | + player := LoadPlayer(gameId, playerUid, req.TopType) |
| 173 | player.Name = req.PlayerName | 170 | player.Name = req.PlayerName |
| 174 | player.Icon = req.PlayerIcon | 171 | player.Icon = req.PlayerIcon |
| 175 | 172 | ||
| @@ -218,10 +215,8 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -218,10 +215,8 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 218 | rsp.RoomRankInfo = GetInfoFromRoom(player, room, config) | 215 | rsp.RoomRankInfo = GetInfoFromRoom(player, room, config) |
| 219 | 216 | ||
| 220 | // 记录日志 | 217 | // 记录日志 |
| 221 | - recordBase := NewRecordBase(player.Uid, config.Id) | ||
| 222 | - _ = svmysql.Create(NewRecordAddScore(recordBase, | ||
| 223 | - req.AddScore, oldScore, newScore), | ||
| 224 | - gameId) | 218 | + recordBase := NewRecordBase(player.Uid, req.TopType, config.Id) |
| 219 | + SaveRecordAddScore(gameId, NewRecordAddScore(recordBase, req.AddScore, oldScore, newScore)) | ||
| 225 | 220 | ||
| 226 | return | 221 | return |
| 227 | } | 222 | } |
service/roomrank/player.go
| @@ -11,10 +11,15 @@ import ( | @@ -11,10 +11,15 @@ import ( | ||
| 11 | "math/rand" | 11 | "math/rand" |
| 12 | ) | 12 | ) |
| 13 | 13 | ||
| 14 | +func tryInitPlayer(gameId string, player *Player) { | ||
| 15 | + svmysql.InitTable(player, gameId, false) | ||
| 16 | +} | ||
| 17 | + | ||
| 14 | // SavePlayer 存储数据 | 18 | // SavePlayer 存储数据 |
| 15 | func SavePlayer(gameId string, player *Player) { | 19 | func SavePlayer(gameId string, player *Player) { |
| 16 | - player.UpdateTime = lxtime.NowUninx() | 20 | + tryInitPlayer(gameId, player) |
| 17 | 21 | ||
| 22 | + player.UpdateTime = lxtime.NowUninx() | ||
| 18 | err := svmysql.Save(player, gameId) | 23 | err := svmysql.Save(player, gameId) |
| 19 | if err != nil { | 24 | if err != nil { |
| 20 | lxalilog.Errors(err, "roomrank.SavePlayer error", gameId, player.Uid, player.ActivityId) | 25 | lxalilog.Errors(err, "roomrank.SavePlayer error", gameId, player.Uid, player.ActivityId) |
| @@ -23,12 +28,14 @@ func SavePlayer(gameId string, player *Player) { | @@ -23,12 +28,14 @@ func SavePlayer(gameId string, player *Player) { | ||
| 23 | } | 28 | } |
| 24 | 29 | ||
| 25 | // LoadPlayer 获取数据 外部接口 | 30 | // LoadPlayer 获取数据 外部接口 |
| 26 | -func LoadPlayer(gameId string, playerUid int64) (player *Player) { | ||
| 27 | - player = NewPlayer(playerUid) | 31 | +func LoadPlayer(gameId string, playerUid int64, topType int) (player *Player) { |
| 32 | + player = NewPlayer(playerUid, topType) | ||
| 33 | + tryInitPlayer(gameId, player) | ||
| 34 | + | ||
| 28 | has, err := svmysql.First(player, gameId) | 35 | has, err := svmysql.First(player, gameId) |
| 29 | if has { | 36 | if has { |
| 30 | } else { | 37 | } else { |
| 31 | - player.Init(playerUid) | 38 | + player.Init(playerUid, topType) |
| 32 | err = svmysql.Create(player, gameId) | 39 | err = svmysql.Create(player, gameId) |
| 33 | if err != nil { | 40 | if err != nil { |
| 34 | lxalilog.Errors(err, "roomrank._LoadPlayer Create error", gameId, player.Uid, player.ActivityId) | 41 | lxalilog.Errors(err, "roomrank._LoadPlayer Create error", gameId, player.Uid, player.ActivityId) |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +package roomrank | ||
| 2 | + | ||
| 3 | +import "apigame/service-common/svmysql" | ||
| 4 | + | ||
| 5 | +func SaveRecordGetSettleAward(gameId string, record *RecordGetSettleAward) { | ||
| 6 | + svmysql.InitTable(record, gameId, false) | ||
| 7 | + _ = svmysql.Create(record, gameId) | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +func SaveRecordAddScore(gameId string, record *RecordAddScore) { | ||
| 11 | + svmysql.InitTable(record, gameId, false) | ||
| 12 | + _ = svmysql.Create(record, gameId) | ||
| 13 | +} |
service/roomrank/room.go
| @@ -10,13 +10,13 @@ import ( | @@ -10,13 +10,13 @@ import ( | ||
| 10 | "sort" | 10 | "sort" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | -func tryInitTable(gameId string, room *Room) { | 13 | +func tryInitRoom(gameId string, room *Room) { |
| 14 | svmysql.InitTable(room, gameId, false) | 14 | svmysql.InitTable(room, gameId, false) |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | // SaveRoom 存储数据 | 17 | // SaveRoom 存储数据 |
| 18 | func SaveRoom(gameId string, room *Room) { | 18 | func SaveRoom(gameId string, room *Room) { |
| 19 | - tryInitTable(gameId, room) | 19 | + tryInitRoom(gameId, room) |
| 20 | 20 | ||
| 21 | room.UpdateTime = lxtime.NowUninx() | 21 | room.UpdateTime = lxtime.NowUninx() |
| 22 | room.Encode() | 22 | room.Encode() |
| @@ -35,7 +35,7 @@ func LoadRoom(gameId string, activityId int64, roomUid int64) (room *Room, has b | @@ -35,7 +35,7 @@ func LoadRoom(gameId string, activityId int64, roomUid int64) (room *Room, has b | ||
| 35 | has = false | 35 | has = false |
| 36 | return | 36 | return |
| 37 | } | 37 | } |
| 38 | - tryInitTable(gameId, room) | 38 | + tryInitRoom(gameId, room) |
| 39 | 39 | ||
| 40 | var err error | 40 | var err error |
| 41 | has, err = svmysql.First(room, gameId) | 41 | has, err = svmysql.First(room, gameId) |
| @@ -71,7 +71,7 @@ func CreateRoom(gameId string, activityId int64, roomConfigId int) (room *Room, | @@ -71,7 +71,7 @@ func CreateRoom(gameId string, activityId int64, roomConfigId int) (room *Room, | ||
| 71 | // FindRoom 查找 | 71 | // FindRoom 查找 |
| 72 | func FindRoom(gameId string, activityId int64, roomConfigId int) (rooms []*Room, has bool) { | 72 | func FindRoom(gameId string, activityId int64, roomConfigId int) (rooms []*Room, has bool) { |
| 73 | roomDemo := &Room{ActivityId: activityId} | 73 | roomDemo := &Room{ActivityId: activityId} |
| 74 | - tryInitTable(gameId, roomDemo) | 74 | + tryInitRoom(gameId, roomDemo) |
| 75 | info := roomDemo.MysqlInfo(gameId) | 75 | info := roomDemo.MysqlInfo(gameId) |
| 76 | 76 | ||
| 77 | info.DbMysql = info.DbMysql.Where("config_id = ? AND closed = false", roomConfigId) | 77 | info.DbMysql = info.DbMysql.Where("config_id = ? AND closed = false", roomConfigId) |