From 2dd14fd1b4e3086925295b995c7a8e1835447fe7 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Fri, 26 Jun 2026 17:42:21 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E5=8F=96=E8=B2=A8=E7=A2=BC=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=B9=E4=BB=A5=E5=95=86=E5=93=81=E7=82=BA=E4=B8=BB?= =?UTF-8?q?=E3=80=81=E7=B6=81=E5=95=86=E5=93=81=E7=A2=BC=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E7=A9=BA=E8=B2=A8=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. pickupCodes 查詢補 product eager load,避免 N+1。 2. 列表商品欄改依綁定型態顯示:綁商品碼直接顯示商品名且不顯示貨道;綁貨道碼(舊)維持反查商品名並保留貨道號。 3. 桌面表格標題「商品 / 貨道」改為「商品」,手機卡片同步調整。 --- .../Controllers/Admin/SalesController.php | 2 +- .../pickup-codes/partials/tab-list.blade.php | 43 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/Admin/SalesController.php b/app/Http/Controllers/Admin/SalesController.php index becc8e2..01f8f24 100644 --- a/app/Http/Controllers/Admin/SalesController.php +++ b/app/Http/Controllers/Admin/SalesController.php @@ -376,7 +376,7 @@ class SalesController extends Controller // 1. 取貨碼列表 (list) if (!$isAjax || $tab === 'list') { // 僅顯示目前帳號可存取機台的取貨碼(機台授權以 machine_user 為準,whereHas 會套用 Machine 的 machine_access 全域 scope) - $query = PickupCode::with(['machine.slots.product', 'creator', 'order']) + $query = PickupCode::with(['machine.slots.product', 'product', 'creator', 'order']) ->whereHas('machine') ->latest(); diff --git a/resources/views/admin/sales/pickup-codes/partials/tab-list.blade.php b/resources/views/admin/sales/pickup-codes/partials/tab-list.blade.php index 1eb5373..cc35db6 100644 --- a/resources/views/admin/sales/pickup-codes/partials/tab-list.blade.php +++ b/resources/views/admin/sales/pickup-codes/partials/tab-list.blade.php @@ -80,7 +80,7 @@ - {{ __('Product / Slot') }} + {{ __('Product') }} @@ -125,15 +125,25 @@ @php - $slot = $code->machine?->slots->where('slot_no', $code->slot_no)->first(); - $productName = $slot ? ($slot->product?->name ?? __('Empty')) : __('Empty'); + // 綁商品碼(新):直接取 product 名稱,不顯示貨道。 + // 綁貨道碼(舊,向後相容):由貨道反查商品,並保留貨道資訊。 + if ($code->product_id) { + $productName = $code->product?->name ?? __('Empty'); + $slotLabel = null; + } else { + $slot = $code->machine?->slots->where('slot_no', $code->slot_no)->first(); + $productName = $slot ? ($slot->product?->name ?? __('Empty')) : __('Empty'); + $slotLabel = $code->slot_no; + } @endphp
{{ $productName }}
+ @if($slotLabel)
{{ __('Slot') - }}: {{ $code->slot_no }}
+ }}: {{ $slotLabel }} + @endif
@@ -281,19 +291,24 @@
+ @php + if ($code->product_id) { + $prodMobile = $code->product?->name ?? __('Empty'); + $slotMobileLabel = null; + } else { + $slotMobile = $code->machine?->slots->where('slot_no', $code->slot_no)->first(); + $prodMobile = $slotMobile ? ($slotMobile->product?->name ?? __('Empty')) : __('Empty'); + $slotMobileLabel = $code->slot_no; + } + @endphp

- {{ __('Slot') }}

+ {{ __('Product') }}

- {{ $code->slot_no }} - @php - $slotMobile = $code->machine?->slots->where('slot_no', - $code->slot_no)->first(); - $prodMobile = $slotMobile ? ($slotMobile->product?->name ?? __('Empty')) : - __('Empty'); - @endphp - ({{ $prodMobile - }}) + {{ $prodMobile }} + @if($slotMobileLabel) + {{ __('Slot') }}: {{ $slotMobileLabel }} + @endif