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

161 lines
5.0 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
  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. err = im_service.SendGroupCustomMessage(param.Order.ActivityId, im.NoticeLiveRedPackStart,
  87. map[string]interface{}{
  88. "live_red_envelope_rule_id": info.Id,
  89. "prompt": info.Prompt,
  90. "timestamp": time.Now().Unix(),
  91. })
  92. if err != nil {
  93. err = fmt.Errorf("发送腾讯im信息出现错误: err->%v, info_id->%v, out_trade_no->%v",
  94. err, info.Id, param.Order.OutTradeNo)
  95. logger.Error(err.Error())
  96. }
  97. } else if param.Order.GoodType == 2 { // 打赏
  98. history := new(models.RewardHistory)
  99. exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo)
  100. if err != nil || !exist || history.Status != -1 {
  101. err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  102. logger.Error(err.Error())
  103. return
  104. }
  105. _, err = history.UpdateStatus(history.Id, 0)
  106. if err != nil {
  107. err = fmt.Errorf("打赏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  108. logger.Error(err.Error())
  109. }
  110. } else if param.Order.GoodType == 1 { // 霸屏
  111. history := new(models.BullyScreenHistory)
  112. exist, err = history.GetByOutTradeNo(param.Order.OutTradeNo)
  113. if err != nil || !exist || history.Status != -1 {
  114. err = fmt.Errorf("打赏历史异常: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  115. logger.Error(err.Error())
  116. return
  117. }
  118. _, err = history.UpdateStatus(history.Id, 0)
  119. if err != nil {
  120. err = fmt.Errorf("霸屏状态发送变化: err->%v, out_trade_no %v", err, param.Order.OutTradeNo)
  121. logger.Error(err.Error())
  122. }
  123. }
  124. return
  125. }
  126. func HandleFailed(param *orderDelayQueueParam) (err error) {
  127. var exist bool
  128. // 退还库存
  129. if param.Order.GoodType == 4 {
  130. order := new(models.CustomerOrder)
  131. exist, err = order.GetByOutTradeNO(param.Order.OutTradeNo)
  132. if err != nil || !exist {
  133. err = fmt.Errorf("不存在客户订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo)
  134. logger.Error(err.Error())
  135. return
  136. }
  137. subs := make([]*models.CustomerOrderSub, 0)
  138. err = core.GetXormAuto().Where("is_delete=0 and order_no=?", order.OrderNo).Find(&subs)
  139. if err != nil {
  140. err = fmt.Errorf("不存在客户子订单: err-> %v, out_trade_no->%v", err, param.Order.OutTradeNo)
  141. }
  142. for _, sub := range subs {
  143. _, err = core.GetXormAuto().Where("id=?", sub.GoodsId).
  144. Incr("stock", sub.GoodsNum).Update(&models.CustomerGoods{})
  145. if err != nil {
  146. err = fmt.Errorf("库存返回失败: err->%v, out_trade_no->%v, sub_id->%v", err, param.Order.OutTradeNo, sub.Id)
  147. }
  148. }
  149. }
  150. return
  151. }