query.go 759 B

1234567891011121314151617181920212223242526
  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. // GetLikeNumByReportId 统计报告的点赞数
  17. func GetLikeNumByReportId(reportId, reportChapterId int) (num int64, err error) {
  18. err = global.DEFAULT_MYSQL.Model(YbLike{}).
  19. Where("report_id = ? and report_chapter_id = ? and enabled=1", reportId, reportChapterId).
  20. Count(&num).Error
  21. return
  22. }