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

111 lines
2.9 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/libs/filter"
  5. "hudongzhuanjia/models"
  6. bully_reward_service "hudongzhuanjia/services/bully_reward"
  7. pay_service "hudongzhuanjia/services/pay"
  8. "hudongzhuanjia/utils"
  9. "hudongzhuanjia/utils/code"
  10. "time"
  11. )
  12. //打赏
  13. type RewardCtl struct {
  14. controllers.AuthorCtl
  15. }
  16. func (t *RewardCtl) Reward() {
  17. activityId := t.MustGetInt64("activity_id")
  18. content := t.MustGet("content")
  19. amount := t.MustGetDouble("amount")
  20. uid := t.MustGetUID()
  21. _type := t.DefaultInt("type", 0)
  22. if amount <= 0 {
  23. t.ERROR("打赏金额不能小于0", code.MSG_ERR_Param)
  24. return
  25. }
  26. //检查内容是否包含敏感
  27. if ok, _ := filter.Validate(content); !ok {
  28. t.ERROR("内容包含敏感字", code.MSG_ERR)
  29. return
  30. }
  31. activity := new(models.Activity)
  32. exist, err := models.Get(activity, activityId)
  33. t.CheckErr(err)
  34. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  35. //查询该活动的的打赏服务id
  36. rewardServer := new(models.RewardServer)
  37. exist, err = rewardServer.GetByActivityId(activityId)
  38. t.CheckErr(err)
  39. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  40. amount = utils.Float64CusDecimal(amount, 2)
  41. //查询用户信息
  42. user := new(models.User)
  43. exist, err = models.Get(user, uid)
  44. t.CheckErr(err)
  45. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  46. var res = make(map[string]interface{}, 0)
  47. var expireAt = time.Now().Add(24 * time.Hour).Unix()
  48. res["out_trade_no"] = ""
  49. if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
  50. res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2,
  51. user.Id, activityId, expireAt)
  52. t.CheckErr(err)
  53. }
  54. history := models.RewardHistory{
  55. OutTradeNo: res["out_trade_no"].(string),
  56. ActivityId: activityId,
  57. RewardServerId: rewardServer.Id,
  58. CustomerId: activity.CustomerId,
  59. UserId: user.Id,
  60. Amount: amount,
  61. Content: content,
  62. RehearsalId: activity.RehearsalId,
  63. Status: -1,
  64. ReviewTime: 0,
  65. ExpireTime: expireAt,
  66. Type: _type,
  67. }
  68. if activity.RehearsalId != 0 && _type == 0 { // 线下h5彩排不需要支付
  69. history.Status = 0
  70. }
  71. _, err = models.Add(&history)
  72. t.CheckErr(err)
  73. res["rehearsal_id"] = activity.RehearsalId
  74. t.JSON(res)
  75. }
  76. func (t *RewardCtl) List() {
  77. uid := t.MustGetUID()
  78. activityId := t.MustGetInt64("activity_id")
  79. activity := new(models.Activity)
  80. exist, err := models.Get(activity, activityId)
  81. t.CheckErr(err)
  82. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  83. rs := new(models.RewardServer)
  84. exist, err = rs.GetByActivityId(activityId)
  85. t.CheckErr(err)
  86. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  87. list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id)
  88. t.CheckErr(err)
  89. t.JSON(map[string]interface{}{
  90. "total": len(list),
  91. "list": list,
  92. })
  93. }