healthapp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

83 lines
3.3 KiB

package model
import (
"time"
"gorm.io/gorm"
)
// Product 商品表(融合健康推荐与商城功能)
type Product struct {
gorm.Model
// 基础信息
CategoryID uint `gorm:"index" json:"category_id"` // 关联商品分类
Category string `gorm:"size:50;index" json:"category"` // 分类名(兼容旧字段)
Name string `gorm:"size:200;not null" json:"name"`
Description string `gorm:"type:text" json:"description"`
MainImage string `gorm:"size:500" json:"main_image"`
Images string `gorm:"type:text" json:"images"` // JSON数组
ImageURL string `gorm:"size:255" json:"image_url"` // 兼容旧字段
// 价格库存
Price float64 `gorm:"not null" json:"price"`
OriginalPrice float64 `json:"original_price"`
Stock int `gorm:"default:0" json:"stock"`
SalesCount int `gorm:"default:0" json:"sales_count"`
// 状态
IsActive bool `gorm:"default:true" json:"is_active"`
IsFeatured bool `gorm:"default:false" json:"is_featured"` // 推荐商品
Sort int `gorm:"default:0" json:"sort"`
// 健康相关(体质推荐)
Efficacy string `gorm:"type:text" json:"efficacy"` // 功效说明
Suitable string `gorm:"type:text" json:"suitable"` // 适用人群/体质(兼容旧字段)
ConstitutionTypes string `gorm:"size:200" json:"constitution_types"` // 适合的体质类型(JSON数组)
HealthTags string `gorm:"size:500" json:"health_tags"` // 健康标签(JSON数组)
Ingredients string `gorm:"type:text" json:"ingredients"` // 成分/配料
Usage string `gorm:"type:text" json:"usage"` // 使用方法
Contraindications string `gorm:"type:text" json:"contraindications"` // 禁忌
MallURL string `gorm:"size:255" json:"mall_url"` // 外部商城链接
}
// ConstitutionProduct 体质-产品关联表
type ConstitutionProduct struct {
gorm.Model
ConstitutionType string `gorm:"size:20;index" json:"constitution_type"`
ProductID uint `gorm:"index" json:"product_id"`
Priority int `json:"priority"` // 推荐优先级
Reason string `gorm:"size:200" json:"reason"` // 推荐理由
}
// SymptomProduct 症状-产品关联表
type SymptomProduct struct {
gorm.Model
Keyword string `gorm:"size:50;index" json:"keyword"` // 症状关键词
ProductID uint `gorm:"index" json:"product_id"`
Priority int `json:"priority"`
}
// PurchaseHistory 购买历史表(商城同步)
type PurchaseHistory struct {
gorm.Model
UserID uint `gorm:"index" json:"user_id"`
OrderNo string `gorm:"size:50" json:"order_no"` // 商城订单号
ProductID uint `json:"product_id"`
ProductName string `gorm:"size:100" json:"product_name"`
PurchasedAt time.Time `json:"purchased_at"`
Source string `gorm:"size:20" json:"source"` // mall=保健品商城
}
// TableName 指定表名
func (Product) TableName() string {
return "products"
}
func (ConstitutionProduct) TableName() string {
return "constitution_products"
}
func (SymptomProduct) TableName() string {
return "symptom_products"
}
func (PurchaseHistory) TableName() string {
return "purchase_histories"
}