feat(AdminGoodsSaveHandle): 保存时自动填充 template_snapshot
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 时:直接透传,无需后端处理council/ProductManager
parent
7f32ad87c2
commit
bbea35d837
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue