info('Starting to send appointment reminders...'); // 查询即将到期的预约记录(8小时后的预约) $appointments = RegistrationRecord::where('visit_date', now()->toDate()) ->where('begin_date', now()->subHours(8)) ->where('reminder_sent', 0) ->get(); if ($appointments->isEmpty()) { $this->info('No appointments to send reminders for.'); return BaseCommand::SUCCESS; } $message = new SendMessageJob(); $success_records = []; foreach ($appointments as $appointment) { try { $this->sendAppointmentReminderMessage($appointment); // 标记提醒已发送 $appointment->update(['reminder_sent' => 1]); $success_records[] = $appointment->id; $this->info("Reminder sent for appointment ID: {$appointment->id}"); Log::channel('send_wechat_message')->info('Reminder sent for appointment ID: '. $appointment->id); } catch (Exception|Throwable $e) { // 记录错误日志 $err_msg = "{$e->getMessage()} ON {$e->getFile()}:{$e->getLine()}"; $this->error("Failed to send reminder for appointment ID: {$appointment->id}, Err msg: {$err_msg}"); Log::channel('send_wechat_message')->error('Failed to send reminder for appointment ID: '. $appointment->id, ['error' => $err_msg]); } } $this->info( '['. date('Y-m-d H:i:s').'] Appointment reminders sent successfully. send Record:'. implode(',', $success_records)); return BaseCommand::SUCCESS; } }