'integer', 'file_size' => 'integer', 'backup_type' => 'integer', 'compression_type' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * 获取备份类型枚举 */ public function getBackupTypeEnumAttribute(): BACKUP_TYPE { return BACKUP_TYPE::from($this->backup_type); } /** * 获取压缩类型枚举 */ public function getCompressionTypeEnumAttribute(): COMPRESSION_TYPE { return COMPRESSION_TYPE::from($this->compression_type); } /** * 关联备份记录 */ public function backup(): BelongsTo { return $this->belongsTo(CleanupBackup::class, 'backup_id'); } /** * 按表名筛选 */ public function scopeByTable($query, string $tableName) { return $query->where('table_name', $tableName); } /** * 按备份类型筛选 */ public function scopeByBackupType($query, BACKUP_TYPE $backupType) { return $query->where('backup_type', $backupType->value); } /** * 按压缩类型筛选 */ public function scopeByCompressionType($query, COMPRESSION_TYPE $compressionType) { return $query->where('compression_type', $compressionType->value); } /** * 获取文件大小的可读格式 */ public function getFileSizeHumanAttribute(): string { $bytes = $this->file_size; $units = ['B', 'KB', 'MB', 'GB', 'TB']; for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) { $bytes /= 1024; } return round($bytes, 2) . ' ' . $units[$i]; } }