order_virtual_asset.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package order
  2. //用户虚拟资产表
  3. import (
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. type CygxOrderVirtualAsset struct {
  10. OrderVirtualAssetsId int `orm:"column(order_virtual_assets_id);pk";comment:"订单支付ID"`
  11. OrderCode string `comment:"订单编号"`
  12. UserId int `comment:"用户ID"`
  13. Mobile string `comment:"手机号"`
  14. Email string `comment:"邮箱"`
  15. CompanyId int `comment:"公司ID"`
  16. CompanyName string `comment:"公司名称"`
  17. RealName string `comment:"用户实际名称"`
  18. SellerName string `comment:"所属销售"`
  19. CreateTime time.Time `comment:"创建时间"`
  20. ModifyTime time.Time `comment:"修改时间"`
  21. SourceId int `comment:"来源ID"`
  22. Source string `comment:"来源\n报告 :article\n活动 :activity"`
  23. }
  24. // 添加
  25. func AddCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *CygxOrder) (err error) {
  26. o, err := orm.NewOrm().Begin()
  27. if err != nil {
  28. return
  29. }
  30. defer func() {
  31. fmt.Println(err)
  32. if err == nil {
  33. o.Commit()
  34. } else {
  35. o.Rollback()
  36. }
  37. }()
  38. itemOrderAction := new(CygxOrderAction)
  39. switch itemOrder.TradeType {
  40. case "JSAPI":
  41. itemOrderAction.Action = "公众号支付"
  42. case "NATIVE":
  43. itemOrderAction.Action = "扫码支付"
  44. case "App":
  45. itemOrderAction.Action = "App支付"
  46. case "MICROPAY":
  47. itemOrderAction.Action = "付款码支付"
  48. case "MWEB":
  49. itemOrderAction.Action = "H5支付"
  50. case "FACEPAY":
  51. itemOrderAction.Action = "刷脸支付"
  52. }
  53. itemOrderAction.OrderStatus = 2
  54. itemOrderAction.OrderStatusText = "已支付"
  55. itemOrderAction.OrderCode = item.OrderCode
  56. itemOrderAction.UserId = item.UserId
  57. itemOrderAction.Mobile = item.Mobile
  58. itemOrderAction.Email = item.Email
  59. itemOrderAction.CompanyId = item.CompanyId
  60. itemOrderAction.CompanyName = item.CompanyName
  61. itemOrderAction.RealName = item.RealName
  62. itemOrderAction.SellerName = item.SellerName
  63. itemOrderAction.CreateTime = time.Now()
  64. itemOrderAction.ModifyTime = time.Now()
  65. itemOrderAction.RegisterPlatform = utils.REGISTER_PLATFORM
  66. updateParams := make(map[string]interface{})
  67. updateParams["PayTime"] = itemOrder.PayTime
  68. updateParams["PayMoney"] = itemOrder.PayMoney
  69. updateParams["OrderStatus"] = itemOrder.OrderStatus
  70. updateParams["OutTradeCode"] = itemOrder.OutTradeCode
  71. updateParams["ModifyTime"] = item.ModifyTime
  72. updateParams["PaymentType"] = 1
  73. updateParams["TradeType"] = itemOrder.TradeType
  74. ptrStructOrTableName := "cygx_order"
  75. whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode}
  76. qs := o.QueryTable(ptrStructOrTableName)
  77. for expr, exprV := range whereParam {
  78. qs = qs.Filter(expr, exprV)
  79. }
  80. _, err = qs.Update(updateParams) // 修改订单状态
  81. if err != nil {
  82. return
  83. }
  84. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  85. if err != nil {
  86. return
  87. }
  88. _, err = o.Insert(item) //写入用户用户虚拟资产表
  89. if err != nil {
  90. return
  91. }
  92. return
  93. }
  94. // 获取数量
  95. func GetCygxOrderVirtualAssetdCount(condition string, pars []interface{}) (count int, err error) {
  96. o := orm.NewOrm()
  97. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order_virtual_asset WHERE 1= 1 ` + condition
  98. err = o.Raw(sqlCount, pars).QueryRow(&count)
  99. return
  100. }
  101. // 移除用户活动权限记录
  102. func RemoveCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *CygxOrder) (err error) {
  103. o, err := orm.NewOrm().Begin()
  104. if err != nil {
  105. return
  106. }
  107. defer func() {
  108. fmt.Println(err)
  109. if err == nil {
  110. o.Commit()
  111. } else {
  112. o.Rollback()
  113. }
  114. }()
  115. itemOrderAction := new(CygxOrderAction)
  116. itemOrderAction.Action = "退款成功"
  117. itemOrderAction.OrderStatus = 3
  118. itemOrderAction.OrderStatusText = "已退款"
  119. itemOrderAction.OrderCode = item.OrderCode
  120. itemOrderAction.UserId = item.UserId
  121. itemOrderAction.Mobile = item.Mobile
  122. itemOrderAction.Email = item.Email
  123. itemOrderAction.CompanyId = item.CompanyId
  124. itemOrderAction.CompanyName = item.CompanyName
  125. itemOrderAction.RealName = item.RealName
  126. itemOrderAction.SellerName = item.SellerName
  127. itemOrderAction.CreateTime = time.Now()
  128. itemOrderAction.ModifyTime = time.Now()
  129. itemOrderAction.RegisterPlatform = utils.REGISTER_PLATFORM
  130. updateParams := make(map[string]interface{})
  131. updateParams["OrderStatus"] = itemOrder.OrderStatus
  132. updateParams["ModifyTime"] = item.ModifyTime
  133. ptrStructOrTableName := "cygx_order"
  134. whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode}
  135. qs := o.QueryTable(ptrStructOrTableName)
  136. for expr, exprV := range whereParam {
  137. qs = qs.Filter(expr, exprV)
  138. }
  139. _, err = qs.Update(updateParams) // 修改订单状态
  140. if err != nil {
  141. return
  142. }
  143. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  144. if err != nil {
  145. return
  146. }
  147. //sql := ` DELETE FROM cygx_order_virtual_asset WHERE order_code =? ` // 删除原有的持卡信息 (退款之后不删除相关权益权限)
  148. //_, err = o.Raw(sql, item.OrderCode).Exec()
  149. //if err != nil {
  150. // return
  151. //}
  152. return
  153. }