query.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package yb_comment
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. // GetListByUserId 获取用户的留言列表
  7. func GetListByUserId(userId uint64, reportId, reportChapterId int) (list []*YbComment, err error) {
  8. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  9. Where("user_id = ? and report_id = ? and report_chapter_id = ?", userId, reportId, reportChapterId).
  10. Order("create_time desc, id desc").
  11. Scan(&list).Error
  12. if err == utils.ErrNoRow {
  13. err = nil
  14. }
  15. return
  16. }
  17. // GetHotListByReportId 获取报告的精选留言列表
  18. func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbComment, err error) {
  19. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  20. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  21. Order("hot_top_time desc, id desc").
  22. Offset(offset).
  23. Limit(limit).
  24. Scan(&list).Error
  25. return
  26. }
  27. // GetReplayListByReplyCommentId 获取报告的精选留言的回复列表
  28. func GetReplayListByReplyCommentId(reportId, reportChapterId int, replyCommentIds []int) (list []*YbComment, err error) {
  29. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  30. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and type = 2 and reply_comment_id in ?", reportId, reportChapterId, replyCommentIds).
  31. Order("create_time desc, id desc").
  32. Scan(&list).Error
  33. return
  34. }
  35. // GetSimpleByCommentId 根据评论ID,查询评论
  36. func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error) {
  37. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  38. Select("comment_id, user_id, type, enabled").
  39. Where("comment_id = ?", commentId).First(&item).Error
  40. if err == utils.ErrNoRow {
  41. err = nil
  42. }
  43. return
  44. }