query.go 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package yb_comment
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. // GetListByUserIdReportId 获取用户的留言列表
  7. func GetListByUserIdReportId(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 = ? and enabled = 1 ", userId, reportId, reportChapterId).
  10. Order("create_time desc, comment_id desc").
  11. Scan(&list).Error
  12. if err == utils.ErrNoRow {
  13. err = nil
  14. }
  15. return
  16. }
  17. // GetListByUserIdOldReportId 获取用户的留言列表
  18. func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbComment, err error) {
  19. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  20. Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ? and enabled = 1 ", userId, oldReportId, oldReportChapterId).
  21. Order("create_time desc, comment_id desc").
  22. Scan(&list).Error
  23. if err == utils.ErrNoRow {
  24. err = nil
  25. }
  26. return
  27. }
  28. // GetHotListByReportId 获取报告的精选留言列表
  29. func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbComment, err error) {
  30. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  31. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  32. Order("is_top desc, hot_top_time desc, comment_id desc").
  33. Offset(offset).
  34. Limit(limit).
  35. Scan(&list).Error
  36. return
  37. }
  38. // GetHotListTotalByReportId 获取精选留言总条数
  39. func GetHotListTotalByReportId(reportId, reportChapterId int)(total int64, err error) {
  40. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  41. Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  42. Count(&total).Error
  43. return
  44. }
  45. // GetHotListByOldReportId 获取老报告的精选留言列表
  46. func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbComment, err error) {
  47. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  48. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  49. Order("is_top desc, hot_top_time desc, comment_id desc").
  50. Offset(offset).
  51. Limit(limit).
  52. Scan(&list).Error
  53. return
  54. }
  55. // GetHotListTotalByOldReportId 获取老报告的精选留言总条数
  56. func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int)(total int64, err error) {
  57. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  58. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  59. Count(&total).Error
  60. return
  61. }
  62. // GetReplyListByReplyCommentId 获取报告的精选留言的回复列表
  63. func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbComment, err error) {
  64. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  65. Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
  66. Order("comment_id asc").
  67. Scan(&list).Error
  68. return
  69. }
  70. // GetSimpleByCommentId 根据留言ID,查询留言
  71. func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error) {
  72. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  73. Select("comment_id, user_id, type, enabled").
  74. Where("comment_id = ?", commentId).First(&item).Error
  75. if err == utils.ErrNoRow {
  76. err = nil
  77. }
  78. return
  79. }
  80. // GetMyLatestComment 获取用户最新的留言
  81. func GetMyLatestComment(userId uint64) (item *YbComment, err error){
  82. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  83. Select("comment_id, user_id, type, enabled, is_show_name").
  84. Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
  85. return
  86. }