order.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package request
  2. import (
  3. "gorm.io/gorm"
  4. pb "sghgogs.com/micro/shopping-service/proto"
  5. "time"
  6. )
  7. // Created 创建 订单被创建,但尚未进行任何处理
  8. // Pending Payment 待付款 客户已创建订单,但尚未完成支付
  9. // Paid 已付款 订单支付已成功,等待商家确认
  10. // Processing 处理中 商家已确认订单,并开始处理订单中的商品。
  11. // Shipped 发货中 商品已从商家发货,运送中
  12. // Completed 已完 订单已经成功交付,交易完成。
  13. // Canceled 已取消 订单被取消,交易终止。
  14. // Refund in Progress 退款中 客户请求退款,正在处理中。
  15. // Refunded 已退款 退款已完成,交易终止
  16. // Return in Progress 退货中 客户请求退货,正在处理中
  17. // Returned 已退货 退货已完成,交易终止。
  18. // Under Review 审核中 订单或支付信息正在被审核。
  19. // Order 订单表模型
  20. type Order struct {
  21. ID int64 `gorm:"primary_key;not_null;auto_increment;" json:"id"`
  22. UserID int64 `gorm:"not null" json:"user_id"`
  23. User User `gorm:"foreignKey:UserID" json:"user"`
  24. AddressID int64 `gorm:"not null" json:"address_id"`
  25. Address Address `gorm:"foreignKey:AddressID" json:"address"`
  26. TotalAmount int32 `json:"total_amount"` // 订单总金额
  27. Status pb.OrderStatusEnum `json:"status"` // 订单状态
  28. PaymentMethod pb.PaymentMethodEnum `json:"payment_method"` // 支付方式
  29. OrderItems []OrderItem `gorm:"foreignKey:OrderID" comment:"订单项列表" json:"order_items"`
  30. Payment Payment `gorm:"foreignKey:OrderID" json:"payment"`
  31. CreatedAt time.Time `json:"created_at"`
  32. UpdatedAt *time.Time `json:"updated_at"`
  33. OrderDate gorm.DeletedAt
  34. }
  35. type OrderItem struct {
  36. ID int64 `gorm:"primary_key;not_null;auto_increment;" json:"id"`
  37. OrderID int64 `gorm:"not null" json:"order_id" comment:"订单ID"`
  38. Order Order `gorm:"foreignKey:OrderID" comment:"关联的订单" json:"order"`
  39. ProductID int64 `gorm:"not null" json:"product_id" comment:"商品ID"`
  40. Product Product `gorm:"foreignKey:ProductID" json:"product" comment:"关联的商品"`
  41. Quantity int64 `json:"quantity" comment:"商品数量"`
  42. Subtotal int64 `json:"subtotal" comment:"订单项小计"`
  43. CreatedAt time.Time `json:"created_at"`
  44. UpdatedAt *time.Time `json:"updated_at"`
  45. }