改进 工单回复以及邮件通知

This commit is contained in:
iVampireSP.com 2023-01-10 22:47:55 +08:00
parent ae4233bb39
commit 2d5e10cf0e
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -4,6 +4,7 @@
use App\Models\WorkOrder\WorkOrder as WorkOrderModel; use App\Models\WorkOrder\WorkOrder as WorkOrderModel;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
@ -29,25 +30,31 @@ public function __construct(WorkOrderModel $work_order)
* *
* @return array * @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. * Get the mail representation of the notification.
* *
* *
* @param WorkOrderModel $workOrder
*
* @return MailMessage * @return MailMessage
*/ */
public function toMail(): MailMessage public function toMail(WorkOrderModel $workOrder): MailMessage
{ {
return (new MailMessage) return (new MailMessage)
->line('The introduction to the notification.') ->subject('工单: ' . $workOrder->title . ' 状态更新。')
->action('Notification Action', url('/')) ->line('我们查阅了您的工单并做出了相应处理。')
->line('Thank you for using our application!'); ->line('请前往我们的仪表盘继续跟进问题。');
} }
/** /**
@ -90,4 +97,9 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
]; ];
} }
public function toBroadcast(WorkOrderModel $workOrder): BroadcastMessage
{
return new BroadcastMessage($workOrder->toArray());
}
} }