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

99 lines
2.6 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
  1. package pay_service
  2. import (
  3. "errors"
  4. "hudongzhuanjia/libs/im"
  5. "hudongzhuanjia/models"
  6. im_service "hudongzhuanjia/services/im"
  7. "time"
  8. )
  9. //处理支付成功之后的回调问题
  10. // 直播红包
  11. func Handle(order *models.UserOrder) error {
  12. if order == nil {
  13. return errors.New("订单信息不存在")
  14. }
  15. if order.GoodType == 4 { // 直播商品
  16. customerOrder := new(models.CustomerOrder)
  17. //exist, err := customerOrder.GetByOutTradeNO(order.OutTradeNo)
  18. //if err != nil || !exist {
  19. // return errors.New("直播商品信息异常")
  20. //}
  21. if customerOrder.Status == 1 {
  22. return errors.New("商品已经支付")
  23. }
  24. _, err := customerOrder.UpdateStatusBy(order.OutTradeNo, 0, 1)
  25. if err != nil {
  26. return errors.New("更新状态发送错误")
  27. }
  28. //activity := new(models.Activity)
  29. //exist, err = models.GetById(activity, order.ActivityId)
  30. //if err != nil || !exist {
  31. // return errors.New("互动信息异常")
  32. //}
  33. //
  34. //gift := new(models.OrderGift)
  35. //exist, err = gift.GetByActivityId(order.ActivityId)
  36. //if err != nil {
  37. // return err
  38. //}
  39. //
  40. //prize := new(models.UserPrize)
  41. //prize.UserId = order.UserId
  42. //prize.ActivityId = order.ActivityId
  43. //prize.RehearsalId = activity.RehearsalId
  44. //prize.ActivityName = activity.Name
  45. //prize.PrizeName = gift.GiftName
  46. //prize.PrizeImg = gift.GiftPicUrl
  47. //prize.PrizeType = 4
  48. //prize.IsDelete = false
  49. //prize.CreatedAt = time.Now()
  50. //prize.UpdatedAt = time.Now()
  51. //if exist {
  52. // if gift.Num < 0 {
  53. // } else if gift.Num > 0 {
  54. // count, err := new(models.CustomerOrder).
  55. // Count(activity.Id, activity.RehearsalId, customerOrder.CreatedAt)
  56. // if err != nil {
  57. // return err
  58. // }
  59. //
  60. // if gift.Num <= int(count) { // 人数足够
  61. // return nil
  62. // }
  63. // }
  64. // // gift.Num = 0 and
  65. // _, err = prize.Add()
  66. // if err != nil {
  67. // return err
  68. // }
  69. //}
  70. } else if order.GoodType == 3 { // 直播红包
  71. info := new(models.LiveRedEnvelopeRule)
  72. exist, err := info.GetByOutTradeNo(order.OutTradeNo)
  73. if err != nil || !exist {
  74. return errors.New("直播红包信息异常")
  75. }
  76. return im_service.SendNoticeByActivityId(order.ActivityId, im.NoticeLiveRedPackStart,
  77. map[string]interface{}{
  78. "live_red_envelope_rule_id": info.Id,
  79. "timestamp": time.Now().Unix(),
  80. })
  81. } else if order.GoodType == 2 { // 打赏
  82. history := new(models.RewardHistory)
  83. _, err := history.UpdateStatusByOutTradeNo(order.OutTradeNo, 0)
  84. return err
  85. } else if order.GoodType == 1 { // 霸屏
  86. history := new(models.BullyScreenHistory)
  87. _, err := history.UpdateStatusByOutTradeNo(order.OutTradeNo, 0)
  88. return err
  89. }
  90. return nil
  91. }