From 3f06f36e5056473919e85ab976b846fe28d2112d Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 10:40:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(AdminGoodsSaveHandle):=20template=5Fsnapsho?= =?UTF-8?q?t=20rooms=E4=B8=BA=E7=A9=BA=E6=97=B6DB=E5=85=9C=E5=BA=95=20+=20?= =?UTF-8?q?v1=E2=86=92v3=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 Issue #13: 1. 条件从 empty(template_snapshot) 改为 empty(rooms),解决前端发送空rooms对象时跳过兜底的问题 2. 新增 v1 旧格式兼容:sections+map 扁平结构自动升級为 v3 rooms 数组 --- .../vr_ticket/hook/AdminGoodsSaveHandle.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php index 60a6742..3c6c44e 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php @@ -62,9 +62,9 @@ class AdminGoodsSaveHandle $configs = json_decode($rawConfig, true); if (is_array($configs) && !empty($configs)) { - // 0) 填充 template_snapshot(前端没传时兜底从 vr_seat_templates 读) + // 0) 填充 template_snapshot(前端没传、或 rooms 为空时兜底从 vr_seat_templates 读) foreach ($configs as $i => &$config) { - if (empty($config['template_snapshot'])) { + if (empty($config['template_snapshot']) || empty($config['template_snapshot']['rooms'])) { $templateId = intval($config['template_id'] ?? 0); if ($templateId > 0) { $template = Db::name('vr_seat_templates')->find($templateId); @@ -74,6 +74,22 @@ class AdminGoodsSaveHandle $seatMap = json_decode($template['seat_map'] ?? '{}', true); $allRooms = $seatMap['rooms'] ?? []; + // ── v1→v3 兼容迁移 ── + // v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构 + if (empty($allRooms) && !empty($seatMap['sections'])) { + $v1Sections = $seatMap['sections'] ?? []; + $v1Map = $seatMap['map'] ?? []; + $v1Seats = $seatMap['seats'] ?? []; + $v1RoomId = $config['selected_rooms'][0] ?? 'room_1'; + $allRooms = [[ + 'id' => $v1RoomId, + 'name' => $seatMap['venue']['name'] ?? '主馆', + 'sections' => $v1Sections, + 'map' => $v1Map, + 'seats' => $v1Seats, + ]]; + } + // 按 selected_rooms 过滤,只存用户选中的房间 $selectedRoomIds = array_column( array_filter($allRooms, function ($r) use ($config) {