From 8a33e7fa296b7aa3e3ddbd6f8d64ed4092f6bd3b Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 12:42:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(AdminGoodsSaveHandle):=20=E7=A9=BAid?= =?UTF-8?q?=E6=88=BF=E9=97=B4=E7=94=A8=E6=95=B0=E7=BB=84=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=20room=5F0/room=5F1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DB 中模板5的room[0].id为空,selected_rooms发来room_0。 filter无法匹配空id导致selectedRoomIds=[],rooms为空。 修复:空id时用数组索引作为room_N(N从0开始)进行匹配。 PHP 7.x兼容,无str_starts_with。 --- .../vr_ticket/hook/AdminGoodsSaveHandle.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php index 6932bf6..069db6d 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php @@ -11,6 +11,9 @@ class AdminGoodsSaveHandle */ public function handle($params = []) { + $debugPath = '/tmp/vr_debug.log'; + @file_put_contents($debugPath, "[HOOK_FIRED] hook_name=" . ($params['hook_name'] ?? 'NULL') . ", goods_id=" . ($params['goods_id'] ?? 'NULL') . ", item_type=" . ($params['data']['item_type'] ?? 'NULL') . "\n", FILE_APPEND); + $hookName = $params['hook_name'] ?? ''; // ────────────────────────────────────────────────────── @@ -106,9 +109,12 @@ class AdminGoodsSaveHandle } // 按 selected_rooms 过滤(支持前端标准化的 "room_0" 格式双向兼容) + // 注意:v3 格式 room.id 可能为空(用数组索引代替 id), + // 此时 room_0 对应 rooms[0],room_1 对应 rooms[1],以此类推 $selectedRoomIds = array_column( - array_filter($allRooms, function ($r) use ($selectedRooms) { + array_filter($allRooms, function ($r) use ($selectedRooms, &$roomIdx) { $rid = $r['id'] ?? ''; + // 直接匹配 if (in_array($rid, $selectedRooms)) { return true; } @@ -116,12 +122,20 @@ class AdminGoodsSaveHandle if (strpos($rid, 'room_') === 0 && in_array(substr($rid, 5), $selectedRooms)) { return true; } - if (in_array('room_' . $rid, $selectedRooms)) { + if (!empty($rid) && in_array('room_' . $rid, $selectedRooms)) { + return true; + } + // 空 id:用数组索引替代(room_0→rooms[0], room_1→rooms[1]) + static $roomIndex = -1; + $roomIndex++; + if ($rid === '' && in_array('room_' . $roomIndex, $selectedRooms)) { return true; } return false; }), null ); + // 重置静态索引(避免跨模板污染) + unset($roomIndex); $config['template_snapshot'] = [ 'venue' => $seatMap['venue'] ?? [],