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

215 lines
6.2 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
  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. "hudongzhuanjia/utils/define"
  10. "strings"
  11. "time"
  12. "github.com/ouxuanserver/osmanthuswine/src/core"
  13. )
  14. type BullyScreenCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. //获取待审核列表
  18. func (t *BullyScreenCtl) WaitReview() {
  19. activityId := t.MustGetInt64("activity_id")
  20. activity := new(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. bullyScreenServer := new(models.BullyScreenServer)
  26. exist, err = bullyScreenServer.GetByActivityId(activityId)
  27. t.CheckErr(err)
  28. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  29. //根据霸屏服务得id获取待审核得霸屏列表
  30. t.CheckErr(bully_reward_service.CheckBullyScreenStatus(bullyScreenServer.Id))
  31. result, err := bully_reward_service.GetBullyScreenReview(bullyScreenServer.Id, activity.RehearsalId)
  32. t.CheckErr(err)
  33. t.JSON(map[string]interface{}{
  34. "total": len(result),
  35. "list": result,
  36. })
  37. }
  38. //审核操作
  39. func (t *BullyScreenCtl) Review() {
  40. customerId := t.MustGetUID()
  41. idList := t.MustGet("ids")
  42. status := t.MustGetBool("status")
  43. ids := strings.Split(idList, "|")
  44. rehearsalId := t.MustGetInt64("rehearsal_id")
  45. //将金额退回给用户
  46. result := make([]*models.BullyScreenHistory, 0)
  47. err := core.GetXormAuto().Where("is_delete=0").In("id", ids).Find(&result)
  48. t.CheckErr(err)
  49. for _, v := range result {
  50. if v.Status != 0 {
  51. t.ERROR("该霸屏已处理", code.MSG_USER_DATA_ERROR)
  52. }
  53. if status { // true 失败 、、 false 成功
  54. _, err = v.UpdateStatus(v.Id, 1)
  55. t.CheckErr(err)
  56. if rehearsalId != 0 { // 彩排
  57. continue
  58. }
  59. //todo: 回退金额给用户 ==> 直接微信退款
  60. // 1. 提请微信退款
  61. // 2. 查询退款是否成功
  62. // 3. 退款成功设置状态
  63. // 4. 写入金额流水记录
  64. _, err = pay_service.Refund("欧轩互动-霸屏拉黑", v.OutTradeNo)
  65. t.CheckErr(err)
  66. } else {
  67. _, err = v.UpdateStatus(v.Id, 2)
  68. t.CheckErr(err)
  69. // todo: 审核成功
  70. // 1. 金额打入主账号的打赏钱包里面
  71. // 2. 记录金额流水
  72. if rehearsalId != 0 {
  73. continue
  74. }
  75. wallet := new(models.BullyScreenWallet)
  76. _, err = wallet.IncrBalance(customerId, v.Amount)
  77. t.CheckErr(err)
  78. _, err = core.GetXormAuto().InsertOne(&models.BullyScreenWalletHistory{
  79. CustomerId: customerId,
  80. UserId: v.UserId,
  81. Money: v.Amount,
  82. Type: "霸屏",
  83. Status: "交易成功",
  84. Mark: "霸屏金额",
  85. CreatedAt: time.Now(),
  86. UpdatedAt: time.Now(),
  87. })
  88. t.CheckErr(err)
  89. }
  90. }
  91. t.SUCCESS("审核成功")
  92. }
  93. //获取黑名单列表
  94. func (t *BullyScreenCtl) Blacklist() {
  95. activityId := t.MustGetInt64("activity_id")
  96. activity := new(models.Activity)
  97. exist, err := models.Get(activity, activityId)
  98. t.CheckErr(err)
  99. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  100. //获取霸屏服务得id
  101. bullyScreenServer := new(models.BullyScreenServer)
  102. exist, err = bullyScreenServer.GetByActivityId(activityId)
  103. t.CheckErr(err)
  104. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏活动不存在")
  105. //根据霸屏服务得id获取待审核得霸屏列表
  106. result, err := bully_reward_service.GetBullyScreenBlacklist(bullyScreenServer.Id, activity.RehearsalId)
  107. t.CheckErr(err)
  108. t.DisplayByData(map[string]interface{}{
  109. "total": len(result),
  110. "list": result,
  111. })
  112. }
  113. //获取目前霸屏得总金额
  114. func (t *BullyScreenCtl) Amount() {
  115. activityId := t.MustGetInt64("activity_id")
  116. rehearsalId := t.MustGetInt64("rehearsal_id")
  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 := core.GetXormAuto().Where("bully_screen_server_id=? and status=3 and "+
  123. " is_delete=false and rehearsal_id=?", bullyScreenServer.Id, rehearsalId).
  124. Sum(new(models.BullyScreenHistory), "second")
  125. t.CheckErr(err)
  126. t.JSON(map[string]interface{}{
  127. "amount": utils.Float64CusDecimal(totalSecond*bullyScreenServer.Price, 2),
  128. })
  129. }
  130. type ModuleService struct {
  131. models.ActivityModuleService `xorm:"extends"`
  132. History models.ModuleServiceHistory `xorm:"extends"`
  133. }
  134. //获取最新得霸屏记录
  135. func (t *BullyScreenCtl) Latest() {
  136. activityId := t.MustGetInt64("activity_id")
  137. activity := new(models.Activity)
  138. exist, err := models.Get(activity, activityId)
  139. t.CheckErr(err)
  140. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  141. //获取霸屏服务得id
  142. bullyScreenServer := new(models.BullyScreenServer)
  143. exist, err = bullyScreenServer.GetByActivityId(activityId)
  144. t.CheckErr(err)
  145. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  146. result, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId)
  147. t.CheckErr(err)
  148. if result == nil || result.Id == 0 {
  149. t.JSON(result)
  150. }
  151. //根据主活动得id获取所有得模块列表
  152. module := new(ModuleService)
  153. exist, err = core.GetXormAuto().Table(new(models.ActivityModuleService)).Alias("s").
  154. Join("LEFT", new(models.ModuleServiceHistory).Alias("h"),
  155. "s.service_module_history_id=h.id and h.is_delete=0 and h.name=?", define.MODULE_BULLYS).
  156. Where("s.activity_id=? and s.is_delete=0", bullyScreenServer.ActivityId).
  157. Get(module)
  158. t.CheckErr(err)
  159. if !exist {
  160. t.ERROR("该服务模块尚未开通", code.MSG_ERR_Param)
  161. }
  162. //更改推送状态
  163. result.BullyScreenHistory.Status = 3
  164. result.BullyScreenHistory.UpdatedAt = time.Now()
  165. t.CheckErr(models.Save(map[string]interface{}{
  166. "id =": result.BullyScreenHistory.Id,
  167. }, &result.BullyScreenHistory, "status", "updated_at"))
  168. t.JSON(result)
  169. }
  170. // 霸屏服务器开关
  171. func (t *BullyScreenCtl) Details() {
  172. activityId := t.MustGetInt64("activity_id")
  173. server := new(models.BullyScreenServer)
  174. exist, err := server.GetByActivityId(activityId)
  175. t.CheckErr(err)
  176. t.Assert(exist, code.MSG_BULLY_SCREEN_SERVER_NOT_EXIST, "霸屏不存在")
  177. t.JSON(map[string]interface{}{
  178. "server": server,
  179. })
  180. }