Преглед на файлове

优化获取并搜索任务规则

15313670163 преди 6 месеца
родител
ревизия
46331f5dc4
променени са 1 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. 9 2
      app/JsonRpc/CollectorService.php

+ 9 - 2
app/JsonRpc/CollectorService.php

@@ -221,6 +221,7 @@ class CollectorService implements CollectorServiceInterface
      */
     public function getRule(array $data): array
     {
+        $where = [];
         if(isset($data['web_id'])){
             $web = Web::where('id',$data['web_id'])->get();
             if(empty($web->toArray())){
@@ -238,7 +239,13 @@ class CollectorService implements CollectorServiceInterface
                 ['name','like','%'.$data['keyWord'].'%']
             ];
         }
-        $rep = Rule::withCount(relations:'arts')->where($where)->limit($data['pageSize'])->orderBy("created_at","desc")->offset(($data['page']-1)*$data['pageSize'])->get();
+        var_dump("===============",$where);
+        if(empty($where)){
+            $rep = Rule::withCount(relations:'arts')->limit($data['pageSize'])->orderBy("created_at","desc")->offset(($data['page']-1)*$data['pageSize'])->get();
+        }else{
+            $rep = Rule::withCount(relations:'arts')->where($where)->limit($data['pageSize'])->orderBy("created_at","desc")->offset(($data['page']-1)*$data['pageSize'])->get();
+        }
+        
         $count = Rule::where($where)->count();
         if($count==0){
             return Result::error('暂无相关规则任务!');
@@ -391,7 +398,7 @@ class CollectorService implements CollectorServiceInterface
      * 把可采集的列表页连接 打包成一个大数组
      * @return void
      */
-    public function addUrlArr($data)
+    public function addUrlArr($data):array
     {
         $arrList = [];
         array_push($arrList,$data['first_url']);