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

170 lines
5.3 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
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
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 pay_service
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/ouxuanserver/osmanthuswine/src/core"
  6. "hudongzhuanjia/libs/im"
  7. "hudongzhuanjia/logger"
  8. "hudongzhuanjia/models"
  9. im_service "hudongzhuanjia/services/im"
  10. "time"
  11. )
  12. //处理支付成功之后的回调问题
  13. // 直播红包
  14. func HandleSuccess(param *OrderDelayQueueParam) (err error) {
  15. var exist bool
  16. if param.Order.GoodType == 4 { // 直播商品
  17. customerOrder := new(models.CustomerOrder)
  18. //exist, err := customerOrder.GetByOutTradeNO(order.OutTradeNo)
  19. //if err != nil || !exist {
  20. // return errors.New("直播商品信息异常")
  21. //}
  22. if customerOrder.Status == 1 {
  23. return errors.New("商品已经支付")
  24. }
  25. _, err := customerOrder.UpdateStatusBy(param.Order.OutTradeNo, 0, 1)
  26. if err != nil {
  27. return errors.New("更新状态发送错误")
  28. }
  29. //activity := new(models.Activity)
  30. //exist, err = models.GetById(activity, order.ActivityId)
  31. //if err != nil || !exist {
  32. // return errors.New("互动信息异常")
  33. //}
  34. //
  35. //gift := new(models.OrderGift)
  36. //exist, err = gift.GetByActivityId(order.ActivityId)
  37. //if err != nil {
  38. // return err
  39. //}
  40. //
  41. //prize := new(models.UserPrize)
  42. //prize.UserId = order.UserId
  43. //prize.ActivityId = order.ActivityId
  44. //prize.RehearsalId = activity.RehearsalId
  45. //prize.ActivityName = activity.Name
  46. //prize.PrizeName = gift.GiftName
  47. //prize.PrizeImg = gift.GiftPicUrl
  48. //prize.PrizeType = 4
  49. //prize.IsDelete = false
  50. //prize.CreatedAt = time.Now()
  51. //prize.UpdatedAt = time.Now()
  52. //if exist {
  53. // if gift.Num < 0 {
  54. // } else if gift.Num > 0 {
  55. // count, err := new(models.CustomerOrder).
  56. // Count(activity.Id, activity.RehearsalId, customerOrder.CreatedAt)
  57. // if err != nil {
  58. // return err
  59. // }
  60. //
  61. // if gift.Num <= int(count) { // 人数足够
  62. // return nil
  63. // }
  64. // }
  65. // // gift.Num = 0 and
  66. // _, err = prize.Add()
  67. // if err != nil {
  68. // return err
  69. // }
  70. //}
  71. } else if param.Order.GoodType == 3 { // 直播红包
  72. info := new(models.LiveRedEnvelopeRule)
  73. _, err = info.UpdateStatusByOutTradeNo(param.Order.OutTradeNo, 1)
  74. if err != nil {
  75. err = fmt.Errorf("状态改变出现错误: err->%v, out_trade_no->%v", err, param.Order.OutTradeNo)
  76. logger.Error(err.Error())
  77. return
  78. }
  79. exist, err = info.GetByOutTradeNo(param.Order.OutTradeNo)
  80. if err != nil || !exist || info.Status != 1 {
  81. err = fmt.Errorf("直播红包信息异常: err-> %v, exist->%v, status->%v, out_trade_no->%v",
  82. err, exist, info.Status, param.Order.OutTradeNo)
  83. logger.Error(err.Error())
  84. return
  85. }
  86. user := new(models.User)
  87. exist, err = models.GetById(user, info.UserId)
  88. if err != nil || !exist {
  89. err = fmt.Errorf("直播红包用户信息异常: err-> %v, exist->%v, status->%v, out_trade_no->%v",
  90. err, exist, info.Status, param.Order.OutTradeNo)
  91. logger.Error(err.Error())
  92. return
  93. }
  94. err = im_service.SendGroupCustomMessage(fmt.Sprint(info.UserId), param.Order.ActivityId, im.NoticeLiveRedPackStart,
  95. map[string]interface{}{
  96. "live_red_envelope_rule_id": info.Id,
  97. "prompt": info.Prompt,
  98. "timestamp": time.Now().Unix(),
  99. })
  100. if err != nil {
  101. err = fmt.Errorf("发送腾讯im信息出现错误: err->%v, info_id->%v, out_trade_no->%v",
  102. err, info.Id, param.Order.OutTradeNo)
  103. logger.Error(err.Error())
  104. }
  105. } else if param.Order.GoodType == 2 { // 打赏
  106. history := new(models.RewardHistory)
  107. exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo)
  108. if err != nil || !exist || history.Status != -1 {
  109. err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  110. logger.Error(err.Error())
  111. return
  112. }
  113. _, err = history.UpdateStatus(history.Id, 0)
  114. if err != nil {
  115. err = fmt.Errorf("打赏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  116. logger.Error(err.Error())
  117. }
  118. } else if param.Order.GoodType == 1 { // 霸屏
  119. history := new(models.BullyScreenHistory)
  120. exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo)
  121. if err != nil || !exist || history.Status != -1 {
  122. err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  123. logger.Error(err.Error())
  124. return
  125. }
  126. _, err = history.UpdateStatus(history.Id, 0)
  127. if err != nil {
  128. err = fmt.Errorf("霸屏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  129. logger.Error(err.Error())
  130. }
  131. }
  132. return
  133. }
  134. func HandleFailed(param *OrderDelayQueueParam) (err error) {
  135. var exist bool
  136. // 退还库存
  137. if param.Order.GoodType == 4 {
  138. order := new(models.CustomerOrder)
  139. exist, err = order.GetByOutTradeNO(param.Order.OutTradeNo)
  140. if err != nil || !exist {
  141. err = fmt.Errorf("不存在客户订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo)
  142. logger.Error(err.Error())
  143. return
  144. }
  145. subs := make([]*models.CustomerOrderSub, 0)
  146. err = core.GetXormAuto().Where("is_delete=0 and order_no=?", order.OrderNo).Find(&subs)
  147. if err != nil {
  148. err = fmt.Errorf("不存在客户子订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo)
  149. }
  150. for _, sub := range subs {
  151. _, err = core.GetXormAuto().Where("id=?", sub.GoodsId).
  152. Incr("stock", sub.GoodsNum).Update(&models.CustomerGoods{})
  153. if err != nil {
  154. err = fmt.Errorf("库存返回失败: err->%v, out_trade_no->%v, sub_id->%v", err, param.Order.OutTradeNo, sub.Id)
  155. }
  156. }
  157. }
  158. return
  159. }