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

189 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
  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. rehearsalId := t.MustGetInt64("rehearsal_id")
  66. uid := t.MustGetUID()
  67. result, err := models.GetRewardHistoryByIds(ids)
  68. t.CheckErr(err)
  69. // 审核
  70. for _, v := range result {
  71. if status { // false 通过 , true 不通过
  72. v.Status = 1
  73. _, err = models.Update(v.Id, v, "status")
  74. t.CheckErr(err)
  75. if rehearsalId != 0 { // 彩排不需要金额
  76. continue
  77. }
  78. _, err = pay_service.Refund("欧轩互动-打赏拉黑", v.OutTradeNo)
  79. t.CheckErr(err)
  80. } else {
  81. //增加客户的金额
  82. v.Status = 2
  83. _, err = models.Update(v.Id, v, "status")
  84. t.CheckErr(err)
  85. if rehearsalId != 0 && v.Type == 0 { // 线下h5彩排不需要金额
  86. continue
  87. }
  88. go im_service.SendGroupCustomMessage(v.UserId, v.ActivityId, im_service.NoticeReward,
  89. map[string]interface{}{
  90. "amount": v.Amount,
  91. "content": v.Content,
  92. })
  93. wallet := new(models.RewardWallet)
  94. _, err = wallet.IncrBalance(uid, v.Amount)
  95. t.CheckErr(err)
  96. history := models.RewardWalletHistory{
  97. CustomerId: uid,
  98. Money: v.Amount,
  99. Type: "打赏",
  100. UserId: v.UserId,
  101. RewardHistoryId: v.Id,
  102. RewardAccount: v.RewardAmount,
  103. Status: "交易成功",
  104. Mark: "打赏金额",
  105. }
  106. _, err = models.Add(history)
  107. t.CheckErr(err)
  108. }
  109. }
  110. // 发送审核的信息
  111. t.JSON("审核成功")
  112. }
  113. //获取打赏得总金额
  114. func (t *RewardCtl) Amount() {
  115. activityId := t.MustGetInt64("activity_id")
  116. activity := new(models.Activity)
  117. exist, err := models.Get(activity, activityId)
  118. t.CheckErr(err)
  119. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  120. //获取打赏服务得id
  121. server := new(models.RewardServer)
  122. exist, err = server.GetByActivityId(activityId)
  123. t.CheckErr(err)
  124. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  125. totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId)
  126. t.CheckErr(err)
  127. t.DisplayByData(map[string]interface{}{
  128. "amount": utils.Float64CusDecimal(totalAmount, 2),
  129. })
  130. }
  131. // 黑名单
  132. func (t *RewardCtl) Blacklist() {
  133. activityId := t.MustGetInt64("activity_id")
  134. rehearsalId := t.MustGetInt64("rehearsal_id")
  135. // 获取打赏的服务id
  136. server := new(models.RewardServer)
  137. exist, err := server.GetByActivityId(activityId)
  138. t.CheckErr(err)
  139. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  140. // 根据打赏服务id获取待审核的名单
  141. // status=true 代表审核不通过还是通过
  142. // 目前表示不通过,bully_screen也一样
  143. result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
  144. t.CheckErr(err)
  145. t.JSON(map[string]interface{}{
  146. "total": len(result),
  147. "list": result,
  148. })
  149. }
  150. // 开启打赏
  151. func (t *RewardCtl) Details() {
  152. activityId := t.MustGetInt64("activity_id")
  153. server := new(models.RewardServer)
  154. exist, err := server.GetByActivityId(activityId)
  155. t.CheckErr(err)
  156. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  157. t.JSON(map[string]interface{}{
  158. "server": server,
  159. })
  160. }