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

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