comment.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/models/tables/yb_community_question_comment"
  9. "hongze/hongze_yb/services"
  10. userService "hongze/hongze_yb/services/user"
  11. "strconv"
  12. )
  13. // Comment 发布留言
  14. func Comment(c *gin.Context) {
  15. var req request.ReqComment
  16. if c.ShouldBind(&req) != nil {
  17. response.Fail("入参错误", c)
  18. return
  19. }
  20. userInfo := userService.GetInfoByClaims(c)
  21. var qaAvatarUrl string
  22. //if userInfo.QaAvatarUrl == "" {
  23. // avatar, err := yb_community_question_comment.GetUserAvatarRandom()
  24. // if err != nil {
  25. // response.FailMsg("发布失败", err.Error(), c)
  26. // return
  27. // }
  28. // qaAvatarUrl = avatar.AvatarUrl
  29. // err = wx_user.ModifyQaAvatarUrl(qaAvatarUrl, userInfo.UserID)
  30. // if err != nil {
  31. // response.FailMsg("发布失败", err.Error(), c)
  32. // return
  33. // }
  34. //} else {
  35. // qaAvatarUrl = userInfo.QaAvatarUrl
  36. //}
  37. // 2022-0914修改为全随机
  38. avatar, e := yb_community_question_comment.GetUserAvatarRandom()
  39. if e != nil {
  40. response.FailMsg("发布失败", e.Error(), c)
  41. return
  42. }
  43. qaAvatarUrl = avatar.AvatarUrl
  44. req.IsShowName = 0
  45. if userInfo.NickName != `` { //非空串时为实名
  46. req.IsShowName = 1
  47. }
  48. ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName, qaAvatarUrl)
  49. if err != nil {
  50. response.FailMsg(errMsg, err.Error(), c)
  51. return
  52. }
  53. response.OkData("留言成功", responseModel.RespCommunityQuestionCommentAdd{
  54. CommunityQuestionCommentID: ybCommunityQuestionComment.CommunityQuestionCommentID,
  55. }, c)
  56. return
  57. }
  58. // DeleteComment 删除留言
  59. func DeleteComment(c *gin.Context) {
  60. var req *request.ReqDel
  61. if c.ShouldBind(&req) != nil {
  62. response.Fail("参数异常", c)
  63. return
  64. }
  65. userInfo := userService.GetInfoByClaims(c)
  66. err, errMsg := yb_community_question.Delete(userInfo, req.CommunityQuestionCommentID)
  67. if err != nil {
  68. response.FailMsg(errMsg, err.Error(), c)
  69. return
  70. }
  71. response.Ok("删除留言成功", c)
  72. return
  73. }
  74. // HotList 获取精选留言
  75. func HotList(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.List(userinfo.UserID, communityQuestionID, true, 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(hotTotal)),
  93. HotTotal: hotTotal,
  94. MyTotal: myTotal,
  95. }, c)
  96. return
  97. }
  98. // MyList 获取我的留言
  99. func MyList(c *gin.Context) {
  100. communityQuestionIDStr := c.DefaultQuery("community_question_id", "")
  101. communityQuestionID, err := strconv.Atoi(communityQuestionIDStr)
  102. if err != nil {
  103. response.Fail("问答id异常", c)
  104. return
  105. }
  106. userinfo := userService.GetInfoByClaims(c)
  107. page := services.GetCurrPageByClaims(c)
  108. pageSize := services.GetPageSizeByClaims(c)
  109. list, hotTotal, myTotal, err, errMsg := yb_community_question.MyList(userinfo.UserID, communityQuestionID, page, pageSize)
  110. if err != nil {
  111. response.FailMsg(errMsg, err.Error(), c)
  112. return
  113. }
  114. response.OkData("查询成功", responseModel.RespCommunityQuestionCommentList{
  115. List: list,
  116. Paging: responseModel.GetPaging(page, pageSize, int(myTotal)),
  117. HotTotal: hotTotal,
  118. MyTotal: myTotal,
  119. }, c)
  120. return
  121. }
  122. // GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
  123. func GetNeedCommentAnonymousUserTips(c *gin.Context) {
  124. userinfo := userService.GetInfoByClaims(c)
  125. // true 不弹框,false弹框
  126. if userinfo.NickName != `` {
  127. response.OkData("获取成功", true, c)
  128. return
  129. }
  130. ok, err := yb_community_question.GetNeedCommentAnonymousUserTips(userinfo.UserID)
  131. if err != nil {
  132. response.FailMsg("获取失败", err.Error(), c)
  133. return
  134. }
  135. response.OkData("获取成功", ok, c)
  136. }
  137. // SetCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
  138. func SetCommentAnonymousUserTips(c *gin.Context) {
  139. userinfo := userService.GetInfoByClaims(c)
  140. err := yb_community_question.SetYbCommentAnonymousUserTips(userinfo.UserID)
  141. if err != nil {
  142. response.FailMsg("设置失败", err.Error(), c)
  143. return
  144. }
  145. response.Ok("设置成功", c)
  146. }