diff --git a/service/system/article.go b/service/system/article.go index 3238b79..d886ddc 100644 --- a/service/system/article.go +++ b/service/system/article.go @@ -36,11 +36,14 @@ func (a ArticleService) GetArticleById(id, userId string) (article *common.Artic err = global.GVA_DB.Where("id = ?", id).First(&article).Error err = global.GVA_DB.Table("articles").Where("id = ?", id).Update("reading_num", gorm.Expr("reading_num + ?", 1)).Error - // 判断是否收藏 - var favorite app.Favorite - err = global.GVA_DB.Where("wz_id = ? AND user_id = ?", id, userId).First(&favorite).Error - if favorite.ID != 0 { - article.IsFavorite = 1 + if userId != "" { + // 判断是否收藏 + var favorite app.Favorite + global.GVA_DB.Where("wz_id = ? AND user_id = ?", id, userId).First(&favorite) + if favorite.ID != 0 { + article.IsFavorite = 1 + } } + return }