package cardholder import ( "apigame/service-common/svconst" "apigame/service-common/svmysql" "apigame/util/util-lx/lxalilog" "apigame/util/util-lx/lxtime" "encoding/json" "fmt" ) // Player 卡牌活动持久数据 type Player struct { Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"` ActivityId int64 `gorm:"comment:活动ID"` Details *PlayerDetails `gorm:"-"` // 详情 DetailsText string `gorm:"comment:详情封装"` CreateTime int64 `gorm:"comment:创建时间戳"` UpdateTime int64 `gorm:"comment:修改时间戳"` } func (d *Player) MysqlInfo(suffix string) *svmysql.MysqlInfo { tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_DATA return &svmysql.MysqlInfo{ DbMysql: svconst.DbCommon, TableName: fmt.Sprintf("%s_%s", tableName, suffix), } } func NewPlayer(uid int64) *Player { d := &Player{ Uid: uid, Details: NewPlayerDetails(), } d.Encode() return d } // PlayerDetails 详情 type PlayerDetails struct { Cards map[int]int // 每张卡集了多少张 k=卡牌ID v=数量 Album map[int]int // 卡组奖励领取 k=卡组ID v=数量 StarSequenceScales map[string]int // 星级序列刻度 k=ID_用户序列_用户分组 v=刻度 CardSequenceScales map[string]int // 卡牌序列刻度 k=ID_用户序列_用户分组 v=刻度 Round int // 卡册当前轮次 StarCount int // 星星点数 LastStarCount int // 上期活动剩余星星点数 AutoExchangeHolder int // 活动切换时自动兑换的卡包 2024年4月26日 这里策划要求改为只能兑换一个最高级的 } func NewPlayerDetails() *PlayerDetails { return &PlayerDetails{ Cards: make(map[int]int), Album: make(map[int]int), StarSequenceScales: make(map[string]int), CardSequenceScales: make(map[string]int), Round: 1, StarCount: 0, AutoExchangeHolder: 0, } } func (d *Player) Init(uid int64) { d.Uid = uid d.CreateTime = lxtime.NowUninx() } // Encode 打包数据 func (d *Player) Encode() { details, err := json.Marshal(d.Details) if err != nil { lxalilog.Errors(err, "Player Encode Error", d.Uid, d.ActivityId) return } d.DetailsText = string(details) } // Decode 分包数据 func (d *Player) Decode() { err := json.Unmarshal([]byte(d.DetailsText), d.Details) if err != nil { lxalilog.Errors(err, "Player Decode Error", d.Uid, d.ActivityId) return } }