cqp 2 miesięcy temu
rodzic
commit
886d19a95a

+ 36 - 0
app/Service/ImportService.php

@@ -838,6 +838,9 @@ class ImportService extends Service
             $main_tmp = [];
             foreach ($value as $k => $val) {
                 if (!empty($table_config[$k]['is_main'])) {
+
+                    if ($table_config[$k]['key'] == 'employee_title') continue;
+
                     $main_tmp[$table_config[$k]['key']] = $val;
                 }
             }
@@ -935,10 +938,19 @@ class ImportService extends Service
         $keys = array_column($table_config, 'key');
         $codeIdx = array_search('code', $keys);
         $stateIdx = array_search('state', $keys);
+        $attrIdx = array_search('item_attribute', $keys);
+        $budgetIdx = array_search('budget', $keys);
         $typeIdx = array_search('type', $keys);     // 明细类型列
         $code2Idx = array_search('code_2', $keys);  // 资产/工号列
         $dateIdx = array_search('start_time', $keys);
         $date2Idx = array_search('end_time', $keys);
+        $empIdx = array_search('charge_id', $keys);
+
+        $allEmpNumbers = array_filter(array_unique(array_column($array, $empIdx)));
+        $dbEmps = Employee::where('del_time', 0)
+            ->whereIn('number', $allEmpNumbers)
+            ->where('top_depart_id', $user['top_depart_id'])
+            ->pluck('id', 'number')->toArray();
 
         $code_map = $this->getItemList($array, $user, $codeIdx);
         // 这里的 getDataList 需要适配平铺后的 code_2 列
@@ -950,6 +962,7 @@ class ImportService extends Service
         $mainDataConsistency = []; // 一致性校验
 
         $state_type_map = array_flip(Item::State_Type);
+        $attr_map = array_flip(Item::Item_Attribute);
         $detail_type_map = array_flip(ItemDetails::$type_name);
 
         // 识别主表字段列索引
@@ -961,6 +974,7 @@ class ImportService extends Service
         foreach ($array as $rowIndex => $rowValue) {
             $displayLine = $rowIndex + 1;
             $valCode = trim($rowValue[$codeIdx] ?? '');
+            $valEmp = trim($row[$empIdx] ?? '');
             if ($valCode === '') continue;
 
             // --- A. 主表一致性校验 ---
@@ -987,6 +1001,28 @@ class ImportService extends Service
                 $array[$rowIndex][$stateIdx] = $state_type_map[$state_text];
             }
 
+            $attr_text = $rowValue[$attrIdx] ?? '';
+            if (!isset($attr_map[$attr_text])) {
+                $errors[] = "第{$displayLine}行:项目属性[{$attr_text}]无效";
+            } else {
+                $array[$rowIndex][$attrIdx] = $attr_map[$attr_text];
+            }
+
+            $budget_text = $rowValue[$budgetIdx] ?? 0;
+            if(! empty($budget_text)){
+                $res = $this->checkNumber($budget_text, 2, 'non-negative');
+                if (!$res['valid']) $errors[] = "第{$displayLine}行预算:" . $res['error'];
+            }
+
+            // D. 人员校验
+            if(! empty($valEmp)){
+                if (!isset($dbEmps[$valEmp])) {
+                    $errors[] = "第{$displayLine}行:人员工号[{$valEmp}]不存在";
+                } else {
+                    $array[$rowIndex][$empIdx] = $dbEmps[$valEmp];
+                }
+            }
+
             // 日期转换
             foreach ([$dateIdx, $date2Idx] as $dIdx) {
                 if ($dIdx !== false && !empty($rowValue[$dIdx])) {

+ 1 - 1
app/Service/ItemService.php

@@ -302,7 +302,7 @@ class ItemService extends Service
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
-        $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_merge_recursive(array_column($data['data'],'crt_id')),array_column($data['data'],'charge_id')));
+        $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_merge_recursive(array_column($data['data'],'charge_id'), array_column($data['data'],'crt_id'))));
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['start_time'] = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';

+ 55 - 0
config/excel/item.php

@@ -24,6 +24,61 @@ return [
             'enums' => [],
             'comments' => '必填'
         ],
+        [
+            'key' =>'budget',
+            'export' =>'budget',
+            'value' => '预算',
+            'required' => false,
+            'is_main' => true,
+            'default' => 0,
+            'unique' => false,
+            'enums' => [],
+            'comments' => ''
+        ],
+        [
+            'key' =>'field',
+            'export' =>'field',
+            'value' => '领域',
+            'required' => false,
+            'is_main' => true,
+            'default' => "",
+            'unique' => false,
+            'enums' => [],
+            'comments' => ''
+        ],
+        [
+            'key' =>'item_attribute',
+            'export' =>'item_attribute',
+            'value' => '项目属性',
+            'required' => true,
+            'is_main' => true,
+            'default' => \App\Model\Item::Attr_TYPE_ONE,
+            'unique' => false,
+            'enums' => array_values(\App\Model\Item::Item_Attribute),
+            'comments' => '必填'
+        ],
+        [
+            'key' =>'charge_id',
+            'export' =>'charge_number',
+            'value' => '负责人工号',
+            'required' => false,
+            'is_main' => true,
+            'default' => "",
+            'unique' => false,
+            'enums' => [],
+            'comments' => '选填(填写负责人工号)'
+        ],
+        [
+            'key' =>'employee_title',
+            'export' =>'charge_name',
+            'value' => '负责人名称',
+            'required' => false,
+            'is_main' => true,
+            'default' => "",
+            'unique' => false,
+            'enums' => [],
+            'comments' => '选填(便于操作人查看编码对应的名称)'
+        ],
         [
             'key' =>'start_time',
             'export' =>'start_time',