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

188 lines
4.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
  1. package pc
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. bully_reward_service "hudongzhuanjia/services/bully_reward"
  7. im_service "hudongzhuanjia/services/im"
  8. "hudongzhuanjia/services/pay"
  9. "hudongzhuanjia/utils"
  10. "hudongzhuanjia/utils/code"
  11. "strings"
  12. "time"
  13. )
  14. type RewardCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. //获取最新的打赏记录
  18. func (t *RewardCtl) Latest() {
  19. activityId := t.MustGetInt64("activity_id")
  20. rehearsalId := t.MustGetInt64("rehearsal_id")
  21. //获取打赏服务得id
  22. server := new(models.RewardServer)
  23. exist, err := server.GetByActivityId(activityId)
  24. t.CheckErr(err)
  25. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  26. result, err := bully_reward_service.GetRewardLatest(server.Id, rehearsalId)
  27. t.CheckErr(err)
  28. if result == nil || result.Id == 0 {
  29. t.JSON(result)
  30. }
  31. result.User.Openid = ""
  32. result.User.Unionid = ""
  33. result.RewardHistory.RewardAmount = fmt.Sprintf("%.2f", result.RewardHistory.Amount)
  34. t.CheckErr(models.Save(map[string]interface{}{
  35. "id=": result.RewardHistory.Id,
  36. }, &models.RewardHistory{
  37. Status: 3,
  38. UpdatedAt: time.Now(),
  39. }, "status", "update_at"))
  40. t.JSON(result)
  41. }
  42. //获取待审核列表
  43. func (t *RewardCtl) WaitReview() {
  44. activityId := t.MustGetInt64("activity_id")
  45. rehearsalId := t.MustGetInt64("rehearsal_id")
  46. //获取打赏服务得id
  47. server := new(models.RewardServer)
  48. exist, err := server.GetByActivityId(activityId)
  49. t.CheckErr(err)
  50. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  51. //// todo: 检查订单
  52. //t.CheckErr(bully_reward_service.CheckRewardStatus(server.Id))
  53. result, err := bully_reward_service.GetRewardReview(server.Id, rehearsalId)
  54. t.CheckErr(err)
  55. //根据打赏服务得id获取待审核得打赏列表
  56. t.JSON(map[string]interface{}{
  57. "total": len(result),
  58. "list": result,
  59. })
  60. }
  61. //审核
  62. func (t *RewardCtl) Review() {
  63. status := t.MustGetBool("status")
  64. ids := strings.Split(t.MustGet("ids"), "|")
  65. uid := t.MustGetUID()
  66. result, err := models.GetRewardHistoryByIds(ids)
  67. t.CheckErr(err)
  68. // 审核
  69. for _, v := range result {
  70. if status { // false 通过 , true 不通过
  71. v.Status = 1
  72. _, err = models.Update(v.Id, v, "status")
  73. t.CheckErr(err)
  74. if v.RehearsalId != 0 && v.Type == 0 { // 彩排不需要金额
  75. continue
  76. }
  77. _, err = pay_service.Refund("欧轩互动-打赏敏感关键字拉黑", v.OutTradeNo)
  78. t.CheckErr(err)
  79. } else {
  80. //增加客户的金额
  81. v.Status = 2
  82. _, err = models.Update(v.Id, v, "status")
  83. t.CheckErr(err)
  84. if v.RehearsalId != 0 && v.Type == 0 { // 线下h5彩排不需要金额
  85. continue
  86. }
  87. go im_service.SendGroupCustomMessage(v.UserId, v.ActivityId, im_service.NoticeReward,
  88. map[string]interface{}{
  89. "amount": v.Amount,
  90. "content": v.Content,
  91. })
  92. wallet := new(models.RewardWallet)
  93. _, err = wallet.IncrBalance(uid, v.Amount)
  94. t.CheckErr(err)
  95. history := models.RewardWalletHistory{
  96. CustomerId: uid,
  97. Money: v.Amount,
  98. Type: "打赏",
  99. UserId: v.UserId,
  100. RewardHistoryId: v.Id,
  101. RewardAccount: v.RewardAmount,
  102. Status: "交易成功",
  103. Mark: "打赏金额",
  104. }
  105. _, err = models.Add(history)
  106. t.CheckErr(err)
  107. }
  108. }
  109. // 发送审核的信息
  110. t.JSON("审核成功")
  111. }
  112. //获取打赏得总金额
  113. func (t *RewardCtl) Amount() {
  114. activityId := t.MustGetInt64("activity_id")
  115. activity := new(models.Activity)
  116. exist, err := models.Get(activity, activityId)
  117. t.CheckErr(err)
  118. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  119. //获取打赏服务得id
  120. server := new(models.RewardServer)
  121. exist, err = server.GetByActivityId(activityId)
  122. t.CheckErr(err)
  123. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  124. totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId)
  125. t.CheckErr(err)
  126. t.DisplayByData(map[string]interface{}{
  127. "amount": utils.Float64CusDecimal(totalAmount, 2),
  128. })
  129. }
  130. // 黑名单
  131. func (t *RewardCtl) Blacklist() {
  132. activityId := t.MustGetInt64("activity_id")
  133. rehearsalId := t.MustGetInt64("rehearsal_id")
  134. // 获取打赏的服务id
  135. server := new(models.RewardServer)
  136. exist, err := server.GetByActivityId(activityId)
  137. t.CheckErr(err)
  138. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  139. // 根据打赏服务id获取待审核的名单
  140. // status=true 代表审核不通过还是通过
  141. // 目前表示不通过,bully_screen也一样
  142. result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
  143. t.CheckErr(err)
  144. t.JSON(map[string]interface{}{
  145. "total": len(result),
  146. "list": result,
  147. })
  148. }
  149. // 开启打赏
  150. func (t *RewardCtl) Details() {
  151. activityId := t.MustGetInt64("activity_id")
  152. server := new(models.RewardServer)
  153. exist, err := server.GetByActivityId(activityId)
  154. t.CheckErr(err)
  155. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  156. t.JSON(map[string]interface{}{
  157. "server": server,
  158. })
  159. }