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

119 lines
6.7 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
4 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
4 years ago
5 years ago
4 years ago
4 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 int `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 int `json:"user_prize_id" xorm:"not null default 0 comment('用户奖品id') INT(11)"`
  13. ActivityId int `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 int `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 int `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 int `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') INT(11)"`
  21. OrderEntryPersonName string `json:"order_entry_person_name" xorm:"not null default '' comment('订单录入人员名字') INT(11)"`
  22. BuyerId int `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
  23. TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额')"`
  24. PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额')"`
  25. Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]')"`
  26. Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付即待发货3已发货4确认收货5申请退款6已退款7申请退货8已退货9已取消]')"`
  27. ExpireTime int64 `json:"expire_time" xorm:"not null default 0 comment('订单过时') INT(11)"`
  28. Type int `json:"type" xorm:"not null default 0 comment('订单类型、0录入订单1直播订单')"`
  29. // 快递信息
  30. Receiver string `json:"receiver" xorm:"not null default '' comment('收件人') VARCHAR(128)"`
  31. Address string `json:"address" xorm:"not null default '' comment('收件人地址') VARCHAR(255)"`
  32. Phone string `json:"phone" xorm:"not null default '' comment('收件人电话') VARCHAR(128)"`
  33. IsDrawCash int `json:"is_draw_cash" xorm:"not null default 0 comment('订单是否提取贷款0否1是') TINYINT(1)"`
  34. ExpressId int `json:"express_id" xorm:"not null default '0' comment('快递公司名字') INT(11)"`
  35. ExpressName string `json:"express_name" xorm:"not null default '' comment('快递名字') VARCHAR(128)"`
  36. ExpressNo string `json:"express_no" xorm:"not null default '' comment('快递单号') VARCHAR(128)"`
  37. CancelTime time.Time `json:"cancel_time" xorm:"comment('取消时间') DATETIME"`
  38. AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"`
  39. GoodsId int `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
  40. GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
  41. GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
  42. // 无关变量
  43. OrderTime string `json:"order_time,omitempty" xorm:"-"`
  44. Good *CustomerGoods `json:"good,omitempty" xorm:"-"`
  45. User *User `json:"user,omitempty" xorm:"-"`
  46. ServicePhone string `json:"service_phone" xorm:"-"`
  47. SubOrders []*SubOrderResult `json:"sub_orders,omitempty" xorm:"-"`
  48. }
  49. func (t *CustomerOrder) TableName() string {
  50. return CustomerOrderTableName
  51. }
  52. func (t *CustomerOrder) Alias(name string) string {
  53. return Alias(t, name)
  54. }
  55. func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) {
  56. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
  57. }
  58. func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int, status []string, page, pageSize int, archId interface{}) ([]*CustomerOrder, error) {
  59. orders := make([]*CustomerOrder, 0)
  60. err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+
  61. "rehearsal_id=? and area_id=? and arch_id=?", userId, activityId, rehearsalId, areaId, archId).
  62. In("status", status).Desc("created_at").Limit(pageSize, page*pageSize).Find(&orders)
  63. return orders, err
  64. }
  65. func (t *CustomerOrder) UpdateStatusBy(outTradeNo string, originStatus, status int) (int64, error) {
  66. t.Status = status
  67. return core.GetXormAuto().Where("is_delete=0 and status=? and out_trade_no=?",
  68. originStatus, outTradeNo).Cols("status, cancel_time").Update(t)
  69. }
  70. func GetExpiredAtLiveCustomerOrder() ([]*CustomerOrder, error) {
  71. orders := make([]*CustomerOrder, 0)
  72. err := core.GetXormAuto().Where("type=1 and is_delete=0 and "+
  73. "status=0 and expire_time <= ? and out_trade_no<>''", time.Now().Unix()).Find(&orders)
  74. if err != nil {
  75. return nil, err
  76. }
  77. return orders, nil
  78. }
  79. func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId interface{}, _type int) (int64, error) {
  80. s := core.GetXormAuto().NoAutoCondition().
  81. Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
  82. activityId, rehearsalId, archId)
  83. defer s.Close()
  84. if _type == 1 {
  85. s.Distinct("buyer_id")
  86. }
  87. count, err := s.Count(t)
  88. return count, err
  89. }
  90. func (t *CustomerOrder) SumCustomerOrder(activityId, rehearsalId, archId interface{}, limit int) ([]map[string]string, error) {
  91. res := make([]map[string]string, 0)
  92. err := core.GetXormAuto().Table(t).Select("order_entry_person_id, order_entry_person_name, COALESCE(SUM(goods_num), 0) as num").
  93. NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
  94. activityId, rehearsalId, archId).GroupBy("order_entry_person_id,order_entry_person_name").Limit(limit).
  95. Desc("num").Find(&res)
  96. return res, err
  97. }
  98. func (t *CustomerOrder) TotalCustomerOrderGoodsNum(activityId, rehearsalId, archId interface{}) (int64, error) {
  99. sum, err := core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
  100. activityId, rehearsalId, archId).SumInt(t, "goods_num")
  101. return sum, err
  102. }