Files
star-erp/app/Modules/Procurement/Notifications/NewPurchaseOrder.php
sky121113 882091ce5f feat(notification): 實作通知輪詢與優化顯示名稱
- 新增通知輪詢 API 與前端自動更新機制
- 修正生產工單單號格式為 PRO-YYYYMMDD-XX
- 確保通知顯示實際建立者名稱而非系統
2026-02-12 17:13:09 +08:00

55 lines
1.5 KiB
PHP

<?php
namespace App\Modules\Procurement\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Modules\Procurement\Models\PurchaseOrder;
class NewPurchaseOrder extends Notification
{
use Queueable;
protected $purchaseOrder;
protected $creatorName;
/**
* Create a new notification instance.
*/
public function __construct(PurchaseOrder $purchaseOrder, string $creatorName)
{
$this->purchaseOrder = $purchaseOrder;
$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' => 'purchase_order',
'action' => 'created',
'purchase_order_id' => $this->purchaseOrder->id,
'code' => $this->purchaseOrder->code,
'creator_name' => $this->creatorName,
'message' => "{$this->creatorName} 建立了新的採購單:{$this->purchaseOrder->code}",
'link' => route('purchase-orders.index', ['search' => $this->purchaseOrder->code]), // 暫時導向列表並搜尋,若有詳情頁可改
];
}
}