|
@@ -18,6 +18,7 @@ use App\Model\MonthlyDdOrder;
|
|
|
use App\Model\MonthlyPsOrder;
|
|
use App\Model\MonthlyPsOrder;
|
|
|
use App\Model\MonthlyPwOrder;
|
|
use App\Model\MonthlyPwOrder;
|
|
|
use App\Model\PLeaveOverOrder;
|
|
use App\Model\PLeaveOverOrder;
|
|
|
|
|
+use App\Model\Priority;
|
|
|
use App\Model\RuleSet;
|
|
use App\Model\RuleSet;
|
|
|
use App\Model\RuleSetDetails;
|
|
use App\Model\RuleSetDetails;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -45,6 +46,7 @@ class ImportService extends Service
|
|
|
'overtimeOrder', // 加班单
|
|
'overtimeOrder', // 加班单
|
|
|
'feeOrder', // 费用项目单
|
|
'feeOrder', // 费用项目单
|
|
|
'RDOrder', // 研发支出辅助帐
|
|
'RDOrder', // 研发支出辅助帐
|
|
|
|
|
+ 'priority', // 优先级
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
public function getTableTitleXls($data,$user){
|
|
public function getTableTitleXls($data,$user){
|
|
@@ -3967,6 +3969,142 @@ class ImportService extends Service
|
|
|
return [!empty($errors) ? implode('|', $errors) : "", $update_map, $maps];
|
|
return [!empty($errors) ? implode('|', $errors) : "", $update_map, $maps];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 优先级
|
|
|
|
|
+ public function priorityImport($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. 业务逻辑校验
|
|
|
|
|
+ list($error, $update_map) = $this->priorityCheck($array, $user, $table_config);
|
|
|
|
|
+ if (!empty($error)) return [0, $error];
|
|
|
|
|
+
|
|
|
|
|
+ $time = time();
|
|
|
|
|
+ $insert = [];
|
|
|
|
|
+ $update = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($array as $key => $value) {
|
|
|
|
|
+ $main_tmp = [];
|
|
|
|
|
+ foreach ($value as $k => $val){
|
|
|
|
|
+ if(!empty($table_config[$k]['is_main'])){
|
|
|
|
|
+ $main_tmp[$table_config[$k]['key']] = $val;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($update_map[$key])) {
|
|
|
|
|
+ // 更新逻辑
|
|
|
|
|
+ $update[] = array_merge($main_tmp, [
|
|
|
|
|
+ 'id' => $update_map[$key],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 新增逻辑
|
|
|
|
|
+ $main_tmp['top_depart_id'] = $user['top_depart_id'];
|
|
|
|
|
+ $main_tmp['crt_time'] = $time;
|
|
|
|
|
+ $insert[] = $main_tmp;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!empty($insert)) {
|
|
|
|
|
+ foreach (array_chunk($insert, 500) as $chunk) {
|
|
|
|
|
+ Priority::insert($chunk);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($update)) {
|
|
|
|
|
+ foreach ($update as $item) {
|
|
|
|
|
+ $uId = $item['id'];
|
|
|
|
|
+ unset($item['id']);
|
|
|
|
|
+ Priority::where('id', $uId)->update($item);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return [false, "导入失败:" . $e->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function priorityCheck(&$array, $user, $table_config)
|
|
|
|
|
+ {
|
|
|
|
|
+ $keys = array_column($table_config, 'key');
|
|
|
|
|
+ $codeIdx = array_search('code', $keys);
|
|
|
|
|
+ $sortIdx = array_search('sort', $keys);
|
|
|
|
|
+ $typeIdx = array_search('type', $keys);
|
|
|
|
|
+ $isUseIdx = array_search('is_use', $keys);
|
|
|
|
|
+
|
|
|
|
|
+ $type_map = array_flip(Priority::TYPE_TITLE);
|
|
|
|
|
+ $isUse_map = array_flip(Priority::IS_USE);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前企业下已存在的优先级,用于判断是新增还是更新
|
|
|
|
|
+ $dbMap = Priority::where('del_time', 0)
|
|
|
|
|
+ ->where('top_depart_id', $user['top_depart_id'])
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->keyBy('code')
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ $errors = [];
|
|
|
|
|
+ $update = [];
|
|
|
|
|
+ $excelCodes = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($array as $rowIndex => $value) {
|
|
|
|
|
+ $displayLine = $rowIndex + 1;
|
|
|
|
|
+ $valCode = trim($value[$codeIdx] ?? '');
|
|
|
|
|
+
|
|
|
|
|
+ if ($valCode === '') {
|
|
|
|
|
+ $errors[] = "第{$displayLine}行:编码不能为空";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 校验 Excel 内部是否重复
|
|
|
|
|
+ if (isset($excelCodes[$valCode])) {
|
|
|
|
|
+ $errors[] = "第{$displayLine}行:编码[{$valCode}]在文件中重复出现";
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $excelCodes[$valCode] = true;
|
|
|
|
|
+
|
|
|
|
|
+ // 类型
|
|
|
|
|
+ $e_text = $value[$typeIdx] ?? '';
|
|
|
|
|
+ if (!isset($type_map[$e_text])) {
|
|
|
|
|
+ $errors[] = "第{$displayLine}行:类型[{$e_text}]无效";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $array[$rowIndex][$typeIdx] = $type_map[$e_text];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 是否启用
|
|
|
|
|
+ $e_text = $value[$isUseIdx] ?? '';
|
|
|
|
|
+ if (!isset($isUse_map[$e_text])) {
|
|
|
|
|
+ $errors[] = "第{$displayLine}行:是否启用[{$e_text}]无效";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $array[$rowIndex][$isUseIdx] = $isUse_map[$e_text];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 数字格式校验
|
|
|
|
|
+ $sort = $value[$sortIdx];
|
|
|
|
|
+ if (filter_var($sort, FILTER_VALIDATE_INT) === false) return [false, "第{$displayLine}行排序字段排序字段必须是整数且不能含有小数点"];
|
|
|
|
|
+
|
|
|
|
|
+ // 如果数据库已存在,记录为更新操作
|
|
|
|
|
+ if (isset($dbMap[$valCode])) {
|
|
|
|
|
+ $update[$rowIndex] = $dbMap[$valCode]['id'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $error_string = !empty($errors) ? implode('|', $errors) : "";
|
|
|
|
|
+ return [$error_string, $update];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 解析并校验时间
|
|
* 解析并校验时间
|
|
|
*/
|
|
*/
|