feat(notification): 實作通知輪詢與優化顯示名稱
- 新增通知輪詢 API 與前端自動更新機制 - 修正生產工單單號格式為 PRO-YYYYMMDD-XX - 確保通知顯示實際建立者名稱而非系統
This commit is contained in:
54
app/Modules/Production/Notifications/NewProductionOrder.php
Normal file
54
app/Modules/Production/Notifications/NewProductionOrder.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Production\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use App\Modules\Production\Models\ProductionOrder;
|
||||
|
||||
class NewProductionOrder extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $productionOrder;
|
||||
protected $creatorName;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(ProductionOrder $productionOrder, string $creatorName)
|
||||
{
|
||||
$this->productionOrder = $productionOrder;
|
||||
$this->creatorName = $creatorName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'production_order',
|
||||
'action' => 'created',
|
||||
'production_order_id' => $this->productionOrder->id,
|
||||
'code' => $this->productionOrder->code,
|
||||
'creator_name' => $this->creatorName,
|
||||
'message' => "{$this->creatorName} 建立了新的生產工單:{$this->productionOrder->code}",
|
||||
'link' => route('production-orders.index', ['search' => $this->productionOrder->code]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user