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

110 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
  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. res["out_trade_no"] = ""
  48. if activity.RehearsalId == 0 || _type == 1 { // 直播不用彩排
  49. res, err = pay_service.UnifiedOrder("欧轩互动-打赏支付", user.Openid, int64(amount*100), 2,
  50. user.Id, activityId, time.Now().Add(1*time.Hour).Unix())
  51. t.CheckErr(err)
  52. }
  53. history := models.RewardHistory{
  54. OutTradeNo: res["out_trade_no"].(string),
  55. ActivityId: activityId,
  56. RewardServerId: rewardServer.Id,
  57. CustomerId: activity.CustomerId,
  58. UserId: user.Id,
  59. Amount: amount,
  60. Content: content,
  61. RehearsalId: activity.RehearsalId,
  62. Status: -1,
  63. ReviewTime: 0,
  64. ExpireTime: time.Now().Add(24 * time.Hour).Unix(),
  65. Type: _type,
  66. }
  67. if activity.RehearsalId != 0 && _type == 0 { // 线下h5彩排不需要支付
  68. history.Status = 0
  69. }
  70. _, err = models.Add(&history)
  71. t.CheckErr(err)
  72. res["rehearsal_id"] = activity.RehearsalId
  73. t.JSON(res)
  74. }
  75. func (t *RewardCtl) List() {
  76. uid := t.MustGetUID()
  77. activityId := t.MustGetInt64("activity_id")
  78. activity := new(models.Activity)
  79. exist, err := models.Get(activity, activityId)
  80. t.CheckErr(err)
  81. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  82. rs := new(models.RewardServer)
  83. exist, err = rs.GetByActivityId(activityId)
  84. t.CheckErr(err)
  85. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  86. list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id)
  87. t.CheckErr(err)
  88. t.JSON(map[string]interface{}{
  89. "total": len(list),
  90. "list": list,
  91. })
  92. }