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

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