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

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