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

202 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
4 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. pay_service "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.MustGetInt("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.MustGetInt("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.GetAccountId()
  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. "admin": 1,
  96. "amount": v.Amount,
  97. "content": v.Content,
  98. })
  99. wallet := new(models.RewardWallet)
  100. _, err = wallet.IncrBalance(uid, v.Amount)
  101. t.CheckErr(err)
  102. history := models.RewardWalletHistory{
  103. CustomerId: uid,
  104. Money: v.Amount,
  105. Type: "打赏",
  106. UserId: v.UserId,
  107. RewardHistoryId: v.Id,
  108. RewardAccount: v.RewardAmount,
  109. Status: "交易成功",
  110. Mark: "打赏金额",
  111. }
  112. _, err = models.Add(history)
  113. t.CheckErr(err)
  114. }
  115. }
  116. // 发送审核的信息
  117. t.JSON("审核成功")
  118. }
  119. //获取打赏得总金额
  120. func (t *RewardCtl) Amount() {
  121. activityId := t.MustGetInt("activity_id")
  122. activity := new(models.Activity)
  123. exist, err := models.Get(activity, activityId)
  124. t.CheckErr(err)
  125. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  126. //获取打赏服务得id
  127. server := new(models.RewardServer)
  128. exist, err = server.GetByActivityId(activityId)
  129. t.CheckErr(err)
  130. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  131. totalAmount, err := new(models.RewardHistory).SumMoney(server.Id, activity.RehearsalId, activity.ArchId)
  132. t.CheckErr(err)
  133. t.DisplayByData(map[string]interface{}{
  134. "amount": utils.Float64CusDecimal(totalAmount, 2),
  135. })
  136. }
  137. // 黑名单
  138. func (t *RewardCtl) Blacklist() {
  139. activityId := t.MustGetInt("activity_id")
  140. activity := new(models.Activity)
  141. exist, err := models.Get(activity, activityId)
  142. t.CheckErr(err)
  143. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  144. // 获取打赏的服务id
  145. server := new(models.RewardServer)
  146. exist, err = server.GetByActivityId(activityId)
  147. t.CheckErr(err)
  148. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  149. // 根据打赏服务id获取待审核的名单
  150. // status=true 代表审核不通过还是通过
  151. // 目前表示不通过,bully_screen也一样
  152. result, err := bully_reward_service.GetRewardBlacklist(server.Id, activity.RehearsalId, activity.ArchId)
  153. t.CheckErr(err)
  154. t.JSON(map[string]interface{}{
  155. "total": len(result),
  156. "list": result,
  157. })
  158. }
  159. // 开启打赏
  160. func (t *RewardCtl) Details() {
  161. activityId := t.MustGetInt("activity_id")
  162. server := new(models.RewardServer)
  163. exist, err := server.GetByActivityId(activityId)
  164. t.CheckErr(err)
  165. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  166. t.JSON(map[string]interface{}{
  167. "server": server,
  168. })
  169. }