ソースを参照

fix:新增点赞、吐槽、获取配置等接口

Roc 2 年 前
コミット
738e005f82

+ 194 - 0
controller/community/comment.go

@@ -1 +1,195 @@
 package community
 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)
+}

+ 2 - 2
controller/community/question.go

@@ -5,7 +5,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/logic/yb_community_question_like_roast"
+	"hongze/hongze_yb/logic/yb_community_question"
 	"hongze/hongze_yb/models/request"
 	"hongze/hongze_yb/models/request"
 
 
 	respond "hongze/hongze_yb/models/response"
 	respond "hongze/hongze_yb/models/response"
@@ -338,7 +338,7 @@ func SetLikeOrRoast(c *gin.Context) {
 	}
 	}
 	userinfo := userService.GetInfoByClaims(c)
 	userinfo := userService.GetInfoByClaims(c)
 
 
-	communityQuestionLikeRoast, likeNum, roastNum, err, errMsg := yb_community_question_like_roast.SetLikeOrRoast(userinfo.UserID, req.CommunityQuestionId, req.OpType, req.Enable, req.SourceAgent)
+	communityQuestionLikeRoast, likeNum, roastNum, err, errMsg := yb_community_question.SetLikeOrRoast(userinfo.UserID, req.CommunityQuestionId, req.OpType, req.Enable, req.SourceAgent)
 	if err != nil {
 	if err != nil {
 		response.FailMsg(errMsg, err.Error(), c)
 		response.FailMsg(errMsg, err.Error(), c)
 		return
 		return

+ 340 - 0
logic/yb_community_question/yb_community_question_comment.go

@@ -0,0 +1,340 @@
+package yb_community_question
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/wx_user"
+	"hongze/hongze_yb/models/tables/yb_comment"
+	"hongze/hongze_yb/models/tables/yb_comment_anonymous_user"
+	"hongze/hongze_yb/models/tables/yb_community_question_comment"
+	"hongze/hongze_yb/services"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/services/wx_app"
+	"hongze/hongze_yb/utils"
+	"strconv"
+	"time"
+)
+
+// Comment 发布留言
+func Comment(user user.UserInfo, communityQuestionID uint32, content string, sourceAgent, isShowName int8) (ybCommunityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment, err error, errMsg string) {
+	errMsg = "发布留言失败"
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("yb_community_question Comment: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+	//校验请求入参
+	if isShowName != 0 && isShowName != 1 {
+		errMsg = "匿名设置出错"
+		err = errors.New(errMsg)
+		return
+	}
+	if content == "" {
+		errMsg = "请输入留言内容"
+		err = errors.New(errMsg)
+		return
+	}
+	if sourceAgent == 0 {
+		errMsg = "请输入留言来源"
+		err = errors.New(errMsg)
+		return
+	}
+	if communityQuestionID <= 0 {
+		errMsg = "请输入问答ID"
+		err = errors.New(errMsg)
+		return
+	}
+	// 敏感词过滤
+	if user.RecordInfo.OpenID != "" && user.RecordInfo.CreatePlatform == 6 { //只有小程序的用户才能走敏感词过滤接口
+		checkResult, tErr := wx_app.MsgSecCheck(user.RecordInfo.OpenID, content)
+		/*if tErr != nil {
+			errMsg = "敏感词过滤失败" + tErr.Error()
+			err = errors.New("敏感词过滤失败")
+			return
+		}*/
+		if tErr == nil {
+			if checkResult.Result != nil {
+				if checkResult.Result.Suggest != "pass" {
+					errMsg = "含有违禁词,不允许发布:" + checkResult.Result.Suggest + ".命中标签:" + strconv.Itoa(checkResult.Result.Label)
+					err = errors.New("含有违禁词,不允许发布。")
+					return
+				}
+			}
+		}
+	}
+
+	//新增留言
+	now := time.Now()
+	ybCommunityQuestionComment = &yb_community_question_comment.YbCommunityQuestionComment{
+		//CommunityQuestionCommentID: 0,
+		CommunityQuestionID: communityQuestionID,
+		UserID:              user.UserID,
+		Content:             content,
+		//ReplyCommentID:             0,
+		//IsTop:                      0,
+		//IsHot:                      0,
+		//HotTopTime:                 time.Time{},
+		Type:        1,
+		Enabled:     1,
+		IsShowName:  isShowName,
+		SourceAgent: sourceAgent,
+		//TopTime:                    time.Time{},
+		//HotTime:                    time.Time{},
+		ModifyTime: now,
+		CreateTime: now,
+	}
+	err = ybCommunityQuestionComment.Create()
+	if err != nil {
+		errMsg = "新增留言失败"
+		return
+	}
+
+	// TODO 给管理员发送模板消息
+	return
+}
+
+// Delete 删除留言
+func Delete(user user.UserInfo, communityQuestionCommentID uint64) (err error, errMsg string) {
+	errMsg = `删除留言失败`
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("comment Delete: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+	if communityQuestionCommentID <= 0 {
+		errMsg = `请输入留言ID`
+		err = errors.New(errMsg)
+		return
+	}
+	//校验请求入参
+	communityQuestionCommentInfo, err := yb_community_question_comment.GetByCommunityQuestionCommentId(communityQuestionCommentID)
+	if err != nil {
+		errMsg = `查询留言出错`
+		return
+	}
+	if communityQuestionCommentInfo.CommunityQuestionCommentID <= 0 {
+		errMsg = `留言不存在`
+		err = errors.New(errMsg)
+		return
+	}
+	if communityQuestionCommentInfo.UserID != user.UserID {
+		errMsg = `不允许删除他人的留言`
+		err = errors.New(errMsg)
+		return
+	}
+	if communityQuestionCommentInfo.Type != 1 {
+		errMsg = `不允许删除回复`
+		err = errors.New(errMsg)
+		return
+	}
+	if communityQuestionCommentInfo.Enabled == 0 {
+		return
+	}
+	err = yb_community_question_comment.Delete(user.UserID, communityQuestionCommentInfo.CommunityQuestionCommentID)
+	if err != nil {
+		errMsg = `删除留言出错`
+		return
+	}
+	return
+}
+
+// MyList 我的留言列表
+func MyList(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportChapterId int) (ret response.RespMyCommentList, err error) {
+	list, err := List(user, reportId, reportChapterId, oldReportId, oldReportChapterId, false, 0, 0)
+	if err != nil {
+		return
+	}
+	//查询我的最新一条留言是否勾选匿名的设置
+	lastComment, tErr := yb_comment.GetMyLatestComment(user.UserID)
+	if tErr == nil {
+		ret.IsShowName = lastComment.IsShowName
+	}
+	ret.List = list.List
+	return
+}
+
+// List 查询精选留言列表或我的留言列表
+func List(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
+	var errMsg string
+	defer func() {
+		if err != nil {
+			global.LOG.Critical(fmt.Sprintf("comment List: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
+		}
+	}()
+
+	if reportId <= 0 && reportChapterId <= 0 && oldReportId <= 0 && oldReportChapterId <= 0 {
+		err = errors.New("请输入报告ID")
+		return
+	}
+	if reportId <= 0 && oldReportId <= 0 {
+		err = errors.New("请输入报告ID")
+		return
+	}
+	//处理老报告, 转化成新报告ID
+	if reportId <= 0 && reportChapterId <= 0 && (oldReportId > 0 || oldReportChapterId > 0) {
+		reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(oldReportId), uint64(oldReportChapterId))
+		if err != nil {
+			return
+		}
+	} else {
+		// 判断报告ID是否正确
+		err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
+		if err != nil {
+			return
+		}
+	}
+	offset := (pageIndex - 1) * pageSize
+	var commentList []*yb_comment.YbComment
+	var total int64
+	//查询精选留言
+	if hotFlag {
+		if reportId > 0 {
+			commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言列表出错")
+				return
+			}
+			total, err = yb_comment.GetHotListTotalByReportId(reportId, reportChapterId)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言总数出错")
+				return
+			}
+		} else {
+			commentList, err = yb_comment.GetHotListByOldReportId(oldReportId, oldReportChapterId, offset, pageSize)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言列表出错")
+				return
+			}
+			total, err = yb_comment.GetHotListTotalByOldReportId(oldReportId, oldReportChapterId)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言总数出错")
+				return
+			}
+		}
+	} else {
+		//查询个人留言
+		if reportId > 0 {
+			commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言列表出错")
+				return
+			}
+		} else {
+			commentList, err = yb_comment.GetListByUserIdOldReportId(user.UserID, oldReportId, oldReportChapterId)
+			if err != nil {
+				errMsg = err.Error()
+				err = errors.New("查询精选留言列表出错")
+				return
+			}
+		}
+
+	}
+
+	var commentIds []uint64
+	var userIds []uint64
+	for _, v := range commentList {
+		commentIds = append(commentIds, v.CommentId)
+		userIds = append(userIds, v.UserId)
+	}
+	// 查询所有的回复列表
+	replyListMap := make(map[uint64][]*response.ReplyItem)
+	if len(commentIds) > 0 {
+		replyList, tErr := yb_comment.GetReplyListByReplyCommentId(commentIds)
+		if tErr != nil {
+			errMsg = tErr.Error()
+			err = errors.New("查询回复出错")
+			return
+		}
+		for _, v := range replyList {
+			t := new(response.ReplyItem)
+			t.CommentId = v.CommentId
+			t.Content = v.Content
+			t.AdminId = v.AdminId
+			t.CreateTime = v.CreateTime
+			t.ReplyCommentId = v.ReplyCommentId
+			t.AdminName = "弘则研究"
+			t.AdminImgUrl = utils.DEFAULT_HONGZE_SYS_LOGO
+			replyListMap[v.ReplyCommentId] = append(replyListMap[v.ReplyCommentId], t)
+		}
+	}
+
+	// 查询精选留言相关的用户
+	var userOthers []*wx_user.WxUser
+	if len(userIds) > 0 {
+		userOthers, err = wx_user.GetByUserIds(userIds)
+		if err != nil {
+			errMsg = err.Error()
+			err = errors.New("查询精选留言用户出错")
+			return
+		}
+	}
+	usersMap := make(map[uint64]*wx_user.WxUser)
+	for _, v := range userOthers {
+		usersMap[v.UserID] = v
+	}
+	var list []*response.RespCommentItem
+	for _, v := range commentList {
+		tmp := new(response.RespCommentItem)
+		tmp.CommentId = v.CommentId
+		tmp.UserId = v.UserId
+		tmp.UserName = "匿名用户" + strconv.Itoa(int(3333+v.UserId))
+		tmp.UserImgUrl = utils.DEFAULT_HONGZE_USER_LOGO
+		if info, ok := usersMap[v.UserId]; ok && v.IsShowName == 1 {
+			tmp.UserName = info.NickName
+			tmp.UserImgUrl = info.Headimgurl
+		}
+		tmp.Content = v.Content
+		tmp.IsHot = v.IsHot
+		tmp.IsTop = v.IsTop
+		tmp.HotTopTime = v.HotTopTime
+		tmp.CreateTime = v.CreateTime
+		tmp.IsShowName = v.IsShowName
+		if existList, ok := replyListMap[v.CommentId]; ok {
+			tmp.ReplyList = existList
+		}
+		list = append(list, tmp)
+	}
+	ret.List = list
+	if hotFlag {
+		ret.Paging = response.GetPaging(pageIndex, pageSize, int(total))
+	}
+	return
+}
+
+// GetNeedCommentAnonymousUserTips 获取是否 弹出让去设置头像 的提示框
+func GetNeedCommentAnonymousUserTips(userId uint64) (ok bool, err error) {
+	ybCommentAnonymousUser, err := yb_comment_anonymous_user.GetByUserId(userId)
+	if err != nil {
+		return
+	}
+	//如果找不到,那么认为是第一次评论,那么需要弹框提示
+	if ybCommentAnonymousUser.UserID <= 0 {
+		ok = true
+	}
+	return
+}
+
+// SetYbCommentAnonymousUserTips 设置不再提示 弹出让去设置头像 的提示框
+func SetYbCommentAnonymousUserTips(userId uint64) (err error) {
+	ybCommentAnonymousUser, err := yb_comment_anonymous_user.GetByUserId(userId)
+	if err != nil {
+		return
+	}
+	//如果找不到,那么认为是第一次评论,那么需要弹框提示
+	if ybCommentAnonymousUser.UserID <= 0 {
+		//ybCommentAnonymousUser = &yb_comment_anonymous_user.YbCommentAnonymousUser{
+		//	UserID:     userId,
+		//	CreateTime: time.Now(),
+		//}
+		//err = ybCommentAnonymousUser.Create()
+		err = yb_comment_anonymous_user.CreateBySql(userId, time.Now())
+	}
+	return
+}

