From 05b69588f5dbfe670b11c9e75b2dfbab4165603c Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 13:31:17 +0800 Subject: [PATCH] chore: remove debug logging from AdminGoodsSaveHandle All debugging code (vr_debug.log writes) removed. Template snapshot rebuild is now stable and verified. --- .../vr_ticket/hook/AdminGoodsSaveHandle.php | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php index 069db6d..c6f1762 100644 --- a/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php +++ b/shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php @@ -11,9 +11,6 @@ class AdminGoodsSaveHandle */ public function handle($params = []) { - $debugPath = '/tmp/vr_debug.log'; - @file_put_contents($debugPath, "[HOOK_FIRED] hook_name=" . ($params['hook_name'] ?? 'NULL') . ", goods_id=" . ($params['goods_id'] ?? 'NULL') . ", item_type=" . ($params['data']['item_type'] ?? 'NULL') . "\n", FILE_APPEND); - $hookName = $params['hook_name'] ?? ''; // ────────────────────────────────────────────────────── @@ -68,16 +65,13 @@ class AdminGoodsSaveHandle $rawConfig = $data['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) { $configs = null; } - if (is_array($configs) && !empty($configs)) { + if (is_array($configs) && !empty($configs)) { // 0) 重建 template_snapshot — 前端不发送 template_snapshot, // 当 template_snapshot 为空、或 selected_rooms 有值时,从 DB 重建 foreach ($configs as $i => &$config) { @@ -89,11 +83,9 @@ class AdminGoodsSaveHandle $template = Db::name('vr_seat_templates')->find($templateId); $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')); - + // 注意:v3 格式 room.id 可能为空(用数组索引代替 id), + // 此时 room_0 对应 rooms[0],room_1 对应 rooms[1],以此类推 // ── v1→v3 兼容迁移 ── - // v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构 if (empty($allRooms) && !empty($seatMap['sections'])) { $v1Sections = $seatMap['sections'] ?? []; $v1Map = $seatMap['map'] ?? []; @@ -112,7 +104,7 @@ class AdminGoodsSaveHandle // 注意:v3 格式 room.id 可能为空(用数组索引代替 id), // 此时 room_0 对应 rooms[0],room_1 对应 rooms[1],以此类推 $selectedRoomIds = array_column( - array_filter($allRooms, function ($r) use ($selectedRooms, &$roomIdx) { + array_filter($allRooms, function ($r) use ($selectedRooms) { $rid = $r['id'] ?? ''; // 直接匹配 if (in_array($rid, $selectedRooms)) { @@ -134,8 +126,6 @@ class AdminGoodsSaveHandle return false; }), null ); - // 重置静态索引(避免跨模板污染) - unset($roomIndex); $config['template_snapshot'] = [ 'venue' => $seatMap['venue'] ?? [], @@ -145,9 +135,6 @@ 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),