From cb7bce5cef446a2a341399b76ee4aec2c40ddc99 Mon Sep 17 00:00:00 2001 From: Echo <1711788888@qq.com> Date: Mon, 11 Dec 2023 18:56:34 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BF=AE=E6=94=B9=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/system/article.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 }