['文件不存在'], ]); } $import = new UserImport(); Excel::import($import, $realPath); // 删除临时文件 if (file_exists($realPath)) { unlink($realPath); } return [ 'success_count' => $import->getSuccessCount(), 'error_count' => $import->getErrorCount(), 'errors' => $import->getErrors(), ]; } /** * 导入部门数据 */ public function importDepartments(string $filePath, string $realPath): array { if (!file_exists($realPath)) { throw ValidationException::withMessages([ 'file' => ['文件不存在'], ]); } $import = new DepartmentImport(); Excel::import($import, $realPath); // 删除临时文件 if (file_exists($realPath)) { unlink($realPath); } return [ 'success_count' => $import->getSuccessCount(), 'error_count' => $import->getErrorCount(), 'errors' => $import->getErrors(), ]; } /** * 获取导出文件路径 */ public function getExportFilePath(string $filename): string { return storage_path('app/exports/' . $filename); } /** * 删除导出文件 */ public function deleteExportFile(string $filename): bool { $path = $this->getExportFilePath($filename); if (file_exists($path)) { return unlink($path); } return true; } }