diff --git a/backend/app/Command/CleanRequestLogsCommand.php b/backend/app/Command/CleanRequestLogsCommand.php new file mode 100644 index 0000000..45065e3 --- /dev/null +++ b/backend/app/Command/CleanRequestLogsCommand.php @@ -0,0 +1,40 @@ +setDescription('清理过期的 API 请求日志'); + $this->addOption('days', 'd', InputOption::VALUE_OPTIONAL, '保留天数', 90); + } + + public function handle(): void + { + $days = (int) $this->input->getOption('days'); + $cutoff = Carbon::now()->subDays($days); + + $deleted = ApiRequestLog::query() + ->where('created_at', '<', $cutoff) + ->delete(); + + $this->info("已清理 {$deleted} 条超过 {$days} 天的请求日志。"); + } +}