diff --git a/configs/feat-roomrank-decode.go b/configs/feat-roomrank-decode.go new file mode 100644 index 0000000..ab1e058 --- /dev/null +++ b/configs/feat-roomrank-decode.go @@ -0,0 +1,20 @@ +package configs + +// Decode 解析配置原始数据 +func (c *RoomRankConfig) Decode(gameId string, configRaw *RoomRankConfigRaw) { + c.GameId = gameId + c.Raw = configRaw + + c.Id = configRaw.Id + // 解析奖励 + + c.GenerateConfigClient() +} + +// GenerateConfigClient 生成给客户端的配置 +func (c *RoomRankConfig) GenerateConfigClient() { + configClient := &RoomRankConfigClient{ + Id: c.Id, + } + c.Client = configClient +} diff --git a/configs/feat-roomrank.go b/configs/feat-roomrank.go new file mode 100644 index 0000000..c39995a --- /dev/null +++ b/configs/feat-roomrank.go @@ -0,0 +1,59 @@ +package configs + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "fmt" +) + +// RoomRankConfig 房间排行活动配置 分析后数据 +type RoomRankConfig struct { + Raw *RoomRankConfigRaw `json:"-"` + + Id int64 // ID + + Client *RoomRankConfigClient + GameId string // 所属游戏ID +} + +func (c *RoomRankConfig) RedisInfo(gameId string) *svredis.RedisInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + return &svredis.RedisInfo{ + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, gameId), + CacheTime: 300, + } +} + +// RoomRankConfigRaw 卡牌活动配置 原始数据 +type RoomRankConfigRaw struct { + Id int64 // ID + OpenLevel int // 开启等级 + PreviewTime int64 // 预告时间 + StartTime int64 // 开始时间 + EndTime int64 // 结束时间 + Round int // 轮数 + Awards string `json:"-"` // 奖励配置 + AlbumConfig string `json:"-"` // 卡组配置 + CardConfig string `json:"-"` // 卡牌配置 + CardHolderConfig string `json:"-"` // 卡包开卡规则 + NormalCardStarSequence string `json:"-"` // 卡片星级配置 + CardSequenceConfig string `json:"-"` // 卡片星级对应卡牌配置 + StarShopConfig string `json:"-"` // 星星商店配置 + Ver string // 版本号 + Status int // 状态 0=关闭 1=开启 + UpdateTime int64 // 修改时间戳 +} + +func (c *RoomRankConfigRaw) MysqlInfo(gameId string) *svmysql.MysqlInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbConfig.Where("status = ?", 1), + TableName: tableName + gameId, + } +} + +// RoomRankConfigClient 卡牌活动配置 给客户端数据 +type RoomRankConfigClient struct { + Id int64 `form:"id" json:"id"` // ID +} diff --git a/configs/init.go b/configs/init.go index 8ce1cf0..8aba420 100644 --- a/configs/init.go +++ b/configs/init.go @@ -1,11 +1,20 @@ package configs +import "apigame/service-common/svconst" + func Init() bool { - gameId := "10149" + for _, gameId := range svconst.GameList { + _, _ = GetApiGameConfig(gameId) + } + + for _, gameId := range svconst.GameListCardHolder { + _, _ = GetCardActivityConfig(gameId) + } - _, _ = GetApiGameConfig(gameId) - _, _ = GetCardActivityConfig(gameId) + for _, gameId := range svconst.GameListRoomRank { + _, _ = GetRoomRankConfig(gameId) + } return true } diff --git a/configs/registry.go b/configs/registry.go index 3149e77..9a70ba6 100644 --- a/configs/registry.go +++ b/configs/registry.go @@ -52,3 +52,29 @@ func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) { return } + +// GetRoomRankConfig 获取 房间排行活动配置 +func GetRoomRankConfig(gameId string) (conf *RoomRankConfig, has bool) { + var err error + conf = new(RoomRankConfig) + has = svredis.LoadData(gameId, conf) + if has { + fmt.Println("dwjw GetRoomRankConfig use cache") + return + } + confRaw := new(RoomRankConfigRaw) + has, err = svmysql.First(confRaw, gameId) + if err != nil { + return + } + if !has { + return + } + + conf.Decode(gameId, confRaw) + + fmt.Println("dwjw GetRoomRankConfig save cache") + svredis.SaveData(gameId, conf) + + return +} diff --git a/controllers/roomrank.go b/controllers/roomrank.go new file mode 100644 index 0000000..d48b85e --- /dev/null +++ b/controllers/roomrank.go @@ -0,0 +1,35 @@ +package controllers + +import ( + "apigame/models" + "apigame/service/roomrank" +) + +// RoomRankController 绑定控制器 +type RoomRankController struct { + BaseController +} + +// GetConfig 活动配置 +func (c *RoomRankController) GetConfig() { + req := new(models.ReqRoomRankGetConfig) + if !c.GetPostData(req) { + return + } + + code, rsp := roomrank.HandleGetConfig(req) + + c.RetRspCodeData(code, rsp) +} + +// Info 房间排行信息 +func (c *RoomRankController) Info() { + req := new(models.ReqRoomRankInfo) + if !c.GetPostData(req) { + return + } + + code, rsp := roomrank.HandleInfo(req) + + c.RetRspCodeData(code, rsp) +} diff --git a/main.go b/main.go index e80ade1..46a1428 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,11 @@ package main import ( "apigame/configs" _ "apigame/routers" + "apigame/service" "apigame/service-common/svconst" "apigame/service-common/svlog" "apigame/service-common/svmysql" "apigame/service-common/svredis" - "apigame/service/cardholder" "github.com/astaxie/beego" "github.com/astaxie/beego/logs" "github.com/astaxie/beego/plugins/cors" @@ -63,7 +63,7 @@ func Init() bool { return false } - cardholder.Init() + service.Init() return true } diff --git a/models/roomrank.go b/models/roomrank.go new file mode 100644 index 0000000..3d65dc4 --- /dev/null +++ b/models/roomrank.go @@ -0,0 +1,28 @@ +package models + +// ReqRoomRankGetConfig 请求 活动配置 +type ReqRoomRankGetConfig struct { + BaseLoginInfo + BaseSign +} + +// RspRoomRankGetConfig 返回 活动配置 +type RspRoomRankGetConfig struct { + ActivityId int64 `form:"activity_id" json:"activity_id"` // 活动配置 0=无活动 + Config any `form:"config" json:"config"` // 活动配置对象 +} + +// RoomRankInfo 房间排行信息 +type RoomRankInfo struct { +} + +// ReqRoomRankInfo 请求 房间排行信息 +type ReqRoomRankInfo struct { + BaseLoginInfo + BaseSign +} + +// RspRoomRankInfo 返回 房间排行信息 +type RspRoomRankInfo struct { + RoomRankInfo +} diff --git a/routers/router.go b/routers/router.go index c2fe590..b6d27db 100644 --- a/routers/router.go +++ b/routers/router.go @@ -22,5 +22,11 @@ func init() { // 上期剩余星星自动兑换信息 beego.Router(prefix+"/cardholder/autoexchangeinfo", &controllers.CardHolderController{}, "post:AutoExchangeInfo") + // 房间排行活动 + // 活动配置 + beego.Router(prefix+"/roomrank/getconfig", &controllers.RoomRankController{}, "post:GetConfig") + // 房间排行信息 + beego.Router(prefix+"/roomrank/info", &controllers.RoomRankController{}, "post:Info") + beego.ErrorController(&controllers.ErrorController{}) } diff --git a/service-common/svconst/mysql.go b/service-common/svconst/mysql.go index 3ef85ec..116f669 100644 --- a/service-common/svconst/mysql.go +++ b/service-common/svconst/mysql.go @@ -13,9 +13,10 @@ const ( MYSQL_TABLE_S_CARDHOLDER_CONFIG = "s_card_activity_" // 开卡包活动配置 MYSQL_TABLE_S_CARDHOLDER_DATA = "s_cardholder_data_" // 开卡包活动数据 - MYSQL_TABLE_S_CARDHOLDER_RECORD_GETNEW = "s_cardholder_record_getnew_" // 开卡包活动日志获得卡包 MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN = "s_cardholder_record_open_" // 开卡包活动日志开卡包 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum_" // 开卡包活动日志领取卡组奖励 MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround_" // 开卡包活动日志领取轮次奖励 + MYSQL_TABLE_S_ROOMRANK_CONFIG = "s_roomrank_activity_" // 房间排行活动配置 + MYSQL_TABLE_S_ROOMRANK_DATA = "s_roomrank_data_" // 房间排行持久数据 ) diff --git a/service-common/svconst/vars.go b/service-common/svconst/vars.go index c2c254a..f889b1e 100644 --- a/service-common/svconst/vars.go +++ b/service-common/svconst/vars.go @@ -9,5 +9,7 @@ var ( DbCommon *gorm.DB DbConfig *gorm.DB + GameList = []string{"10149"} GameListCardHolder = []string{"10149"} + GameListRoomRank = []string{"10149"} ) diff --git a/service/cardholder/dto-game.go b/service/cardholder/dto-game.go index a502090..e609812 100644 --- a/service/cardholder/dto-game.go +++ b/service/cardholder/dto-game.go @@ -10,12 +10,14 @@ import ( // DataCardHolder 卡牌活动持久数据 type DataCardHolder struct { - Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` - ActivityId int64 `gorm:"comment:活动ID"` + Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` + ActivityId int64 `gorm:"comment:活动ID"` + Details *DataCardHolderDetails `gorm:"-"` // 活动详情 DetailsText string `gorm:"comment:活动详情封装"` - CreateTime int64 `gorm:"comment:创建时间戳"` - UpdateTime int64 `gorm:"comment:修改时间戳"` + + CreateTime int64 `gorm:"comment:创建时间戳"` + UpdateTime int64 `gorm:"comment:修改时间戳"` } func (d *DataCardHolder) MysqlInfo(gameId string) *svmysql.MysqlInfo { diff --git a/service/cardholder/init.go b/service/cardholder/init.go deleted file mode 100644 index bc5a4f3..0000000 --- a/service/cardholder/init.go +++ /dev/null @@ -1,19 +0,0 @@ -package cardholder - -import ( - "apigame/service-common/svconst" - "apigame/service-common/svmysql" -) - -func Init() { - - // create table - // 卡牌卡包 - for _, gameId := range svconst.GameListCardHolder { - svmysql.InitTable(new(DataCardHolder), gameId) - svmysql.InitTable(new(RecordCardHolderOpen), gameId) - svmysql.InitTable(new(RecordCardHolderRewardAlbum), gameId) - svmysql.InitTable(new(RecordCardHolderRewardRound), gameId) - } - -} diff --git a/service/code-msg/code-msg.go b/service/code-msg/code-msg.go index e2df54c..b72fb1b 100644 --- a/service/code-msg/code-msg.go +++ b/service/code-msg/code-msg.go @@ -48,6 +48,8 @@ const ( RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR = "2105" RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR = "2106" RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR = "2107" + + RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR = "2200" ) var recodeText = map[string]string{ @@ -96,6 +98,8 @@ var recodeText = map[string]string{ RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR: "商店ID错误", RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR: "星星商店星星不足", RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR: "没有星星商店自动兑换信息", + + RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR: "活动未开放", } func RecodeText(code string) string { diff --git a/service/init.go b/service/init.go new file mode 100644 index 0000000..b5e5dfa --- /dev/null +++ b/service/init.go @@ -0,0 +1,25 @@ +package service + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service/cardholder" + "apigame/service/roomrank" +) + +func Init() { + + // create table + // 卡牌卡包 + for _, gameId := range svconst.GameListCardHolder { + svmysql.InitTable(new(cardholder.DataCardHolder), gameId) + svmysql.InitTable(new(cardholder.RecordCardHolderOpen), gameId) + svmysql.InitTable(new(cardholder.RecordCardHolderRewardAlbum), gameId) + svmysql.InitTable(new(cardholder.RecordCardHolderRewardRound), gameId) + } + // 卡牌卡包 + for _, gameId := range svconst.GameListRoomRank { + svmysql.InitTable(new(roomrank.DataRoomRank), gameId) + } + +} diff --git a/service/roomrank/dto-game.go b/service/roomrank/dto-game.go new file mode 100644 index 0000000..4ed1fc8 --- /dev/null +++ b/service/roomrank/dto-game.go @@ -0,0 +1,42 @@ +package roomrank + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/util/util-lx/lxtime" +) + +// DataRoomRank 房间排行持久数据 +type DataRoomRank struct { + Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` + ActivityId int64 `gorm:"comment:活动ID"` + + UserType int `gorm:"comment:用户类型"` // 0=新手用户 1=优质用户 2=普通用户 3=垃圾用户 + UserScore int `gorm:"comment:用户评级分"` + UserClass int `gorm:"comment:用户评级"` + + RoomUid int `gorm:"comment:所在房间唯一ID"` + + CreateTime int64 `gorm:"comment:创建时间戳"` + UpdateTime int64 `gorm:"comment:修改时间戳"` +} + +func (d *DataRoomRank) MysqlInfo(gameId string) *svmysql.MysqlInfo { + tableName := svconst.MYSQL_TABLE_S_ROOMRANK_DATA + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbCommon, + TableName: tableName + gameId, + } +} + +func NewDataRoomRank(uid int64) *DataRoomRank { + d := &DataRoomRank{ + Uid: uid, + } + return d +} + +func (d *DataRoomRank) Init(uid int64) { + d.Uid = uid + d.CreateTime = lxtime.NowUninx() +} diff --git a/service/roomrank/handle.go b/service/roomrank/handle.go new file mode 100644 index 0000000..f1591cd --- /dev/null +++ b/service/roomrank/handle.go @@ -0,0 +1,49 @@ +package roomrank + +import ( + "apigame/configs" + "apigame/models" + "apigame/service/code-msg" +) + +// HandleGetConfig 活动配置 +func HandleGetConfig(req *models.ReqRoomRankGetConfig) (code string, rsp models.RspRoomRankGetConfig) { + rsp = models.RspRoomRankGetConfig{} + code = code_msg.RECODE_OK + + // 尝试更新配置 + config, _ := configs.GetRoomRankConfig(req.GameID) + rsp.ActivityId = config.Id + + rsp.Config = config.Client + + return +} + +// HandleInfo 房间排行信息 +func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRankInfo) { + rsp = models.RspRoomRankInfo{} + code = code_msg.RECODE_OK + + // 尝试更新配置 + config, hasConfig := configs.GetRoomRankConfig(req.GameID) + if !hasConfig { + code = code_msg.RECODE_MERGE_ROOMRANK_NOTOPEN_ERROR + return + } + + // todo 检查是否在结算中 + //// 判断预告时间 + //sec := lxtime.NowUninx() + //if sec < config.StartTime { + // code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR + // return + //} + + // 读取游戏数据 + gameData := LoadData(req.GameID, req.UID, config) + + rsp.RoomRankInfo = GetInfo(gameData, config) + + return +} diff --git a/service/roomrank/logic.go b/service/roomrank/logic.go new file mode 100644 index 0000000..e939bfc --- /dev/null +++ b/service/roomrank/logic.go @@ -0,0 +1,50 @@ +package roomrank + +import ( + "apigame/configs" + "apigame/models" + "apigame/service-common/svmysql" + "apigame/util/util-lx/lxtime" +) + +// SaveData 存储数据 +func SaveData(gameId string, d *DataRoomRank) { + d.UpdateTime = lxtime.NowUninx() + + _ = svmysql.Save(d, gameId) +} + +func _LoadData(gameId string, uid int64) (d *DataRoomRank) { + d = NewDataRoomRank(uid) + has, err := svmysql.First(d, gameId) + if err != nil { + return + } + if has { + } else { + d.Init(uid) + _ = svmysql.Insert(d, gameId) + } + return +} + +// LoadData 获取数据 外部接口 +func LoadData(gameId string, uid int64, config *configs.RoomRankConfig) (d *DataRoomRank) { + configId := config.Id + d = _LoadData(gameId, uid) + // 如果当前有上线活动(活动ID不为0),且活动ID和玩家数据不同,说明活动已切换 需更新 + if configId != 0 && + configId != d.ActivityId { + + d.ActivityId = configId + + SaveData(gameId, d) + } + return +} + +// GetInfo 活动信息 +func GetInfo(gameData *DataRoomRank, conf *configs.RoomRankConfig) models.RoomRankInfo { + info := models.RoomRankInfo{} + return info +} -- libgit2 0.21.0