Lae/app/Notifications/WorkOrder/WorkOrder.php

65 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-01-10 12:46:53 +00:00
<?php
2023-01-13 14:11:56 +00:00
namespace App\Notifications\WorkOrder;
2023-01-10 12:46:53 +00:00
use App\Models\WorkOrder\WorkOrder as WorkOrderModel;
2023-01-13 14:11:56 +00:00
use App\Notifications\Channels\WebChannel;
use App\Notifications\Channels\WeComChannel;
2023-01-10 12:46:53 +00:00
use Illuminate\Bus\Queueable;
2023-01-17 13:02:04 +00:00
use Illuminate\Contracts\Queue\ShouldQueue;
2023-01-10 12:46:53 +00:00
use Illuminate\Notifications\Notification;
2023-01-17 13:02:04 +00:00
class WorkOrder extends Notification implements ShouldQueue
2023-01-10 12:46:53 +00:00
{
use Queueable;
2023-01-10 13:42:27 +00:00
public WorkOrderModel $work_order;
2023-01-10 12:46:53 +00:00
/**
* Create a new notification instance.
*
* @return void
*/
2023-01-10 13:42:27 +00:00
public function __construct(WorkOrderModel $work_order)
2023-01-10 12:46:53 +00:00
{
2023-01-10 13:42:27 +00:00
$this->work_order = $work_order;
2023-01-10 12:46:53 +00:00
}
/**
* Get the notification's delivery channels.
*/
2023-03-01 14:30:21 +00:00
public function via(): array
2023-01-10 12:46:53 +00:00
{
2023-03-01 15:13:07 +00:00
if (! $this->work_order->notify) {
return [];
}
2023-03-01 14:30:21 +00:00
return [WeComChannel::class, WebChannel::class];
2023-01-10 12:46:53 +00:00
}
/**
* Get the array representation of the notification.
*/
public function toArray(WorkOrderModel $workOrder): array
2023-01-10 12:46:53 +00:00
{
$array = $workOrder->toArray();
2023-01-11 12:19:05 +00:00
2023-03-01 14:43:21 +00:00
$array['latest_reply'] = $workOrder->replies()->latest()->first()?->toArray() ?? [];
2023-02-07 09:04:11 +00:00
$array['event'] = 'work-order.'.$workOrder->status;
return $array;
2023-01-10 12:46:53 +00:00
}
public function toWeCom(WorkOrderModel $workOrder): false|array
{
$workOrder->load(['module', 'user']);
return [
2023-03-01 14:30:21 +00:00
'key' => $workOrder->wecom_key,
2023-01-10 12:46:53 +00:00
'view' => 'notifications.work_order',
2023-01-30 16:14:07 +00:00
'data' => $workOrder,
2023-01-10 12:46:53 +00:00
];
}
}