fix: 模板硬删除场景下优雅降级 + snapshot 同步清空

方案逻辑(用户提出):
- 模板被硬删除后,GetGoodsViewData() 将 template_id + template_snapshot 同时置 null
- 前端看到选单为空,用户可重新选择或清空配置
- AdminGoodsSaveHandle() 跳过不存在模板的 snapshot 重建(continue)

修改文件:
- SeatSkuService.php: GetGoodsViewData() 加硬删除检测,空模板时清空 config
- AdminGoodsSaveHandle.php: 模板不存在时 continue,不触发 json_decode(null) Fatal Error
council/ProductManager
Council 2026-04-20 14:32:38 +08:00
parent fa35d785a9
commit 5675bb679f
2 changed files with 25 additions and 0 deletions

View File

@ -81,6 +81,15 @@ class AdminGoodsSaveHandle
// 条件snapshot 为空,或者前端有 selected_rooms // 条件snapshot 为空,或者前端有 selected_rooms
if ($templateId > 0 && (!empty($selectedRooms) || empty($config['template_snapshot']) || empty($config['template_snapshot']['rooms']))) { if ($templateId > 0 && (!empty($selectedRooms) || empty($config['template_snapshot']) || empty($config['template_snapshot']['rooms']))) {
$template = Db::name('vr_seat_templates')->find($templateId); $template = Db::name('vr_seat_templates')->find($templateId);
// 模板不存在时(硬删除场景):
// - 跳过 snapshot 重建,保持 template_id=null 状态
// - 前端下次打开时将看到选单为空,用户可重新选择或清空配置
if (empty($template)) {
continue;
}
$seatMap = json_decode($template['seat_map'] ?? '{}', true); $seatMap = json_decode($template['seat_map'] ?? '{}', true);
$allRooms = $seatMap['rooms'] ?? []; $allRooms = $seatMap['rooms'] ?? [];
// 注意v3 格式 room.id 可能为空(用数组索引代替 id // 注意v3 格式 room.id 可能为空(用数组索引代替 id

View File

@ -377,6 +377,22 @@ class SeatSkuService extends BaseService
->where('id', $templateId) ->where('id', $templateId)
->find(); ->find();
// 模板不存在时(硬删除场景):
// - 将 template_id 置 null让前端选单显示为空
// - 同时清掉 template_snapshot下次保存时整块 config 干净地失效
if (empty($seatTemplate)) {
$config['template_id'] = null;
$config['template_snapshot'] = null;
\think\facade\Db::name('Goods')->where('id', $goodsId)->update([
'vr_goods_config' => json_encode([$config], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
]);
return [
'vr_seat_template' => null,
'goods_spec_data' => [],
'goods_config' => $config,
];
}
// 解码 seat_map JSON存储时是 JSON 字符串) // 解码 seat_map JSON存储时是 JSON 字符串)
if (!empty($seatTemplate['seat_map'])) { if (!empty($seatTemplate['seat_map'])) {
$decoded = json_decode($seatTemplate['seat_map'], true); $decoded = json_decode($seatTemplate['seat_map'], true);