From 3dbb3948620f5d86afbb4034f13dbe46f078e61e Mon Sep 17 00:00:00 2001 From: sky121113 Date: Wed, 1 Apr 2026 16:10:40 +0800 Subject: [PATCH] =?UTF-8?q?[REFACTOR]=20=E7=A7=BB=E9=99=A4=E6=A9=9F?= =?UTF-8?q?=E5=8F=B0=E7=AE=A1=E7=90=86=E8=88=87=E5=BA=AB=E5=AD=98=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E4=B8=AD=E7=9A=84=E8=B2=A8=E9=81=93=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=A5=97=E7=94=A8=E5=8A=9F=E8=83=BD=E8=88=87=E6=97=A5=E8=AA=8C?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E5=86=97=E9=A4=98=E5=88=86=E9=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 移除 MachineController 貨道更新 API 的 apply_all_same_product 驗證規則。 2. 簡化 MachineService 的 updateSlot 邏輯,取消「同步套用至同機台其他相同商品」的批次異動功能以確保資料準確性。 3. 清理 index.blade.php 機台管理頁面中的「貨道狀態 (Slot Status)」分頁、相關 Alpine.js 函式與專用的貨道編輯 Modal。 4. 修正 stock.blade.php 庫存管理介面,移除編輯 Modal 內的同步切換開關。 --- .../Controllers/Admin/MachineController.php | 1 - app/Services/Machine/MachineService.php | 27 +- .../views/admin/machines/index.blade.php | 246 +----------------- resources/views/admin/remote/stock.blade.php | 17 +- 4 files changed, 11 insertions(+), 280 deletions(-) diff --git a/app/Http/Controllers/Admin/MachineController.php b/app/Http/Controllers/Admin/MachineController.php index 5f39a41..8df0cd9 100644 --- a/app/Http/Controllers/Admin/MachineController.php +++ b/app/Http/Controllers/Admin/MachineController.php @@ -129,7 +129,6 @@ class MachineController extends AdminController 'stock' => 'nullable|integer|min:0', 'expiry_date' => 'nullable|date', 'batch_no' => 'nullable|string|max:50', - 'apply_all_same_product' => 'boolean' ]); $this->machineService->updateSlot($machine, $validated); diff --git a/app/Services/Machine/MachineService.php b/app/Services/Machine/MachineService.php index c46305a..f2e9898 100644 --- a/app/Services/Machine/MachineService.php +++ b/app/Services/Machine/MachineService.php @@ -105,26 +105,15 @@ class MachineService $stock = $data['stock'] ?? null; $expiryDate = $data['expiry_date'] ?? null; $batchNo = $data['batch_no'] ?? null; - $applyAllSame = $data['apply_all_same_product'] ?? false; + $slot = $machine->slots()->where('slot_no', $slotNo)->firstOrFail(); - $slot = $machine->slots()->where('slot_no', $slotNo)->with('product')->firstOrFail(); - - if ($applyAllSame && $slot->product_id) { - // 更新該機台內所有相同商品的貨道 - $machine->slots()->where('product_id', $slot->product_id)->update([ - 'stock' => $stock !== null ? (int)$stock : DB::raw('stock'), - 'expiry_date' => $expiryDate, - 'batch_no' => $batchNo, - ]); - } else { - // 僅更新單一貨道 - $updateData = [ - 'expiry_date' => $expiryDate, - 'batch_no' => $batchNo, - ]; - if ($stock !== null) $updateData['stock'] = (int)$stock; - $slot->update($updateData); - } + $updateData = [ + 'expiry_date' => $expiryDate, + 'batch_no' => $batchNo, + ]; + if ($stock !== null) $updateData['stock'] = (int)$stock; + + $slot->update($updateData); }); } diff --git a/resources/views/admin/machines/index.blade.php b/resources/views/admin/machines/index.blade.php index 69641f0..54caa08 100644 --- a/resources/views/admin/machines/index.blade.php +++ b/resources/views/admin/machines/index.blade.php @@ -18,11 +18,6 @@ window.machineApp = function() { viewMode: 'fleet', selectedMachine: null, slots: [], - showExpiryModal: false, - selectedSlot: null, - tempExpiry: '', - applyToAllSame: false, - updating: false, init() { const d = new Date(); @@ -46,15 +41,6 @@ window.machineApp = function() { await this.fetchLogs(); }, - async fetchDrawerSlots() { - this.loading = true; - try { - const res = await fetch('/admin/machines/' + this.currentMachineId + '/slots-ajax'); - const data = await res.json(); - if (data.success) this.slots = data.slots; - } catch(e) { console.error('fetchDrawerSlots error:', e); } - finally { this.loading = false; } - }, async fetchLogs() { this.loading = true; @@ -84,64 +70,12 @@ window.machineApp = function() { finally { this.loading = false; } }, - openSlotEdit(slot) { - this.selectedSlot = slot; - this.tempExpiry = slot.expiry_date ? slot.expiry_date.split('T')[0] : ''; - this.applyToAllSame = false; - this.showExpiryModal = true; - }, - - async saveExpiry() { - this.updating = true; - try { - const csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); - const machineId = this.selectedMachine ? this.selectedMachine.id : this.currentMachineId; - const res = await fetch('/admin/machines/' + machineId + '/slots/expiry', { - method: 'POST', - headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, - body: JSON.stringify({ - slot_no: this.selectedSlot.slot_no, - expiry_date: this.tempExpiry, - stock: this.selectedSlot.stock, - batch_no: this.selectedSlot.batch_no, - apply_all_same_product: this.applyToAllSame - }) - }); - const data = await res.json(); - if (data.success) { - this.showExpiryModal = false; - if (this.selectedMachine) { - await this.openCabinet(this.selectedMachine.id); - } else { - // Refresh slots in offcanvas - const slotRes = await fetch(`/api/v1/machines/${machineId}/slots`); - const slotData = await slotRes.json(); - this.slots = slotData.slots; - } - } - } catch(e) { console.error('saveExpiry error:', e); } - finally { this.updating = false; } - }, - - getSlotColorClass(slot) { - if (!slot.expiry_date) return 'bg-slate-50/50 dark:bg-slate-800/50 text-slate-400 border-slate-200/60 dark:border-slate-700/50'; - const todayStr = new Date().toISOString().split('T')[0]; - const expiryStr = slot.expiry_date; - if (expiryStr < todayStr) { - return 'bg-rose-50/60 dark:bg-rose-500/10 text-rose-600 dark:text-rose-400 border-rose-200 dark:border-rose-500/30 shadow-sm shadow-rose-500/5'; - } - const diffDays = Math.round((new Date(expiryStr) - new Date(todayStr)) / 86400000); - if (diffDays <= 7) { - return 'bg-amber-50/60 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-500/30 shadow-sm shadow-amber-500/5'; - } - return 'bg-emerald-50/60 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-200 dark:border-emerald-500/30 shadow-sm shadow-emerald-500/5'; - } }; };
+ @keydown.escape.window="showLogPanel = false">
@@ -445,11 +379,6 @@ window.machineApp = function() { class="whitespace-nowrap py-4 px-1 border-b-2 font-bold text-[13px] sm:text-sm transition duration-300"> {{ __('Device Status Logs') }} -
@@ -565,58 +494,6 @@ window.machineApp = function() {
- -
-
- -
- -
@@ -627,125 +504,4 @@ window.machineApp = function() { - - @endsection diff --git a/resources/views/admin/remote/stock.blade.php b/resources/views/admin/remote/stock.blade.php index 2f31d26..59dcd41 100644 --- a/resources/views/admin/remote/stock.blade.php +++ b/resources/views/admin/remote/stock.blade.php @@ -14,12 +14,10 @@ window.stockApp = function(initialMachineId) { // Modal State showEditModal: false, - selectedSlot: null, formData: { stock: 0, expiry_date: '', - batch_no: '', - apply_all_same_product: false + batch_no: '' }, async init() { @@ -73,8 +71,7 @@ window.stockApp = function(initialMachineId) { this.formData = { stock: slot.stock || 0, expiry_date: slot.expiry_date ? slot.expiry_date.split('T')[0] : '', - batch_no: slot.batch_no || '', - apply_all_same_product: false + batch_no: slot.batch_no || '' }; this.showEditModal = true; }, @@ -444,16 +441,6 @@ window.stockApp = function(initialMachineId) { - -
- -