🎨 优化文章相关接口

This commit is contained in:
2025-07-25 23:02:57 +08:00
parent bb2a68fb61
commit 7951f77f47
3 changed files with 12 additions and 10 deletions

View File

@@ -75,13 +75,13 @@ func (s ArticleService) APPGetArticleList(pageInfo request.GetList) (list []vo.A
return
}
func (s ArticleService) APPGetArticle(id string, userId uint) (article vo.ArticleVo, err error) {
func (s ArticleService) APPGetArticle(id string, userId uint) (article *vo.ArticleVo, err error) {
err = global.GVA_DB.Table("article").Where("id = ?", id).First(&article).Error
if err != nil {
global.GVA_LOG.Error("获取文章失败", zap.Error(err))
return
}
article.IsBuy = 1 // 设置为已购买
article.IsBuy = 1
global.GVA_DB.Table("app_user").Select("avatar").Where("id = ?", article.TeacherId).Scan(&article.TeacherAvatar)
@@ -89,10 +89,10 @@ func (s ArticleService) APPGetArticle(id string, userId uint) (article vo.Articl
if article.IsFree == 0 {
// 如果不是免费文章,判断用户是否购买过
var count int64
err = global.GVA_DB.Model(&app.Order{}).Where("article_id = ? AND user_id = ?", id, userId).Count(&count).Error
err = global.GVA_DB.Model(&app.Order{}).Where("article_id = ? AND user_id = ? AND status = 2", id, userId).Count(&count).Error
if err != nil {
global.GVA_LOG.Error("查询用户购买记录失败", zap.Error(err))
return
return nil, err
}
if count == 0 {
// 用户没有购买过隐藏Content