+ 1 - 1
logic/yb_community_question_like_roast/yb_community_question_like_roast.go → logic/yb_community_question/yb_community_question_like_roast.go

@@ -1,4 +1,4 @@
-package yb_community_question_like_roast
+package yb_community_question
 
 
 import (
 import (
 	"errors"
 	"errors"

+ 9 - 9
models/request/comment/comment.go

@@ -1,15 +1,15 @@
 package comment
 package comment
 
 
 type ReqComment struct {
 type ReqComment struct {
-	Content                string `description:"留言内容" json:"content"`
-	ReportId               int `description:"报告ID" json:"report_id" `
-	ReportChapterId        int `description:"报告章节ID" json:"report_chapter_id" `
-	IsShowName             int8 `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
-	SourceAgent            int  `description:"留言入口来源,1:小程序,2:pc" json:"source_agent"`
-	OldReportId            int `description:"老后台报告ID (research_report_id)" json:"old_report_id" `
-	OldReportChapterId     int `description:"老后台报告章节ID(research_report_type_id)" json:"old_report_chapter_id" `
+	Content            string `description:"留言内容" json:"content"`
+	ReportId           int    `description:"报告ID" json:"report_id" `
+	ReportChapterId    int    `description:"报告章节ID" json:"report_chapter_id" `
+	IsShowName         int8   `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+	SourceAgent        int    `description:"留言入口来源,1:小程序,2:pc" json:"source_agent"`
+	OldReportId        int    `description:"老后台报告ID (research_report_id)" json:"old_report_id" `
+	OldReportChapterId int    `description:"老后台报告章节ID(research_report_type_id)" json:"old_report_chapter_id" `
 }
 }
 
 
 type ReqDel struct {
 type ReqDel struct {
-	CommentId        uint64 `description:"留言ID" json:"comment_id"`
-}
+	CommentId uint64 `description:"留言ID" json:"comment_id"`
+}

+ 13 - 0
models/request/community.go

@@ -49,3 +49,16 @@ type ReqCommunityQuestionLikeRoast struct {
 	Enable              int8   `description:"状态. 0-无效数据(已取消点赞/吐槽) 1-有效数据(点赞/吐槽)" json:"enable"`
 	Enable              int8   `description:"状态. 0-无效数据(已取消点赞/吐槽) 1-有效数据(点赞/吐槽)" json:"enable"`
 	SourceAgent         int8   `description:"点赞入口来源,1:小程序,2:小程序pc" json:"source_agent"`
 	SourceAgent         int8   `description:"点赞入口来源,1:小程序,2:小程序pc" json:"source_agent"`
 }
 }
+
+// ReqComment 问答新增评论请求
+type ReqComment struct {
+	CommunityQuestionID uint32 `description:"问答id" json:"community_question_id" `
+	Content             string `description:"留言内容" json:"content"`
+	IsShowName          int8   `description:"是否匿名 0-匿名,1-不匿名" json:"is_show_name"`
+	SourceAgent         int8   `description:"留言入口来源,1:小程序,2:pc" json:"source_agent"`
+}
+
+// ReqDel 删除评论
+type ReqDel struct {
+	CommunityQuestionCommentID uint64 `description:"留言ID" json:"community_question_comment_id"`
+}

+ 5 - 0
models/response/community.go

@@ -66,3 +66,8 @@ type RespCommunityQuestionLikeRoast struct {
 	RoastNum int64 `description:"吐槽总数" json:"roast_num"`
 	RoastNum int64 `description:"吐槽总数" json:"roast_num"`
 	Enabled  int8  `description:"本次点赞/吐槽结果: 0-已取消赞 1-有效赞" json:"like_enabled"`
 	Enabled  int8  `description:"本次点赞/吐槽结果: 0-已取消赞 1-有效赞" json:"like_enabled"`
 }
 }
