config.go 3.65 KB
package confroomrank

import (
	"apigame/configs/confbase"
	"apigame/service-common/svconst"
	"apigame/service-common/svmysql"
	"apigame/service-common/svredis"
	"apigame/util/util-lx/lxtime"
	"apigame/util/utstring"
	"fmt"
)

// ActivityConfig 房间排行活动配置 分析后数据
type ActivityConfig struct {
	Raw *ActivityConfigRaw `json:"-"`

	Id          int64 // ID
	OpenLevel   int   // 开启等级
	PreviewTime int64 // 预告时间
	StartTime   int64 // 开始时间
	EndTime     int64 // 结束时间

	Robot map[int]RobotConfig // 机器人配置
	Room  map[int]RoomConfig  // 房间配置

	Client *ActivityConfigClient
	GameId string // 所属游戏ID
}

func (c *ActivityConfig) GetUid() string {
	return utstring.Int64ToString(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: "start_time <= ? AND end_time >= ? AND status = ?",
		CurrentArgs:  []any{timeNow, timeNow, 1},
		CacheKey:     fmt.Sprintf("%s:%d", cacheKey, c.Id),
		CacheCurrent: cacheKey + ":current",
		CacheTime:    300,
	}
}

func (c *ActivityConfig) RedisInfo(suffix string) *svredis.RedisInfo {
	tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG
	return &svredis.RedisInfo{
		CacheKey:  fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix),
		CacheTime: 300,
	}
}

// ActivityConfigRaw 房间排行活动配置 原始数据
type ActivityConfigRaw struct {
	Id          int64 `gorm:"column:id;primaryKey"` // ID
	OpenLevel   int   // 开启等级
	PreviewTime int64 // 预告时间
	StartTime   int64 // 开始时间
	EndTime     int64 // 结束时间

	Robot string // 机器人配置
	Room  string // 房间配置

	Ver        string // 版本号
	Status     int    // 状态 0=关闭 1=开启
	UpdateTime int64  // 修改时间戳
}

func (c *ActivityConfigRaw) MysqlInfo(suffix string) *svmysql.MysqlInfo {
	tableName := svconst.MYSQL_TABLE_S_ROOMRANK_CONFIG
	return &svmysql.MysqlInfo{
		DbMysql:   svconst.DbConfig.Where("status = ?", 1),
		TableName: tableName + suffix,
	}
}

// ActivityConfigClient 房间排行活动配置 给客户端数据
type ActivityConfigClient struct {
	Id int64 `form:"id" json:"id"` // ID
}

// RobotConfig 机器人配置
type RobotConfig struct {
	Id         int `json:"id"`          // id
	MinScore   int `json:"min_score"`   // 最低分数
	TotalScore int `json:"total_score"` // 总分数
	TotalRate  int `json:"total_rate"`  // 总分浮动范围(%)
}

// RoomConfig 房间配置
type RoomConfig struct {
	Id              int      `json:"id"`                // id
	Levels          []int    `json:"levels"`            // 等级范围
	UserClass       int      `json:"user_class"`        // 评级
	UserScore       []int    `json:"user_score"`        // 分数范围
	TotalPlayer     int      `json:"total_player"`      // 房间总人数
	PlayerTypeCount [][]int  `json:"player_type_count"` // 玩家类型数量
	AutoRobot       []int    `json:"auto_robot"`        // 自动填充机器人
	InitRobot       [][]int  `json:"init_robot"`        // 配置机器人
	Awards          []string `json:"awards"`            // 奖励
	SettleScores    []int    `json:"settle_scores"`     // 结算分数调整
	SettleUserType  []int    `json:"settle_user_type"`  // 结算用户类型
}