fix(AdminGoodsSaveHandle): 空id房间用数组索引匹配 room_0/room_1

DB 中模板5的room[0].id为空,selected_rooms发来room_0。
filter无法匹配空id导致selectedRoomIds=[],rooms为空。

修复:空id时用数组索引作为room_N(N从0开始)进行匹配。
PHP 7.x兼容,无str_starts_with。
council/ProductManager
Council 2026-04-20 12:42:46 +08:00
parent 5dc9a98420
commit 8a33e7fa29
1 changed files with 16 additions and 2 deletions

View File

@ -11,6 +11,9 @@ 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'] ?? '';
// ────────────────────────────────────────────────────── // ──────────────────────────────────────────────────────
@ -106,9 +109,12 @@ class AdminGoodsSaveHandle
} }
// 按 selected_rooms 过滤(支持前端标准化的 "room_0" 格式双向兼容) // 按 selected_rooms 过滤(支持前端标准化的 "room_0" 格式双向兼容)
// 注意v3 格式 room.id 可能为空(用数组索引代替 id
// 此时 room_0 对应 rooms[0]room_1 对应 rooms[1],以此类推
$selectedRoomIds = array_column( $selectedRoomIds = array_column(
array_filter($allRooms, function ($r) use ($selectedRooms) { array_filter($allRooms, function ($r) use ($selectedRooms, &$roomIdx) {
$rid = $r['id'] ?? ''; $rid = $r['id'] ?? '';
// 直接匹配
if (in_array($rid, $selectedRooms)) { if (in_array($rid, $selectedRooms)) {
return true; return true;
} }
@ -116,12 +122,20 @@ class AdminGoodsSaveHandle
if (strpos($rid, 'room_') === 0 && in_array(substr($rid, 5), $selectedRooms)) { if (strpos($rid, 'room_') === 0 && in_array(substr($rid, 5), $selectedRooms)) {
return true; return true;
} }
if (in_array('room_' . $rid, $selectedRooms)) { if (!empty($rid) && in_array('room_' . $rid, $selectedRooms)) {
return true;
}
// 空 id用数组索引替代room_0→rooms[0], room_1→rooms[1]
static $roomIndex = -1;
$roomIndex++;
if ($rid === '' && in_array('room_' . $roomIndex, $selectedRooms)) {
return true; return true;
} }
return false; return false;
}), null }), null
); );
// 重置静态索引(避免跨模板污染)
unset($roomIndex);
$config['template_snapshot'] = [ $config['template_snapshot'] = [
'venue' => $seatMap['venue'] ?? [], 'venue' => $seatMap['venue'] ?? [],