Browse Source

修改b端:获取资讯列表的接口

FengR 4 tuần trước cách đây
mục cha
commit
59d75fc735
2 tập tin đã thay đổi với 25 bổ sung4 xóa
  1. 9 1
      app/JsonRpc/NewsService.php
  2. 16 3
      app/Model/Article.php

+ 9 - 1
app/JsonRpc/NewsService.php

@@ -469,9 +469,17 @@ class NewsService implements NewsServiceInterface
           $query->whereIn('article.status', $status1);
         }
       })
+      ->select('article.*')
       // 非管理员限制
       ->when($type_id != 10000, function ($query) use ($user_id) {
-        $query->where('article.admin_user_id', '=', $user_id);
+        // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
+        $query->where('article.admin_user_id', $user_id)
+              ->leftJoin('article_ignore', function ($join) {
+                  // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
+                  $join->on('article_ignore.article_id', '=', 'article.id')
+                       ->whereColumn('article_ignore.website_id', 'article.web_site_id');
+              })
+              ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
       })
       // 基础条件
       ->whereNotIn('article.status', [404])

+ 16 - 3
app/Model/Article.php

@@ -20,16 +20,29 @@ class Article extends Model
      */
     public function category()
     {
-        return $this->belongsTo(Category::class, 'category_id', 'id');
+        return $this->belongsTo(Category::class, 'catid', 'id');
     }
     /**
      * 定义与分类的多对一关系
      */
     public function websiteCategory()
     {
-        return $this->belongsTo(WebsiteCategory::class, 'category_id', 'id');
+        return $this->belongsTo(WebsiteCategory::class, 'catid', 'category_id');
+    }
+    /**
+     * 定义与分类的多对一关系
+     */
+    public function websiteCategory()
+    {
+        return $this->belongsTo(WebsiteCategory::class, 'catid', 'category_id');
+    }
+    /**
+     * 定义与分类的多对一关系
+     */
+    public function aricleIgnore()
+    {
+        return $this->belongsTo(ArticleIgnore::class, 'id', 'article_id');
     }
-
     /**
      * The attributes that are mass assignable.
      */