cqpCow 1 年之前
父节点
当前提交
cc341d01b7
共有 5 个文件被更改,包括 34 次插入47 次删除
  1. 6 2
      .idea/workspace.xml
  2. 7 12
      app/Service/MaterialService.php
  3. 7 12
      app/Service/ProcessService.php
  4. 14 0
      app/Service/Service.php
  5. 0 21
      public/.htaccess

+ 6 - 2
.idea/workspace.xml

@@ -2,7 +2,11 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="b5852db3-28ab-419d-82cf-b6c0f6b99397" name="变更" comment="">
-      <change beforePath="$PROJECT_DIR$/app/Service/TechnologyService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/TechnologyService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/MaterialService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/MaterialService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/ProcessService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/ProcessService.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/Service/Service.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Service/Service.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/public/.htaccess" beforeDir="false" afterPath="$PROJECT_DIR$/public/.htaccess" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -153,7 +157,7 @@
       <workItem from="1685669123669" duration="2439000" />
       <workItem from="1685952381761" duration="726000" />
       <workItem from="1686021203384" duration="14595000" />
-      <workItem from="1686099374239" duration="15550000" />
+      <workItem from="1686099374239" duration="19440000" />
     </task>
     <servers />
   </component>

+ 7 - 12
app/Service/MaterialService.php

@@ -73,17 +73,17 @@ class MaterialService extends Service
                 $data['data'][$key]['crt_time'] = time();
             }else{
                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
-                $bool = BasicMaterial::where('del_time',0)
-                    ->where('parent_id',$data['id'])
-                    ->exists();
-                if($bool) return [false,'物料分类下存在子集!'];
-
                 $bool = BasicMaterial::where('title',$value['title'])
                     ->where('id','<>',$data['id'])
                     ->where('del_time',0)
                     ->exists();
             }
             if($bool) return [false,'名称不能重复'];
+
+            $bool = Material::where('del_time',0)
+                ->where('b_m_id',$value['parent_id'])
+                ->exists();
+            if($bool) return [false,'分类下存在物料!'];
         }
 
         return [true,$data];
@@ -193,13 +193,8 @@ class MaterialService extends Service
             $type = BasicMaterial::where('del_time',0)
                 ->select('id','parent_id')
                 ->get()->toArray();
-            $this->getAllIdsArr($type,0,'',$ids);
-            $string = $this->getLongestStr($ids, $data['b_m_id']);
-            $pos = strpos($string, (string)$data['b_m_id']);
-            if ($pos !== false) $id = substr($string, $pos);
-            $res_id = [];
-            if(! empty($id)) $res_id = explode(',',$id);
-            $model->whereIn("b_m_id", $res_id);
+            $result = array_merge($this->getAllDescendants($type,$data['b_m_id']),[$data['b_m_id']]);
+            $model->whereIn("b_m_id", $result);
         }
 
         $list = $this->limit($model,'',$data);

+ 7 - 12
app/Service/ProcessService.php

@@ -69,17 +69,17 @@ class ProcessService extends Service
                 $data['data'][$key]['crt_time'] = time();
             }else{
                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
-                $bool = BasicProcess::where('del_time',0)
-                    ->where('parent_id',$data['id'])
-                    ->exists();
-                if($bool) return [false,'物料分类下存在子集!'];
-
                 $bool = BasicProcess::where('title',$value['title'])
                     ->where('id','<>',$data['id'])
                     ->where('del_time',0)
                     ->exists();
             }
             if($bool) return [false,'名称不能重复'];
+
+            $bool = Process::where('del_time',0)
+                ->where('p_id',$value['parent_id'])
+                ->exists();
+            if($bool) return [false,'分类下存在工序!'];
         }
 
         return [true,$data];
@@ -142,13 +142,8 @@ class ProcessService extends Service
             $type = BasicProcess::where('del_time',0)
                 ->select('id','parent_id')
                 ->get()->toArray();
-            $this->getAllIdsArr($type,0,'',$ids);
-            $string = $this->getLongestStr($ids, $data['p_id']);
-            $pos = strpos($string, (string)$data['p_id']);
-            if ($pos !== false) $id = substr($string, $pos);
-            $res_id = [];
-            if(! empty($id)) $res_id = explode(',',$id);
-            $model->whereIn("p_id", $res_id);
+            $result = array_merge($this->getAllDescendants($type,$data['p_id']),[$data['p_id']]);
+            $model->whereIn("p_id", $result);
         }
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
 

+ 14 - 0
app/Service/Service.php

@@ -218,4 +218,18 @@ class Service
         }
         return $longest;
     }
+
+    function getAllDescendants($data, $id) {
+        $result = array(); // 存储结果的数组
+
+        foreach ($data as $node) {
+            if ($node['parent_id'] == $id) { // 如果当前节点的父 ID 等于指定 ID,则将该节点添加到结果中
+                $result[] = $node['id'];
+                // 递归查询该节点的所有子孙节点,并将结果合并到结果数组中
+                $result = array_merge($result, $this->getAllDescendants($data, $node['id']));
+            }
+        }
+
+        return $result;
+    }
 }

+ 0 - 21
public/.htaccess

@@ -1,21 +0,0 @@
-<IfModule mod_rewrite.c>
-    <IfModule mod_negotiation.c>
-        Options -MultiViews -Indexes
-    </IfModule>
-
-    RewriteEngine On
-
-    # Handle Authorization Header
-    RewriteCond %{HTTP:Authorization} .
-    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
-
-    # Redirect Trailing Slashes If Not A Folder...
-    RewriteCond %{REQUEST_FILENAME} !-d
-    RewriteCond %{REQUEST_URI} (.+)/$
-    RewriteRule ^ %1 [L,R=301]
-
-    # Handle Front Controller...
-    RewriteCond %{REQUEST_FILENAME} !-d
-    RewriteCond %{REQUEST_FILENAME} !-f
-    RewriteRule ^ index.php [L]
-</IfModule>