chore: remove debug logging from AdminGoodsSaveHandle

All debugging code (vr_debug.log writes) removed.
Template snapshot rebuild is now stable and verified.
council/ProductManager
Council 2026-04-20 13:31:17 +08:00
parent c03737308b
commit 05b69588f5
1 changed files with 4 additions and 17 deletions

View File

@ -11,9 +11,6 @@ class AdminGoodsSaveHandle
*/ */
public function handle($params = []) 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'] ?? ''; $hookName = $params['hook_name'] ?? '';
// ────────────────────────────────────────────────────── // ──────────────────────────────────────────────────────
@ -68,16 +65,13 @@ class AdminGoodsSaveHandle
$rawConfig = $data['vr_goods_config'] ?? ''; $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)) { 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) {
$configs = null; $configs = null;
} }
if (is_array($configs) && !empty($configs)) { if (is_array($configs) && !empty($configs)) {
// 0) 重建 template_snapshot — 前端不发送 template_snapshot // 0) 重建 template_snapshot — 前端不发送 template_snapshot
// 当 template_snapshot 为空、或 selected_rooms 有值时,从 DB 重建 // 当 template_snapshot 为空、或 selected_rooms 有值时,从 DB 重建
foreach ($configs as $i => &$config) { foreach ($configs as $i => &$config) {
@ -89,11 +83,9 @@ class AdminGoodsSaveHandle
$template = Db::name('vr_seat_templates')->find($templateId); $template = Db::name('vr_seat_templates')->find($templateId);
$seatMap = json_decode($template['seat_map'] ?? '{}', true); $seatMap = json_decode($template['seat_map'] ?? '{}', true);
$allRooms = $seatMap['rooms'] ?? []; $allRooms = $seatMap['rooms'] ?? [];
// DEBUG // 注意v3 格式 room.id 可能为空(用数组索引代替 id
$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')); // 此时 room_0 对应 rooms[0]room_1 对应 rooms[1],以此类推
// ── v1→v3 兼容迁移 ── // ── v1→v3 兼容迁移 ──
// v1 旧格式没有 rooms 嵌套,只有 sections+map 扁平结构
if (empty($allRooms) && !empty($seatMap['sections'])) { if (empty($allRooms) && !empty($seatMap['sections'])) {
$v1Sections = $seatMap['sections'] ?? []; $v1Sections = $seatMap['sections'] ?? [];
$v1Map = $seatMap['map'] ?? []; $v1Map = $seatMap['map'] ?? [];
@ -112,7 +104,7 @@ class AdminGoodsSaveHandle
// 注意v3 格式 room.id 可能为空(用数组索引代替 id // 注意v3 格式 room.id 可能为空(用数组索引代替 id
// 此时 room_0 对应 rooms[0]room_1 对应 rooms[1],以此类推 // 此时 room_0 对应 rooms[0]room_1 对应 rooms[1],以此类推
$selectedRoomIds = array_column( $selectedRoomIds = array_column(
array_filter($allRooms, function ($r) use ($selectedRooms, &$roomIdx) { array_filter($allRooms, function ($r) use ($selectedRooms) {
$rid = $r['id'] ?? ''; $rid = $r['id'] ?? '';
// 直接匹配 // 直接匹配
if (in_array($rid, $selectedRooms)) { if (in_array($rid, $selectedRooms)) {
@ -134,8 +126,6 @@ class AdminGoodsSaveHandle
return false; return false;
}), null }), null
); );
// 重置静态索引(避免跨模板污染)
unset($roomIndex);
$config['template_snapshot'] = [ $config['template_snapshot'] = [
'venue' => $seatMap['venue'] ?? [], 'venue' => $seatMap['venue'] ?? [],
@ -145,9 +135,6 @@ 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),