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

196 lines
5.1 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
  1. package pc
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. bully_reward_service "hudongzhuanjia/services/bully_reward"
  7. "hudongzhuanjia/services/pay"
  8. "hudongzhuanjia/utils"
  9. "hudongzhuanjia/utils/code"
  10. "strings"
  11. "time"
  12. "github.com/ouxuanserver/osmanthuswine/src/core"
  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.RAW(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.RAW(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. // todo: false 代表通过, true 代表不通过
  64. idList := t.MustGet("ids")
  65. status := t.MustGetBool("status")
  66. ids := strings.Split(idList, "|")
  67. rehearsalId := t.MustGetInt64("rehearsal_id")
  68. result := make([]*models.RewardHistory, 0)
  69. err := core.GetXormAuto().Where("is_delete=0").In("id", ids).Find(&result)
  70. t.CheckErr(err)
  71. // 审核
  72. for _, v := range result {
  73. if v.Status != 0 {
  74. t.ERROR("该打赏已处理", code.MSG_USER_DATA_ERROR)
  75. }
  76. if status { // false 通过 , true 不通过
  77. // 回退金额给用户
  78. // 应该微信退款
  79. _, err := v.UpdateStatus(v.Id, 1)
  80. t.CheckErr(err)
  81. if rehearsalId != 0 { // 彩排不需要金额
  82. continue
  83. }
  84. _, err = pay_service.Refund("欧轩互动-打赏拉黑", v.OutTradeNo)
  85. t.CheckErr(err)
  86. } else {
  87. //增加客户的金额
  88. _, err := v.UpdateStatus(v.Id, 2)
  89. t.CheckErr(err)
  90. if rehearsalId != 0 { // 彩排不需要金额
  91. continue
  92. }
  93. uid := t.MustGetUID()
  94. customer := new(models.Customer)
  95. exist, err := models.GetById(customer, uid)
  96. t.CheckErr(err)
  97. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  98. wallet := new(models.RewardWallet)
  99. _, err = wallet.IncrBalance(uid, v.Amount)
  100. t.CheckErr(err)
  101. _, err = core.GetXormAuto().InsertOne(&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. CreatedAt: time.Now(),
  111. UpdatedAt: time.Now(),
  112. })
  113. t.CheckErr(err)
  114. }
  115. }
  116. // 发送审核的信息
  117. t.RAW("审核成功")
  118. }
  119. //获取打赏得总金额
  120. func (t *RewardCtl) Amount() {
  121. activityId := t.MustGetInt64("activity_id")
  122. rehearsalId := t.MustGetInt64("rehearsal_id")
  123. //获取打赏服务得id
  124. server := new(models.RewardServer)
  125. exist, err := server.GetByActivityId(activityId)
  126. t.CheckErr(err)
  127. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  128. totalAmount, err := core.GetXormAuto().Where("reward_server_id=? and status=3 and is_delete=0 "+
  129. " and rehearsal_id=?", server.Id, rehearsalId).Sum(new(models.RewardHistory), "amount")
  130. t.CheckErr(err)
  131. t.DisplayByData(map[string]interface{}{
  132. "amount": utils.Float64CusDecimal(totalAmount, 2),
  133. })
  134. }
  135. // 黑名单
  136. func (t *RewardCtl) Blacklist() {
  137. activityId := t.MustGetInt64("activity_id")
  138. rehearsalId := t.MustGetInt64("rehearsal_id")
  139. // 获取打赏的服务id
  140. server := new(models.RewardServer)
  141. exist, err := server.GetByActivityId(activityId)
  142. t.CheckErr(err)
  143. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  144. // 根据打赏服务id获取待审核的名单
  145. // status=true 代表审核不通过还是通过
  146. // 目前表示不通过,bully_screen也一样
  147. result, err := bully_reward_service.GetRewardBlacklist(server.Id, rehearsalId)
  148. t.CheckErr(err)
  149. t.JSON(map[string]interface{}{
  150. "total": len(result),
  151. "list": result,
  152. })
  153. }
  154. // 开启打赏
  155. func (t *RewardCtl) Details() {
  156. activityId := t.MustGetInt64("activity_id")
  157. server := new(models.RewardServer)
  158. exist, err := server.GetByActivityId(activityId)
  159. t.CheckErr(err)
  160. t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在")
  161. t.JSON(map[string]interface{}{
  162. "server": server,
  163. })
  164. }