From 0a2fd29d7c074faa59ce9e1a8bf946b5baba59b9 Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 12:23:58 +0800 Subject: [PATCH] debug: add temp logging to trace template_snapshot rebuild --- .../plugins/vr_ticket/hook/AdminGoodsSaveHandle.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php index 6e72975..91c3a22 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php @@ -60,6 +60,10 @@ class AdminGoodsSaveHandle // 直接从数据库读 vr_goods_config(避免 $params['data'] 值拷贝的引用链问题) $goodsRow = Db::name('Goods')->field('vr_goods_config')->find($goodsId); $rawConfig = $goodsRow['vr_goods_config'] ?? ''; + + // DEBUG: 记录关键值 + $debugPath = defined('RUNTIME_PATH') ? RUNTIME_PATH . 'vr_debug.log' : '/tmp/vr_debug.log'; + $debugInfo = ["[" . date('H:i:s') . "] goodsId=$goodsId, rawConfig_len=" . strlen($rawConfig) . ", rawConfig_preview=" . substr($rawConfig, 0, 200)]; if (!empty($rawConfig)) { $configs = json_decode($rawConfig, true); if (json_last_error() !== JSON_ERROR_NONE) { @@ -76,11 +80,10 @@ class AdminGoodsSaveHandle // 条件:snapshot 为空,或者前端有 selected_rooms if ($templateId > 0 && (!empty($selectedRooms) || empty($config['template_snapshot']) || empty($config['template_snapshot']['rooms']))) { $template = Db::name('vr_seat_templates')->find($templateId); - if (empty($template)) { - continue; - } $seatMap = json_decode($template['seat_map'] ?? '{}', true); $allRooms = $seatMap['rooms'] ?? []; + // DEBUG + $debugInfo[] = "templateId=$templateId, selectedRooms=" . json_encode($selectedRooms) . ", template_found=" . ($template ? 'YES' : 'NO') . ", seatMap_keys=" . (is_array($seatMap) ? implode(',', array_keys($seatMap)) : 'NOT_ARRAY') . ", allRooms_count=" . count($allRooms) . ", allRooms_ids=" . json_encode(array_column($allRooms, 'id')); // ── v1→v3 兼容迁移 ── // v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构 @@ -124,6 +127,9 @@ class AdminGoodsSaveHandle } unset($config); // 解除引用,避免后续误改 + // 写入调试日志 + @file_put_contents($debugPath, implode("\n", $debugInfo) . "\n", FILE_APPEND); + // 将填充后的完整 config 写回 goods 表 Db::name('Goods')->where('id', $goodsId)->update([ 'vr_goods_config' => json_encode($configs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),