fix(AdminGoodsSaveHandle): template_snapshot rooms为空时DB兜底 + v1→v3迁移

修复 Issue #13:
1. 条件从 empty(template_snapshot) 改为 empty(rooms),解决前端发送空rooms对象时跳过兜底的问题
2. 新增 v1 旧格式兼容:sections+map 扁平结构自动升級为 v3 rooms 数组
council/ProductManager
Council 2026-04-20 10:40:26 +08:00
parent effe522ebf
commit 3f06f36e50
1 changed files with 18 additions and 2 deletions

View File

@ -62,9 +62,9 @@ class AdminGoodsSaveHandle
$configs = json_decode($rawConfig, true); $configs = json_decode($rawConfig, true);
if (is_array($configs) && !empty($configs)) { if (is_array($configs) && !empty($configs)) {
// 0) 填充 template_snapshot前端没传时兜底从 vr_seat_templates 读) // 0) 填充 template_snapshot前端没传、或 rooms 为空时兜底从 vr_seat_templates 读)
foreach ($configs as $i => &$config) { 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); $templateId = intval($config['template_id'] ?? 0);
if ($templateId > 0) { if ($templateId > 0) {
$template = Db::name('vr_seat_templates')->find($templateId); $template = Db::name('vr_seat_templates')->find($templateId);
@ -74,6 +74,22 @@ class AdminGoodsSaveHandle
$seatMap = json_decode($template['seat_map'] ?? '{}', true); $seatMap = json_decode($template['seat_map'] ?? '{}', true);
$allRooms = $seatMap['rooms'] ?? []; $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 过滤,只存用户选中的房间 // 按 selected_rooms 过滤,只存用户选中的房间
$selectedRoomIds = array_column( $selectedRoomIds = array_column(
array_filter($allRooms, function ($r) use ($config) { array_filter($allRooms, function ($r) use ($config) {