🎨 新增用户端文章接口&优化部分旧接口

This commit is contained in:
2025-07-31 02:40:13 +08:00
parent 9f220dc025
commit 4ce59a3090
5 changed files with 92 additions and 4 deletions

View File

@@ -75,7 +75,7 @@ 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 int) (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))
@@ -94,7 +94,9 @@ func (s ArticleService) APPGetArticle(id string, userId uint) (article *vo.Artic
global.GVA_LOG.Error("查询用户购买记录失败", zap.Error(err))
return nil, err
}
if count == 0 {
// 如果count = 0 或者 TeacherId 不等于 userId表示用户没有购买过该文章
if count == 0 && article.TeacherId != userId {
// 用户没有购买过隐藏Content
article.Content = ""
article.IsBuy = 0 // 设置为未购买
@@ -103,3 +105,39 @@ func (s ArticleService) APPGetArticle(id string, userId uint) (article *vo.Artic
return
}
// AppPush app端推送文章
func (s ArticleService) AppPush(req article.Article) (err error) {
err = global.GVA_DB.Create(&req).Error
if err != nil {
global.GVA_LOG.Error("推送文章失败", zap.Error(err))
return err
}
return nil
}
func (s ArticleService) GetMyArticleList(req request.GetList) (list []article.Article, total int64, err error) {
limit := req.PageSize
offset := req.PageSize * (req.Page - 1)
db := global.GVA_DB.Model(&article.Article{}).Where("teacher_id = ?", req.TeacherId)
if req.Title != "" {
db = db.Where("title LIKE ?", "%"+req.Title+"%")
}
if req.CategoryId != 0 {
db = db.Where("category_id = ?", req.CategoryId)
}
if req.Status != 0 {
db = db.Where("status = ?", req.Status)
}
err = db.Count(&total).Error
if err != nil {
return nil, 0, err
}
err = db.Limit(limit).Offset(offset).Find(&list).Error
return list, total, err
}