互动
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.

83 lines
4.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const UserOrderTableName = TableNamePrefix + "user_order"
  7. type UserOrder struct {
  8. Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
  9. IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINYINT(1)" description:"是否删除"`
  10. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME" description:"创建时间"`
  11. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME" description:"更新时间"`
  12. // 订单信息
  13. DeviceInfo string `json:"device_info" xorm:"not null default('') comment('设备号') VARCHAR(32)"`
  14. GoodType int64 `json:"good_type" xorm:"not null default(0) comment('1霸屏2打赏3直播红包4商品订单')"`
  15. Body string `json:"body" xorm:"not null default('') comment('') VARCHAR(128)"`
  16. OutTradeNo string `json:"out_trade_no" xorm:"not null default('') comment('商户订单号') VARCHAR(32)"`
  17. FeeType string `json:"fee_type" xorm:"not null default('CNY') comment('货币种类') VARCHAR(16)"`
  18. TotalFee int64 `json:"total_fee" xorm:"not null default(0) comment('订单总金额,单位是分') INT(88)"`
  19. TradeType string `json:"trade_type" xorm:"not null default('JSAPI') comment('交易类型') VARCHAR(16)"`
  20. OpenId string `json:"open_id" xorm:"not null default('') comment('用户标识') VARCHAR(128)"`
  21. UserId int64 `json:"user_id" xorm:"not null default(0) comment('用户id') INT(11)"`
  22. ActivityId int64 `json:"activity_id" xorm:"not null default(0) comment('活动id') INT(11)"`
  23. TransactionId string `json:"transaction_id" xorm:"not null default('') comment('微信支付订单号') VARCHAR(32)"`
  24. TimeStart string `json:"time_start" xorm:"not null default('') comment('交易起始时间') VARCHAR(14)"`
  25. TimeExpire string `json:"time_expire" xorm:"not null default('') comment('交易结束时间') VARCHAR(14)"`
  26. TimeEnd string `json:"time_end" xorm:"not null default('') comment('交易结算时间') VARCHAR(14)"`
  27. PrepayId string `json:"prepay_id" xorm:"not null default('') comment('预支付交易会话标识') VARCHAR(64)"`
  28. Status int `json:"status" xorm:"not null default(0) comment('0尚未支付/支付中1支付成功2已撤销3转入退款4退款成功5支付失败6订单关闭7订单超时') TINYINT(1)"`
  29. ErrMsg string `json:"err_msg" xorm:"not null default '' comment('出现错误') VARCHAR(255)"`
  30. // 退款
  31. SuccessTime time.Time `json:"success_time" xorm:"not null default '' comment('退款成功时间') VARCHAR(20)"`
  32. RefundRecvAccount string `json:"refund_recv_account" xorm:"not null default '' comment('入账账号') VARCHAR(64)"`
  33. RefundAccount string `json:"refund_account" xorm:"not null default '' comment('入账账号') VARCHAR(64)"`
  34. }
  35. func (t *UserOrder) TableName() string {
  36. return UserOrderTableName
  37. }
  38. func (t *UserOrder) AliasName(alias string) string {
  39. return AliasTableName(t, alias)
  40. }
  41. func (t *UserOrder) AddUserOrder() (int64, error) {
  42. return core.GetXormAuto().InsertOne(t)
  43. }
  44. func (t *UserOrder) GetByOutTradeNo(no string) (bool, error) {
  45. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", no).Get(t)
  46. }
  47. func (t *UserOrder) UpdateStatusById(id interface{}) (int64, error) {
  48. return core.GetXormAuto().Where("id=? and is_delete=0", id).
  49. Cols("time_end, transaction_id, status").Update(t)
  50. }
  51. func (t *UserOrder) UpdateStatusByOutTradeNo(outTradeNo interface{}, status int) (int64, error) {
  52. t.Status = status
  53. return core.GetXormAuto().Where("out_trade_no=? and is_delete=0", outTradeNo).
  54. Cols("time_end, transaction_id, status").Update(t)
  55. }
  56. func (t *UserOrder) UpdateErrByOutTradeNo(outTradeNo interface{}) (int64, error) {
  57. return core.GetXormAuto().Where("out_trade_no=? and is_delete=0", outTradeNo).
  58. Cols("err_msg").Update(t)
  59. }
  60. func (t *UserOrder) UpdateRefundByOutTradeNo(outTradeNo interface{}) (int64, error) {
  61. return core.GetXormAuto().Where("out_trade_no=?", outTradeNo).
  62. Cols("success_time", "status", "refund_recv_account", "refund_account").Update(t)
  63. }
  64. func GetUserOrdersByStatus(expire string, status ...int) ([]*UserOrder, error) {
  65. orders := make([]*UserOrder, 0)
  66. err := core.GetXormAuto().Where("is_delete=0 and time_expire <= ?", expire).
  67. In("status", status).Desc("created_at").Find(&orders)
  68. return orders, err
  69. }