Explorar el Código

验证关键词

FengR hace 2 meses
padre
commit
cf8f29183c
Se han modificado 1 ficheros con 16 adiciones y 24 borrados
  1. 16 24
      app/JsonRpc/PublicRpcService.php

+ 16 - 24
app/JsonRpc/PublicRpcService.php

@@ -4315,44 +4315,36 @@ class PublicRpcService implements PublicRpcServiceInterface
         }
         $where['id'] = $data['id'] ?? null;
         if($data['type'] == 'style'){
-            $template_class_keyword = TemplateClass::when(!empty($where),function($query)use($where){
+            $type = '风格';
+            $all_keywords = 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);
-                // return Result::success($keyword);
-            }
-            if(in_array($keyword,$template_class_keyword)){
-                return Result::error('此风格关键词已存在!');
-            }
+            
         }
         if($data['type'] == 'skin'){
-            $template_keyword = Template::when(!empty($where),function($query)use($where){
+            $type = '皮肤';
+            $all_keywords = 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);
-            }
-            if(in_array($keyword,$template_keyword)){
-                return Result::error('此皮肤关键词已存在!');
-            }
         }
         if($data['type'] == 'sector'){
-            $sector_keyword = Sector::when(!empty($where),function($query)use($where){
+            $type = '通栏';
+            $all_keywords = 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::when(!empty($where),function($query)use($where){
+            $type = '组件';
+            $all_keywords = 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('此组件关键词已存在!');
+        }
+        foreach($all_keywords as $key => $value){
+            // $value_keyword[$key] = $value;
+            $value_keyword = json_decode($value ?? '[]',true);
+            $repeat_keywords = array_intersect($arr_keyword,$value_keyword);
+            if(count($repeat_keywords) == count($keyword)){
+                return Result::error('此'.$type.'关键词已存在!');
             }
         }