debug: add temp logging to trace template_snapshot rebuild

council/ProductManager
Council 2026-04-20 12:23:58 +08:00
parent da001797ab
commit 0a2fd29d7c
1 changed files with 9 additions and 3 deletions

View File

@ -60,6 +60,10 @@ class AdminGoodsSaveHandle
// 直接从数据库读 vr_goods_config避免 $params['data'] 值拷贝的引用链问题) // 直接从数据库读 vr_goods_config避免 $params['data'] 值拷贝的引用链问题)
$goodsRow = Db::name('Goods')->field('vr_goods_config')->find($goodsId); $goodsRow = Db::name('Goods')->field('vr_goods_config')->find($goodsId);
$rawConfig = $goodsRow['vr_goods_config'] ?? ''; $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)) { if (!empty($rawConfig)) {
$configs = json_decode($rawConfig, true); $configs = json_decode($rawConfig, true);
if (json_last_error() !== JSON_ERROR_NONE) { if (json_last_error() !== JSON_ERROR_NONE) {
@ -76,11 +80,10 @@ 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);
if (empty($template)) {
continue;
}
$seatMap = json_decode($template['seat_map'] ?? '{}', true); $seatMap = json_decode($template['seat_map'] ?? '{}', true);
$allRooms = $seatMap['rooms'] ?? []; $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→v3 兼容迁移 ──
// v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构 // v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构
@ -124,6 +127,9 @@ class AdminGoodsSaveHandle
} }
unset($config); // 解除引用,避免后续误改 unset($config); // 解除引用,避免后续误改
// 写入调试日志
@file_put_contents($debugPath, implode("\n", $debugInfo) . "\n", FILE_APPEND);
// 将填充后的完整 config 写回 goods 表 // 将填充后的完整 config 写回 goods 表
Db::name('Goods')->where('id', $goodsId)->update([ Db::name('Goods')->where('id', $goodsId)->update([
'vr_goods_config' => json_encode($configs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), 'vr_goods_config' => json_encode($configs, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),