Files
sale/backend/internal/models/product.go
T
nuyue 46daa0999b
Build and Push Docker Image / build-and-push (push) Successful in 1m3s
Build and Push Docker Image / deploy (push) Successful in 7s
feat: add shipping template management and update favicon
2026-07-12 18:52:27 +08:00

52 lines
2.1 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Product struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:255;not null" json:"name"`
Description string `json:"description"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
Weight float64 `gorm:"type:decimal(10,2);default:0" json:"weight"` // 商品克重(克)
MinPurchase int `gorm:"default:1" json:"min_purchase"`
MaxPurchase *int `json:"max_purchase"`
MinWeight *float64 `json:"min_weight"`
MaxWeight *float64 `json:"max_weight"`
MinAmount *float64 `json:"min_amount"`
MaxAmount *float64 `json:"max_amount"`
RequireCredit bool `gorm:"default:false" json:"require_credit"`
CreditCost int `gorm:"default:0" json:"credit_cost"`
CreditReward int `gorm:"default:0" json:"credit_reward"`
Images string `gorm:"type:text" json:"images"`
IsActive bool `gorm:"default:true" json:"is_active"`
BrandID *uint `json:"brand_id"`
Brand *Brand `json:"brand,omitempty"`
ShippingTemplateID *uint `json:"shipping_template_id"`
ShippingTemplate *ShippingTemplate `json:"shipping_template,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Categories []Category `gorm:"many2many:product_categories;" json:"categories,omitempty"`
CustomFields []ProductCustomField `json:"custom_fields,omitempty"`
}
func (Product) TableName() string {
return "products"
}
type ProductCustomField struct {
ID uint `gorm:"primaryKey" json:"id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
FieldName string `gorm:"size:100;not null" json:"field_name"`
FieldValue string `json:"field_value"`
CreatedAt time.Time `json:"created_at"`
}
func (ProductCustomField) TableName() string {
return "product_custom_fields"
}