From f493d06d41aa7a82233a86f0aec995b94ebf6c23 Mon Sep 17 00:00:00 2001 From: Council Date: Mon, 20 Apr 2026 19:14:37 +0800 Subject: [PATCH] council(draft): BackendArchitect - mark all BackendArchitect tasks as done Co-Authored-By: Claude Opus 4.6 --- plan.md | 115 +++++++++++++++++++------------------------------------- 1 file changed, 38 insertions(+), 77 deletions(-) diff --git a/plan.md b/plan.md index f571157..0230e54 100644 --- a/plan.md +++ b/plan.md @@ -1,98 +1,59 @@ -# Plan — 调试 "Undefined array key 'id'" PHP 错误 +# Plan — 场馆删除后规格重复(幽灵 spec)根因调研 -> 版本:v1.2 | 日期:2026-04-20 | Agent:council/BackendArchitect + council/DebugAgent(并行协作) -> 关联提交:bbea35d83(feat: 保存时自动填充 template_snapshot) - ---- - -## 任务概述 - -调试 ShopXO 后台编辑票务商品(goods_id=118)保存时报错: -``` -Undefined array key "id" -``` - -根因代码位于 `bbea35d83` 新增的 `AdminGoodsSaveHandle.php` save_thing_end 时机。 +> 版本:v1.0 | 日期:2026-04-20 | Agent:council/BackendArchitect +> 任务:调研「场馆删除后编辑商品出现规格重复错误」问题 --- ## 任务清单 -- [x] [Done: council/BackendArchitect] **Task 1**: 根因定位 — 逐行分析所有 "id" 访问位置 -- [x] [Done: council/BackendArchitect] **Task 2**: Db::name() 表前缀问题 — ShopXO 插件表前缀行为确认 -- [x] [Done: council/BackendArchitect] **Task 3**: 根因 1 — `$r['id']` 空安全(AdminGoodsSaveHandle 第 77 行) -- [x] [Done: council/BackendArchitect] **Task 4**: 根因 2 — `find()` 返回 null 的空安全(AdminGoodsSaveHandle 第 71 行) -- [x] [Done: council/BackendArchitect] **Task 5**: 根因 3 — `$config['template_id']` / `selected_rooms` 数据类型问题 -- [x] [Done: council/BackendArchitect] **Task 6**: SeatSkuService::BatchGenerate 类似问题审计 -- [x] [Done: council/BackendArchitect] **Task 7**: 修复方案汇总 + 建议修复优先级 -- [x] [Done: council/BackendArchitect] **Task 8**: 将修复方案写入 `reviews/BackendArchitect-on-Issue-13-debug.md` +### BackendArchitect(Task B1-B6) -- [x] [Done: council/DebugAgent] **Task 9**: Round 1 静态分析 → `reviews/DebugAgent-PRELIMINARY.md` -- [x] [Done: council/DebugAgent] **Task 10**: Round 2 — 验证 database.php 前缀配置 + 读取 Admin.php 第 66 行 -- [x] [Done: council/DebugAgent] **Task 11**: Round 2 — 编写 DebugAgent 最终根因报告 → `reviews/DebugAgent-ROOT_CAUSE.md` -- [x] [Done: council/BackendArchitect] **Task 12**: Round 2 — 评审 DebugAgent ROOT_CAUSE 报告 → `reviews/BackendArchitect-on-DebugAgent-ROOT_CAUSE.md` - -- [x] [Done: council/SecurityEngineer] **Task 13**: Round 2 — 独立安全审计(6项子任务)→ `reviews/SecurityEngineer-AUDIT.md` - - Q1: "Undefined array key 'id'" 最可能出现的行 → Primary: Line 77 - - Q2: Db::name() 表前缀行为 → 等价,排除 - - Q3: find() 返回 null 处理 → Secondary: Line 71 - - Q4: $configs JSON 解码类型安全 → 部分安全 - - Q5: selected_rooms 数据结构 → 类型正确但无空安全 - - Q6: BatchGenerate + item_type → 安全 +- [x] [Done: council/BackendArchitect] **Task B1**: AdminGoodsSaveHandle.php 全链路追踪 — vr_goods_config 读取/解析/snapshot 重建 +- [x] [Done: council/BackendArchitect] **Task B2**: spec_base_id_map 如何被转换成规格项(已验证:存储在模板表,与幽灵 spec 无关) +- [x] [Done: council/BackendArchitect] **Task B3**: SeatSkuService GetGoodsViewData 模板不存在时的 fallback(单模板处理,多模板有缺陷) +- [x] [Done: council/BackendArchitect] **Task B4**: 幽灵 spec 产生环节 + 清理时机(保存时未清理,写回 DB) +- [x] [Done: council/BackendArchitect] **Task B5**: 商品保存规格去重逻辑(GoodsService.php:1859) +- [x] [Done: council/BackendArchitect] **Task B6**: 根因分析报告(含行号)→ `reviews/council-ghost-spec-BackendArchitect.md` --- -## 阶段划分 +## 根因结论 -| 阶段 | 内容 | -|------|------| -| **Draft** | ✅ Task 1-6(BackendArchitect)+ Task 9(DebugAgent)+ Task 13(SecurityEngineer)| -| **Review** | ✅ Task 7(BackendArchitect)+ Task 11(DebugAgent)+ Task 12(BackendArchitect)| -| **Finalize** | ✅ Task 8 + Task 12 + Task 13:所有评审报告输出完毕 | +| 优先级 | 根因 | 文件:行号 | +|--------|------|-----------| +| **P1** | 无效 config 块未从数组移除,`continue` 后脏数据写回 DB | AdminGoodsSaveHandle.php:88-89 + 148-150 | +| **P2** | GetGoodsViewData 单模板模式,多模板时覆盖有效块 | SeatSkuService.php:368 + 386-388 | +| **P3** | BatchGenerate 对无效 template_id 返回 code=-2,阻断保存 | AdminGoodsSaveHandle.php:164-170 | +| **P4** | 前端过滤后 configs 为空时用户无声失去配置 | AdminGoodsSave.php:196-229 | +| **P5** | loadSoldSeats 未实现(TODO 注释) | ticket_detail.html:375-383 | --- -## 根因结论(已验证) - -1. **Primary(99%)**: `AdminGoodsSaveHandle.php:77` — `$r['id']` 无空安全,rooms 中缺少 id key 时崩溃 -2. **Secondary(5%)**: `AdminGoodsSaveHandle.php:71` — `find()` 返回 null 后直接访问 `$template['seat_map']` -3. **Tertiary(静默)**: `AdminGoodsSaveHandle.php:77` — `selected_rooms` 类型不匹配,`in_array` 永远 false -4. **已排除**: 表前缀问题 — `Db::name()` 和 `BaseService::table()` 均查询 `vrt_vr_seat_templates`,等价 -5. **已排除**: SeatSkuService::BatchGenerate — 第 100 行已有 `!empty()` 空安全 fallback -6. **SecurityEngineer 补充**: PHP 8+ 中 `null['key']` 抛出 `TypeError`(非 Warning);`$configs` JSON 解码有 `is_array` 防御;`item_type` 有 `?? ''` 兜底;修复建议已在 `reviews/SecurityEngineer-AUDIT.md` - -## DebugAgent 补充结论(Round 1) - -6. **PHP 8+ `??` 行为**:`$template['seat_map'] ?? '{}'` 对空数组 `[]` 的键访问**无效**,需用 `isset()` -7. **vr_goods_config JSON 解码**:有 `is_array()` 防御,访问 `$config['template_id']` 安全 - ---- - -## 执行顺序(DebugAgent Round 2) - -``` -Task 10: 读 shopxo/config/database.php → 确认 prefix 值;读 Admin.php 第 66 行 -Task 11: 综合输出 reports/DebugAgent-ROOT_CAUSE.md -``` - ---- - -## 关键文件(只读) +## 关键文件 | 文件 | 关注点 | |------|--------| -| `shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php` | save_thing_end 逻辑,template_snapshot 填充代码 | -| `shopxo/app/plugins/vr_ticket/service/SeatSkuService.php` | BatchGenerate、ensureAndFillVrSpecTypes | -| `shopxo/app/plugins/vr_ticket/service/BaseService.php` | table() 前缀方法 | -| `shopxo/config/database.php` | ShopXO 数据库表前缀配置(Task 10 需读) | -| `docs/VR_GOODS_CONFIG_SPEC.md` | vr_goods_config v3.0 JSON 格式 | -| `docs/PHASE2_PLAN.md` | 项目背景 | +| `shopxo/app/plugins/vr_ticket/hook/AdminGoodsSaveHandle.php` | P1 根因:continue 不删除脏 config | +| `shopxo/app/plugins/vr_ticket/service/SeatSkuService.php` | GetGoodsViewData:P2 根因,多模板处理缺陷 | +| `shopxo/app/plugins/vr_ticket/hook/AdminGoodsSave.php` | 前端过滤逻辑:P4 体验问题 | +| `shopxo/app/plugins/vr_ticket/admin/Admin.php` | VenueDelete:硬删除逻辑(第 888 行) | +| `shopxo/app/plugins/vr_ticket/view/goods/ticket_detail.html` | loadSoldSeats 未实现(P5) | +| `shopxo/app/service/GoodsService.php` | 规格列值去重检测(第 1859 行) | --- -## 修复记录 +## 修复方案 -- [x] **Fix Commit**: `804d465d0` — P1+P2 空安全修复已合并到 main - - `AdminGoodsSaveHandle.php:71-73`:新增 `if (empty($template)) { continue; }` - - `AdminGoodsSaveHandle.php:80`:`$r['id']` 前加 `isset()` 空安全 - - 合并到 main:`49930844f` +### P1 Fix(立即实施) +1. AdminGoodsSaveHandle.php:88 — `continue` 改为 `unset($configs[$i])` +2. AdminGoodsSaveHandle.php:145 后 — 添加 `$configs = array_values($configs);` +3. AdminGoodsSaveHandle.php:148 — 写回前加 `if (!empty($configs))` +4. AdminGoodsSaveHandle.php:158-173 — BatchGenerate 前增加模板存在性显式校验 + +### P2 Fix(高优先级) +1. SeatSkuService.php GetGoodsViewData — 遍历所有有效配置块,不只处理 `$vrGoodsConfig[0]` +2. 修改 DB 写回逻辑为写回 `validConfigs` 而非 `[$config]` + +### P3 Fix(中优先级) +1. AdminGoodsSave.php — configs 为空时提示用户重新选择场馆