ba127826b2
- model/product_attr.go: 新增 4 张字典表 struct(TenantBase 范式)
- model/product.go: Product 增加 4 个可空外键 + belongs-to 关联
- handler/product_attr.go: 4 组 16 个 CRUD handler(shop_id 隔离)
- handler/product.go: FindOrCreate/Update 支持写入 4 个属性 ID
- handler/public.go: Preload 4 表 + 三级回退介绍 + 默认话术常量
- router/router.go: /product-options/{origins,shelf-lives,storages,description-docs} 路由
- main.go: AutoMigrate 注册 4 个新 model
- testutil/setup.go: SQLite 测试库补齐新列与新表
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
2.1 KiB
Go
43 lines
2.1 KiB
Go
package model
|
|
|
|
type ProductCategory struct {
|
|
TenantBase
|
|
Name string `gorm:"size:100;not null" json:"name"`
|
|
ParentID *uint64 `json:"parent_id"`
|
|
SortOrder int `gorm:"default:0" json:"sort_order"`
|
|
}
|
|
|
|
type Product struct {
|
|
TenantBase
|
|
PublicID string `gorm:"size:36;uniqueIndex" json:"public_id"`
|
|
Code string `gorm:"size:50" json:"code"`
|
|
Barcode string `gorm:"size:100" json:"barcode"`
|
|
Name string `gorm:"size:200;not null" json:"name"`
|
|
Series string `gorm:"size:100" json:"series"`
|
|
Spec string `gorm:"size:100" json:"spec"`
|
|
Unit string `gorm:"size:20" json:"unit"`
|
|
CategoryID *uint64 `json:"category_id"`
|
|
Brand string `gorm:"size:100" json:"brand"`
|
|
PurchasePrice float64 `gorm:"type:decimal(12,2)" json:"purchase_price"`
|
|
SalePrice float64 `gorm:"type:decimal(12,2)" json:"sale_price"`
|
|
MinStock int `gorm:"default:0" json:"min_stock"`
|
|
Description string `gorm:"type:text" json:"description"`
|
|
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
|
Remark string `gorm:"size:500" json:"remark"`
|
|
NamePinyin string `gorm:"size:400;index" json:"-"`
|
|
NameInitials string `gorm:"size:100;index" json:"-"`
|
|
|
|
// 商品属性字典外键(可空,公开页展示用)
|
|
OriginID *uint64 `json:"origin_id"`
|
|
ShelfLifeID *uint64 `json:"shelf_life_id"`
|
|
StorageID *uint64 `json:"storage_id"`
|
|
DescriptionDocID *uint64 `json:"description_doc_id"`
|
|
|
|
Category *ProductCategory `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
|
Images []ProductImage `gorm:"foreignKey:ProductID" json:"images,omitempty"`
|
|
Origin *ProductOriginOption `gorm:"foreignKey:OriginID" json:"origin,omitempty"`
|
|
ShelfLife *ProductShelfLifeOption `gorm:"foreignKey:ShelfLifeID" json:"shelf_life,omitempty"`
|
|
Storage *ProductStorageOption `gorm:"foreignKey:StorageID" json:"storage,omitempty"`
|
|
DescriptionDoc *ProductDescriptionDoc `gorm:"foreignKey:DescriptionDocID" json:"description_doc,omitempty"`
|
|
}
|