getKey(); $backup = CleanupBackup::with(['files', 'sqlBackups'])->find($backupId); if (!$backup) { return $this->response() ->error('备份不存在'); } $html = '
'; // 基本信息 $html .= '
'; $html .= '
基本信息
'; $html .= ''; $html .= '
'; // 大小信息 $html .= '
'; $html .= '
大小信息
'; $html .= ''; $html .= '
'; $html .= '
'; // 备份文件列表 if ($backup->files->isNotEmpty()) { $html .= '
'; $html .= '
备份文件
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; foreach ($backup->files as $file) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
表名文件名文件大小类型压缩
' . $file->table_name . '' . $file->file_name . '' . $this->formatBytes($file->file_size) . '' . $this->getBackupTypeName($file->backup_type) . '' . $this->getCompressionTypeName($file->compression_type) . '
'; $html .= '
'; $html .= '
'; } // SQL备份内容 if ($backup->sqlBackups->isNotEmpty()) { $html .= '
'; $html .= '
SQL备份内容
'; $html .= '
'; $html .= ''; $html .= ''; $html .= ''; foreach ($backup->sqlBackups as $sqlBackup) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
表名记录数量内容大小创建时间
' . $sqlBackup->table_name . '' . number_format($sqlBackup->records_count) . '' . $this->formatBytes($sqlBackup->content_size) . '' . $sqlBackup->created_at . '
'; $html .= '
'; $html .= '
'; } return $this->response() ->success('备份详情') ->detail($html); } catch (\Exception $e) { return $this->response() ->error('查看失败:' . $e->getMessage()); } } /** * 获取备份类型名称 */ private function getBackupTypeName($type) { $types = [1 => 'SQL', 2 => 'JSON', 3 => 'CSV']; return $types[$type] ?? '未知'; } /** * 获取压缩类型名称 */ private function getCompressionTypeName($type) { $types = [1 => '无压缩', 2 => 'GZIP', 3 => 'ZIP']; return $types[$type] ?? '未知'; } /** * 获取备份状态标签 */ private function getBackupStatusBadge($status) { $badges = [ 1 => '进行中', 2 => '已完成', 3 => '已失败', ]; return $badges[$status] ?? '未知'; } /** * 格式化字节大小 */ private function formatBytes($bytes) { if ($bytes == 0) return '0 B'; $units = ['B', 'KB', 'MB', 'GB', 'TB']; $base = log($bytes, 1024); $index = floor($base); if ($index >= count($units)) { $index = count($units) - 1; } $size = round(pow(1024, $base - $index), 2); return $size . ' ' . $units[$index]; } /** * 渲染按钮 */ public function render() { return << {$this->title} HTML; } }