option('days'); $dryRun = $this->option('dry-run'); $this->info("开始清理 {$days} 天前的用户日志..."); if ($dryRun) { $this->info('这是一次试运行,不会实际删除数据'); // 计算将要删除的记录数 $expiredDate = now()->subDays($days); $count = \App\Module\Game\Models\UserLog::where('created_at', '<', $expiredDate)->count(); $this->info("将要删除 {$count} 条过期日志记录"); $this->info("过期时间:{$expiredDate->toDateTimeString()}"); return; } try { $deletedCount = UserLogService::cleanExpiredLogs($days); $this->info("成功清理 {$deletedCount} 条过期日志"); } catch (\Exception $e) { $this->error("清理过期日志失败:{$e->getMessage()}"); return 1; } return 0; } }