|
|
@@ -9,6 +9,7 @@ use App\Model\Employee;
|
|
|
use App\Model\Fee;
|
|
|
use App\Model\Item;
|
|
|
use App\Model\ItemDetails;
|
|
|
+use App\Model\MonthlyDdOrder;
|
|
|
use App\Model\MonthlyPsOrder;
|
|
|
use App\Model\MonthlyPwOrder;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -26,6 +27,7 @@ class ImportService extends Service
|
|
|
'monthPwOrder', // 人员月度研发工时单
|
|
|
'monthDwOrder', // 设备月度研发工时单
|
|
|
'monthPsOrder', // 人员月度工资单
|
|
|
+ 'monthDdOrder', // 设备月度折旧单
|
|
|
];
|
|
|
|
|
|
public function getTableTitleXls($data,$user){
|
|
|
@@ -123,6 +125,17 @@ class ImportService extends Service
|
|
|
return [true, [$config_array, $filename]];
|
|
|
}
|
|
|
|
|
|
+ private function monthDdOrder($data,$user){
|
|
|
+ $config = $this->getTableConfig($data['type']);
|
|
|
+ if(empty($config)) return [false, ['导入配置表头文件不存在','']];
|
|
|
+
|
|
|
+ $config_array = $config['array'] ?? [];
|
|
|
+ //生成下载文件
|
|
|
+ $filename = $config['name'] . "导入模板_" . time() . '.' . 'xlsx';
|
|
|
+
|
|
|
+ return [true, [$config_array, $filename]];
|
|
|
+ }
|
|
|
+
|
|
|
//导入入口
|
|
|
public function importAll($data,$user){
|
|
|
// //不超时
|
|
|
@@ -915,14 +928,37 @@ class ImportService extends Service
|
|
|
->where('top_depart_id', $user['top_depart_id'])
|
|
|
->get()->keyBy('code');
|
|
|
|
|
|
- $existingMonths = DB::table('monthly_pw_order')
|
|
|
- ->where('top_depart_id', $user['top_depart_id'])
|
|
|
- ->pluck('month')
|
|
|
- ->toArray();
|
|
|
- $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ $errors = [];
|
|
|
+
|
|
|
+ //时间转换
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ if ($valMonthRaw === '') continue;
|
|
|
+
|
|
|
+ list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
+ if (!$mStatus) {
|
|
|
+ $errors[] = "第" . ($rowIndex + 1) . "行:月份格式错误({$valMonthRaw})";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准化并存回数组,这样后面的循环直接拿到的就是时间戳
|
|
|
+ $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ $array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
+ $uniqueMonths[] = $valMonthTs;
|
|
|
+ }
|
|
|
+
|
|
|
+ $existingMonthsMap = [];
|
|
|
+ if (!empty($uniqueMonths)) {
|
|
|
+ $existingMonths = DB::table('monthly_pw_order')
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->whereIn('month', array_unique($uniqueMonths))
|
|
|
+ ->pluck('month')
|
|
|
+ ->toArray();
|
|
|
+ $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ }
|
|
|
|
|
|
$excelAggregator = [];
|
|
|
- $errors = [];
|
|
|
$update_map = [];
|
|
|
|
|
|
foreach ($array as $rowIndex => $row) {
|
|
|
@@ -930,7 +966,7 @@ class ImportService extends Service
|
|
|
$displayLine = $rowIndex + 1;
|
|
|
|
|
|
$valCode = trim($row[$codeIdx] ?? '');
|
|
|
- $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ $valMonthTs = trim($row[$monthIdx] ?? '');
|
|
|
$valEmp = trim($row[$empIdx] ?? '');
|
|
|
$valStartRaw = $row[$startIdx] ?? '';
|
|
|
$valEndRaw = $row[$endIdx] ?? '';
|
|
|
@@ -940,15 +976,7 @@ class ImportService extends Service
|
|
|
$valNum3Raw = $row[$num3Idx] ?? 0;
|
|
|
$valNum4Raw = $row[$num4Idx] ?? 0;
|
|
|
|
|
|
- // --- A. 日期转换校验 ---
|
|
|
- // 转换月份
|
|
|
- list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
- if (!$mStatus) {
|
|
|
- $errors[] = "第{$displayLine}行:月份格式错误({$valMonthRaw})";
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 强制格式化为当月1号的时间戳,确保聚合逻辑一致
|
|
|
- $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ if (!is_numeric($valMonthTs)) continue;
|
|
|
|
|
|
// 转换开始日期
|
|
|
list($sStatus, $startTime) = $this->convertExcelCellToDate($valStartRaw);
|
|
|
@@ -1018,7 +1046,6 @@ class ImportService extends Service
|
|
|
if(! $res['valid']) $errors[] = "第{$displayLine}行研发总工时:" . $res['error'];
|
|
|
|
|
|
// 将转换后的时间戳写回原数组,方便后续写入数据库时直接使用
|
|
|
- $array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
$array[$rowIndex][$startIdx] = $startTime;
|
|
|
$array[$rowIndex][$endIdx] = $endTime;
|
|
|
}
|
|
|
@@ -1167,14 +1194,37 @@ class ImportService extends Service
|
|
|
->where('top_depart_id', $user['top_depart_id'])
|
|
|
->get()->keyBy('code');
|
|
|
|
|
|
- $existingMonths = DB::table('monthly_dw_order')
|
|
|
- ->where('top_depart_id', $user['top_depart_id'])
|
|
|
- ->pluck('month')
|
|
|
- ->toArray();
|
|
|
- $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ $errors = [];
|
|
|
+
|
|
|
+ //时间转换
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ if ($valMonthRaw === '') continue;
|
|
|
+
|
|
|
+ list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
+ if (!$mStatus) {
|
|
|
+ $errors[] = "第" . ($rowIndex + 1) . "行:月份格式错误({$valMonthRaw})";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准化并存回数组,这样后面的循环直接拿到的就是时间戳
|
|
|
+ $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ $array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
+ $uniqueMonths[] = $valMonthTs;
|
|
|
+ }
|
|
|
+
|
|
|
+ $existingMonthsMap = [];
|
|
|
+ if (!empty($uniqueMonths)) {
|
|
|
+ $existingMonths = DB::table('monthly_dw_order')
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->whereIn('month', array_unique($uniqueMonths))
|
|
|
+ ->pluck('month')
|
|
|
+ ->toArray();
|
|
|
+ $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ }
|
|
|
|
|
|
$excelAggregator = [];
|
|
|
- $errors = [];
|
|
|
$update_map = [];
|
|
|
|
|
|
foreach ($array as $rowIndex => $row) {
|
|
|
@@ -1182,7 +1232,7 @@ class ImportService extends Service
|
|
|
$displayLine = $rowIndex + 1;
|
|
|
|
|
|
$valCode = trim($row[$codeIdx] ?? '');
|
|
|
- $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ $valMonthTs = trim($row[$monthIdx] ?? '');
|
|
|
$valDev = trim($row[$devIdx] ?? '');
|
|
|
$valStartRaw = $row[$startIdx] ?? '';
|
|
|
$valEndRaw = $row[$endIdx] ?? '';
|
|
|
@@ -1192,15 +1242,7 @@ class ImportService extends Service
|
|
|
$valNum3Raw = $row[$num3Idx] ?? 0;
|
|
|
$valNum4Raw = $row[$num4Idx] ?? 0;
|
|
|
|
|
|
- // --- A. 日期转换校验 ---
|
|
|
- // 转换月份
|
|
|
- list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
- if (!$mStatus) {
|
|
|
- $errors[] = "第{$displayLine}行:月份格式错误({$valMonthRaw})";
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 强制格式化为当月1号的时间戳,确保聚合逻辑一致
|
|
|
- $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ if (!is_numeric($valMonthTs)) continue;
|
|
|
|
|
|
// 转换开始日期
|
|
|
list($sStatus, $startTime) = $this->convertExcelCellToDate($valStartRaw);
|
|
|
@@ -1270,7 +1312,6 @@ class ImportService extends Service
|
|
|
if(! $res['valid']) $errors[] = "第{$displayLine}行研发总工时:" . $res['error'];
|
|
|
|
|
|
// 将转换后的时间戳写回原数组,方便后续写入数据库时直接使用
|
|
|
- $array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
$array[$rowIndex][$startIdx] = $startTime;
|
|
|
$array[$rowIndex][$endIdx] = $endTime;
|
|
|
}
|
|
|
@@ -1416,14 +1457,37 @@ class ImportService extends Service
|
|
|
->where('top_depart_id', $user['top_depart_id'])
|
|
|
->get()->keyBy('code');
|
|
|
|
|
|
- $existingMonths = DB::table('monthly_ps_order')
|
|
|
- ->where('top_depart_id', $user['top_depart_id'])
|
|
|
- ->pluck('month')
|
|
|
- ->toArray();
|
|
|
- $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ $errors = [];
|
|
|
+
|
|
|
+ //时间转换
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ if ($valMonthRaw === '') continue;
|
|
|
+
|
|
|
+ list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
+ if (!$mStatus) {
|
|
|
+ $errors[] = "第" . ($rowIndex + 1) . "行:月份格式错误({$valMonthRaw})";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准化并存回数组,这样后面的循环直接拿到的就是时间戳
|
|
|
+ $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ $array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
+ $uniqueMonths[] = $valMonthTs;
|
|
|
+ }
|
|
|
+
|
|
|
+ $existingMonthsMap = [];
|
|
|
+ if (!empty($uniqueMonths)) {
|
|
|
+ $existingMonths = DB::table('monthly_ps_order')
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->whereIn('month', array_unique($uniqueMonths))
|
|
|
+ ->pluck('month')
|
|
|
+ ->toArray();
|
|
|
+ $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ }
|
|
|
|
|
|
$excelAggregator = [];
|
|
|
- $errors = [];
|
|
|
$update_map = [];
|
|
|
|
|
|
foreach ($array as $rowIndex => $row) {
|
|
|
@@ -1431,22 +1495,14 @@ class ImportService extends Service
|
|
|
$displayLine = $rowIndex + 1;
|
|
|
|
|
|
$valCode = trim($row[$codeIdx] ?? '');
|
|
|
- $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ $valMonthTs = trim($row[$monthIdx] ?? '');
|
|
|
$valEmp = trim($row[$empIdx] ?? '');
|
|
|
|
|
|
$valNumRaw = $row[$numIdx] ?? 0;
|
|
|
$valNum2Raw = $row[$num2Idx] ?? 0;
|
|
|
$valNum3Raw = $row[$num3Idx] ?? 0;
|
|
|
|
|
|
- // --- A. 日期转换校验 ---
|
|
|
- // 转换月份
|
|
|
- list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
- if (!$mStatus) {
|
|
|
- $errors[] = "第{$displayLine}行:月份格式错误({$valMonthRaw})";
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 强制格式化为当月1号的时间戳,确保聚合逻辑一致
|
|
|
- $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
+ if (!is_numeric($valMonthTs)) continue;
|
|
|
|
|
|
$aggKey = $valCode ?: "NEW_ORDER_" . $valMonthTs;
|
|
|
|
|
|
@@ -1488,16 +1544,237 @@ class ImportService extends Service
|
|
|
if(! $res['valid']) $errors[] = "第{$displayLine}行社保:" . $res['error'];
|
|
|
$res = $this->checkNumber($valNum3Raw,2,'non-negative');
|
|
|
if(! $res['valid']) $errors[] = "第{$displayLine}行公积金:" . $res['error'];
|
|
|
+ }
|
|
|
|
|
|
- // 将转换后的时间戳写回原数组,方便后续写入数据库时直接使用
|
|
|
+ $error_string = !empty($errors) ? implode('|', $errors) : "";
|
|
|
+ return [$error_string, $update_map, $dbEmps];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设备月度折旧单
|
|
|
+ public function monthDdOrderImport($array, $user, $other_param)
|
|
|
+ {
|
|
|
+ $upload = $array[0];
|
|
|
+ list($status, $msg) = $this->compareTableAndReturn($upload, $other_param);
|
|
|
+ if (!$status) return [false, $msg];
|
|
|
+ $table_config = $msg;
|
|
|
+
|
|
|
+ unset($array[0]);
|
|
|
+ if (empty($array)) return [false, '导入数据不能为空'];
|
|
|
+
|
|
|
+ list($array, $error) = $this->checkCommon($array, $table_config);
|
|
|
+ if (!empty($error)) return [0, $error];
|
|
|
+
|
|
|
+ // 2. 详细校验 (这里会返回 update_map 和 dbDevs 映射)
|
|
|
+ list($error, $update_map, $dbDevs) = $this->monthDdOrderCheck($array, $user, $table_config);
|
|
|
+ if (!empty($error)) return [0, $error];
|
|
|
+
|
|
|
+ $keys = array_column($table_config, 'key');
|
|
|
+ $codeIdx = array_search('code', $keys);
|
|
|
+ $monthIdx = array_search('month', $keys);
|
|
|
+ $empIdx = array_search('device_id', $keys);
|
|
|
+
|
|
|
+ // --- 步骤 1: 数据聚合分组 ---
|
|
|
+ // 将 Excel 数据按“单据”维度归类
|
|
|
+ $groups = [];
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ $cCode = trim($row[$codeIdx] ?? '');
|
|
|
+ $cMonthTs = $row[$monthIdx]; // 校验阶段已转为时间戳
|
|
|
+
|
|
|
+ // 聚合 Key:有编码用编码,没编码用月份标记
|
|
|
+ $aggKey = $cCode ?: "MONTH_" . $cMonthTs;
|
|
|
+
|
|
|
+ if (!isset($groups[$aggKey])) {
|
|
|
+ $groups[$aggKey] = [
|
|
|
+ 'main_id' => $update_map[$rowIndex] ?? 0, // 如果存在则是编辑
|
|
|
+ 'code' => $cCode,
|
|
|
+ 'month' => $cMonthTs,
|
|
|
+ 'details' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 准备详情行数据
|
|
|
+ $detailTmp = [];
|
|
|
+ foreach ($table_config as $k => $conf) {
|
|
|
+ if (!$conf['is_main']) {
|
|
|
+ $fieldKey = $conf['key'];
|
|
|
+ $fieldVal = $row[$k];
|
|
|
+ // 如果是人员,转换为 ID
|
|
|
+ if ($fieldKey == 'device_id') {
|
|
|
+ $fieldVal = $dbDevs[$fieldVal] ?? 0;
|
|
|
+ }
|
|
|
+ $detailTmp[$fieldKey] = $fieldVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $groups[$aggKey]['details'][] = $detailTmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 步骤 2: 开启事务写入 ---
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $time = time();
|
|
|
+ foreach ($groups as $aggKey => $group) {
|
|
|
+ $mainId = $group['main_id'];
|
|
|
+
|
|
|
+ if ($mainId > 0) {
|
|
|
+ // 删除旧详情
|
|
|
+ DB::table('monthly_dd_order_details')->where('del_time',0)
|
|
|
+ ->where('main_id', $mainId)
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+ } else {
|
|
|
+ // B. 新增逻辑
|
|
|
+ $newCode = $this->generateBillNo([
|
|
|
+ 'top_depart_id' => $user['top_depart_id'],
|
|
|
+ 'type' => MonthlyDdOrder::Order_type,
|
|
|
+ 'period' => date("Ym", $group['month'])
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $mainId = DB::table('monthly_dd_order')->insertGetId([
|
|
|
+ 'code' => $newCode,
|
|
|
+ 'month' => $group['month'],
|
|
|
+ 'top_depart_id' => $user['top_depart_id'],
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'upd_time' => $time,
|
|
|
+ 'del_time' => 0
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // C. 批量插入详情
|
|
|
+ $insertDetails = [];
|
|
|
+ foreach ($group['details'] as $detail) {
|
|
|
+ $detail['main_id'] = $mainId;
|
|
|
+ $detail['top_depart_id']= $user['top_depart_id'];
|
|
|
+ $detail['crt_time'] = $time;
|
|
|
+ $detail['del_time'] = 0;
|
|
|
+ $insertDetails[] = $detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($insertDetails)) {
|
|
|
+ DB::table('monthly_dd_order_details')->insert($insertDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, "失败:" . $e->getMessage() . " (行号:" . $e->getLine() . ")"];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function monthDdOrderCheck(&$array, $user, $table_config)
|
|
|
+ {
|
|
|
+ $keys = array_column($table_config, 'key');
|
|
|
+ $codeIdx = array_search('code', $keys);
|
|
|
+ $monthIdx = array_search('month', $keys);
|
|
|
+ $devIdx = array_search('device_id', $keys);
|
|
|
+
|
|
|
+ $numIdx = array_search('depreciation_amount', $keys);
|
|
|
+
|
|
|
+ // 1. 预加载基础数据
|
|
|
+ $allEmpNumbers = array_filter(array_unique(array_column($array, $devIdx)));
|
|
|
+ $dbDevs = Device::where('del_time', 0)
|
|
|
+ ->whereIn('code', $allEmpNumbers)
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->pluck('id', 'code')->toArray();
|
|
|
+
|
|
|
+ $allCodes = array_filter(array_unique(array_column($array, $codeIdx)));
|
|
|
+ $dbOrders = DB::table('monthly_dd_order')
|
|
|
+ ->whereIn('code', $allCodes)
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->get()->keyBy('code');
|
|
|
+
|
|
|
+ $errors = [];
|
|
|
+
|
|
|
+ //时间转换
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ $valMonthRaw = trim($row[$monthIdx] ?? '');
|
|
|
+ if ($valMonthRaw === '') continue;
|
|
|
+
|
|
|
+ list($mStatus, $valMonthTs) = $this->convertExcelCellToDate($valMonthRaw);
|
|
|
+ if (!$mStatus) {
|
|
|
+ $errors[] = "第" . ($rowIndex + 1) . "行:月份格式错误({$valMonthRaw})";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 标准化并存回数组,这样后面的循环直接拿到的就是时间戳
|
|
|
+ $valMonthTs = strtotime(date('Y-m-01', $valMonthTs));
|
|
|
$array[$rowIndex][$monthIdx] = $valMonthTs;
|
|
|
+ $uniqueMonths[] = $valMonthTs;
|
|
|
+ }
|
|
|
+
|
|
|
+ $existingMonthsMap = [];
|
|
|
+ if (!empty($uniqueMonths)) {
|
|
|
+ $existingMonths = DB::table('monthly_dd_order')
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->whereIn('month', array_unique($uniqueMonths))
|
|
|
+ ->pluck('month')
|
|
|
+ ->toArray();
|
|
|
+ $existingMonthsMap = array_fill_keys($existingMonths, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ $excelAggregator = [];
|
|
|
+ $update_map = [];
|
|
|
+
|
|
|
+ foreach ($array as $rowIndex => $row) {
|
|
|
+ // 用户看到的行号(假设数据从第2行开始)
|
|
|
+ $displayLine = $rowIndex + 1;
|
|
|
+
|
|
|
+ $valCode = trim($row[$codeIdx] ?? '');
|
|
|
+ $valMonthTs = trim($row[$monthIdx] ?? '');
|
|
|
+ $valDev = trim($row[$devIdx] ?? '');
|
|
|
+ $valNumRaw = $row[$numIdx] ?? 0;
|
|
|
+
|
|
|
+ if (!is_numeric($valMonthTs)) continue;
|
|
|
+
|
|
|
+ $aggKey = $valCode ?: "NEW_ORDER_" . $valMonthTs;
|
|
|
+
|
|
|
+ // --- B. 校验单据与月份的一致性 ---
|
|
|
+ if ($valCode && isset($dbOrders[$valCode])) {
|
|
|
+ $dbOrder = $dbOrders[$valCode];
|
|
|
+ if ($dbOrder->month != $valMonthTs) {
|
|
|
+ $errors[] = "第{$displayLine}行:单据编码[{$valCode}]对应月份为[" . date('Y-m', $dbOrder->month) . "],与导入月份不符";
|
|
|
+ }
|
|
|
+ $update_map[$rowIndex] = $dbOrder->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- C. 校验设备存在性与单据内唯一性 ---
|
|
|
+ if (!isset($dbDevs[$valDev])) {
|
|
|
+ $errors[] = "第{$displayLine}行:设备的资产编码[{$valDev}]不存在";
|
|
|
+ } else {
|
|
|
+ if (isset($excelAggregator[$aggKey]['devs'][$valDev])) {
|
|
|
+ $errors[] = "第{$displayLine}行:设备的资产编码[{$valDev}]在同一单据中重复";
|
|
|
+ }
|
|
|
+ $excelAggregator[$aggKey]['devs'][$valDev] = true;
|
|
|
+
|
|
|
+ if (isset($excelAggregator[$aggKey]['month_ts']) && $excelAggregator[$aggKey]['month_ts'] !== $valMonthTs) {
|
|
|
+ $errors[] = "第{$displayLine}行:同组数据的月份不统一";
|
|
|
+ }
|
|
|
+ $excelAggregator[$aggKey]['month_ts'] = $valMonthTs;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- E. 月份唯一单据校验 (新增) ---
|
|
|
+ if (!$valCode) {
|
|
|
+ if (isset($existingMonthsMap[$valMonthTs])) {
|
|
|
+ $errors[] = "第{$displayLine}行:月份[ " . date('Y-m', $valMonthTs) . " ]已存在单据,请填编码编辑";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- F. 数字校验
|
|
|
+ $res = $this->checkNumber($valNumRaw,2,'non-negative');
|
|
|
+ if(! $res['valid']) $errors[] = "第{$displayLine}行月折旧额:" . $res['error'];
|
|
|
}
|
|
|
|
|
|
$error_string = !empty($errors) ? implode('|', $errors) : "";
|
|
|
- return [$error_string, $update_map, $dbEmps];
|
|
|
+ return [$error_string, $update_map, $dbDevs];
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//公共校验 -----------------------------------------
|
|
|
private function checkCommon($array, $table_config) {
|
|
|
$error = [];
|