diff --git a/app/Console/Commands/ExportV2Log.php b/app/Console/Commands/ExportV2Log.php new file mode 100644 index 0000000..5c1fdfe --- /dev/null +++ b/app/Console/Commands/ExportV2Log.php @@ -0,0 +1,52 @@ +argument('days'); + $date = Carbon::now()->subDays($days)->startOfDay(); + + $logs = \DB::table('v2_log') + ->where('created_at', '>=', $date->timestamp) + ->get(); + + $fileName = "v2_logs_" . Carbon::now()->format('Y_m_d_His') . ".csv"; + $handle = fopen(storage_path("logs/$fileName"), 'w'); + + // 根据您的表结构 + fputcsv($handle, ['Level', 'ID', 'Title', 'Host', 'URI', 'Method', 'Data', 'IP', 'Context', 'Created At', 'Updated At']); + + foreach ($logs as $log) { + fputcsv($handle, [ + $log->level, + $log->id, + $log->title, + $log->host, + $log->uri, + $log->method, + $log->data, + $log->ip, + $log->context, + Carbon::createFromTimestamp($log->created_at)->toDateTimeString(), + Carbon::createFromTimestamp($log->updated_at)->toDateTimeString() + ]); + } + + fclose($handle); + $this->info("Logs exported to $fileName"); + } +}