order.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package order
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxOrderResp struct {
  8. OrderId int `orm:"column(order_id);pk";comment:"订单id"`
  9. OrderCode string `comment:"订单编号"`
  10. OutTradeCode string `comment:"外部交易号"`
  11. PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
  12. GoodsName string `comment:"商品名称"`
  13. GoodsId int `comment:"商品ID"`
  14. BuyerInvoice string `comment:"买家发票信息"`
  15. GoodsMoney float64 `comment:"商品总价"`
  16. OrderMoney float64 `comment:"订单总价"`
  17. Point int `comment:"订单消耗积分"`
  18. PointMoney float64 `comment:"订单消耗积分抵多少钱"`
  19. PayMoney float64 `comment:"订单实付金额"`
  20. RefundMoney float64 `comment:"订单退款金额"`
  21. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  22. PayTime time.Time `comment:"订单付款时间"`
  23. SourceId int `comment:"来源ID"`
  24. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  25. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  26. UserId int `comment:"用户ID"`
  27. Mobile string `comment:"手机号"`
  28. Email string `comment:"邮箱"`
  29. CompanyId int `comment:"公司ID"`
  30. CompanyName string `comment:"公司名称"`
  31. RealName string `comment:"用户实际名称"`
  32. SellerName string `comment:"所属销售"`
  33. CreateTime time.Time `comment:"创建时间"`
  34. ModifyTime time.Time `comment:"修改时间"`
  35. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  36. StartDate time.Time `comment:"开始时间"`
  37. EndDate time.Time `comment:"结束时间"`
  38. }
  39. // 订单表
  40. type CygxOrder struct {
  41. OrderId int `orm:"column(order_id);pk";comment:"订单id"`
  42. OrderCode string `comment:"订单编号"`
  43. OutTradeCode string `comment:"外部交易号"`
  44. PaymentType int `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
  45. GoodsName string `comment:"商品名称"`
  46. GoodsId int `comment:"商品ID"`
  47. BuyerInvoice string `comment:"买家发票信息"`
  48. GoodsMoney float64 `comment:"商品总价"`
  49. OrderMoney float64 `comment:"订单总价"`
  50. Point int `comment:"订单消耗积分"`
  51. PointMoney float64 `comment:"订单消耗积分抵多少钱"`
  52. PayMoney float64 `comment:"订单实付金额"`
  53. RefundTime time.Time `comment:"订单退款时间"`
  54. RefundMoney float64 `comment:"订单退款金额"`
  55. OrderStatus int `comment:"订单状态,0:已取消、1:待支付、2:已支付、3:已退款"`
  56. PayTime time.Time `comment:"订单付款时间"`
  57. SourceId int `comment:"来源ID"`
  58. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  59. SourceTitle string `comment:"来源名称,活动或者报告标题"`
  60. UserId int `comment:"用户ID"`
  61. Mobile string `comment:"手机号"`
  62. Email string `comment:"邮箱"`
  63. CompanyId int `comment:"公司ID"`
  64. CompanyName string `comment:"公司名称"`
  65. RealName string `comment:"用户实际名称"`
  66. SellerName string `comment:"所属销售"`
  67. SellerId int `comment:"所属销售Id"`
  68. CreateTime time.Time `comment:"创建时间"`
  69. ModifyTime time.Time `comment:"修改时间"`
  70. RegisterPlatform int `comment:"来源 1小程序,2:网页"`
  71. OrderType int `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
  72. StartDate time.Time `comment:"开始时间"`
  73. EndDate time.Time `comment:"结束时间"`
  74. }
  75. // 订单操作表
  76. type CygxOrderAction struct {
  77. ActionId int64 `orm:"column(action_id);pk"` // 动作id
  78. Action string // 动作内容
  79. OrderStatus int // 订单状态,0:已取消、1:待支付、2:已支付、3:已退款
  80. OrderStatusText string // 订单状态名称
  81. OrderCode string // 订单编号
  82. UserId int // 用户ID
  83. Mobile string // 手机号
  84. Email string // 邮箱
  85. CompanyId int // 公司ID
  86. CompanyName string // 公司名称
  87. RealName string // 用户实际名称
  88. SellerName string // 所属销售
  89. CreateTime time.Time // 创建时间
  90. ModifyTime time.Time // 修改时间
  91. RegisterPlatform int // 来源 1小程序,2:网页
  92. AdminId int // 管理员ID
  93. AdminName string // 管理员姓名
  94. }
  95. func GetCygxOrderList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxOrder, err error) {
  96. o := orm.NewOrm()
  97. sql := `SELECT *
  98. FROM
  99. cygx_order
  100. WHERE 1 = 1 ` + condition
  101. sql += ` LIMIT ?,? `
  102. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  103. return
  104. }
  105. // 自动取消订单
  106. func CancelCygxOrder(item *CygxOrder) (err error) {
  107. o, err := orm.NewOrm().Begin()
  108. if err != nil {
  109. return
  110. }
  111. defer func() {
  112. fmt.Println(err)
  113. if err == nil {
  114. o.Commit()
  115. } else {
  116. o.Rollback()
  117. }
  118. }()
  119. itemOrderAction := new(CygxOrderAction)
  120. itemOrderAction.Action = "超时自动取消订单"
  121. itemOrderAction.OrderStatus = 0
  122. itemOrderAction.OrderStatusText = "已取消"
  123. itemOrderAction.OrderCode = item.OrderCode
  124. itemOrderAction.UserId = item.UserId
  125. itemOrderAction.Mobile = item.Mobile
  126. itemOrderAction.Email = item.Email
  127. itemOrderAction.CompanyId = item.CompanyId
  128. itemOrderAction.CompanyName = item.CompanyName
  129. itemOrderAction.RealName = item.RealName
  130. itemOrderAction.SellerName = item.SellerName
  131. itemOrderAction.CreateTime = time.Now()
  132. itemOrderAction.ModifyTime = time.Now()
  133. itemOrderAction.RegisterPlatform = item.RegisterPlatform
  134. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  135. if err != nil {
  136. return
  137. }
  138. updateParams := make(map[string]interface{})
  139. updateParams["OrderStatus"] = 0
  140. updateParams["ModifyTime"] = item.ModifyTime
  141. ptrStructOrTableName := "cygx_order"
  142. whereParam := map[string]interface{}{"order_code": item.OrderCode}
  143. qs := o.QueryTable(ptrStructOrTableName)
  144. for expr, exprV := range whereParam {
  145. qs = qs.Filter(expr, exprV)
  146. }
  147. _, err = qs.Update(updateParams)
  148. if err != nil {
  149. return
  150. }
  151. return
  152. }