notificationService = $notificationService; } /** * Execute the console command. */ public function handle(): int { $limit = (int) $this->option('limit'); $this->info('开始重试未发送的通知...'); $this->info("最大处理数量: {$limit}"); try { $sentCount = $this->notificationService->retryUnsentNotifications($limit); if ($sentCount > 0) { $this->info("成功发送 {$sentCount} 条通知"); } else { $this->info('没有需要重试的通知'); } Log::info('重试未发送通知完成', [ 'sent_count' => $sentCount, 'limit' => $limit ]); return self::SUCCESS; } catch (\Exception $e) { $this->error('重试未发送通知失败: ' . $e->getMessage()); Log::error('重试未发送通知失败', [ 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return self::FAILURE; } } }