From 426253b1c344900712ed80fd18da2f31476399a3 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Tue, 12 May 2026 17:15:53 +0800 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=E5=BC=B7=E5=8C=96=E9=81=A0=E7=AB=AF?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E4=B8=AD=E5=BF=83=E7=9A=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=82=99=E8=A8=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 新增 remote_commands 資料表的 remark 欄位以儲存操作備註。 2. 更新 RemoteCommand 模型,將 note 與 remark 加入可批量賦值名單。 3. 更新 MachineService 的 dispatchDispense 函式,支援接收與記錄操作備註。 4. 更新 RemoteController 的 storeCommand 邏輯,將前端輸入的備註存入 remark 並支援遠端出貨指令。 5. 優化操作紀錄搜尋邏輯,支援搜尋備註欄位。 6. 重構指令中心操作紀錄介面,桌面版新增「操作備註」欄位,並優化手機版卡片顯示。 7. 調整表格欄位寬度與標頭樣式,解決「指令類型」寬度過大的問題。 --- .../Controllers/Admin/RemoteController.php | 8 ++- app/Models/Machine/RemoteCommand.php | 2 + app/Services/Machine/MachineService.php | 5 +- ...42_add_remark_to_remote_commands_table.php | 28 +++++++++ .../partials/tab-history-index.blade.php | 57 +++++++++++++++---- 5 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 database/migrations/2026_05_12_170742_add_remark_to_remote_commands_table.php diff --git a/app/Http/Controllers/Admin/RemoteController.php b/app/Http/Controllers/Admin/RemoteController.php index 89fa1ce..bf1f5a3 100644 --- a/app/Http/Controllers/Admin/RemoteController.php +++ b/app/Http/Controllers/Admin/RemoteController.php @@ -53,7 +53,8 @@ class RemoteController extends Controller ->orWhere('serial_no', 'like', "%{$search}%"); })->orWhereHas('user', function ($uq) use ($search) { $uq->where('name', 'like', "%{$search}%"); - }); + })->orWhere('remark', 'like', "%{$search}%") + ->orWhere('note', 'like', "%{$search}%"); }); } @@ -145,7 +146,8 @@ class RemoteController extends Controller $this->machineService->dispatchDispense( Machine::findOrFail($validated['machine_id']), $validated['slot_no'], - auth()->id() + auth()->id(), + $validated['note'] ?? null ); } else { $payload = []; @@ -169,7 +171,7 @@ class RemoteController extends Controller 'command_type' => $validated['command_type'], 'payload' => $payload, 'status' => 'pending', - 'note' => $validated['note'] ?? null, + 'remark' => $validated['note'] ?? null, ]); // 推播 MQTT 指令 diff --git a/app/Models/Machine/RemoteCommand.php b/app/Models/Machine/RemoteCommand.php index 27ba7af..a569bbd 100644 --- a/app/Models/Machine/RemoteCommand.php +++ b/app/Models/Machine/RemoteCommand.php @@ -16,6 +16,8 @@ class RemoteCommand extends Model 'payload', 'status', 'ttl', + 'note', + 'remark', 'executed_at', ]; diff --git a/app/Services/Machine/MachineService.php b/app/Services/Machine/MachineService.php index fc8d1e1..7c74693 100644 --- a/app/Services/Machine/MachineService.php +++ b/app/Services/Machine/MachineService.php @@ -403,9 +403,9 @@ class MachineService /** * 遠端出貨指令下發 (指令模式,不再預扣庫存) */ - public function dispatchDispense(Machine $machine, string $slotNo, ?int $userId = null): RemoteCommand + public function dispatchDispense(Machine $machine, string $slotNo, ?int $userId = null, ?string $remark = null): RemoteCommand { - return DB::transaction(function () use ($machine, $slotNo, $userId) { + return DB::transaction(function () use ($machine, $slotNo, $userId, $remark) { $slot = $machine->slots()->where('slot_no', $slotNo)->lockForUpdate()->firstOrFail(); // 併行檢查:若有 pending 指令,超過 1 分鐘視為逾時可覆蓋 @@ -440,6 +440,7 @@ class MachineService 'user_id' => $userId, 'command_type' => 'dispense', 'status' => 'pending', + 'remark' => $remark, 'payload' => [ 'slot_no' => (string)$slotNo, 'current_stock' => $slot->stock, diff --git a/database/migrations/2026_05_12_170742_add_remark_to_remote_commands_table.php b/database/migrations/2026_05_12_170742_add_remark_to_remote_commands_table.php new file mode 100644 index 0000000..273da52 --- /dev/null +++ b/database/migrations/2026_05_12_170742_add_remark_to_remote_commands_table.php @@ -0,0 +1,28 @@ +string('remark')->nullable()->after('note')->comment('操作備註'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('remote_commands', function (Blueprint $table) { + $table->dropColumn('remark'); + }); + } +}; diff --git a/resources/views/admin/remote/partials/tab-history-index.blade.php b/resources/views/admin/remote/partials/tab-history-index.blade.php index 9d7030c..2f0dc22 100644 --- a/resources/views/admin/remote/partials/tab-history-index.blade.php +++ b/resources/views/admin/remote/partials/tab-history-index.blade.php @@ -129,10 +129,13 @@ class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800 text-center whitespace-nowrap"> {{ __('Picked up Time') }} + class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800 whitespace-nowrap"> {{ __('Command Type') }} + class="px-6 py-4 text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-[0.15em] border-b border-slate-100 dark:border-slate-800 whitespace-nowrap"> + {{ __('Operation Note') }} + {{ __('Operator') }} @@ -190,22 +193,39 @@ @endif -
+
- @if($item->note) - - @endif
+ +
+ @if($item->remark) + {{ $item->remark }} + @endif + + @if($item->note) +
+ + + + +
+ @endif + + @if(!$item->remark && !$item->note) + - + @endif +
+
- @if($item->note) - - @endif
+ @if($item->remark || $item->note) +
+

{{ __('Operation Note') }}

+
+ @if($item->remark) + {{ $item->remark }} + @endif + @if($item->note) +
+ + + + +
+ @endif +
+
+ @endif

{{ __('Creation Time') }}