Files
sale/backend/internal/models/order.go
T
admin 33f5d242e9 feat: 商品添加克重字段,订单添加通道费,运费按重量计算
- 商品模型: 添加weight字段(克重)
- 订单模型: 添加channel_fee字段(支付通道费)
- 后台商品管理: 添加克重输入框
- 后台订单详情: 显示通道费
- 订单创建: 根据商品重量计算运费,添加通道费计算
- 购物车: 根据商品重量计算运费,显示通道费

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 20:01:45 +08:00

73 lines
2.9 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type Order struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"`
SupplierID *uint `gorm:"index" json:"supplier_id"`
Subtotal float64 `gorm:"type:decimal(10,2);not null" json:"subtotal"`
ShippingFee float64 `gorm:"type:decimal(10,2);default:0" json:"shipping_fee"`
ServiceFee float64 `gorm:"type:decimal(10,2);default:0" json:"service_fee"`
Tax float64 `gorm:"type:decimal(10,2);default:0" json:"tax"`
ChannelFee float64 `gorm:"type:decimal(10,2);default:0" json:"channel_fee"` // 支付通道费
TotalAmount float64 `gorm:"type:decimal(10,2);not null" json:"total_amount"`
RefundAmount *float64 `gorm:"type:decimal(10,2)" json:"refund_amount"`
RefundStatus string `gorm:"size:20" json:"refund_status"`
RefundReason string `json:"refund_reason"`
Status string `gorm:"size:20;not null;default:'pending_payment'" json:"status"`
ShippingAddressID *uint `json:"shipping_address_id"`
TrackingNumber string `gorm:"size:100" json:"tracking_number"`
ShippingPhoto string `gorm:"type:text" json:"shipping_photo"`
ExpressPhoto string `gorm:"type:text" json:"express_photo"`
CustomsPhoto string `gorm:"type:text" json:"customs_photo"`
PaymentMethod string `gorm:"size:50" json:"payment_method"`
PaymentExpiresAt *time.Time `json:"payment_expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
OrderItems []OrderItem `json:"order_items,omitempty"`
ShippingAddress *Address `json:"shipping_address,omitempty"`
User User `json:"user,omitempty"`
}
func (Order) TableName() string {
return "orders"
}
type OrderItem struct {
ID uint `gorm:"primaryKey" json:"id"`
OrderID uint `gorm:"index;not null" json:"order_id"`
ProductID uint `gorm:"index;not null" json:"product_id"`
Quantity int `gorm:"not null" json:"quantity"`
Price float64 `gorm:"type:decimal(10,2);not null" json:"price"`
Product Product `json:"product,omitempty"`
}
func (OrderItem) TableName() string {
return "order_items"
}
const (
OrderStatusPendingPayment = "pending_payment"
OrderStatusPendingConfirm = "pending_confirm"
OrderStatusPendingShip = "pending_ship"
OrderStatusShipped = "shipped"
OrderStatusCompleted = "completed"
OrderStatusRefunding = "refunding"
OrderStatusRefunded = "refunded"
OrderStatusCancelled = "cancelled"
)
const (
RefundStatusNone = ""
RefundStatusPending = "pending"
RefundStatusApproved = "approved"
RefundStatusRejected = "rejected"
RefundStatusCompleted = "completed"
)