query.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package yb_like
  2. import (
  3. "hongze/hongze_yb/global"
  4. "hongze/hongze_yb/utils"
  5. )
  6. // GetLikeByUserIdAndReportId 获取点赞记录
  7. func GetLikeByUserIdAndReportId(userId uint64, reportId, reportChapterId int) (item *YbLike, err error) {
  8. err = global.DEFAULT_MYSQL.Model(YbLike{}).
  9. Where("user_id = ? and report_id = ? and report_chapter_id = ?", userId, reportId, reportChapterId).
  10. First(&item).Error
  11. if err == utils.ErrNoRow {
  12. err = nil
  13. }
  14. return
  15. }
  16. // GetLikeByUserIdAndOldReportId 获取点赞记录
  17. func GetLikeByUserIdAndOldReportId(userId uint64, oldReportId, oldReportChapterId int) (item *YbLike, err error) {
  18. err = global.DEFAULT_MYSQL.Model(YbLike{}).
  19. Where("user_id = ? and old_report_id = ? and old_report_chapter_id = ?", userId, oldReportId, oldReportChapterId).
  20. First(&item).Error
  21. if err == utils.ErrNoRow {
  22. err = nil
  23. }
  24. return
  25. }
  26. // GetLikeNumByReportId 统计报告的点赞数
  27. func GetLikeNumByReportId(reportId, reportChapterId int) (num int64, err error) {
  28. err = global.DEFAULT_MYSQL.Model(YbLike{}).
  29. Where("report_id = ? and report_chapter_id = ? and enabled=1", reportId, reportChapterId).
  30. Count(&num).Error
  31. return
  32. }
  33. // GetLikeNumByOldReportId 统计报告的点赞数
  34. func GetLikeNumByOldReportId(oldReportId, oldReportChapterId int) (num int64, err error) {
  35. err = global.DEFAULT_MYSQL.Model(YbLike{}).
  36. Where("old_report_id = ? and old_report_chapter_id = ? and enabled=1", oldReportId, oldReportChapterId).
  37. Count(&num).Error
  38. return
  39. }