+
+// RespCommunityQuestionCommentAdd 问答留言返回
+type RespCommunityQuestionCommentAdd struct {
+	CommunityQuestionCommentID uint64 `description:"留言ID" json:"community_question_comment_id"`
+}

+ 18 - 0
models/tables/yb_comment_anonymous_user/create.go

@@ -0,0 +1,18 @@
+package yb_comment_anonymous_user
+
+import (
+	"hongze/hongze_yb/global"
+	"time"
+)
+
+func (item *YbCommentAnonymousUser) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommentAnonymousUser{}).Create(item).Error
+	return
+}
+
+// CreateBySql 通过sql创建记录
+func CreateBySql(userId uint64, createTime time.Time) (err error) {
+	sql := "INSERT INTO `yb_comment_anonymous_user` (`user_id`,`create_time`) VALUES (51988,'2022-07-12 14:33:30.443')"
+	err = global.DEFAULT_MYSQL.Exec(sql, userId, createTime).Error
+	return
+}

+ 15 - 0
models/tables/yb_comment_anonymous_user/query.go

@@ -0,0 +1,15 @@
+package yb_comment_anonymous_user
+
+import (
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByUserId 根据用户ID,查询记录
+func GetByUserId(userId uint64) (item *YbCommentAnonymousUser, err error) {
+	err = global.DEFAULT_MYSQL.Where("user_id =  ? ", userId).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}

+ 25 - 0
models/tables/yb_comment_anonymous_user/yb_comment_anonymous_user.go

@@ -0,0 +1,25 @@
+package yb_comment_anonymous_user
+
+import (
+	"time"
+)
+
+// YbCommentAnonymousUser 问答社区评论匿名表
+type YbCommentAnonymousUser struct {
+	UserID     uint64    `gorm:"primaryKey;column:user_id;type:bigint(9) unsigned;not null;default:0" json:"-"` // 用户id
+	CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` // 添加时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbCommentAnonymousUser) TableName() string {
+	return "yb_comment_anonymous_user"
+}
+
+// YbCommentAnonymousUserColumns get sql column name.获取数据库列名
+var YbCommentAnonymousUserColumns = struct {
+	UserID     string
+	CreateTime string
+}{
+	UserID:     "user_id",
+	CreateTime: "create_time",
+}

+ 8 - 0
models/tables/yb_community_question_comment/create.go

@@ -0,0 +1,8 @@
+package yb_community_question_comment
+
+import "hongze/hongze_yb/global"
+
+func (item *YbCommunityQuestionComment) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(item).Error
+	return
+}

+ 112 - 0
models/tables/yb_community_question_comment/query.go

@@ -0,0 +1,112 @@
+package yb_community_question_comment
+
+import (
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByCommunityQuestionCommentId 根据留言ID,查询留言
+func GetByCommunityQuestionCommentId(communityQuestionCommentId uint64) (item *YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Where("community_question_comment_id =  ? ", communityQuestionCommentId).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
+// GetListByUserIdReportId 获取用户的留言列表
+func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list []*YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("user_id = ? and report_id = ? and report_chapter_id = ? and enabled = 1 ", userId, reportId, reportChapterId).
+		Order("create_time desc, comment_id desc").
+		Scan(&list).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
+// GetListByUserIdOldReportId 获取用户的留言列表
+func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ? and enabled = 1 ", userId, oldReportId, oldReportChapterId).
+		Order("create_time desc, comment_id desc").
+		Scan(&list).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
+// GetHotListByReportId 获取报告的精选留言列表
+func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
+		Order("is_top desc, hot_top_time desc, comment_id desc").
+		Offset(offset).
+		Limit(limit).
+		Scan(&list).Error
+	return
+}
+
+// GetHotListTotalByReportId 获取精选留言总条数
+func GetHotListTotalByReportId(reportId, reportChapterId int) (total int64, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
+		Count(&total).Error
+	return
+}
+
+// GetHotListByOldReportId 获取老报告的精选留言列表
+func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
+		Order("is_top desc, hot_top_time desc, comment_id desc").
+		Offset(offset).
+		Limit(limit).
+		Scan(&list).Error
+	return
+}
+
+// GetHotListTotalByOldReportId 获取老报告的精选留言总条数
+func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total int64, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
+		Count(&total).Error
+	return
+}
+
+// GetReplyListByReplyCommentId 获取报告的精选留言的回复列表
+func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
+		Order("comment_id asc").
+		Scan(&list).Error
+	return
+}
+
+type SimpleYbCommunityQuestionComment struct {
+	CommunityQuestionCommentID uint64 `gorm:"primaryKey;column:community_question_comment_id;type:bigint(20) unsigned;not null" json:"-"`
+	UserID                     uint64 `gorm:"column:user_id;type:bigint(20) unsigned;not null;default:0" json:"userId"` // 用户id
+	Type                       int8   `gorm:"column:type;type:tinyint(1);not null;default:1" json:"type"`               // 留言类型 1-评论 2-回复
+	Enabled                    int8   `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"`         // 是否有效, 0-无效留言 1-有效留言
+}
+
+// GetSimpleByCommentId 根据留言ID,查询留言
+func GetSimpleByCommentId(commentId uint64) (item *SimpleYbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Select("community_question_comment_id, user_id, type, enabled").
+		Where("comment_id = ?", commentId).First(&item).Error
+	if err == utils.ErrNoRow {
+		err = nil
+	}
+	return
+}
+
+// GetMyLatestComment 获取用户最新的留言
+func GetMyLatestComment(userId uint64) (item *YbCommunityQuestionComment, err error) {
+	err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
+		Select("comment_id, user_id, type, enabled, is_show_name").
+		Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
+	return
+}

+ 40 - 0
models/tables/yb_community_question_comment/update.go

@@ -0,0 +1,40 @@
+package yb_community_question_comment
+
+import "hongze/hongze_yb/global"
+
+// Update 更新对应字段数据
+func (item *YbCommunityQuestionComment) Update(updateCols []string) (err error) {
+	err = global.DEFAULT_MYSQL.Model(item).Select(updateCols).Updates(*item).Error
+	return
+}
+
+// Delete 软删除,隐藏评论
+func Delete(userId uint64, commentId uint64) (err error) {
+	tx := global.DEFAULT_MYSQL.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+	sql1 := ` UPDATE yb_community_question_comment
+			SET
+            	enabled = 0,
+				modify_time = NOW(),
+				is_hot = 0,
+				is_top = 0
+			WHERE type = 1 and user_id = ? and community_question_comment_id = ?`
+	err = tx.Exec(sql1, userId, commentId).Error
+	if err != nil {
+		return
+	}
+	// 删除相关联的回复
+	sql2 := ` UPDATE yb_community_question_comment
+			SET
+            	enabled = 0,
+				modify_time = NOW()
+			WHERE reply_comment_id = ? and type = 2`
+	err = tx.Exec(sql2, commentId).Error
+	return
+}

+ 67 - 0
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -0,0 +1,67 @@
+package yb_community_question_comment
+
+import (
+	"time"
+)
+
+// YbCommunityQuestionComment 研报问答社区 用户留言表
+type YbCommunityQuestionComment struct {
+	CommunityQuestionCommentID uint64    `gorm:"primaryKey;column:community_question_comment_id;type:bigint(20) unsigned;not null" json:"-"`
+	CommunityQuestionID        uint32    `gorm:"column:community_question_id;type:int(10) unsigned;not null;default:0" json:"communityQuestionId"` // 问答ID
+	UserID                     uint64    `gorm:"column:user_id;type:bigint(20) unsigned;not null;default:0" json:"userId"`                         // 用户id
+	Content                    string    `gorm:"column:content;type:text" json:"content"`                                                          // 留言内容
+	ReplyCommentID             uint64    `gorm:"column:reply_comment_id;type:bigint(20) unsigned;not null;default:0" json:"replyCommentId"`        // 回复的留言ID
+	IsTop                      int8      `gorm:"column:is_top;type:tinyint(2);not null;default:0" json:"isTop"`                                    // 是否置顶(0-未置顶,1-置顶)
+	IsHot                      int8      `gorm:"column:is_hot;type:tinyint(2);not null;default:0" json:"isHot"`                                    // 是否设置精选(0-未设置,1-已设置)
+	HotTopTime                 time.Time `gorm:"column:hot_top_time;type:datetime" json:"hotTopTime"`                                              // 设置精选或者设置置顶的时间
+	Type                       int8      `gorm:"column:type;type:tinyint(1);not null;default:1" json:"type"`                                       // 留言类型 1-评论 2-回复
+	Enabled                    int8      `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"`                                 // 是否有效, 0-无效留言 1-有效留言
+	IsShowName                 int8      `gorm:"column:is_show_name;type:tinyint(1);not null;default:0" json:"isShowName"`                         // 是否匿名 0-匿名,1-不匿名
+	SourceAgent                int8      `gorm:"column:source_agent;type:tinyint(1);not null;default:1" json:"sourceAgent"`                        // 留言入口来源,1:小程序,2:小程序pc, 4:web pc
+	TopTime                    time.Time `gorm:"column:top_time;type:datetime" json:"topTime"`                                                     // 设置精选的时间
+	HotTime                    time.Time `gorm:"column:hot_time;type:datetime" json:"hotTime"`                                                     // 设置置顶的时间
+	ModifyTime                 time.Time `gorm:"column:modify_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"modifyTime"`            // 修改时间
+	CreateTime                 time.Time `gorm:"column:create_time;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"createTime"`            // 创建时间
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *YbCommunityQuestionComment) TableName() string {
+	return "yb_community_question_comment"
+}
+
+// YbCommunityQuestionCommentColumns get sql column name.获取数据库列名
+var YbCommunityQuestionCommentColumns = struct {
+	CommunityQuestionCommentID string
+	CommunityQuestionID        string
+	UserID                     string
+	Content                    string
+	ReplyCommentID             string
+	IsTop                      string
+	IsHot                      string
+	HotTopTime                 string
+	Type                       string
+	Enabled                    string
+	IsShowName                 string
+	SourceAgent                string
+	TopTime                    string
+	HotTime                    string
+	ModifyTime                 string
+	CreateTime                 string
+}{
+	CommunityQuestionCommentID: "community_question_comment_id",
+	CommunityQuestionID:        "community_question_id",
+	UserID:                     "user_id",
+	Content:                    "content",
+	ReplyCommentID:             "reply_comment_id",
+	IsTop:                      "is_top",
+	IsHot:                      "is_hot",
+	HotTopTime:                 "hot_top_time",
+	Type:                       "type",
+	Enabled:                    "enabled",
+	IsShowName:                 "is_show_name",
+	SourceAgent:                "source_agent",
+	TopTime:                    "top_time",
+	HotTime:                    "hot_time",
+	ModifyTime:                 "modify_time",
+	CreateTime:                 "create_time",
+}

+ 4 - 0
routers/community.go

@@ -19,4 +19,8 @@ func InitCommunity(r *gin.Engine) {
 	rGroup.GET("/question/research_group", community.ResearchGroupList)
 	rGroup.GET("/question/research_group", community.ResearchGroupList)
 	rGroup.POST("/question/audio/log", community.AddAudioLog)
 	rGroup.POST("/question/audio/log", community.AddAudioLog)
 	rGroup.POST("/set_like_or_roast", community.SetLikeOrRoast)
 	rGroup.POST("/set_like_or_roast", community.SetLikeOrRoast)
+	rGroup.POST("/comment", community.Comment)
+	rGroup.POST("/comment/delete", community.DeleteComment)
+	rGroup.GET("/need_anonymousUser_tips", community.GetNeedCommentAnonymousUserTips)
+	rGroup.POST("/set_anonymousUser_tips", community.SetCommentAnonymousUserTips)
 }
 }