cqp 1 týždeň pred
rodič
commit
e62e600b61
1 zmenil súbory, kde vykonal 30 pridanie a 0 odobranie
  1. 30 0
      app/Service/ImportService.php

+ 30 - 0
app/Service/ImportService.php

@@ -1210,6 +1210,21 @@ class ImportService extends Service
                 }
             }
 
+            // ================== 【新增需求:导入时的子集联动更新】 ==================
+            // 1. 重新去数据库捞一下本次导入/更新涉及到的所有【顶级父节点】
+            $topParents = Fee::where('del_time', 0)
+                ->where('top_depart_id', $user['top_depart_id'])
+                ->whereIn('code', $all_codes)
+                ->where('parent_id', 0) // 只找顶级
+                ->select('id', 'is_other', 'is_direct')
+                ->get();
+
+            // 2. 统一对这些顶级节点的子集进行刷洗
+            $service = new FeeService();
+            foreach ($topParents as $parent) {
+                $service->syncChildrenAttributes($parent->id, $parent->is_other, $parent->is_direct);
+            }
+
             DB::commit();
         } catch (\Exception $e) {
             DB::rollBack();
@@ -1224,6 +1239,8 @@ class ImportService extends Service
         $codeIdx = array_search('code', $keys);
         $parentIdx = array_search('parent_id', $keys);
         $isOtherIdx = array_search('is_other', $keys);
+        $isDirectIdx = array_search('is_direct', $keys);
+        $sortIdx = array_search('sort', $keys);
 
         // 1. 获取基础数据
         list($dbFeeMap, $excelCodesMap) = $this->getFeeList($array, $user, $codeIdx);
@@ -1233,6 +1250,7 @@ class ImportService extends Service
         $parent_code_map = [];
 
         $is_other_map = array_flip(Fee::IS_OTHER);
+        $is_direct_map = array_flip(Fee::IS_DIRECT);
 
         // 2. 建立 Excel 内部父子关系映射(用于环路追溯)
         $currentExcelMap = [];
@@ -1264,6 +1282,18 @@ class ImportService extends Service
                 $array[$rowIndex][$isOtherIdx] = $is_other_map[$is_other_text];
             }
 
+            $is_direct_text = $value[$isDirectIdx] ?? '';
+            if (!isset($is_direct_map[$is_direct_text])) {
+                $errors[] = "第{$displayLine}行:是否直接投入费用[{$is_direct_text}]无效";
+            } else {
+                $array[$rowIndex][$isDirectIdx] = $is_direct_map[$is_direct_text];
+            }
+
+            if($is_other_text && $is_direct_text) $errors[] = "第{$displayLine}行:是否其他费用与是否直接投入费用不能同时开启";
+
+            $sort_v = trim($value[$sortIdx] ?? 0);
+            if(! is_numeric($sort_v))  $errors[] = "第{$displayLine}行:排序请填写数字";
+
             if ($valParentCode !== '') {
                 // --- A. 存在性校验 ---
                 // 这里会检查 006 是否在数据库,或者是否在本次 Excel 的其他行中