comment.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package community
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/logic/yb_community_question"
  6. "hongze/hongze_yb/models/request"
  7. responseModel "hongze/hongze_yb/models/response"
  8. userService "hongze/hongze_yb/services/user"
  9. "hongze/hongze_yb/utils"
  10. "strconv"
  11. )
  12. // Comment 发布留言
  13. func Comment(c *gin.Context) {
  14. var req request.ReqComment
  15. if c.ShouldBind(&req) != nil {
  16. response.Fail("入参错误", c)
  17. return
  18. }
  19. userInfo := userService.GetInfoByClaims(c)
  20. ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName)
  21. if err != nil {
  22. response.FailMsg(errMsg, err.Error(), c)
  23. return
  24. }
  25. response.OkData("留言成功", responseModel.RespCommunityQuestionCommentAdd{
  26. CommunityQuestionCommentID: ybCommunityQuestionComment.CommunityQuestionCommentID,
  27. }, c)
  28. return
  29. }
  30. // DeleteComment 删除留言
  31. func DeleteComment(c *gin.Context) {
  32. var req *request.ReqDel
  33. if c.ShouldBind(&req) != nil {
  34. response.Fail("参数异常", c)
  35. return
  36. }
  37. userInfo := userService.GetInfoByClaims(c)
  38. err, errMsg := yb_community_question.Delete(userInfo, req.CommunityQuestionCommentID)
  39. if err != nil {
  40. response.FailMsg(errMsg, err.Error(), c)
  41. return
  42. }
  43. response.Ok("删除留言成功", c)
  44. return
  45. }
  46. // HotList 获取精选留言
  47. func HotList(c *gin.Context) {
  48. reqReportId := c.DefaultQuery("report_id", "")
  49. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  50. reqOldReportId := c.DefaultQuery("old_report_id", "")
  51. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  52. reqPageIndex := c.DefaultQuery("current_index", "1")
  53. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  54. pageIndex, err := strconv.Atoi(reqPageIndex)
  55. if err != nil {
  56. response.Fail("请输入正确的条数限制", c)
  57. return
  58. }
  59. pageSize, err := strconv.Atoi(reqPageSize)
  60. if err != nil {
  61. response.Fail("请输入正确的页码", c)
  62. return
  63. }
  64. var (
  65. reportId int
  66. reportChapterId int
  67. oldReportId int
  68. oldReportChapterId int
  69. )
  70. if reqReportId != "" {
  71. reportId, err = strconv.Atoi(reqReportId)
  72. if err != nil {
  73. response.Fail("报告ID格式有误", c)
  74. return
  75. }
  76. }
  77. if reqReportChapterId != "" {
  78. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  79. if err != nil {
  80. response.Fail("章节ID格式有误", c)
  81. return
  82. }
  83. }
  84. if reqOldReportId != "" {
  85. oldReportId, err = strconv.Atoi(reqOldReportId)
  86. if err != nil {
  87. response.Fail("老报告ID格式有误", c)
  88. return
  89. }
  90. }
  91. if reqOldReportChapterId != "" {
  92. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  93. if err != nil {
  94. response.Fail("章节ID格式有误", c)
  95. return
  96. }
  97. }
  98. userinfo := userService.GetInfoByClaims(c)
  99. list, err := yb_community_question.List(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId, true, pageIndex, pageSize)
  100. if err != nil {
  101. response.Fail(err.Error(), c)
  102. return
  103. }
  104. response.OkData("查询成功", list, c)
  105. return
  106. }
  107. // MyList 获取我的留言
  108. func MyList(c *gin.Context) {
  109. reqReportId := c.DefaultQuery("report_id", "")
  110. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  111. reqOldReportId := c.DefaultQuery("old_report_id", "")
  112. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  113. var (
  114. reportId int
  115. reportChapterId int
  116. oldReportId int
  117. oldReportChapterId int
  118. err error
  119. )
  120. if reqReportId != "" {
  121. reportId, err = strconv.Atoi(reqReportId)
  122. if err != nil {
  123. response.Fail("报告ID格式有误", c)
  124. return
  125. }
  126. }
  127. if reqReportChapterId != "" {
  128. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  129. if err != nil {
  130. response.Fail("章节ID格式有误", c)
  131. return
  132. }
  133. }
  134. if reqOldReportId != "" {
  135. oldReportId, err = strconv.Atoi(reqOldReportId)
  136. if err != nil {
  137. response.Fail("老报告ID格式有误", c)
  138. return
  139. }
  140. }
  141. if reqOldReportChapterId != "" {
  142. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  143. if err != nil {
  144. response.Fail("章节ID格式有误", c)
  145. return
  146. }
  147. }
  148. userinfo := userService.GetInfoByClaims(c)
  149. list, err := yb_community_question.MyList(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId)
  150. if err != nil {
  151. response.Fail(err.Error(), c)
  152. return
  153. }
  154. response.OkData("查询成功", list, c)
  155. return
  156. }
  157. // GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
  158. func GetNeedCommentAnonymousUserTips(c *gin.Context) {
  159. userinfo := userService.GetInfoByClaims(c)
  160. ok, err := yb_community_question.GetNeedCommentAnonymousUserTips(userinfo.UserID)
  161. if err != nil {
  162. response.FailMsg("获取失败", err.Error(), c)
  163. return
  164. }
  165. response.OkData("获取成功", ok, c)
  166. }
  167. // SetCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
  168. func SetCommentAnonymousUserTips(c *gin.Context) {
  169. userinfo := userService.GetInfoByClaims(c)
  170. err := yb_community_question.SetYbCommentAnonymousUserTips(userinfo.UserID)
  171. if err != nil {
  172. response.FailMsg("设置失败", err.Error(), c)
  173. return
  174. }
  175. response.Ok("设置成功", c)
  176. }