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

71 lines
3.9 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
  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. AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
  15. AreaName string `json:"area_name" xorm:"not null default '' comment('地区名字') VARCHAR(255)"`
  16. RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/0正式') BIGINT(20)"`
  17. OutTradeNo string `json:"out_trade_no" xorm:"not null default '' comment('订单流水号') VARCHAR(255)"`
  18. OrderEntryPersonId int64 `json:"order_enter_person_id" xorm:"not null default 0 comment('订单录入人员id') BIGINT(20)"`
  19. BuyerId int64 `json:"buyer_id" xorm:"not null default 0 comment('user表id') BIGINT(20)"`
  20. GoodsId int64 `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"`
  21. GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"`
  22. GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"`
  23. TotalAmount float64 `json:"total_amount" xorm:"not null default 0.00 comment('订单总额') DECIMAL(18)"`
  24. PayAmount float64 `json:"pay_amount" xorm:"not null default 0.00 comment('支付金额') DECIMAL(18)"`
  25. Postage float64 `json:"postage" xorm:"not null default 0.00 comment('邮费[0免邮]') DECIMAL(18)"`
  26. Status int `json:"status" xorm:"not null default 0 comment('订单状态[0未支付1已支付2待发货3已发货4确认收货5申请退款6已退款]')"`
  27. // 快递信息
  28. Receiver string `json:"receiver" xorm:"not null default '' comment('收件人') VARCHAR(128)"`
  29. Address string `json:"address" xorm:"not null default '' comment('收件人地址') VARCHAR(255)"`
  30. Phone string `json:"phone" xorm:"not null default '' comment('收件人电话') VARCHAR(128)"`
  31. // 无关变量
  32. OrderTime string `json:"order_time" xorm:"-"`
  33. Good *CustomerGoods `json:"good" xorm:"-"`
  34. User *User `json:"user" xorm:"-"`
  35. OrderEntryPersonName string `json:"order_entry_person_name" xorm:"-"`
  36. }
  37. func (t *CustomerOrder) TableName() string {
  38. return CustomerOrderTableName
  39. }
  40. func (t *CustomerOrder) SoftDeleteById(id int64) (int64, error) {
  41. t.IsDelete = true
  42. return core.GetXormAuto().Where("id=?", id).Cols("is_delete").Update(t)
  43. }
  44. func (t *CustomerOrder) Add() (int64, error) {
  45. return core.GetXormAuto().InsertOne(t)
  46. }
  47. func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) {
  48. return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
  49. }
  50. func (t *CustomerOrder) Count(activityId, rehearsalId int64, limitTime time.Time) (int64, error) {
  51. return core.GetXormAuto().Where("created_at >= ? and activity_id=? and rehearsal_id=? and is_delete=0",
  52. limitTime, activityId, rehearsalId).Count(t)
  53. }
  54. func GetCustomerOrdersByActivityId(activityId, rehearsalId, areaId int64, status int) ([]*CustomerOrder, error) {
  55. orders := make([]*CustomerOrder, 0)
  56. err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=? and area_id=?",
  57. status, activityId, rehearsalId, areaId).Asc("created_at").Find(&orders)
  58. return orders, err
  59. }