123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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
- }
|