feat(notification): 實作通知輪詢與優化顯示名稱

- 新增通知輪詢 API 與前端自動更新機制
- 修正生產工單單號格式為 PRO-YYYYMMDD-XX
- 確保通知顯示實際建立者名稱而非系統
This commit is contained in:
2026-02-12 17:13:09 +08:00
parent 299602d3b1
commit 882091ce5f
14 changed files with 528 additions and 47 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Modules\Production\Observers;
use App\Modules\Production\Models\ProductionOrder;
use App\Modules\Production\Notifications\NewProductionOrder;
use App\Modules\Core\Models\User;
use Illuminate\Support\Facades\Notification;
class ProductionOrderObserver
{
/**
* Handle the ProductionOrder "created" event.
*/
public function created(ProductionOrder $productionOrder): void
{
// 找出有檢視生產工單權限的使用者
$users = User::permission('production_orders.view')->get();
$creatorName = $productionOrder->user ? $productionOrder->user->name : '系統';
if ($users->isNotEmpty()) {
Notification::send($users, new NewProductionOrder($productionOrder, $creatorName));
}
}
}