From bbea35d83743490f187405899ff12cf562827ea3 Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 09:36:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(AdminGoodsSaveHandle):=20=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E8=87=AA=E5=8A=A8=E5=A1=AB=E5=85=85=20templa?= =?UTF-8?q?te=5Fsnapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue #13 Step 1: - save_thing_end 时机:遍历 vr_goods_config[],检测 template_snapshot 是否缺失 - 若缺失:从 vr_seat_templates 读最新 seat_map,按 selected_rooms 过滤 rooms - 将填充后的完整 config JSON 写回 goods 表,再执行 BatchGenerate - 前端已传 template_snapshot 时:直接透传,无需后端处理 --- .../vr_ticket/hook/AdminGoodsSaveHandle.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php index db18c7f..b4c0793 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php @@ -62,6 +62,36 @@ class AdminGoodsSaveHandle $configs = json_decode($rawConfig, true); if (is_array($configs) && !empty($configs)) { + // 0) 填充 template_snapshot(前端没传时兜底从 vr_seat_templates 读) + foreach ($configs as $i => &$config) { + if (empty($config['template_snapshot'])) { + $templateId = intval($config['template_id'] ?? 0); + if ($templateId > 0) { + $template = Db::name('vr_seat_templates')->find($templateId); + $seatMap = json_decode($template['seat_map'] ?? '{}', true); + $allRooms = $seatMap['rooms'] ?? []; + + // 按 selected_rooms 过滤,只存用户选中的房间 + $selectedRoomIds = array_column( + array_filter($allRooms, function ($r) use ($config) { + return in_array($r['id'], $config['selected_rooms'] ?? []); + }), null + ); + + $config['template_snapshot'] = [ + 'venue' => $seatMap['venue'] ?? [], + 'rooms' => $selectedRoomIds, + ]; + } + } + } + unset($config); // 解除引用,避免后续误改 + + // 将填充后的完整 config 写回 goods 表 + Db::name('Goods')->where('id', $goodsId)->update([ + 'vr_goods_config' => json_encode($configs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + ]); + // a) 清空原生规格数据 —— 避免列偏移 Db::name('GoodsSpecType')->where('goods_id', $goodsId)->delete(); Db::name('GoodsSpecBase')->where('goods_id', $goodsId)->delete();