order_virtual_asset.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package order
  2. //用户虚拟资产表
  3. import (
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "hongze/hongze_mfyx/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 GetCygxOrderVirtualAssetdCountByVivo(sourceId, userId int) (count int, err error) {
  96. o := orm.NewOrm()
  97. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order_virtual_asset WHERE source IN ('activityvideo','activityvoice') AND source_id = ? AND user_id = ? `
  98. err = o.Raw(sqlCount, sourceId, userId).QueryRow(&count)
  99. return
  100. }
  101. // 获取数量
  102. func GetCygxOrderVirtualAssetdCount(condition string, pars []interface{}) (count int, err error) {
  103. o := orm.NewOrm()
  104. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_order_virtual_asset WHERE 1= 1 ` + condition
  105. err = o.Raw(sqlCount, pars).QueryRow(&count)
  106. return
  107. }
  108. // 移除用户活动权限记录
  109. func RemoveCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *CygxOrder) (err error) {
  110. o, err := orm.NewOrm().Begin()
  111. if err != nil {
  112. return
  113. }
  114. defer func() {
  115. fmt.Println(err)
  116. if err == nil {
  117. o.Commit()
  118. } else {
  119. o.Rollback()
  120. }
  121. }()
  122. itemOrderAction := new(CygxOrderAction)
  123. itemOrderAction.Action = "退款成功"
  124. itemOrderAction.OrderStatus = 3
  125. itemOrderAction.OrderStatusText = "已退款"
  126. itemOrderAction.OrderCode = item.OrderCode
  127. itemOrderAction.UserId = item.UserId
  128. itemOrderAction.Mobile = item.Mobile
  129. itemOrderAction.Email = item.Email
  130. itemOrderAction.CompanyId = item.CompanyId
  131. itemOrderAction.CompanyName = item.CompanyName
  132. itemOrderAction.RealName = item.RealName
  133. itemOrderAction.SellerName = item.SellerName
  134. itemOrderAction.CreateTime = time.Now()
  135. itemOrderAction.ModifyTime = time.Now()
  136. itemOrderAction.RegisterPlatform = utils.REGISTER_PLATFORM
  137. updateParams := make(map[string]interface{})
  138. updateParams["OrderStatus"] = itemOrder.OrderStatus
  139. updateParams["ModifyTime"] = item.ModifyTime
  140. ptrStructOrTableName := "cygx_order"
  141. whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode}
  142. qs := o.QueryTable(ptrStructOrTableName)
  143. for expr, exprV := range whereParam {
  144. qs = qs.Filter(expr, exprV)
  145. }
  146. _, err = qs.Update(updateParams) // 修改订单状态
  147. if err != nil {
  148. return
  149. }
  150. _, err = o.Insert(itemOrderAction) // 写入订单操作信息
  151. if err != nil {
  152. return
  153. }
  154. //sql := ` DELETE FROM cygx_order_virtual_asset WHERE order_code =? ` // 删除原有的持卡信息 (退款之后不删除相关权益权限)
  155. //_, err = o.Raw(sql, item.OrderCode).Exec()
  156. //if err != nil {
  157. // return
  158. //}
  159. return
  160. }