From 2d5e10cf0eb8e77045445507916d7cff965fb734 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Tue, 10 Jan 2023 22:47:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E4=BB=A5=E5=8F=8A=E9=82=AE=E4=BB=B6=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Notifications/WorkOrder.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/Notifications/WorkOrder.php b/app/Notifications/WorkOrder.php index dffa620..85ddfde 100644 --- a/app/Notifications/WorkOrder.php +++ b/app/Notifications/WorkOrder.php @@ -4,6 +4,7 @@ use App\Models\WorkOrder\WorkOrder as WorkOrderModel; use Illuminate\Bus\Queueable; +use Illuminate\Notifications\Messages\BroadcastMessage; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; @@ -29,25 +30,31 @@ public function __construct(WorkOrderModel $work_order) * * @return array */ - public function via(): array + public function via(WorkOrderModel $workOrder): array { - return [WeComChannel::class]; + $methods = [WeComChannel::class, 'broadcast']; + + if (in_array($workOrder->status, ['processing', 'replied'])) { + $methods[] = 'mail'; + } + + return $methods; } /** * Get the mail representation of the notification. * * + * @param WorkOrderModel $workOrder + * * @return MailMessage */ - public function toMail(): MailMessage + public function toMail(WorkOrderModel $workOrder): MailMessage { return (new MailMessage) - ->line('The introduction to the notification.') - ->action('Notification Action', url('/')) - ->line('Thank you for using our application!'); - - + ->subject('工单: ' . $workOrder->title . ' 状态更新。') + ->line('我们查阅了您的工单并做出了相应处理。') + ->line('请前往我们的仪表盘继续跟进问题。'); } /** @@ -90,4 +97,9 @@ public function toWeCom(WorkOrderModel $workOrder): false|array ]; } + public function toBroadcast(WorkOrderModel $workOrder): BroadcastMessage + { + return new BroadcastMessage($workOrder->toArray()); + } + }