优化代码

This commit is contained in:
iVampireSP.com 2023-03-01 22:30:21 +08:00
parent 3be7700971
commit df7d20408d
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -7,7 +7,6 @@
use App\Notifications\Channels\WeComChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class WorkOrder extends Notification implements ShouldQueue
@ -29,26 +28,9 @@ public function __construct(WorkOrderModel $work_order)
/**
* Get the notification's delivery channels.
*/
public function via(WorkOrderModel $workOrder): array
public function via(): array
{
$methods = [WeComChannel::class, WebChannel::class];
if (in_array($workOrder->status, ['processing', 'replied'])) {
$methods[] = 'mail';
}
return $methods;
}
/**
* Get the mail representation of the notification.
*/
public function toMail(WorkOrderModel $workOrder): MailMessage
{
return (new MailMessage)
->subject('工单: '.$workOrder->title.' 状态更新。')
->line('我们查阅了您的工单并做出了相应处理。')
->line('请前往我们的仪表盘继续跟进问题。');
return [WeComChannel::class, WebChannel::class];
}
/**
@ -67,23 +49,10 @@ public function toWeCom(WorkOrderModel $workOrder): false|array
{
$workOrder->load(['module', 'user']);
$wecom_key = config('settings.wecom.robot_hook.default');
if ($workOrder->module) {
$module = $workOrder->module;
$wecom_key = $module->makeVisible(['wecom_key'])->wecom_key ?? $wecom_key;
}
return [
'key' => $wecom_key,
'key' => $workOrder->wecom_key,
'view' => 'notifications.work_order',
'data' => $workOrder,
];
}
// public function toBroadcast(WorkOrderModel $workOrder): BroadcastMessage
// {
// return new BroadcastMessage($workOrder->toArray());
// }
}