|
|
@@ -296,7 +296,7 @@ class ImportService extends Service
|
|
|
->toArray();
|
|
|
}
|
|
|
|
|
|
- private function employeeCheck(&$array, $user, $table_config)
|
|
|
+ private function employeeCheck1(&$array, $user, $table_config)
|
|
|
{
|
|
|
$keys = array_column($table_config, 'key');
|
|
|
$codeIdx = array_search('number', $keys);
|
|
|
@@ -420,6 +420,164 @@ class ImportService extends Service
|
|
|
return [$error_str, $update_mapping, $detail_storage];
|
|
|
}
|
|
|
|
|
|
+ private function employeeCheck(&$array, $user, $table_config)
|
|
|
+ {
|
|
|
+ $keys = array_column($table_config, 'key');
|
|
|
+ $codeIdx = array_search('number', $keys);
|
|
|
+ $sexIdx = array_search('sex', $keys);
|
|
|
+ $eductionIdx = array_search('education', $keys);
|
|
|
+ $stateIdx = array_search('state', $keys);
|
|
|
+ $manIdx = array_search('man_type', $keys);
|
|
|
+ $entrustIdx = array_search('entrust_type', $keys);
|
|
|
+ $depIdx = array_search('depart_code', $keys);
|
|
|
+ $employeeTypeIdx = array_search('employee_type', $keys);
|
|
|
+
|
|
|
+ // 获取手机号字段在 Excel 中的列索引
|
|
|
+ $mobileIdx = array_search('mobile', $keys);
|
|
|
+
|
|
|
+ $code_map = $this->getEmployeeList($array, $user, $codeIdx);
|
|
|
+ $dep_map = $this->getEDataList($array, $user, $depIdx);
|
|
|
+
|
|
|
+ // --- 核心:提取 Excel 中所有不为空的手机号,批量去数据库核对唯一性 ---
|
|
|
+ $excelMobiles = [];
|
|
|
+ if ($mobileIdx !== false) {
|
|
|
+ $excelMobiles = array_unique(array_filter(array_map(function($row) use ($mobileIdx) {
|
|
|
+ return isset($row[$mobileIdx]) ? trim((string)$row[$mobileIdx]) : '';
|
|
|
+ }, $array)));
|
|
|
+ }
|
|
|
+
|
|
|
+ $dbMobileMap = [];
|
|
|
+ if (!empty($excelMobiles)) {
|
|
|
+ // 如果是全系统(跨租户)唯一,就不加 top_depart_id 条件
|
|
|
+ // 如果只需当前公司内唯一,请追加 ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ $dbMobileMap = Employee::where('del_time', 0)
|
|
|
+ ->whereIn('mobile', $excelMobiles)
|
|
|
+ ->get(['id', 'number', 'mobile'])
|
|
|
+ ->keyBy('mobile')
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ $errors = [];
|
|
|
+ $update_mapping = [];
|
|
|
+ $detail_storage = [];
|
|
|
+ $mainDataConsistency = [];
|
|
|
+
|
|
|
+ $sex_map = array_flip(Employee::SEX_TYPE);
|
|
|
+ $e_map = array_flip(Employee::Education);
|
|
|
+ $state_map = array_flip(Employee::State_Type);
|
|
|
+ $man_map = array_flip(Employee::Man_Type);
|
|
|
+ $wt_map = array_flip(Employee::WT_Type);
|
|
|
+ $employeeT_map = array_flip(Employee::E_State_Type);
|
|
|
+
|
|
|
+ $mainColIndices = [];
|
|
|
+ foreach ($table_config as $index => $conf) {
|
|
|
+ if (!empty($conf['is_main'])) $mainColIndices[$index] = $conf['value'];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($array as $rowIndex => $rowValue) {
|
|
|
+ $displayLine = $rowIndex + 1;
|
|
|
+ $valCode = trim($rowValue[$codeIdx] ?? '');
|
|
|
+ if ($valCode === '') continue;
|
|
|
+
|
|
|
+ // --- 一致性校验 ---
|
|
|
+ if (!isset($mainDataConsistency[$valCode])) {
|
|
|
+ foreach ($mainColIndices as $idx => $label) {
|
|
|
+ $mainDataConsistency[$valCode][$idx] = trim($rowValue[$idx] ?? '');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ foreach ($mainColIndices as $idx => $label) {
|
|
|
+ $currentVal = trim($rowValue[$idx] ?? '');
|
|
|
+ if ($currentVal !== $mainDataConsistency[$valCode][$idx]) {
|
|
|
+ $errors[] = "第{$displayLine}行:工号[{$valCode}]的主表数据[{$label}]与前文不一致";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 判定更新还是新增
|
|
|
+ if (isset($code_map[$valCode])) {
|
|
|
+ $update_mapping[$rowIndex] = $code_map[$valCode];
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 核心:仅与数据库比对的手机号系统唯一性校验 ---
|
|
|
+ if ($mobileIdx !== false) {
|
|
|
+ $valMobile = trim((string)($rowValue[$mobileIdx] ?? ''));
|
|
|
+ if ($valMobile !== '') {
|
|
|
+ if (isset($dbMobileMap[$valMobile])) {
|
|
|
+ $existUser = $dbMobileMap[$valMobile];
|
|
|
+ // 如果占用了这个手机号的人的工号,跟当前填写的工号对不上,说明是侵占别人的
|
|
|
+ if ($existUser['number'] !== $valCode) {
|
|
|
+// $errors[] = "第{$displayLine}行:手机号[{$valMobile}]已被系统内其他人员(工号:[{$existUser['number']}])占用";
|
|
|
+ $errors[] = "第{$displayLine}行:手机号[{$valMobile}]已被系统内其他人员占用";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 校验及映射转换(性别、学历、状态等)
|
|
|
+ // 性别
|
|
|
+ $sex_text = trim($rowValue[$sexIdx] ?? '');
|
|
|
+ if (!empty($sex_text)) {
|
|
|
+ if (!isset($sex_map[$sex_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:性别[{$sex_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$sexIdx] = $sex_map[$sex_text];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 学历
|
|
|
+ $e_text = trim($rowValue[$eductionIdx] ?? '');
|
|
|
+ if (!empty($e_text)) {
|
|
|
+ if (!isset($e_map[$e_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:学历[{$e_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$eductionIdx] = $e_map[$e_text];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 状态
|
|
|
+ $state_text = trim($rowValue[$stateIdx] ?? '');
|
|
|
+ if (!isset($state_map[$state_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:状态[{$state_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$stateIdx] = $state_map[$state_text];
|
|
|
+ }
|
|
|
+ // 外聘类型
|
|
|
+ $e_text = trim($rowValue[$employeeTypeIdx] ?? '');
|
|
|
+ if (!isset($employeeT_map[$e_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:外聘类型[{$e_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$employeeTypeIdx] = $employeeT_map[$e_text];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 人员类别
|
|
|
+ $man_text = trim($rowValue[$manIdx] ?? '');
|
|
|
+ if (!isset($man_map[$man_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:人员类别[{$man_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$manIdx] = $man_map[$man_text];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 委托类型
|
|
|
+ $wt_text = trim($rowValue[$entrustIdx] ?? '');
|
|
|
+ if (!isset($wt_map[$wt_text])) {
|
|
|
+ $errors[] = "第{$displayLine}行:委托方式[{$wt_text}]无效";
|
|
|
+ } else {
|
|
|
+ $array[$rowIndex][$entrustIdx] = $wt_map[$wt_text];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 解析部门 (分行模式)
|
|
|
+ if ($depIdx !== false && !empty($rowValue[$depIdx])) {
|
|
|
+ $mNum = trim($rowValue[$depIdx]);
|
|
|
+ if (!isset($dep_map[$mNum])) {
|
|
|
+ $errors[] = "第{$displayLine}行:部门编码[{$mNum}]不存在";
|
|
|
+ } else {
|
|
|
+ $detail_storage[$rowIndex][] = ['depart_id' => $dep_map[$mNum]];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $error_str = !empty($errors) ? implode('|', $errors) : "";
|
|
|
+ return [$error_str, $update_mapping, $detail_storage];
|
|
|
+ }
|
|
|
+
|
|
|
private function getEDataList($array, $user, $index1)
|
|
|
{
|
|
|
$depNums = [];
|