Commit 74be11b7cf3581c153edf5b62205fbde88136c14

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

feat✨:房间排行活动基本框架

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