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.
182 lines
6.3 KiB
182 lines
6.3 KiB
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ========== 积分系统 ==========
|
|
|
|
// PointsRecord 积分变动记录
|
|
type PointsRecord struct {
|
|
gorm.Model
|
|
UserID uint `gorm:"index" json:"user_id"`
|
|
Type string `gorm:"size:20" json:"type"` // earn/spend/expire/adjust
|
|
Points int `json:"points"` // 变动积分(正负)
|
|
Balance int `json:"balance"` // 变动后余额
|
|
Source string `gorm:"size:50" json:"source"` // order/activity/system/refund
|
|
ReferenceID uint `json:"reference_id"` // 关联ID(订单ID等)
|
|
Remark string `gorm:"size:200" json:"remark"` // 备注
|
|
ExpireAt *time.Time `json:"expire_at"` // 过期时间(仅获得积分)
|
|
}
|
|
|
|
// 积分变动类型
|
|
const (
|
|
PointsTypeEarn = "earn" // 获得
|
|
PointsTypeSpend = "spend" // 使用
|
|
PointsTypeExpire = "expire" // 过期
|
|
PointsTypeAdjust = "adjust" // 调整
|
|
)
|
|
|
|
// 积分来源
|
|
const (
|
|
PointsSourceOrder = "order" // 订单获得
|
|
PointsSourceActivity = "activity" // 活动获得
|
|
PointsSourceSystem = "system" // 系统调整
|
|
PointsSourceRefund = "refund" // 退款扣除
|
|
)
|
|
|
|
// ========== 商品系统 ==========
|
|
|
|
// ProductCategory 商品分类
|
|
type ProductCategory struct {
|
|
gorm.Model
|
|
Name string `gorm:"size:50" json:"name"`
|
|
ParentID uint `gorm:"default:0" json:"parent_id"`
|
|
Sort int `gorm:"default:0" json:"sort"`
|
|
Icon string `gorm:"size:255" json:"icon"`
|
|
Description string `gorm:"size:200" json:"description"`
|
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
|
}
|
|
|
|
// Product 商品(定义在 product.go 中,此处不重复定义)
|
|
|
|
// ProductSku 商品SKU
|
|
type ProductSku struct {
|
|
gorm.Model
|
|
ProductID uint `gorm:"index" json:"product_id"`
|
|
SkuCode string `gorm:"size:50;uniqueIndex" json:"sku_code"`
|
|
Name string `gorm:"size:100" json:"name"` // 规格名称,如"500g装"
|
|
Attributes string `gorm:"size:500" json:"attributes"` // JSON,如{"weight":"500g","package":"袋装"}
|
|
Price float64 `gorm:"not null" json:"price"`
|
|
Stock int `gorm:"default:0" json:"stock"`
|
|
Image string `gorm:"size:500" json:"image"`
|
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
|
}
|
|
|
|
// ========== 购物车 ==========
|
|
|
|
// CartItem 购物车项
|
|
type CartItem struct {
|
|
gorm.Model
|
|
UserID uint `gorm:"index;not null" json:"user_id"`
|
|
ProductID uint `gorm:"index;not null" json:"product_id"`
|
|
SkuID uint `gorm:"index" json:"sku_id"` // 可选,无SKU时为0
|
|
Quantity int `gorm:"not null;default:1" json:"quantity"`
|
|
Selected bool `gorm:"default:true" json:"selected"` // 是否选中
|
|
}
|
|
|
|
// ========== 收货地址 ==========
|
|
|
|
// Address 收货地址
|
|
type Address struct {
|
|
gorm.Model
|
|
UserID uint `gorm:"index;not null" json:"user_id"`
|
|
ReceiverName string `gorm:"size:50;not null" json:"receiver_name"`
|
|
Phone string `gorm:"size:20;not null" json:"phone"`
|
|
Province string `gorm:"size:50" json:"province"`
|
|
City string `gorm:"size:50" json:"city"`
|
|
District string `gorm:"size:50" json:"district"`
|
|
DetailAddr string `gorm:"size:200;not null" json:"detail_addr"`
|
|
PostalCode string `gorm:"size:10" json:"postal_code"`
|
|
IsDefault bool `gorm:"default:false" json:"is_default"`
|
|
Tag string `gorm:"size:20" json:"tag"` // home/company/other
|
|
}
|
|
|
|
// ========== 订单系统 ==========
|
|
|
|
// Order 订单
|
|
type Order struct {
|
|
gorm.Model
|
|
UserID uint `gorm:"index;not null" json:"user_id"`
|
|
OrderNo string `gorm:"size:50;uniqueIndex" json:"order_no"`
|
|
Status string `gorm:"size:20;index" json:"status"` // pending/paid/shipped/completed/cancelled/refunding/refunded
|
|
TotalAmount float64 `json:"total_amount"` // 商品总金额
|
|
DiscountAmount float64 `json:"discount_amount"` // 优惠金额
|
|
ShippingFee float64 `json:"shipping_fee"` // 运费
|
|
PayAmount float64 `json:"pay_amount"` // 实付金额
|
|
PointsUsed int `json:"points_used"` // 使用积分
|
|
PointsEarned int `json:"points_earned"` // 获得积分
|
|
PayMethod string `gorm:"size:20" json:"pay_method"` // wechat/alipay/points
|
|
PayTime *time.Time `json:"pay_time"`
|
|
ShipTime *time.Time `json:"ship_time"`
|
|
ReceiveTime *time.Time `json:"receive_time"`
|
|
// 收货信息(快照)
|
|
ReceiverName string `gorm:"size:50" json:"receiver_name"`
|
|
ReceiverPhone string `gorm:"size:20" json:"receiver_phone"`
|
|
ReceiverAddr string `gorm:"size:300" json:"receiver_addr"`
|
|
// 物流信息
|
|
ShippingCompany string `gorm:"size:50" json:"shipping_company"`
|
|
TrackingNo string `gorm:"size:50" json:"tracking_no"`
|
|
// 其他
|
|
Remark string `gorm:"size:500" json:"remark"` // 买家留言
|
|
CancelReason string `gorm:"size:200" json:"cancel_reason"`
|
|
}
|
|
|
|
// 订单状态
|
|
const (
|
|
OrderStatusPending = "pending" // 待支付
|
|
OrderStatusPaid = "paid" // 已支付
|
|
OrderStatusShipped = "shipped" // 已发货
|
|
OrderStatusCompleted = "completed" // 已完成
|
|
OrderStatusCancelled = "cancelled" // 已取消
|
|
OrderStatusRefunding = "refunding" // 退款中
|
|
OrderStatusRefunded = "refunded" // 已退款
|
|
)
|
|
|
|
// OrderItem 订单商品
|
|
type OrderItem struct {
|
|
gorm.Model
|
|
OrderID uint `gorm:"index;not null" json:"order_id"`
|
|
ProductID uint `json:"product_id"`
|
|
SkuID uint `json:"sku_id"`
|
|
ProductName string `gorm:"size:200" json:"product_name"` // 快照
|
|
SkuName string `gorm:"size:100" json:"sku_name"` // 快照
|
|
Image string `gorm:"size:500" json:"image"` // 快照
|
|
Price float64 `json:"price"` // 快照单价
|
|
Quantity int `json:"quantity"`
|
|
TotalAmount float64 `json:"total_amount"` // 小计
|
|
}
|
|
|
|
// ========== 表名定义 ==========
|
|
|
|
func (PointsRecord) TableName() string {
|
|
return "points_records"
|
|
}
|
|
|
|
func (ProductCategory) TableName() string {
|
|
return "product_categories"
|
|
}
|
|
|
|
// Product TableName 在 product.go 中定义
|
|
|
|
func (ProductSku) TableName() string {
|
|
return "product_skus"
|
|
}
|
|
|
|
func (CartItem) TableName() string {
|
|
return "cart_items"
|
|
}
|
|
|
|
func (Address) TableName() string {
|
|
return "addresses"
|
|
}
|
|
|
|
func (Order) TableName() string {
|
|
return "orders"
|
|
}
|
|
|
|
func (OrderItem) TableName() string {
|
|
return "order_items"
|
|
}
|
|
|