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

242 lines
7.6 KiB

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