order_refund.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxOrderRefund struct {
  7. //OrderRefundID uint64 `description:"主键id"`
  8. OrderRefundId int `orm:"column(order_refund_id);pk";comment:"主键id"`
  9. OrderCode string `description:"订单编号"`
  10. RefundTradeCode string `description:"退款交易号"`
  11. RefundMoney float64 `description:"退款金额"`
  12. RefundWay int `description:"退款方式(1:微信商户,2:支付宝商户,3:线下)"`
  13. RefundTime time.Time `description:"退款时间"`
  14. Remark string `description:"备注"`
  15. CreateTime time.Time `description:"创建时间"`
  16. AdminId int `description:"管理员ID"`
  17. AdminName string `description:"管理员姓名"`
  18. }
  19. type CygxOrderRefundReq struct {
  20. OrderCode string `description:"订单编号"`
  21. Remark string `description:"备注"`
  22. }
  23. // 添加CygxOrderRefund
  24. func AddCygxOrderRefund(item *CygxOrderRefund, orderStatus int) (err error) {
  25. to := orm.NewOrmUsingDB("hz_cygx")
  26. o, err := to.Begin()
  27. if err != nil {
  28. return
  29. }
  30. defer func() {
  31. if err != nil {
  32. _ = o.Rollback()
  33. } else {
  34. _ = o.Commit()
  35. }
  36. }()
  37. updateParams := make(map[string]interface{})
  38. updateParams["OrderStatus"] = orderStatus
  39. updateParams["RefundMoney"] = item.RefundMoney
  40. updateParams["RefundRemark"] = item.Remark
  41. updateParams["RefundTime"] = time.Now()
  42. ptrStructOrTableName := "cygx_order"
  43. whereParam := map[string]interface{}{"order_code": item.OrderCode}
  44. qs := o.QueryTable(ptrStructOrTableName)
  45. for expr, exprV := range whereParam {
  46. qs = qs.Filter(expr, exprV)
  47. }
  48. _, err = qs.Update(updateParams)
  49. if err != nil {
  50. return
  51. }
  52. _, err = o.Insert(item)
  53. return
  54. }