trade_order.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package order
  2. import (
  3. "eta/eta_mini_ht_api/models"
  4. "gorm.io/gorm"
  5. "time"
  6. )
  7. type PaymentStatus string
  8. type PaymentType string
  9. const (
  10. PaymentStatusPending PaymentStatus = "pending"
  11. PaymentStatusProcessing PaymentStatus = "processing"
  12. PaymentStatusDone PaymentStatus = "done"
  13. PaymentStatusFailed PaymentStatus = "failed"
  14. PaymentTypePay PaymentType = "pay"
  15. PaymentTypeRefund PaymentType = "refund"
  16. )
  17. type TradeOrder struct {
  18. ID int `gorm:"column:id;primaryKey"`
  19. TransactionID string `gorm:"column:transaction_id;type:varchar(255);comment:第三方平台ID"`
  20. ProductOrderID string `gorm:"column:product_order_id;type:varchar(255);comment:商品订单号"`
  21. PaymentAccount string `gorm:"column:payment_account;type:varchar(255);comment:支付账号"`
  22. PaymentWay string `gorm:"column:payment_way;type:enum('wechat');comment:支付渠道"`
  23. Amount string `gorm:"column:amount;type:varchar(20);comment:支付金额"`
  24. Currency string `gorm:"column:currency;type:varchar(255);comment:货币"`
  25. MerchantID string `gorm:"column:merchant_id;type:varchar(255);comment:商户id"`
  26. UserID int `gorm:"column:user_id;type:int(11);comment:用户id"`
  27. TemplateUserID int `gorm:"column:template_user_id;type:int(11);comment:临时用户id"`
  28. PaymentType PaymentType `gorm:"column:payment_type;type:enum('pay','refund');comment:订单类型"`
  29. PaymentStatus PaymentStatus `gorm:"column:payment_status;type:enum('pending','processing','done','failed');comment:支付状态"`
  30. DealTime time.Time `gorm:"column:deal_time;type:datetime;comment:完成时间"`
  31. CreatedTime time.Time `gorm:"column:created_time;type:datetime;comment:创建时间"`
  32. UpdatedTime time.Time `gorm:"column:updated_time;type:datetime;comment:更新时间"`
  33. }
  34. func (to *TradeOrder) TableName() string {
  35. return "trade_orders"
  36. }
  37. func (to *TradeOrder) BeforeCreate(_ *gorm.DB) (err error) {
  38. to.CreatedTime = time.Now()
  39. to.PaymentStatus = PaymentStatusPending
  40. return
  41. }
  42. func GetUnFailedTradeFlowByProductOrder(no string) (list []TradeOrder, err error) {
  43. db := models.Main()
  44. err = db.Where("product_order_id=? and payment_status!=? order by updated_time,created_time desc", no, PaymentStatusFailed).Find(&list).Error
  45. return
  46. }