comment.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. "hongze/hongze_yb/services"
  9. userService "hongze/hongze_yb/services/user"
  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. req.IsShowName = 0
  21. if userInfo.NickName != `` { //非空串时为实名
  22. req.IsShowName = 1
  23. }
  24. ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName)
  25. if err != nil {
  26. response.FailMsg(errMsg, err.Error(), c)
  27. return
  28. }
  29. response.OkData("留言成功", responseModel.RespCommunityQuestionCommentAdd{
  30. CommunityQuestionCommentID: ybCommunityQuestionComment.CommunityQuestionCommentID,
  31. }, c)
  32. return
  33. }
  34. // DeleteComment 删除留言
  35. func DeleteComment(c *gin.Context) {
  36. var req *request.ReqDel
  37. if c.ShouldBind(&req) != nil {
  38. response.Fail("参数异常", c)
  39. return
  40. }
  41. userInfo := userService.GetInfoByClaims(c)
  42. err, errMsg := yb_community_question.Delete(userInfo, req.CommunityQuestionCommentID)
  43. if err != nil {
  44. response.FailMsg(errMsg, err.Error(), c)
  45. return
  46. }
  47. response.Ok("删除留言成功", c)
  48. return
  49. }
  50. // HotList 获取精选留言
  51. func HotList(c *gin.Context) {
  52. communityQuestionIDStr := c.DefaultQuery("community_question_id", "")
  53. communityQuestionID, err := strconv.Atoi(communityQuestionIDStr)
  54. if err != nil {
  55. response.Fail("问答id异常", c)
  56. return
  57. }
  58. userinfo := userService.GetInfoByClaims(c)
  59. page := services.GetCurrPageByClaims(c)
  60. pageSize := services.GetPageSizeByClaims(c)
  61. list, hotTotal, myTotal, err, errMsg := yb_community_question.List(userinfo.UserID, communityQuestionID, true, page, pageSize)
  62. if err != nil {
  63. response.FailMsg(errMsg, err.Error(), c)
  64. return
  65. }
  66. response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
  67. List: list,
  68. Paging: responseModel.GetPaging(page, pageSize, int(hotTotal)),
  69. HotTotal: hotTotal,
  70. MyTotal: myTotal,
  71. }, c)
  72. return
  73. }
  74. // MyList 获取我的留言
  75. func MyList(c *gin.Context) {
  76. communityQuestionIDStr := c.DefaultQuery("community_question_id", "")
  77. communityQuestionID, err := strconv.Atoi(communityQuestionIDStr)
  78. if err != nil {
  79. response.Fail("问答id异常", c)
  80. return
  81. }
  82. userinfo := userService.GetInfoByClaims(c)
  83. page := services.GetCurrPageByClaims(c)
  84. pageSize := services.GetPageSizeByClaims(c)
  85. list, hotTotal, myTotal, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionID, page, pageSize)
  86. if err != nil {
  87. response.FailMsg(errMsg, err.Error(), c)
  88. return
  89. }
  90. response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
  91. List: list,
  92. Paging: responseModel.GetPaging(page, pageSize, int(myTotal)),
  93. HotTotal: hotTotal,
  94. MyTotal: myTotal,
  95. }, c)
  96. return
  97. }
  98. // GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
  99. func GetNeedCommentAnonymousUserTips(c *gin.Context) {
  100. userinfo := userService.GetInfoByClaims(c)
  101. // true 不弹框,false弹框
  102. if userinfo.NickName != `` {
  103. response.OkData("获取成功", true, c)
  104. return
  105. }
  106. ok, err := yb_community_question.GetNeedCommentAnonymousUserTips(userinfo.UserID)
  107. if err != nil {
  108. response.FailMsg("获取失败", err.Error(), c)
  109. return
  110. }
  111. response.OkData("获取成功", ok, c)
  112. }
  113. // SetCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
  114. func SetCommentAnonymousUserTips(c *gin.Context) {
  115. userinfo := userService.GetInfoByClaims(c)
  116. err := yb_community_question.SetYbCommentAnonymousUserTips(userinfo.UserID)
  117. if err != nil {
  118. response.FailMsg("设置失败", err.Error(), c)
  119. return
  120. }
  121. response.Ok("设置成功", c)
  122. }