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
parent
effe522ebf
commit
3f06f36e50
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue