Explorar o código

验证关键词

FengR hai 2 meses
pai
achega
076474b6ed
Modificáronse 1 ficheiros con 16 adicións e 14 borrados
  1. 16 14
      app/JsonRpc/PublicRpcService.php

+ 16 - 14
app/JsonRpc/PublicRpcService.php

@@ -4309,19 +4309,15 @@ class PublicRpcService implements PublicRpcServiceInterface
             return Result::success('关键词为空');
         }
         $arr_keyword = json_decode($data['keyword'],true);
-        // return Result::success(is_array($keyword));
-        // $keyword_list = array_column($keyword,'keyword');
-        if(is_array($arr_keyword) && count($arr_keyword) != 1){
-            $keyword = array_map('trim', $arr_keyword);
-            if(count($keyword) != count(array_unique($keyword))){
-                return Result::error('关键词不能重复!');
-            }
-            
+        $keyword = array_map('trim', $arr_keyword);
+        if(count($keyword) != count(array_unique($keyword))){
+            return Result::error('关键词不能重复!');
         }
-        // return Result::success(json_encode($keyword,JSON_UNESCAPED_UNICODE));
-        // return Result::success(['template_keyword'=>$template_keyword,'keyword'=>$keyword]);
+        $where['id'] = $data['id'] ?? null;
         if($data['type'] == 'style'){
-            $template_class_keyword = TemplateClass::pluck('keyword')->toArray();
+            $template_class_keyword = TemplateClass::when(!empty($where),function($query)use($where){
+                $query->where('id','!=',$where['id']);
+            })->pluck('keyword')->toArray();
             $keyword = json_encode($keyword, JSON_UNESCAPED_UNICODE);
             if(is_array($arr_keyword) && count($arr_keyword) != 1){
                 $keyword = preg_replace('/,/', ', ', $keyword);
@@ -4332,7 +4328,9 @@ class PublicRpcService implements PublicRpcServiceInterface
             }
         }
         if($data['type'] == 'skin'){
-            $template_keyword = Template::pluck('template_keyword')->toArray();
+            $template_keyword = Template::when(!empty($where),function($query)use($where){
+                $query->where('id','!=',$where['id']);
+            })->pluck('template_keyword')->toArray();
             $keyword = json_encode($keyword, JSON_UNESCAPED_UNICODE);
             if(is_array($arr_keyword) && count($arr_keyword) != 1){
                 $keyword = preg_replace('/,/', ', ', $keyword);
@@ -4342,13 +4340,17 @@ class PublicRpcService implements PublicRpcServiceInterface
             }
         }
         if($data['type'] == 'sector'){
-            $sector_keyword = Sector::where('template_id',$data['template_id'])->pluck('sector_keyword')->toArray();
+            $sector_keyword = Sector::when(!empty($where),function($query)use($where){
+                $query->where('id','!=',$where['id']);
+            })->where('template_id',$data['template_id'])->pluck('sector_keyword')->toArray();
             if(in_array($keyword,$sector_keyword)){
                 return Result::error('此通栏关键词已存在!');
             }
         }
         if($data['type'] == 'component'){
-            $component_keyword = Component::pluck('component_keyword')->toArray();
+            $component_keyword = Component::when(!empty($where),function($query)use($where){
+                $query->where('id','!=',$where['id']);
+            })->pluck('component_keyword')->toArray();
             if(in_array($keyword,$component_keyword)){
                 return Result::error('此组件关键词已存在!');
             }