This commit is contained in:
2026-01-09 15:58:09 +08:00
parent bd76520d22
commit ead5f17b7c
18 changed files with 1175 additions and 121 deletions

View File

@@ -10,19 +10,20 @@ import (
// Product 产品实体
type Product struct {
ID string `gorm:"primaryKey;type:varchar(36)" comment:"产品ID"`
OldID *string `gorm:"type:varchar(36);index" comment:"旧产品ID用于兼容"`
Name string `gorm:"type:varchar(100);not null" comment:"产品名称"`
Code string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"产品编号"`
Description string `gorm:"type:text" comment:"产品简介"`
Content string `gorm:"type:text" comment:"产品内容"`
CategoryID string `gorm:"type:varchar(36);not null" comment:"产品分类ID"`
Price decimal.Decimal `gorm:"type:decimal(10,2);not null;default:0" comment:"产品价格"`
CostPrice decimal.Decimal `gorm:"type:decimal(10,2);default:0" comment:"成本价"`
Remark string `gorm:"type:text" comment:"备注"`
IsEnabled bool `gorm:"default:false" comment:"是否启用"`
IsVisible bool `gorm:"default:false" comment:"是否展示"`
IsPackage bool `gorm:"default:false" comment:"是否组合包"`
ID string `gorm:"primaryKey;type:varchar(36)" comment:"产品ID"`
OldID *string `gorm:"type:varchar(36);index" comment:"旧产品ID用于兼容"`
Name string `gorm:"type:varchar(100);not null" comment:"产品名称"`
Code string `gorm:"type:varchar(50);uniqueIndex;not null" comment:"产品编号"`
Description string `gorm:"type:text" comment:"产品简介"`
Content string `gorm:"type:text" comment:"产品内容"`
CategoryID string `gorm:"type:varchar(36);not null" comment:"一级分类ID"`
SubCategoryID *string `gorm:"type:varchar(36);index" comment:"二级分类ID"`
Price decimal.Decimal `gorm:"type:decimal(10,2);not null;default:0" comment:"产品价格"`
CostPrice decimal.Decimal `gorm:"type:decimal(10,2);default:0" comment:"成本价"`
Remark string `gorm:"type:text" comment:"备注"`
IsEnabled bool `gorm:"default:false" comment:"是否启用"`
IsVisible bool `gorm:"default:false" comment:"是否展示"`
IsPackage bool `gorm:"default:false" comment:"是否组合包"`
// 组合包相关关联
PackageItems []*ProductPackageItem `gorm:"foreignKey:PackageID" comment:"组合包项目列表"`
// UI组件相关字段
@@ -34,7 +35,8 @@ type Product struct {
SEOKeywords string `gorm:"type:text" comment:"SEO关键词"`
// 关联关系
Category *ProductCategory `gorm:"foreignKey:CategoryID" comment:"产品分类"`
Category *ProductCategory `gorm:"foreignKey:CategoryID" comment:"一级分类"`
SubCategory *ProductSubCategory `gorm:"foreignKey:SubCategoryID" comment:"二级分类"`
Documentation *ProductDocumentation `gorm:"foreignKey:ProductID" comment:"产品文档"`
CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"`
@@ -118,3 +120,34 @@ func (p *Product) GetOldID() string {
func (p *Product) HasOldID() bool {
return p.OldID != nil && *p.OldID != ""
}
// HasSubCategory 检查是否有二级分类
func (p *Product) HasSubCategory() bool {
return p.SubCategoryID != nil && *p.SubCategoryID != ""
}
// GetFullCategoryPath 获取完整分类路径(一级分类/二级分类)
func (p *Product) GetFullCategoryPath() string {
if p.Category == nil {
return ""
}
if p.SubCategory != nil {
return p.Category.Name + " / " + p.SubCategory.Name
}
return p.Category.Name
}
// GetFullCategoryCode 获取完整分类编号(一级分类编号.二级分类编号)
func (p *Product) GetFullCategoryCode() string {
if p.Category == nil {
return ""
}
if p.SubCategory != nil {
return p.Category.Code + "." + p.SubCategory.Code
}
return p.Category.Code
}