community_question_comment.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package yb
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_mobile_admin/controllers"
  6. ybRequest "hongze/hongze_mobile_admin/models/request/yb"
  7. ybResponse "hongze/hongze_mobile_admin/models/response/yb"
  8. "hongze/hongze_mobile_admin/services/yb"
  9. "hongze/hongze_mobile_admin/utils"
  10. )
  11. type CommunityQuestionCommentController struct {
  12. controllers.BaseAuth
  13. }
  14. // List
  15. // @Title 获取问答评论列表
  16. // @Description 获取问答评论列表
  17. // @Param CommunityQuestionCommentId query int false "评论id"
  18. // @Param HotStatus query int false "精选状态 -1:全部 0-未精选,1-已精选"
  19. // @Param Keyword query string false "关键字搜索"
  20. // @Success 200 {object} yb.CommunityQuestionCommentListResp
  21. // @router /community/question/comment/list [get]
  22. func (c *CommunityQuestionCommentController) List() {
  23. //sysUser := c.AdminWx
  24. // 权限校验
  25. //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  26. //if err != nil {
  27. // c.FailWithMessage(msg, err.Error())
  28. // return
  29. //}
  30. condition := ""
  31. pars := make([]interface{}, 0)
  32. // 来源
  33. source, _ := c.GetInt("Source", 1)
  34. if source <= 0 {
  35. source = 1
  36. }
  37. // 评论ID
  38. communityQuestionCommentId, _ := c.GetInt("CommunityQuestionCommentId", 0)
  39. if communityQuestionCommentId > 0 {
  40. condition += ` AND a.community_question_comment_id = ? `
  41. pars = append(pars, communityQuestionCommentId)
  42. } else {
  43. //精选状态状态
  44. hotStatus, _ := c.GetInt("HotStatus", 0)
  45. if hotStatus >= 0 {
  46. condition += ` AND a.is_hot = ? `
  47. pars = append(pars, hotStatus)
  48. }
  49. //关键字
  50. keyword := c.GetString("Keyword", "")
  51. if keyword != "" {
  52. condition += ` AND a.content like "%` + keyword + `%"`
  53. }
  54. }
  55. var startSize int
  56. pageSize, _ := c.GetInt("PageSize")
  57. currentIndex, _ := c.GetInt("CurrentIndex")
  58. if pageSize <= 0 {
  59. pageSize = utils.PageSize20
  60. }
  61. if currentIndex <= 0 {
  62. currentIndex = 1
  63. }
  64. startSize = paging.StartIndex(currentIndex, pageSize)
  65. total, list, err := yb.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize, source)
  66. if err != nil {
  67. c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
  68. return
  69. }
  70. page := paging.GetPaging(currentIndex, pageSize, total)
  71. c.OkDetailed(ybResponse.CommunityQuestionCommentListResp{
  72. Paging: page,
  73. List: list,
  74. }, "获取成功")
  75. }
  76. // Delete
  77. // @Title 删除评论
  78. // @Description 删除评论
  79. // @Param QuestionId query int false "问题ID"
  80. // @Success 200 string "操作成功"
  81. // @router /community/question/comment/delete [post]
  82. func (c *CommunityQuestionCommentController) Delete() {
  83. //sysUser := c.AdminWx
  84. // 权限校验
  85. //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  86. //if err != nil {
  87. // c.FailWithMessage(msg, err.Error())
  88. // return
  89. //}
  90. var req ybRequest.QuestionCommentDeleteReq
  91. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  92. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  93. return
  94. }
  95. if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil {
  96. c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
  97. return
  98. }
  99. c.OkWithMessage("删除成功")
  100. }
  101. // Hot
  102. // @Title 设置/取消 问题评论精选
  103. // @Description 设置/取消 问题评论精选
  104. // @Success 200 string "操作成功"
  105. // @router /community/question/comment/hot [post]
  106. func (c *CommunityQuestionCommentController) Hot() {
  107. //sysUser := c.AdminWx
  108. // 权限校验
  109. //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  110. //if err != nil {
  111. // c.FailWithMessage(msg, err.Error())
  112. // return
  113. //}
  114. var req ybRequest.QuestionCommentHotReq
  115. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  116. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  117. return
  118. }
  119. if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil {
  120. c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
  121. return
  122. }
  123. c.OkWithMessage("操作成功")
  124. }