Browse Source

前端-修改获取新闻列表

15313670163 2 months ago
parent
commit
9b37af6ca6
1 changed files with 14 additions and 22 deletions
  1. 14 22
      app/JsonRpc/NewsService.php

+ 14 - 22
app/JsonRpc/NewsService.php

@@ -415,38 +415,30 @@ class NewsService implements NewsServiceInterface
 
 
     /**
+     * 获取新闻列表
      * @param array $data
      * @return array
      */
     public function getWebsiteArticleList(array $data): array
     {
         $where= [];
-
-        if(isset($data['title'])  && $data['title']){
-            array_push($where,['article.title','like','%'.$data['title'].'%']);
-        }
-        if(isset($data['category_name'])  && $data['category_name']){
-            array_push($where,['category.name','like','%'.$data['category_name'].'%']);
-        }
-        if(isset($data['author'])  && $data['author']){
-             array_push($where,['article.author','=',$data['author']]);
-        }
-        if(isset($data['islink'])  && $data['islink']!==""){
-            array_push($where,['article.islink','=',$data['islink']]);
-        }
-        if(isset($data['status']) && $data['status']!==""){
-            array_push($where,['article.status','=',$data['status']]);
+       
+       if(isset($data['keyword'])  && !empty($data['keyword'])){
+            array_push($where,['article.title','like','%'.$data['keyword'].'%']);
+        }
+        if(isset($data['catid'])  && !empty($data['catid'])){
+            $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->select('category_id')->first();
+            if(empty($category)){
+               return Result::error("此网站暂无此栏目",0); 
+            }
+            array_push($where,['catid',$data['catid']]);
         }
-        
+
         $rep = Article::where($where)
-            ->whereNotIn('article.status',[404])
-            ->leftJoin('category','article.catid','category.id')
-            ->select("article.*","category.name as category_name")
-            ->orderBy("article.id","desc")
+            ->orderBy("created_at","desc")
             ->limit($data['pageSize'])
             ->offset(($data['page']-1)*$data['pageSize'])->get();
-        $count =  Article::where($where)->whereNotIn('article.status',[404])
-            ->leftJoin('category','article.catid','category.id')->count();
+        $count =  Article::where($where)->count();
         $data = [
             'rows'=>$rep->toArray(),
             'count'=>$count