139 lines
4.1 KiB
Go
139 lines
4.1 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// AssetLevel 藏品等级配置
|
||
type AssetLevel struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||
Level string `gorm:"type:varchar(10);unique;not null"`
|
||
LevelOrder int `gorm:"not null"`
|
||
HourlyRevenue int `gorm:"not null"`
|
||
RequireHours int `gorm:"not null"`
|
||
RequireLikes int `gorm:"not null"`
|
||
IsInitial bool `gorm:"default:false"`
|
||
CreatedAt int64 `gorm:"not null"`
|
||
UpdatedAt int64 `gorm:"not null"`
|
||
}
|
||
|
||
func (AssetLevel) TableName() string { return "asset_levels" }
|
||
|
||
// AssetLevelRecord 藏品等级记录
|
||
type AssetLevelRecord struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||
AssetID int64 `gorm:"unique;not null"`
|
||
CurrentLevel string `gorm:"type:varchar(10);not null;default:'N'"`
|
||
SeasonExhibitionHours int `gorm:"default:0;not null"`
|
||
SeasonLikes int `gorm:"default:0;not null"`
|
||
LifetimeExhibitionHours int `gorm:"default:0;not null"`
|
||
LifetimeLikes int `gorm:"default:0;not null"`
|
||
SeasonID string `gorm:"type:varchar(50)"`
|
||
UpdatedAt int64 `gorm:"not null"`
|
||
}
|
||
|
||
func (AssetLevelRecord) TableName() string { return "asset_level_records" }
|
||
|
||
// AssetLevelChangeLog 等级变化日志
|
||
type AssetLevelChangeLog struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||
AssetID int64 `gorm:"not null;index"`
|
||
FromLevel string `gorm:"type:varchar(10)"`
|
||
ToLevel string `gorm:"type:varchar(10);not null"`
|
||
TriggerType string `gorm:"type:varchar(20);not null"`
|
||
TriggerHours int `gorm:"default:0"`
|
||
TriggerLikes int `gorm:"default:0"`
|
||
ChangeReason string `gorm:"type:varchar(255)"`
|
||
CreatedAt int64 `gorm:"not null;index"`
|
||
}
|
||
|
||
func (AssetLevelChangeLog) TableName() string { return "asset_level_change_logs" }
|
||
|
||
// Season 赛季配置
|
||
type Season struct {
|
||
ID string `gorm:"primaryKey;type:varchar(50)"`
|
||
Name string `gorm:"type:varchar(100);not null"`
|
||
DurationDays int `gorm:"not null;default:84"`
|
||
StartTime int64 `gorm:"not null"`
|
||
EndTime int64 `gorm:"not null"`
|
||
ResetStrategy string `gorm:"type:varchar(20);default:'percentage_decay'"`
|
||
ResetLevel bool `gorm:"default:true"`
|
||
Status string `gorm:"type:varchar(20);default:'active'"`
|
||
CreatedAt int64 `gorm:"not null"`
|
||
UpdatedAt int64 `gorm:"not null"`
|
||
}
|
||
|
||
func (Season) TableName() string { return "seasons" }
|
||
|
||
// CalculateEndTime 计算赛季结束时间
|
||
func (s *Season) CalculateEndTime() int64 {
|
||
return s.StartTime + int64(s.DurationDays)*86400000
|
||
}
|
||
|
||
// BeforeCreate 创建前钩子
|
||
func (s *Season) BeforeCreate(tx *gorm.DB) error {
|
||
now := time.Now().UnixMilli()
|
||
s.CreatedAt = now
|
||
s.UpdatedAt = now
|
||
s.EndTime = s.CalculateEndTime()
|
||
if s.Status == "" {
|
||
s.Status = "active"
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// BeforeUpdate 更新前钩子
|
||
func (s *Season) BeforeUpdate(tx *gorm.DB) error {
|
||
s.UpdatedAt = time.Now().UnixMilli()
|
||
s.EndTime = s.CalculateEndTime()
|
||
return nil
|
||
}
|
||
|
||
// SeasonDecayConfig 赛季降序百分比配置
|
||
type SeasonDecayConfig struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||
SeasonID string `gorm:"type:varchar(50);not null;uniqueIndex:uk_season_level"`
|
||
Level string `gorm:"type:varchar(10);not null;uniqueIndex:uk_season_level"`
|
||
PreservePercent int `gorm:"not null;default:100"`
|
||
UpdatedAt int64 `gorm:"not null"`
|
||
}
|
||
|
||
func (SeasonDecayConfig) TableName() string { return "season_decay_config" }
|
||
|
||
// 等级常量
|
||
const (
|
||
LevelN = "N"
|
||
LevelR = "R"
|
||
LevelSR = "SR"
|
||
LevelSSR = "SSR"
|
||
LevelUR = "UR"
|
||
)
|
||
|
||
// LevelOrderMap 等级顺序映射
|
||
var LevelOrderMap = map[string]int{
|
||
LevelN: 1,
|
||
LevelR: 2,
|
||
LevelSR: 3,
|
||
LevelSSR: 4,
|
||
LevelUR: 5,
|
||
}
|
||
|
||
// LevelToGradeMap 等级字符串到前端Grade的映射(1-5)
|
||
var LevelToGradeMap = map[string]int{
|
||
LevelN: 1,
|
||
LevelR: 2,
|
||
LevelSR: 3,
|
||
LevelSSR: 4,
|
||
LevelUR: 5,
|
||
}
|
||
|
||
// LevelToGrade 将等级字符串转换为前端Grade
|
||
func LevelToGrade(level string) int {
|
||
if grade, ok := LevelToGradeMap[level]; ok {
|
||
return grade
|
||
}
|
||
return 1 // 默认返回1
|
||
}
|