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

192 lines
5.4 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
  1. package pc
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/models"
  5. bully_reward_service "hudongzhuanjia/services/bully_reward"
  6. "hudongzhuanjia/services/pay"
  7. "hudongzhuanjia/utils"
  8. "hudongzhuanjia/utils/code"
  9. "strings"
  10. "time"
  11. )
  12. type BullyScreenCtl struct {
  13. controllers.AuthorCtl
  14. }
  15. //获取待审核列表
  16. func (t *BullyScreenCtl) WaitReview() {
  17. activityId := t.MustGetInt64("activity_id")
  18. activity := new(models.Activity)
  19. exist, err := models.Get(activity, activityId)
  20. t.CheckErr(err)
  21. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  22. //获取霸屏服务得id
  23. bullyScreenServer := new(models.BullyScreenServer)
  24. exist, err = bullyScreenServer.GetByActivityId(activityId)
  25. t.CheckErr(err)
  26. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  27. //根据霸屏服务得id获取待审核得霸屏列表
  28. t.CheckErr(bully_reward_service.CheckBullyScreenStatus(bullyScreenServer.Id))
  29. result, err := bully_reward_service.GetBullyScreenReview(bullyScreenServer.Id, activity.RehearsalId)
  30. t.CheckErr(err)
  31. t.JSON(map[string]interface{}{
  32. "total": len(result),
  33. "list": result,
  34. })
  35. }
  36. //审核操作
  37. func (t *BullyScreenCtl) Review() {
  38. customerId := t.MustGetUID()
  39. status := t.MustGetBool("status")
  40. ids := strings.Split(t.MustGet("ids"), "|")
  41. //activityId := t.MustGetInt64("activity_id")
  42. rehearsalId := t.MustGetInt64("rehearsal_id")
  43. //// TODO: new feat
  44. //activity := new(models.Activity)
  45. //exist, err := models.Get(activity, activityId)
  46. //t.CheckErr(err)
  47. //t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  48. //将金额退回给用户
  49. result, err := models.GetBullyScreenHistoryByIds(ids)
  50. t.CheckErr(err)
  51. for _, v := range result {
  52. if status { // true 失败 、、 false 成功
  53. v.Status = 1
  54. _, err = models.Update(v.Id, v, "status")
  55. t.CheckErr(err)
  56. if rehearsalId != 0 { // 彩排
  57. continue
  58. }
  59. _, err = pay_service.Refund("欧轩互动-霸屏拉黑", v.OutTradeNo)
  60. t.CheckErr(err)
  61. } else {
  62. v.Status = 2
  63. _, err = models.Update(v.Id, v, "status")
  64. t.CheckErr(err)
  65. if rehearsalId != 0 {
  66. continue
  67. }
  68. // 订单宣告完成
  69. _, err = new(models.UserOrder).UpdateStatusByOutTradeNo(v.OutTradeNo, 2)
  70. t.CheckErr(err)
  71. wallet := new(models.BullyScreenWallet)
  72. _, err = wallet.IncrBalance(customerId, v.Amount)
  73. t.CheckErr(err)
  74. history := models.BullyScreenWalletHistory{
  75. CustomerId: customerId,
  76. UserId: v.UserId,
  77. Money: v.Amount,
  78. Type: "霸屏",
  79. Status: "交易成功",
  80. Mark: "霸屏金额",
  81. CreatedAt: time.Now(),
  82. UpdatedAt: time.Now(),
  83. }
  84. _, err = models.Add(history)
  85. t.CheckErr(err)
  86. }
  87. }
  88. t.SUCCESS("审核成功")
  89. }
  90. //获取黑名单列表
  91. func (t *BullyScreenCtl) Blacklist() {
  92. activityId := t.MustGetInt64("activity_id")
  93. activity := new(models.Activity)
  94. exist, err := models.Get(activity, activityId)
  95. t.CheckErr(err)
  96. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  97. //获取霸屏服务得id
  98. bullyScreenServer := new(models.BullyScreenServer)
  99. exist, err = bullyScreenServer.GetByActivityId(activityId)
  100. t.CheckErr(err)
  101. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏活动不存在")
  102. //根据霸屏服务得id获取待审核得霸屏列表
  103. result, err := bully_reward_service.GetBullyScreenBlacklist(bullyScreenServer.Id, activity.RehearsalId)
  104. t.CheckErr(err)
  105. t.DisplayByData(map[string]interface{}{
  106. "total": len(result),
  107. "list": result,
  108. })
  109. }
  110. //获取目前霸屏得总金额
  111. func (t *BullyScreenCtl) Amount() {
  112. activityId := t.MustGetInt64("activity_id")
  113. activity := new(models.Activity)
  114. exist, err := models.Get(activity, activityId)
  115. t.CheckErr(err)
  116. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  117. //获取霸屏服务得id
  118. bullyScreenServer := new(models.BullyScreenServer)
  119. exist, err = bullyScreenServer.GetByActivityId(activityId)
  120. t.CheckErr(err)
  121. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  122. totalSecond, err := new(models.BullyScreenHistory).SumSecond(bullyScreenServer.Id, activity.RehearsalId)
  123. t.CheckErr(err)
  124. t.JSON(map[string]interface{}{
  125. "amount": utils.Float64CusDecimal(totalSecond*bullyScreenServer.Price, 2),
  126. })
  127. }
  128. //获取最新得霸屏记录
  129. func (t *BullyScreenCtl) Latest() {
  130. activityId := t.MustGetInt64("activity_id")
  131. activity := new(models.Activity)
  132. exist, err := models.Get(activity, activityId)
  133. t.CheckErr(err)
  134. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  135. //获取霸屏服务得id
  136. bullyScreenServer := new(models.BullyScreenServer)
  137. exist, err = bullyScreenServer.GetByActivityId(activityId)
  138. t.CheckErr(err)
  139. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  140. result, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId)
  141. t.CheckErr(err)
  142. if result == nil || result.Id == 0 {
  143. t.JSON(result)
  144. }
  145. //更改推送状态
  146. result.BullyScreenHistory.Status = 3
  147. result.BullyScreenHistory.UpdatedAt = time.Now()
  148. _, err = models.Update(result.BullyScreenHistory.Id, &result.BullyScreenHistory, "status")
  149. t.CheckErr(err)
  150. t.JSON(result)
  151. }
  152. // 霸屏服务器开关
  153. func (t *BullyScreenCtl) Details() {
  154. activityId := t.MustGetInt64("activity_id")
  155. server := new(models.BullyScreenServer)
  156. exist, err := server.GetByActivityId(activityId)
  157. t.CheckErr(err)
  158. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  159. t.JSON(map[string]interface{}{
  160. "server": server,
  161. })
  162. }