community_question_comment.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. //问答id
  33. communityQuestionCommentId, _ := c.GetInt("CommunityQuestionCommentId", 0)
  34. if communityQuestionCommentId > 0 {
  35. condition += ` AND a.community_question_comment_id = ? `
  36. pars = append(pars, communityQuestionCommentId)
  37. } else {
  38. //精选状态状态
  39. hotStatus, _ := c.GetInt("HotStatus", 0)
  40. if hotStatus >= 0 {
  41. condition += ` AND a.is_hot = ? `
  42. pars = append(pars, hotStatus)
  43. }
  44. //关键字
  45. keyword := c.GetString("Keyword", "")
  46. if keyword != "" {
  47. condition += ` AND a.content like "%` + keyword + `%"`
  48. }
  49. }
  50. var startSize int
  51. pageSize, _ := c.GetInt("PageSize")
  52. currentIndex, _ := c.GetInt("CurrentIndex")
  53. if pageSize <= 0 {
  54. pageSize = utils.PageSize20
  55. }
  56. if currentIndex <= 0 {
  57. currentIndex = 1
  58. }
  59. startSize = paging.StartIndex(currentIndex, pageSize)
  60. total, list, err := yb.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
  61. if err != nil {
  62. c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
  63. return
  64. }
  65. page := paging.GetPaging(currentIndex, pageSize, total)
  66. c.OkDetailed(ybResponse.CommunityQuestionCommentListResp{
  67. Paging: page,
  68. List: list,
  69. }, "获取成功")
  70. }
  71. // Delete
  72. // @Title 删除评论
  73. // @Description 删除评论
  74. // @Param QuestionId query int false "问题ID"
  75. // @Success 200 string "操作成功"
  76. // @router /community/question/comment/delete [post]
  77. func (c *CommunityQuestionCommentController) Delete() {
  78. //sysUser := c.AdminWx
  79. // 权限校验
  80. //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  81. //if err != nil {
  82. // c.FailWithMessage(msg, err.Error())
  83. // return
  84. //}
  85. var req ybRequest.QuestionCommentDeleteReq
  86. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  87. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  88. return
  89. }
  90. if err, errMsg := yb.SoftDeleteQuestionComment(req.CommunityQuestionCommentId); err != nil {
  91. c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
  92. return
  93. }
  94. c.OkWithMessage("删除成功")
  95. }
  96. // Hot
  97. // @Title 设置/取消 问题评论精选
  98. // @Description 设置/取消 问题评论精选
  99. // @Success 200 string "操作成功"
  100. // @router /community/question/comment/hot [post]
  101. func (c *CommunityQuestionCommentController) Hot() {
  102. //sysUser := c.AdminWx
  103. // 权限校验
  104. //msg, err := yb.CheckCommunityQuestionPermission(sysUser.AdminId)
  105. //if err != nil {
  106. // c.FailWithMessage(msg, err.Error())
  107. // return
  108. //}
  109. var req ybRequest.QuestionCommentHotReq
  110. if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
  111. c.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  112. return
  113. }
  114. if err, errMsg := yb.SetHotQuestionComment(req.CommunityQuestionCommentId); err != nil {
  115. c.FailWithMessage(errMsg, "DeleteQuestion,Err:"+err.Error())
  116. return
  117. }
  118. c.OkWithMessage("操作成功")
  119. }