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

208 lines
5.5 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
  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. "github.com/ouxuanserver/osmanthuswine/src/core"
  14. )
  15. type RewardCtl struct {
  16. controllers.AuthorCtl
  17. }
  18. //获取最新的打赏记录
  19. func (t *RewardCtl) Latest() {
  20. activityId := t.MustGetInt64("activity_id")
  21. rehearsalId := t.MustGetInt64("rehearsal_id")
  22. //获取打赏服务得id
  23. server := new(models.RewardServer)
  24. exist, err := server.GetByActivityId(activityId)
  25. t.CheckErr(err)
  26. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  27. result, err := bully_reward_service.GetRewardLatest(server.Id, rehearsalId)
  28. t.CheckErr(err)
  29. if result == nil || result.Id == 0 {
  30. t.JSON(result)
  31. }
  32. result.User.Openid = ""
  33. result.User.Unionid = ""
  34. result.RewardHistory.RewardAmount = fmt.Sprintf("%.2f", result.RewardHistory.Amount)
  35. t.CheckErr(models.Save(map[string]interface{}{
  36. "id=": result.RewardHistory.Id,
  37. }, &models.RewardHistory{
  38. Status: 3,
  39. UpdatedAt: time.Now(),
  40. }, "status", "update_at"))
  41. t.JSON(result)
  42. }
  43. //获取待审核列表
  44. func (t *RewardCtl) WaitReview() {
  45. activityId := t.MustGetInt64("activity_id")
  46. rehearsalId := t.MustGetInt64("rehearsal_id")
  47. //获取打赏服务得id
  48. server := new(models.RewardServer)
  49. exist, err := server.GetByActivityId(activityId)
  50. t.CheckErr(err)
  51. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  52. //// todo: 检查订单
  53. //t.CheckErr(bully_reward_service.CheckRewardStatus(server.Id))
  54. result, err := bully_reward_service.GetRewardReview(server.Id, rehearsalId)
  55. t.CheckErr(err)
  56. //根据打赏服务得id获取待审核得打赏列表
  57. t.JSON(map[string]interface{}{
  58. "total": len(result),
  59. "list": result,
  60. })
  61. }
  62. //审核
  63. func (t *RewardCtl) Review() {
  64. // todo: false 代表通过, true 代表不通过
  65. idList := t.MustGet("ids")
  66. status := t.MustGetBool("status")
  67. ids := strings.Split(idList, "|")
  68. rehearsalId := t.MustGetInt64("rehearsal_id")
  69. result := make([]*models.RewardHistory, 0)
  70. err := core.GetXormAuto().Where("is_delete=0").In("id", ids).Find(&result)
  71. t.CheckErr(err)
  72. // 审核
  73. for _, v := range result {
  74. if v.Status != 0 {
  75. t.ERROR("该打赏已处理", code.MSG_USER_DATA_ERROR)
  76. }
  77. if status { // false 通过 , true 不通过
  78. // 回退金额给用户
  79. // 应该微信退款
  80. _, err = v.UpdateStatus(v.Id, 1)
  81. t.CheckErr(err)
  82. if rehearsalId != 0 { // 彩排不需要金额
  83. continue
  84. }
  85. _, err = pay_service.Refund("欧轩互动-打赏拉黑", v.OutTradeNo)
  86. t.CheckErr(err)
  87. } else {
  88. var exist bool
  89. //增加客户的金额
  90. _, err = v.UpdateStatus(v.Id, 2)
  91. t.CheckErr(err)
  92. user := new(models.User)
  93. exist, err = models.Get(user, v.UserId)
  94. t.CheckErr(err)
  95. t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
  96. go im_service.SendGroupCustomMessage(user.Id, v.ActivityId, im_service.NoticeReward,
  97. map[string]interface{}{
  98. "amount": v.Amount,
  99. "content": v.Content,
  100. })
  101. if rehearsalId != 0 { // 彩排不需要金额
  102. continue
  103. }
  104. uid := t.MustGetUID()
  105. customer := new(models.Customer)
  106. exist, err = models.Get(customer, uid)
  107. t.CheckErr(err)
  108. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  109. wallet := new(models.RewardWallet)
  110. _, err = wallet.IncrBalance(uid, v.Amount)
  111. t.CheckErr(err)
  112. _, err = core.GetXormAuto().InsertOne(&models.RewardWalletHistory{
  113. CustomerId: uid,
  114. Money: v.Amount,
  115. Type: "打赏",
  116. UserId: v.UserId,
  117. RewardHistoryId: v.Id,
  118. RewardAccount: v.RewardAmount,
  119. Status: "交易成功",
  120. Mark: "打赏金额",
  121. CreatedAt: time.Now(),
  122. UpdatedAt: time.Now(),
  123. })
  124. t.CheckErr(err)
  125. }
  126. }
  127. // 发送审核的信息
  128. t.JSON("审核成功")
  129. }
  130. //获取打赏得总金额
  131. func (t *RewardCtl) Amount() {
  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. totalAmount, err := core.GetXormAuto().Where("reward_server_id=? and status=3 and is_delete=0 "+
  140. " and rehearsal_id=?", server.Id, rehearsalId).Sum(new(models.RewardHistory), "amount")
  141. t.CheckErr(err)
  142. t.DisplayByData(map[string]interface{}{
  143. "amount": utils.Float64CusDecimal(totalAmount, 2),
  144. })
  145. }
  146. // 黑名单
  147. func (t *RewardCtl) Blacklist() {
  148. activityId := t.MustGetInt64("activity_id")
  149. rehearsalId := t.MustGetInt64("rehearsal_id")
  150. // 获取打赏的服务id
  151. server := new(models.RewardServer)
  152. exist, err := server.GetByActivityId(activityId)
  153. t.CheckErr(err)
  154. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  155. // 根据打赏服务id获取待审核的名单
  156. // status=true 代表审核不通过还是通过
  157. // 目前表示不通过,bully_screen也一样
  158. result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
  159. t.CheckErr(err)
  160. t.JSON(map[string]interface{}{
  161. "total": len(result),
  162. "list": result,
  163. })
  164. }
  165. // 开启打赏
  166. func (t *RewardCtl) Details() {
  167. activityId := t.MustGetInt64("activity_id")
  168. server := new(models.RewardServer)
  169. exist, err := server.GetByActivityId(activityId)
  170. t.CheckErr(err)
  171. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  172. t.JSON(map[string]interface{}{
  173. "server": server,
  174. })
  175. }