comment.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package comment
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. reqComment "hongze/hongze_yb/models/request/comment"
  6. commentService "hongze/hongze_yb/services/comment"
  7. userService "hongze/hongze_yb/services/user"
  8. "hongze/hongze_yb/utils"
  9. "strconv"
  10. )
  11. // Comment 发布留言
  12. func Comment(c *gin.Context) {
  13. // 是否为备用小程序
  14. copyYb := c.Request.Header.Get("CopyYb")
  15. var req reqComment.ReqComment
  16. if c.ShouldBind(&req) !=nil {
  17. response.Fail("入参错误", c)
  18. return
  19. }
  20. userInfo := userService.GetInfoByClaims(c)
  21. data, err := commentService.Comment(userInfo, req, copyYb)
  22. if err != nil {
  23. response.Fail(err.Error(),c)
  24. return
  25. }
  26. response.OkData("留言成功", data, c)
  27. return
  28. }
  29. // Delete 删除留言
  30. func Delete(c *gin.Context) {
  31. var req *reqComment.ReqDel
  32. if c.ShouldBind(&req) != nil {
  33. response.Fail("参数异常", c)
  34. return
  35. }
  36. userInfo := userService.GetInfoByClaims(c)
  37. err := commentService.Delete(userInfo, req)
  38. if err != nil {
  39. response.Fail(err.Error(),c)
  40. return
  41. }
  42. response.Ok("删除留言成功", c)
  43. return
  44. }
  45. // HotList 获取精选留言
  46. func HotList(c *gin.Context) {
  47. reqReportId := c.DefaultQuery("report_id", "")
  48. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  49. reqOldReportId := c.DefaultQuery("old_report_id", "")
  50. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  51. reqPageIndex := c.DefaultQuery("current_index", "1")
  52. reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
  53. pageIndex, err := strconv.Atoi(reqPageIndex)
  54. if err != nil {
  55. response.Fail("请输入正确的条数限制", c)
  56. return
  57. }
  58. pageSize, err := strconv.Atoi(reqPageSize)
  59. if err != nil {
  60. response.Fail("请输入正确的页码", c)
  61. return
  62. }
  63. var (
  64. reportId int
  65. reportChapterId int
  66. oldReportId int
  67. oldReportChapterId int
  68. )
  69. if reqReportId != ""{
  70. reportId, err = strconv.Atoi(reqReportId)
  71. if err != nil {
  72. response.Fail("报告ID格式有误", c)
  73. return
  74. }
  75. }
  76. if reqReportChapterId != "" {
  77. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  78. if err != nil {
  79. response.Fail("章节ID格式有误", c)
  80. return
  81. }
  82. }
  83. if reqOldReportId != ""{
  84. oldReportId, err = strconv.Atoi(reqOldReportId)
  85. if err != nil {
  86. response.Fail("老报告ID格式有误", c)
  87. return
  88. }
  89. }
  90. if reqOldReportChapterId != "" {
  91. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  92. if err != nil {
  93. response.Fail("章节ID格式有误", c)
  94. return
  95. }
  96. }
  97. userinfo := userService.GetInfoByClaims(c)
  98. list, err := commentService.List(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId,true, pageIndex, pageSize)
  99. if err != nil {
  100. response.Fail(err.Error(), c)
  101. return
  102. }
  103. response.OkData("查询成功", list, c )
  104. return
  105. }
  106. // MyList 获取我的留言
  107. func MyList(c *gin.Context) {
  108. reqReportId := c.DefaultQuery("report_id", "")
  109. reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
  110. reqOldReportId := c.DefaultQuery("old_report_id", "")
  111. reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
  112. var (
  113. reportId int
  114. reportChapterId int
  115. oldReportId int
  116. oldReportChapterId int
  117. err error
  118. )
  119. if reqReportId != ""{
  120. reportId, err = strconv.Atoi(reqReportId)
  121. if err != nil {
  122. response.Fail("报告ID格式有误", c)
  123. return
  124. }
  125. }
  126. if reqReportChapterId != "" {
  127. reportChapterId, err = strconv.Atoi(reqReportChapterId)
  128. if err != nil {
  129. response.Fail("章节ID格式有误", c)
  130. return
  131. }
  132. }
  133. if reqOldReportId != ""{
  134. oldReportId, err = strconv.Atoi(reqOldReportId)
  135. if err != nil {
  136. response.Fail("老报告ID格式有误", c)
  137. return
  138. }
  139. }
  140. if reqOldReportChapterId != "" {
  141. oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
  142. if err != nil {
  143. response.Fail("章节ID格式有误", c)
  144. return
  145. }
  146. }
  147. userinfo := userService.GetInfoByClaims(c)
  148. list, err := commentService.MyList(userinfo, reportId, reportChapterId, oldReportId,oldReportChapterId)
  149. if err != nil {
  150. response.Fail(err.Error(), c)
  151. return
  152. }
  153. response.OkData("查询成功", list, c )
  154. return
  155. }