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

88 lines
2.3 KiB

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. activity := new(models.Activity)
  22. exist, err = models.GetById(activity, order.ActivityId)
  23. if err != nil || !exist {
  24. return errors.New("互动信息异常")
  25. }
  26. gift := new(models.OrderGift)
  27. exist, err = gift.GetByActivityId(order.ActivityId)
  28. if err != nil {
  29. return err
  30. }
  31. prize := new(models.UserPrize)
  32. prize.UserId = order.UserId
  33. prize.ActivityId = order.ActivityId
  34. prize.RehearsalId = activity.RehearsalId
  35. prize.ActivityName = activity.Name
  36. prize.PrizeName = gift.GiftName
  37. prize.PrizeImg = gift.GiftPicUrl
  38. prize.PrizeType = 4
  39. prize.IsDelete = false
  40. prize.CreatedAt = time.Now()
  41. prize.UpdatedAt = time.Now()
  42. if exist {
  43. if gift.Num < 0 {
  44. } else if gift.Num > 0 {
  45. count, err := new(models.CustomerOrder).Count(activity.Id, activity.RehearsalId, customerOrder.CreatedAt)
  46. if err != nil {
  47. return err
  48. }
  49. if gift.Num <= int(count) { // 人数足够
  50. return nil
  51. }
  52. }
  53. // gift.Num = 0 and
  54. _, err = prize.Add()
  55. if err != nil {
  56. return err
  57. }
  58. }
  59. } else if order.GoodType == 3 { // 直播红包
  60. info := new(models.LiveRedEnvelopeRule)
  61. exist, err := info.GetByOutTradeNo(order.OutTradeNo)
  62. if err != nil || !exist {
  63. return errors.New("直播红包信息异常")
  64. }
  65. return im_service.SendNoticeByActivityId(order.ActivityId, im.NoticeLiveRedPackStart,
  66. map[string]interface{}{
  67. "live_red_envelope_rule_id": info.Id,
  68. "timestamp": time.Now().Unix(),
  69. })
  70. } else if order.GoodType == 2 { // 打赏
  71. history := new(models.RewardHistory)
  72. _, err := history.UpdateStatusByOutTradeNo(order.OutTradeNo, 0)
  73. return err
  74. } else if order.GoodType == 1 { // 霸屏
  75. history := new(models.BullyScreenHistory)
  76. _, err := history.UpdateStatusByOutTradeNo(order.OutTradeNo, 0)
  77. return err
  78. }
  79. return nil
  80. }