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

112 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
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.MustGetInt("activity_id")
  18. content := t.MustGet("content")
  19. amount := t.MustGetDouble("amount")
  20. uid := t.GetAccountId()
  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, int(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. ArchId: activity.ArchId,
  58. RewardServerId: rewardServer.Id,
  59. CustomerId: activity.CustomerId,
  60. UserId: user.Id,
  61. Amount: amount,
  62. Content: content,
  63. RehearsalId: activity.RehearsalId,
  64. Status: -1,
  65. ReviewTime: 0,
  66. ExpireTime: expireAt,
  67. Type: _type,
  68. }
  69. if activity.RehearsalId != 0 && _type == 0 { // 线下h5彩排不需要支付
  70. history.Status = 0
  71. }
  72. _, err = models.Add(&history)
  73. t.CheckErr(err)
  74. res["rehearsal_id"] = activity.RehearsalId
  75. t.JSON(res)
  76. }
  77. func (t *RewardCtl) List() {
  78. uid := t.GetAccountId()
  79. activityId := t.MustGetInt("activity_id")
  80. activity := new(models.Activity)
  81. exist, err := models.Get(activity, activityId)
  82. t.CheckErr(err)
  83. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  84. rs := new(models.RewardServer)
  85. exist, err = rs.GetByActivityId(activityId)
  86. t.CheckErr(err)
  87. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  88. list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id, activity.ArchId)
  89. t.CheckErr(err)
  90. t.JSON(map[string]interface{}{
  91. "total": len(list),
  92. "list": list,
  93. })
  94. }