65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// CastloveCategory 铸爱工艺分类表模型
|
|
// 对应表 castlove_categories;后台直连写库,本服务只读
|
|
type CastloveCategory struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
Name string `gorm:"type:varchar(64);not null;uniqueIndex;column:name"`
|
|
TypeKey *string `gorm:"type:varchar(32);column:type_key"` // 外部 deep-link key;可空(NULL 时唯一索引不命中)
|
|
SortOrder int32 `gorm:"not null;default:0;column:sort_order"`
|
|
IsActive bool `gorm:"not null;default:true;column:is_active"`
|
|
CreatedAt int64 `gorm:"not null;column:created_at"`
|
|
UpdatedAt int64 `gorm:"not null;column:updated_at"`
|
|
DeletedAt *int64 `gorm:"index;column:deleted_at"`
|
|
}
|
|
|
|
func (CastloveCategory) TableName() string { return "castlove_categories" }
|
|
|
|
func (c *CastloveCategory) BeforeCreate(tx *gorm.DB) error {
|
|
now := time.Now().UnixMilli()
|
|
c.CreatedAt = now
|
|
c.UpdatedAt = now
|
|
return nil
|
|
}
|
|
|
|
func (c *CastloveCategory) BeforeUpdate(tx *gorm.DB) error {
|
|
c.UpdatedAt = time.Now().UnixMilli()
|
|
return nil
|
|
}
|
|
|
|
// CastloveCraft 铸爱工艺卡片表模型
|
|
// 对应表 castlove_crafts;后台直连写库,本服务只读
|
|
type CastloveCraft struct {
|
|
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
|
|
CategoryID int64 `gorm:"not null;index:idx_castlove_crafts_cat_sort;column:category_id"`
|
|
Name string `gorm:"type:varchar(64);not null;column:name"`
|
|
ImageURL string `gorm:"type:text;not null;column:image_url"`
|
|
RoutePath *string `gorm:"type:varchar(255);column:route_path"` // 可空(NULL = 点击弹 toast,不跳转)
|
|
RouteParams *string `gorm:"type:jsonb;column:route_params"` // JSON 字符串,NULL 或合法 JSON 对象
|
|
SortOrder int32 `gorm:"not null;default:0;column:sort_order"`
|
|
IsActive bool `gorm:"not null;default:true;column:is_active"`
|
|
CreatedAt int64 `gorm:"not null;column:created_at"`
|
|
UpdatedAt int64 `gorm:"not null;column:updated_at"`
|
|
DeletedAt *int64 `gorm:"index;column:deleted_at"`
|
|
}
|
|
|
|
func (CastloveCraft) TableName() string { return "castlove_crafts" }
|
|
|
|
func (c *CastloveCraft) BeforeCreate(tx *gorm.DB) error {
|
|
now := time.Now().UnixMilli()
|
|
c.CreatedAt = now
|
|
c.UpdatedAt = now
|
|
return nil
|
|
}
|
|
|
|
func (c *CastloveCraft) BeforeUpdate(tx *gorm.DB) error {
|
|
c.UpdatedAt = time.Now().UnixMilli()
|
|
return nil
|
|
}
|