This commit is contained in:
sjk
2025-11-28 15:18:10 +08:00
parent ad4a600af9
commit 5683f35942
188 changed files with 53680 additions and 1062 deletions

View File

@@ -8,6 +8,25 @@ import (
"gorm.io/gorm"
)
// JSONUintSlice 自定义JSON uint切片类型
type JSONUintSlice []uint
func (j JSONUintSlice) Value() (driver.Value, error) {
return json.Marshal(j)
}
func (j *JSONUintSlice) Scan(value interface{}) error {
if value == nil {
*j = nil
return nil
}
bytes, ok := value.([]byte)
if !ok {
return nil
}
return json.Unmarshal(bytes, j)
}
// JSONSlice 自定义JSON切片类型
type JSONSlice []string
@@ -81,47 +100,50 @@ type Category struct {
Level int `json:"level" gorm:"default:1"`
Icon string `json:"icon" gorm:"size:255"`
Description string `json:"description" gorm:"size:255"`
Platform JSONSlice `json:"platform" gorm:"type:json;comment:平台标识列表"`
Sort int `json:"sort" gorm:"default:0"`
Status int `json:"status" gorm:"default:1"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联字段
Children []Category `json:"children,omitempty" gorm:"-"`
HasChildren bool `json:"hasChildren" gorm:"-"`
}
// Product 商品
type Product struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
CategoryID uint `json:"category_id" gorm:"not null"`
StoreID uint `json:"store_id" gorm:"default:1"`
Name string `json:"name" gorm:"size:100;not null"`
Description string `json:"description" gorm:"type:text"`
Price float64 `json:"price" gorm:"type:decimal(10,2);not null"`
OrigPrice float64 `json:"orig_price" gorm:"type:decimal(10,2)"`
Stock int `json:"stock" gorm:"default:0"`
Sales int `json:"sales" gorm:"default:0"`
CommentCount int `json:"comment_count" gorm:"default:0"`
AverageRating float64 `json:"average_rating" gorm:"type:decimal(3,2);default:0.00"`
MainImage string `json:"main_image" gorm:"size:255"`
Images JSONSlice `json:"images" gorm:"type:json"`
VideoURL string `json:"video_url" gorm:"size:255"`
DetailImages JSONSlice `json:"detail_images" gorm:"type:json"`
Status int `json:"status" gorm:"default:1"`
IsHot bool `json:"is_hot" gorm:"default:false"`
IsNew bool `json:"is_new" gorm:"default:false"`
IsRecommend bool `json:"is_recommend" gorm:"default:false"`
LimitBuy int `json:"limit_buy" gorm:"default:0"`
Points int `json:"points" gorm:"default:0"`
Level int `json:"level" gorm:"default:0"`
Weight float64 `json:"weight" gorm:"type:decimal(8,2)"`
Unit string `json:"unit" gorm:"size:20"`
Sort int `json:"sort" gorm:"default:0"`
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
CategoryID JSONUintSlice `json:"category_id" gorm:"type:json;comment:分类ID列表"` // 改为JSON数组支持多分类
StoreID uint `json:"store_id" gorm:"default:1"`
Name string `json:"name" gorm:"size:100;not null"`
Description string `json:"description" gorm:"type:text"`
Price float64 `json:"price" gorm:"type:decimal(10,2);not null"`
OrigPrice float64 `json:"orig_price" gorm:"type:decimal(10,2)"`
Stock int `json:"stock" gorm:"default:0"`
Sales int `json:"sales" gorm:"default:0"`
CommentCount int `json:"comment_count" gorm:"default:0"`
AverageRating float64 `json:"average_rating" gorm:"type:decimal(3,2);default:0.00"`
MainImage string `json:"main_image" gorm:"size:255"`
Images JSONSlice `json:"images" gorm:"type:json"`
VideoURL string `json:"video_url" gorm:"size:255"`
DetailImages JSONSlice `json:"detail_images" gorm:"type:json"`
Status int `json:"status" gorm:"default:1"`
IsHot bool `json:"is_hot" gorm:"default:false"`
IsNew bool `json:"is_new" gorm:"default:false"`
IsRecommend bool `json:"is_recommend" gorm:"default:false"`
LimitBuy int `json:"limit_buy" gorm:"default:0"`
Points int `json:"points" gorm:"default:0"`
Level int `json:"level" gorm:"default:0"`
Weight float64 `json:"weight" gorm:"type:decimal(8,2)"`
Unit string `json:"unit" gorm:"size:20"`
Sort int `json:"sort" gorm:"default:0"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
// 关联数据
Category Category `json:"category,omitempty" gorm:"foreignKey:CategoryID"`
Categories []Category `json:"categories,omitempty" gorm:"-"` // 读取时填充的分类信息
Store Store `json:"store,omitempty" gorm:"foreignKey:StoreID"`
SKUs []ProductSKU `json:"skus,omitempty" gorm:"foreignKey:ProductID"`
Tags []ProductTag `json:"tags,omitempty" gorm:"many2many:ai_product_tag_relations;"`