123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package community
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/logic/yb_community_question"
- "hongze/hongze_yb/models/request"
- responseModel "hongze/hongze_yb/models/response"
- userService "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "strconv"
- )
- // Comment 发布留言
- func Comment(c *gin.Context) {
- var req request.ReqComment
- if c.ShouldBind(&req) != nil {
- response.Fail("入参错误", c)
- return
- }
- userInfo := userService.GetInfoByClaims(c)
- ybCommunityQuestionComment, err, errMsg := yb_community_question.Comment(userInfo, req.CommunityQuestionID, req.Content, req.SourceAgent, req.IsShowName)
- if err != nil {
- response.FailMsg(errMsg, err.Error(), c)
- return
- }
- response.OkData("留言成功", responseModel.RespCommunityQuestionCommentAdd{
- CommunityQuestionCommentID: ybCommunityQuestionComment.CommunityQuestionCommentID,
- }, c)
- return
- }
- // DeleteComment 删除留言
- func DeleteComment(c *gin.Context) {
- var req *request.ReqDel
- if c.ShouldBind(&req) != nil {
- response.Fail("参数异常", c)
- return
- }
- userInfo := userService.GetInfoByClaims(c)
- err, errMsg := yb_community_question.Delete(userInfo, req.CommunityQuestionCommentID)
- if err != nil {
- response.FailMsg(errMsg, err.Error(), c)
- return
- }
- response.Ok("删除留言成功", c)
- return
- }
- // HotList 获取精选留言
- func HotList(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- reqOldReportId := c.DefaultQuery("old_report_id", "")
- reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
- reqPageIndex := c.DefaultQuery("current_index", "1")
- reqPageSize := c.DefaultQuery("page_size", strconv.Itoa(utils.PageSize20))
- pageIndex, err := strconv.Atoi(reqPageIndex)
- if err != nil {
- response.Fail("请输入正确的条数限制", c)
- return
- }
- pageSize, err := strconv.Atoi(reqPageSize)
- if err != nil {
- response.Fail("请输入正确的页码", c)
- return
- }
- var (
- reportId int
- reportChapterId int
- oldReportId int
- oldReportChapterId int
- )
- if reqReportId != "" {
- reportId, err = strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- }
- if reqReportChapterId != "" {
- reportChapterId, err = strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- if reqOldReportId != "" {
- oldReportId, err = strconv.Atoi(reqOldReportId)
- if err != nil {
- response.Fail("老报告ID格式有误", c)
- return
- }
- }
- if reqOldReportChapterId != "" {
- oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := yb_community_question.List(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId, true, pageIndex, pageSize)
- if err != nil {
- response.Fail(err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c)
- return
- }
- // MyList 获取我的留言
- func MyList(c *gin.Context) {
- reqReportId := c.DefaultQuery("report_id", "")
- reqReportChapterId := c.DefaultQuery("report_chapter_id", "")
- reqOldReportId := c.DefaultQuery("old_report_id", "")
- reqOldReportChapterId := c.DefaultQuery("old_report_chapter_id", "")
- var (
- reportId int
- reportChapterId int
- oldReportId int
- oldReportChapterId int
- err error
- )
- if reqReportId != "" {
- reportId, err = strconv.Atoi(reqReportId)
- if err != nil {
- response.Fail("报告ID格式有误", c)
- return
- }
- }
- if reqReportChapterId != "" {
- reportChapterId, err = strconv.Atoi(reqReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- if reqOldReportId != "" {
- oldReportId, err = strconv.Atoi(reqOldReportId)
- if err != nil {
- response.Fail("老报告ID格式有误", c)
- return
- }
- }
- if reqOldReportChapterId != "" {
- oldReportChapterId, err = strconv.Atoi(reqOldReportChapterId)
- if err != nil {
- response.Fail("章节ID格式有误", c)
- return
- }
- }
- userinfo := userService.GetInfoByClaims(c)
- list, err := yb_community_question.MyList(userinfo, reportId, reportChapterId, oldReportId, oldReportChapterId)
- if err != nil {
- response.Fail(err.Error(), c)
- return
- }
- response.OkData("查询成功", list, c)
- return
- }
- // GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
- func GetNeedCommentAnonymousUserTips(c *gin.Context) {
- userinfo := userService.GetInfoByClaims(c)
- ok, err := yb_community_question.GetNeedCommentAnonymousUserTips(userinfo.UserID)
- if err != nil {
- response.FailMsg("获取失败", err.Error(), c)
- return
- }
- response.OkData("获取成功", ok, c)
- }
- // SetCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
- func SetCommentAnonymousUserTips(c *gin.Context) {
- userinfo := userService.GetInfoByClaims(c)
- err := yb_community_question.SetYbCommentAnonymousUserTips(userinfo.UserID)
- if err != nil {
- response.FailMsg("设置失败", err.Error(), c)
- return
- }
- response.Ok("设置成功", c)
- }
|