53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ActivityAsset 活动藏品表模型
|
|
type ActivityAsset struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
AssetID int64 `gorm:"unique;not null;column:asset_id"`
|
|
OwnerUID int64 `gorm:"not null;index:idx_activity_owner;column:owner_uid"`
|
|
StarID int64 `gorm:"not null;index:idx_activity_star;column:star_id"`
|
|
ActivityID int64 `gorm:"not null;index:idx_activity_owner;column:activity_id"`
|
|
ActivityType string `gorm:"type:varchar(50);not null;index:idx_activity_type;column:activity_type"`
|
|
Name string `gorm:"type:varchar(100);not null;column:name"`
|
|
CoverURL string `gorm:"type:varchar(500);not null;column:cover_url"`
|
|
LikeCount int32 `gorm:"default:0;column:like_count"`
|
|
Status int32 `gorm:"default:0;column:status"` // 0=Pending, 1=Active
|
|
Metadata JSONB `gorm:"type:jsonb;column:metadata"`
|
|
CreatedAt int64 `gorm:"not null;column:created_at"`
|
|
UpdatedAt int64 `gorm:"not null;column:updated_at"`
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (ActivityAsset) TableName() string {
|
|
return "activity_assets"
|
|
}
|
|
|
|
// BeforeCreate 创建前钩子
|
|
func (a *ActivityAsset) BeforeCreate(tx *gorm.DB) error {
|
|
now := time.Now().UnixMilli()
|
|
a.CreatedAt = now
|
|
a.UpdatedAt = now
|
|
if a.Status == 0 {
|
|
a.Status = AssetStatusPending
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BeforeUpdate 更新前钩子
|
|
func (a *ActivityAsset) BeforeUpdate(tx *gorm.DB) error {
|
|
a.UpdatedAt = time.Now().UnixMilli()
|
|
return nil
|
|
}
|
|
|
|
// 活动藏品状态常量
|
|
const (
|
|
ActivityAssetStatusPending = 0 // 待处理
|
|
ActivityAssetStatusActive = 1 // 已激活
|
|
)
|