Forráskód Böngészése

采集器修改导入文章接口

15313670163 3 hónapja
szülő
commit
761c795854
1 módosított fájl, 31 hozzáadás és 26 törlés
  1. 31 26
      app/JsonRpc/CollectorService.php

+ 31 - 26
app/JsonRpc/CollectorService.php

@@ -764,44 +764,49 @@ class CollectorService implements CollectorServiceInterface
     */
     */
     public function addCatid(array $data): array
     public function addCatid(array $data): array
     {
     {
+
         $id = $data['rule_id'];
         $id = $data['rule_id'];
         $art = Article::where('rule_id',$id)->select('id')->count();
         $art = Article::where('rule_id',$id)->select('id')->count();
         if($art==0){
         if($art==0){
             return Result::error('还未采集,请采集');
             return Result::error('还未采集,请采集');
         }else{
         }else{
             $info = Article::where('rule_id',$id)->where('state',0)->select('id')->get();
             $info = Article::where('rule_id',$id)->where('state',0)->select('id')->get();
-        if(empty($info->toArray())){
-            return Result::error('所有文章都已导入,不可修改关联的导航池!'); 
-        }else{
-            //查找此规则任务下的文章是否已经有导入的文章
-            $article = Article::where('rule_id',$id)->where('state',1)->select('id')->get();
-            if(!empty($article->toArray())){
-                //若有已导入的文章则直接复制之前已导入的导航池
-                $catid = Article::whereIn('id',$article)->select('catid')->first();
-                //若未导入的文章已经复制之前的导航,则无需修改
-                $art_catid = Article::whereIn('id',$info)->whereNull('catid')->count();
-                if($art_catid>0){
-                    $result = Article::whereIn('id',$info)->update(['catid'=>$catid['catid']]);
-                }else{
-                    $result = ['已全部关联导航,无需再次关联!'];
-                }
+            if(empty($info->toArray())){
+                return Result::error('所有文章都已导入,不可修改关联的导航池!'); 
             }else{
             }else{
-                //若不存在已导入的文章则判断是否存在导航id
-                if(isset($data['catid'])){
-                    //若存在直接使用此导航id
-                    $result = Article::whereIn('id',$info)->update(['catid'=>$data['catid']]);
-                    
+                //查找此规则任务下的文章是否已经有导入的文章
+                $article = Article::where('rule_id',$id)->where('state',1)->select('id')->get();
+                if(!empty($article->toArray())){
+                    //查询已导入的文章的导航id
+                    $catid = Article::whereIn('id',$article)->select('catid')->first();
+                    //查询未导入的文章id
+                    $art_catid = Article::whereIn('id',$info)->whereNull('catid')->count();
+                    if($art_catid>0){
+                        $cat_arr_id = json_decode($catid['catid']);
+                        $result = Article::whereIn('id',$info)->update(['catid'=>$catid['catid'],'cat_arr_id'=>$cat_arr_id]);
+                    }else{
+                        $result = ['已全部关联导航,无需再次关联!'];
+                    }
                 }else{
                 }else{
-                    //若不存在则返回所有导航栏目
-                    $result = Category::select('id','name')->get();
+                    //若不存在已导入的文章则判断是否存在导航id
+                    if(isset($data['catid'])){
+                        $cat_arr_id = json_decode($data['catid']);
+                        //若存在直接使用此导航id
+                        $result = Article::whereIn('id',$info)->update(['catid'=>$data['catid'],'cat_arr_id'=>$cat_arr_id]);
+                    }else{
+                        //若不存在则返回所有导航栏目
+                        $result = Category::select('id','name')->get();
+                    }
                 }
                 }
+                
             }
             }
-              
         }
         }
+        if(empty($result->toArray())){
+            return Result::error('暂无数据');
+        }else{
+            return  Result::success($result);
         }
         }
-        //查找此规则任务下的文章是否都已经导入
-        
-        return  Result::success($result);
+        // return  Result::success($result);
     }
     }
     /**
     /**
     * 导入文章(生产者)
     * 导入文章(生产者)