|
|
@@ -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])) {
|