query.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
  13. Where("user_id = ? and report_id = ? and enabled = 1 ", userId, reportId)
  14. if reportChapterId > 0 {
  15. tmp = tmp.Where("report_chapter_id = ?", reportChapterId)
  16. }
  17. err = tmp.Order("create_time desc, comment_id desc").
  18. Scan(&list).Error
  19. if err == utils.ErrNoRow {
  20. err = nil
  21. }
  22. return
  23. }
  24. // GetListByUserIdOldReportId 获取用户的留言列表
  25. func GetListByUserIdOldReportId(userId uint64, oldReportId, oldReportChapterId int) (list []*YbComment, err error) {
  26. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  27. Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ? and enabled = 1 ", userId, oldReportId, oldReportChapterId).
  28. Order("create_time desc, comment_id desc").
  29. Scan(&list).Error
  30. if err == utils.ErrNoRow {
  31. err = nil
  32. }
  33. return
  34. }
  35. // GetHotListByReportId 获取报告的精选留言列表
  36. func GetHotListByReportId(reportId, reportChapterId int, offset, limit int) (list []*YbComment, err error) {
  37. //err = global.DEFAULT_MYSQL.Model(YbComment{}).
  38. // Where("report_id = ? and report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId, reportChapterId).
  39. // Order("is_top desc, hot_top_time desc, comment_id desc").
  40. // Offset(offset).
  41. // Limit(limit).
  42. // Scan(&list).Error
  43. tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
  44. Where("report_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId)
  45. // 如果有填写章节id,那么就查询章节id
  46. if reportChapterId > 0 {
  47. tmp = tmp.Where("report_chapter_id = ? ", reportChapterId)
  48. }
  49. err = tmp.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. // GetHotListTotalByReportId 获取精选留言总条数
  56. func GetHotListTotalByReportId(reportId, reportChapterId int) (total int64, err error) {
  57. tmp := global.DEFAULT_MYSQL.Model(YbComment{}).
  58. Where("report_id = ? and enabled = 1 and is_hot = 1 and type = 1", reportId)
  59. // 如果有填写章节id,那么就查询章节id
  60. if reportChapterId > 0 {
  61. tmp = tmp.Where(" report_chapter_id = ? ", reportChapterId)
  62. }
  63. err = tmp.Count(&total).Error
  64. return
  65. }
  66. // GetHotListByOldReportId 获取老报告的精选留言列表
  67. func GetHotListByOldReportId(oldReportId, oldReportChapterId int, offset, limit int) (list []*YbComment, err error) {
  68. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  69. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  70. Order("is_top desc, hot_top_time desc, comment_id desc").
  71. Offset(offset).
  72. Limit(limit).
  73. Scan(&list).Error
  74. return
  75. }
  76. // GetHotListTotalByOldReportId 获取老报告的精选留言总条数
  77. func GetHotListTotalByOldReportId(oldReportId, oldReportChapterId int) (total int64, err error) {
  78. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  79. Where("old_report_id = ? and old_report_chapter_id = ? and enabled = 1 and is_hot = 1 and type = 1", oldReportId, oldReportChapterId).
  80. Count(&total).Error
  81. return
  82. }
  83. // GetReplyListByReplyCommentId 获取报告的精选留言的回复列表
  84. func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbComment, err error) {
  85. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  86. Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
  87. Order("comment_id asc").
  88. Scan(&list).Error
  89. return
  90. }
  91. // GetSimpleByCommentId 根据留言ID,查询留言
  92. func GetSimpleByCommentId(commentId uint64) (item *YbComment, err error) {
  93. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  94. Select("comment_id, user_id, type, enabled").
  95. Where("comment_id = ?", commentId).First(&item).Error
  96. if err == utils.ErrNoRow {
  97. err = nil
  98. }
  99. return
  100. }
  101. // GetMyLatestComment 获取用户最新的留言
  102. func GetMyLatestComment(userId uint64) (item *YbComment, err error) {
  103. err = global.DEFAULT_MYSQL.Model(YbComment{}).
  104. Select("comment_id, user_id, type, enabled, is_show_name").
  105. Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
  106. return
  107. }