fix: update low stock warning threshold to 20% of max_stock

1. 移除硬編碼的門檻值 5。
2. 改用 stock <= (max_stock * 0.2) 進行動態判斷。
3. 增加 max_stock > 0 過濾,避免空貨道產生錯誤警示。
This commit is contained in:
sky121113 2026-05-16 20:07:12 +08:00
parent 88dde0dd25
commit 9bf670b951

View File

@ -207,7 +207,8 @@ class RemoteController extends Controller
$machineQuery = Machine::withCount([
'slots as slots_count',
'slots as low_stock_count' => function ($query) {
$query->where('stock', '<=', 5);
$query->where('max_stock', '>', 0)
->whereRaw('stock <= (max_stock * 0.2)');
},
'slots as expiring_soon_count' => function ($query) {
$query->whereNotNull('expiry_date')