diff --git a/application/index/controller/wms/Wms.php b/application/index/controller/wms/Wms.php index 5c0f2f8..81006a6 100644 --- a/application/index/controller/wms/Wms.php +++ b/application/index/controller/wms/Wms.php @@ -7636,6 +7636,9 @@ class Wms extends Frontend try { $file = request()->file('file'); // 从请求中获取上传的文件 + if(!$file){ + return json(['status'=>'error','msg'=>'未收到上传文件,请确认表单字段名为 file']); + } $info = $file->validate(['size'=>15678000,'ext'=>'xls,xlsx'])->move( '../uploads'); if($info){ $filename = $info->getSaveName(); @@ -7644,19 +7647,22 @@ class Wms extends Frontend // 使用 PhpSpreadsheet 解析 Excel 文件 $spreadsheet = IOFactory::load($filePath); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); - for($i=2;$iextractLastNumber($r); //print_r($matches);die(); - array_push($list,[$item['B'],$item['C'],$item['D'],isset($matches[0])?$matches[0]:'',isset($matches[1])?$matches[1]:'']); + array_push($list,[$item['B'] ?? '',$item['C'] ?? '',$item['D'] ?? '',isset($matches[0])?$matches[0]:'',isset($matches[1])?$matches[1]:'']); } } // 删除上传的临时文件 - unlink($filePath); + if(is_file($filePath)){ + unlink($filePath); + } $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $title = '导出数据'; @@ -7671,7 +7677,11 @@ class Wms extends Frontend // 将秒数转换为毫秒并拼接微秒数 $millisecondTimestamp = (int)($sec * 1000) + (int)($usec * 1000); - $filePath = "{$rootpath}/../../../public/export/{$millisecondTimestamp}.xlsx"; + $exportDir = "{$rootpath}/../../../public/export"; + if(!is_dir($exportDir)){ + mkdir($exportDir, 0755, true); + } + $filePath = "{$exportDir}/{$millisecondTimestamp}.xlsx"; $url = "https://ye4s.wms.gztbyc.com/export/{$millisecondTimestamp}.xlsx"; $write = IOFactory::createWriter($spreadsheet, 'Xlsx'); $res = $write->save($filePath); @@ -7679,8 +7689,9 @@ class Wms extends Frontend } else { return json(['status' => 'error', 'message' => $file->getError()]); } - } catch (Exception $e) { - return json(["msg"=>$e]); + } catch (\Throwable $e) { + \think\Log::error('[split_excel] ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine()); + return json(['status' => 'error', 'msg' => $e->getMessage(), 'at' => $e->getFile() . ':' . $e->getLine()]); } } return $this->view->fetch();