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

93 lines
5.8 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
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. "time"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. const CustomerOrderTableName = TableNamePrefix + "customer_order"
  7. type CustomerOrder struct {
  8. Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
  9. IsDelete bool `json:"is_delete" xorm:"not null default 0 comment('软删除') TINYINT(1)"`
  10. CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
  11. UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
  12. UserPrizeId int64 `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
  13. ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
  14. ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
  15. AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
  16. AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(255)"`
  17. RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') BIGINT(20)"`
  18. OrderNo string `json:"order_no" xorm:"not null default 0 comment('本机订单号') VARCHAR(255)"`
  19. OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('微信订单流水号') VARCHAR(255)"`
  20. OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
  21. BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
  22. GoodsId int64 `json:"goods_id,omitempty" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
  23. GoodsName string `json:"goods_name,omitempty" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
  24. GoodsNum int `json:"goods_num,omitempty" xorm:"not null default 0 comment('商品数量') INT(11)"`
  25. TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额')"`
  26. PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额')"`
  27. Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]')"`
  28. Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付即待发货3已发货4确认收货5申请退款6已退款7申请退货8已退货9已取消]')"`
  29. ExpireTime int64 `json:"expire_time" xorm:"not null default 0 comment('订单过时') INT(11)"`
  30. Type int `json:"type" xorm:"not null default 0 comment('订单类型、0录入订单1直播订单')"`
  31. // 快递信息
  32. Receiver string `json:"receiver" xorm:"not null default '' comment('收件人') VARCHAR(128)"`
  33. Address string `json:"address" xorm:"not null default '' comment('收件人地址') VARCHAR(255)"`
  34. Phone string `json:"phone" xorm:"not null default '' comment('收件人电话') VARCHAR(128)"`
  35. IsDrawCash int `json:"is_draw_cash" xorm:"not null default 0 comment('订单是否提取贷款0否1是') TINYINT(1)"`
  36. ExpressId int `json:"express_id" xorm:"not null default '0' comment('快递公司名字') INT(11)"`
  37. ExpressName string `json:"express_name" xorm:"not null default '' comment('快递名字') VARCHAR(128)"`
  38. ExpressNo string `json:"express_no" xorm:"not null default '' comment('快递单号') VARCHAR(128)"`
  39. CancelTime time.Time `json:"cancel_time" xorm:"comment('取消时间') DATETIME"`
  40. AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"`
  41. // 无关变量
  42. OrderTime string `json:"order_time,omitempty" xorm:"-"`
  43. Good *CustomerGoods `json:"good,omitempty" xorm:"-"`
  44. User *User `json:"user,omitempty" xorm:"-"`
  45. OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"`
  46. ServicePhone string `json:"service_phone" xorm:"-"`
  47. //SubOrders []*CustomerOrderSub `json:"sub_orders" xorm:"-"`
  48. SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"`
  49. }
  50. func (t *CustomerOrder) TableName() string {
  51. return CustomerOrderTableName
  52. }
  53. func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) {
  54. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
  55. }
  56. func (t *CustomerOrder) Count(activityId, rehearsalId int64, limitTime time.Time, archId interface{}) (int64, error) {
  57. return core.GetXormAuto().Where("user_prize_id=0 and created_at >= ? and "+
  58. "activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  59. limitTime, activityId, rehearsalId, archId).Count(t)
  60. }
  61. func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int64, status []string, page, pageSize int, archId interface{}) ([]*CustomerOrder, error) {
  62. orders := make([]*CustomerOrder, 0)
  63. err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+
  64. "rehearsal_id=? and area_id=? and arch_id=?", userId, activityId, rehearsalId, areaId, archId).
  65. In("status", status).Desc("created_at").Limit(pageSize, page*pageSize).Find(&orders)
  66. return orders, err
  67. }
  68. func (t *CustomerOrder) UpdateStatusBy(outTradeNo string, originStatus, status int) (int64, error) {
  69. t.Status = status
  70. return core.GetXormAuto().Where("is_delete=0 and status=? and out_trade_no=?",
  71. originStatus, outTradeNo).Cols("status, cancel_time").Update(t)
  72. }
  73. func GetExpiredAtLiveCustomerOrder() ([]*CustomerOrder, error) {
  74. orders := make([]*CustomerOrder, 0)
  75. err := core.GetXormAuto().Where("type=1 and is_delete=0 and status=0 and expire_time <= ? and out_trade_no<>''", time.Now().Unix()).Find(&orders)
  76. if err != nil {
  77. return nil, err
  78. }
  79. return orders, nil
  80. }