product_order.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type OrderStatus string
  7. type RefundStatus string
  8. type PaymentWay string
  9. const (
  10. //订单状态
  11. OrderStatusPending OrderStatus = "pending"
  12. OrderStatusProcessing OrderStatus = "processing"
  13. OrderStatusPaid OrderStatus = "paid"
  14. OrderStatusClosed OrderStatus = "closed"
  15. OrderStatusRefund OrderStatus = "refund"
  16. //退款状态
  17. RefundStatusSuccess RefundStatus = "success"
  18. RefundStatusPending RefundStatus = "pending"
  19. RefundStatusFailed RefundStatus = "failed"
  20. RefundStatusProcessing RefundStatus = "processing"
  21. WechatPayWay PaymentWay = "wechat"
  22. AliPayWay PaymentWay = "alipay"
  23. detailColumn = "id,order_id,user_id,template_user_id,product_id,status,created_time,updated_time,total_amount"
  24. )
  25. type ProductOrderView struct {
  26. OrderID string
  27. RealName string
  28. Mobile string
  29. ProductType string
  30. ProductName string
  31. TotalAmount string
  32. ValidDuration string
  33. PaymentAmount string
  34. TradeNO string
  35. RefundTradeId string
  36. RefundAmount string
  37. PaymentWay string
  38. PaymentTime string
  39. Status string
  40. RefundStatus string
  41. RefundFinishTime string
  42. Remark string
  43. CreatedTime string
  44. }
  45. type ProductOrder struct {
  46. Id int `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
  47. OrderId string `gorm:"column:order_id;size:255;comment:'订单编号'" json:"order_id"`
  48. UserId int `gorm:"column:user_id;default:null;comment:'用户id'" json:"user_id"`
  49. TemplateUserId int `gorm:"column:template_user_id;default:null;comment:'临时用户id'" json:"template_user_id"`
  50. RealName string `gorm:"column:real_name;default:null;comment:'临时用户id'" json:"real_name"`
  51. AreaCode string `gorm:"column:area_code;default:null;comment:'临时用户id'" json:"area_code"`
  52. Mobile string `gorm:"column:mobile;default:null;comment:'临时用户id'" json:"mobile"`
  53. ProductId int `gorm:"column:product_id;default:null;comment:'产品id'" json:"product_id"`
  54. ProductType MerchantProductType `gorm:"column:product_type;default:null;comment:'产品类型'" json:"product_type"`
  55. ProductName string `gorm:"column:product_name;default:null;comment:'商品名称'" json:"product_name"`
  56. TotalAmount string `gorm:"column:total_amount;size:255;default:null;comment:'金额'" json:"total_amount"`
  57. TradeId int `gorm:"column:trade_id;default:null;comment:'支付订单'" json:"trade_id"`
  58. TradeNo string `gorm:"column:trade_no;default:null;comment:'支付订单'" json:"trade_no"`
  59. RefundTradeId string `column:"refund_trade_id;null;comment:'退款金额'" json:"refund_trade_id"`
  60. RefundAmount string `gorm:"column:refund_amount;size:255;default:null;comment:'退款金额'" json:"refund_amount"`
  61. PaymentAmount string `gorm:"column:payment_amount;size:255;default:null;comment:'支付金额'" json:"payment_amount"`
  62. PaymentWay PaymentWay `gorm:"column:payment_way;enum('wechat','alipay');default:null;comment:'支付渠道'"`
  63. PaymentTime time.Time `gorm:"column:payment_time;default:null;comment:'支付时间'" json:"payment_time"`
  64. ExpiredTime time.Time `gorm:"column:expired_time;default:null;comment:'超时时间'" json:"expired_time"`
  65. Status OrderStatus `gorm:"column:status;type:enum('pending','processing','paid','closed','refund');default:'pending';comment:'订单状态'" json:"status"`
  66. RefundStatus RefundStatus `gorm:"column:refund_status;type:enum('pending','processing','failed','success');default:null;comment:'退款状态'" json:"refund_status"`
  67. RefundFinishTime time.Time `gorm:"column:refund_finish_time;default:null;comment:'退款完成时间'" json:"refund_finish_time"`
  68. ValidDuration string `gorm:"column:valid_duration;default:null;comment:'订单有效期'" json:"valid_duration"`
  69. Remark string `gorm:"column:remark;size:255;default:null;comment:'备注'" json:"remark"`
  70. IsDeleted int `gorm:"column:is_deleted;size:1;default:0;comment:'是否删除'" json:"is_deleted"`
  71. CreatedTime time.Time `gorm:"column:created_time;default:null;comment:'创建时间'" json:"created_time"`
  72. UpdatedTime time.Time `gorm:"column:updated_time;default:null;comment:'更新时间'" json:"updated_time"`
  73. }
  74. func (m *ProductOrder) TableName() string {
  75. return "product_orders"
  76. }
  77. func GetProductOrderByCondition(condition string, sortCondition string, startSize int, pageSize int) (list []*ProductOrder, err error) {
  78. o := orm.NewOrm()
  79. sql := `select * from product_orders where is_deleted=0`
  80. if condition != "" {
  81. sql += condition
  82. }
  83. if sortCondition != "" {
  84. sql += sortCondition
  85. }
  86. sql += ` LIMIT ?,?`
  87. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  88. return
  89. }
  90. func GetProductOrderListByCondition(condition string, sortCondition string) (list []*ProductOrder, err error) {
  91. o := orm.NewOrm()
  92. sql := `select * from product_orders where is_deleted=0`
  93. if condition != "" {
  94. sql += condition
  95. }
  96. if sortCondition != "" {
  97. sql += sortCondition
  98. }
  99. _, err = o.Raw(sql).QueryRows(&list)
  100. return
  101. }
  102. func GetProductOrderCountByCondition(condition string) (total int, err error) {
  103. o := orm.NewOrm()
  104. err = o.Raw("select count(*) from product_orders where is_deleted=0" + condition).QueryRow(&total)
  105. return
  106. }
  107. func GetProductOrderByID(orderNo string) (order *ProductOrder, err error) {
  108. o := orm.NewOrm()
  109. err = o.Raw("select * from product_orders where is_deleted=0 and order_id =?", orderNo).QueryRow(&order)
  110. return
  111. }