62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// AssetRegistry 资产统一索引表模型
|
||
type AssetRegistry struct {
|
||
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
||
AssetID int64 `gorm:"not null;column:asset_id"`
|
||
AssetType string `gorm:"type:varchar(20);not null;column:asset_type"` // 'regular' | 'collection' | 'activity'
|
||
OwnerUID int64 `gorm:"not null;index:idx_registry_owner_star;column:owner_uid"`
|
||
StarID int64 `gorm:"not null;index:idx_registry_owner_star;column:star_id"`
|
||
// 普通藏品专属字段
|
||
Grade *int32 `gorm:"column:grade"` // 仅 regular 类型时有效
|
||
// 典藏专属字段
|
||
CollectionCategory *string `gorm:"type:varchar(50);column:collection_category"` // 仅 collection 类型时有效
|
||
// 活动专属字段
|
||
ActivityID *int64 `gorm:"column:activity_id"` // 仅 activity 类型时有效
|
||
ActivityType *string `gorm:"type:varchar(50);column:activity_type"` // 仅 activity 类型时有效
|
||
// 公共字段
|
||
Status int32 `gorm:"default:0;column:status"`
|
||
LikeCount int32 `gorm:"default:0;column:like_count"`
|
||
DisplayStatus int32 `gorm:"default:0;column:display_status"` // 展示状态:0=待展示, 1=已展示
|
||
CreatedAt int64 `gorm:"not null;column:created_at"`
|
||
UpdatedAt int64 `gorm:"not null;column:updated_at"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (AssetRegistry) TableName() string {
|
||
return "asset_registry"
|
||
}
|
||
|
||
// BeforeCreate 创建前钩子
|
||
func (r *AssetRegistry) BeforeCreate(tx *gorm.DB) error {
|
||
now := time.Now().UnixMilli()
|
||
r.CreatedAt = now
|
||
r.UpdatedAt = now
|
||
return nil
|
||
}
|
||
|
||
// BeforeUpdate 更新前钩子
|
||
func (r *AssetRegistry) BeforeUpdate(tx *gorm.DB) error {
|
||
r.UpdatedAt = time.Now().UnixMilli()
|
||
return nil
|
||
}
|
||
|
||
// 资产类型常量
|
||
const (
|
||
AssetTypeRegular = "regular" // 普通藏品
|
||
AssetTypeCollection = "collection" // 典藏藏品
|
||
AssetTypeActivity = "activity" // 活动藏品
|
||
)
|
||
|
||
// AssetRegistry 状态常量
|
||
const (
|
||
AssetRegistryStatusPending = 0 // 待处理
|
||
AssetRegistryStatusActive = 1 // 已激活
|
||
)
|