12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package yb_comment
- import (
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- // GetListByUserIdReportId 获取用户的留言列表
- func GetListByUserIdReportId(userId uint64, reportId, reportChapterId int) (list []*YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- 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 []*YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- 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 []*YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- 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(YbComment{}).
- 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 []*YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- 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(YbComment{}).
- 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 []*YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
- Order("comment_id asc").
- Scan(&list).Error
- return
- }
- // GetSimpleByCommentId 根据留言ID,查询留言
- func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- Select("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 *YbComment, err error){
- err = global.DEFAULT_MYSQL.Model(YbComment{}).
- 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
- }
|