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

191 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
5 years ago
  1. package pc
  2. import (
  3. "fmt"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. ws_send_service "hudongzhuanjia/services/ws_send"
  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 UpperWallCtl struct {
  15. controllers.AuthorCtl
  16. }
  17. type UpperWallResult struct {
  18. models.UpperWall `xorm:"extends"`
  19. User *models.User `json:"user" xorm:"extends"`
  20. }
  21. //获取所有已审核的上墙消息
  22. func (t *UpperWallCtl) List() {
  23. activityId := t.MustGetInt64("activity_id")
  24. rehearsalId := t.MustGetInt64("rehearsal_id")
  25. result := make([]*UpperWallResult, 0)
  26. err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
  27. Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
  28. Where("w.is_delete=0 and w.status=3 and w.activity_id=? and w.rehearsal_id=?", activityId, rehearsalId).
  29. OrderBy("w.review_time desc").Find(&result)
  30. t.CheckErr(err)
  31. t.JSON(map[string]interface{}{
  32. "total": len(result),
  33. "list": result,
  34. })
  35. }
  36. //获取待审核列表
  37. func (t *UpperWallCtl) WaitReview() {
  38. activityId := t.MustGetInt64("activity_id")
  39. rehearsalId := t.MustGetInt64("rehearsal_id")
  40. //根据霸屏服务得id获取待审核得霸屏列表
  41. result := make([]*UpperWallResult, 0)
  42. err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
  43. Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
  44. Where("w.is_delete=0 and w.status=0 and w.activity_id=? and w.rehearsal_id=?", activityId, rehearsalId).
  45. OrderBy("w.review_time desc").Find(&result)
  46. t.CheckErr(err)
  47. t.JSON(map[string]interface{}{
  48. "total": len(result),
  49. "list": result,
  50. })
  51. }
  52. //审核操作
  53. func (t *UpperWallCtl) Review() {
  54. idList := t.MustGet("ids")
  55. status := t.MustGetBool("status")
  56. uid := t.MustGetUID()
  57. ids := strings.Split(idList, "|")
  58. customer := new(models.Customer)
  59. exist, err := models.Get(customer, uid)
  60. t.CheckErr(err)
  61. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  62. reviewStatus := 1
  63. if !status {
  64. reviewStatus = 3 // 审核通过直接发送ws
  65. }
  66. t.CheckErr(models.Save(map[string]interface{}{
  67. "id in": ids,
  68. }, &models.UpperWall{
  69. Status: reviewStatus,
  70. ReviewTime: time.Now().Unix(),
  71. }, "status", "review_time"))
  72. // false 通过
  73. if !status {
  74. result := make([]*UpperWallResult, 0)
  75. err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
  76. Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
  77. Where("w.is_delete=0").In("w.id", ids).
  78. OrderBy("w.created_at asc").Find(&result)
  79. t.CheckErr(err)
  80. if len(result) == 0 {
  81. t.ERROR("不存在上墙消息", code.MSG_DATA_NOT_EXIST)
  82. return
  83. }
  84. for index := range result {
  85. bi, err := utils.Gif2Base64(result[index].Img)
  86. t.CheckErr(err)
  87. result[index].Img = bi
  88. }
  89. go ws_send_service.SendUpperWall(fmt.Sprintf("%d", result[0].ActivityId),
  90. define.TYPE_CUSTOMER, customer.Id, map[string]interface{}{
  91. "type": "upper_wall",
  92. "customer_id": customer.Id,
  93. "data": map[string]interface{}{
  94. "list": result,
  95. "total": len(result)},
  96. })
  97. }
  98. t.SUCCESS("审核成功")
  99. }
  100. //获取黑名单列表
  101. func (t *UpperWallCtl) Blacklist() {
  102. activityId := t.MustGetInt64("activity_id")
  103. rehearsalId := t.MustGetInt64("rehearsal_id")
  104. result := make([]*UpperWallResult, 0)
  105. err := core.GetXormAuto().Table("ox_upper_wall").Alias("w").
  106. Join("LEFT", "ox_user as u", "w.user_id=u.id and u.is_delete=0").
  107. Where("w.is_delete=0 and w.status=1 and w.status=1 and w.rehearsal_id=? and w.activity_id=?",
  108. rehearsalId, activityId).OrderBy("review_time desc").Find(&result)
  109. t.CheckErr(err)
  110. t.JSON(map[string]interface{}{
  111. "total": len(result),
  112. "list": result,
  113. })
  114. }
  115. //获取目前上墙得总条数
  116. func (t *UpperWallCtl) Total() {
  117. activityId := t.MustGetInt64("activity_id")
  118. rehearsalId := t.MustGetInt64("rehearsal_id")
  119. total, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=3",
  120. activityId, rehearsalId).Count(new(models.UpperWall))
  121. t.CheckErr(err)
  122. t.JSON(map[string]interface{}{
  123. "total": total,
  124. })
  125. }
  126. //二维码
  127. // 跳到主页
  128. func (t *UpperWallCtl) Qrcode() {
  129. activityId := t.MustGetInt64("activity_id")
  130. uid := t.MustGetUID()
  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. area := new(models.AreaStore)
  136. exist, err = area.GetByCustomerId(uid, activityId)
  137. t.CheckErr(err)
  138. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "地区信息异常")
  139. qrcode, err := utils.GenH5Qrcode(define.H5Index, map[string]interface{}{
  140. "activity_id": activityId,
  141. "area_id": area.Id,
  142. "customer_id": uid,
  143. "rehearsal_id": activity.RehearsalId,
  144. })
  145. t.CheckErr(err)
  146. t.JSON(map[string]interface{}{
  147. "qrcode": qrcode,
  148. })
  149. }
  150. func (t *UpperWallCtl) Details() {
  151. activityId := t.MustGetInt64("activity_id")
  152. msgWall := new(models.MsgWallServer)
  153. exist, err := msgWall.GetByActivityId(activityId)
  154. t.CheckErr(err)
  155. if !exist {
  156. t.ERROR("上墙服务模块不存在", code.MSG_ERR)
  157. }
  158. t.JSON(map[string]interface{}{
  159. "msg_wall": msgWall,
  160. })
  161. }