Browse Source

修改获取新闻列表的接口

15313670163 2 months ago
parent
commit
17802c2dd3
2 changed files with 31 additions and 9 deletions
  1. 31 8
      app/JsonRpc/NewsService.php
  2. 0 1
      runtime/hyperf.pid

+ 31 - 8
app/JsonRpc/NewsService.php

@@ -425,7 +425,7 @@ class NewsService implements NewsServiceInterface
 
 
     /**
-     * 获取新闻列表
+     *获取新闻列表 
      * @param array $data
      * @return array
      */
@@ -438,17 +438,40 @@ class NewsService implements NewsServiceInterface
             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(is_array($data['catid'])){
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
+                $where[] = ['catid', 'in', $data['catid']];
+            }else{
+                $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
+                $where[] = ['catid', '=', $data['catid']];
+            }
             if(empty($category)){
                return Result::error("此网站暂无此栏目",0); 
             }
-            array_push($where,['catid',$data['catid']]);
         }
-        $rep = Article::where($where)
-            ->orderBy("created_at","desc")
-            ->limit($data['pageSize'])
-            ->offset(($data['page']-1)*$data['pageSize'])->get();
-        $count =  Article::where($where)->count();
+        // return Result::success($category);
+        $rep = Article::where(function ($query) use ($where) {
+            foreach ($where as $condition) {
+                if ($condition[1] === 'in') {
+                    $query->whereIn($condition[0], $condition[2]);
+                } else {
+                    $query->where($condition[0], $condition[1], $condition[2]);
+                }
+            }
+        })
+        ->orderBy("created_at", "desc")
+        ->limit($data['pageSize'])
+        ->offset(($data['page'] - 1) * $data['pageSize'])
+        ->get();
+        $count =  Article::where(function ($query) use ($where) {
+            foreach ($where as $condition) {
+                if ($condition[1] === 'in') {
+                    $query->whereIn($condition[0], $condition[2]);
+                } else {
+                    $query->where($condition[0], $condition[1], $condition[2]);
+                }
+            }
+        })->count();
         $data = [
             'rows'=>$rep->toArray(),
             'count'=>$count

+ 0 - 1
runtime/hyperf.pid

@@ -1 +0,0 @@
-65376