# SEO & Sitemap 诊断报告

日期：2026-05-09
项目路径：/data/sme-omnistore-p0-remediated-20260509

---

## 1. sitemap.xml 现状

### 问题：参数名不匹配 + 默认租户隔离

| 现象 | 说明 |
|------|------|
| curl /api/sitemap.xml -> 只有根路径 | 默认解析到 tenant_id=1，但数据库 tenant_id=1 无数据 |
| curl /api/sitemap.xml?tid=2 -> 284 条 URL | 正确（1主页+240商品+37分类+6品牌）|

**根本原因：**

sitemap 端点参数名为 tid，但 robots.txt 中 Sitemap 行原用 tenant_id：
  原：Sitemap: ...?tenant_id={tenant_id}
  修复后：Sitemap: ...?tid={tenant_id}

?tenant_id=2 不被 tid 参数接收，导致回退到 tenant_id=1（空数据）。

### 验证结果（tid=2）✅ 已修复

- 首页: http://localhost:8000/tenant-2/
- 商品: /tenant-2/products/{slug} (240条)
- 分类: /tenant-2/category/{slug} (37条)
- 品牌: /tenant-2/brands/{slug} (6条)

商品 slug 格式正确，前台路由 pages/[slug].vue 可正确解析。

---

## 2. robots.txt 现状 ✅ 已修复

Disallow 配置正确，覆盖所有敏感路径：
- /account/* ✅
- /cart/* ✅
- /checkout/* ✅
- /auth/* ✅
- /api/account/* ✅
- /api/cart/* ✅
- /api/checkout/* ✅
- /api/auth/* ✅

Sitemap URL 参数名已修复为 tid，与 sitemap 端点参数一致：
  Sitemap: http://localhost:8000/api/sitemap.xml?tid={tenant_id}

---

## 3. 评价管理现状

### reviews_admin.py（74行）-> 真实实现 ✅
- GET /reviews -> 按状态过滤列表
- PUT /reviews/{id}/status -> approved/hidden 审核
- PUT /reviews/{id}/reply -> 回复
- 租户隔离：admin.tenant_id

### store/reviews.py（144行）-> 真实实现 ✅
- GET /store/reviews/product/{product_id} -> 只返回 status==approved
- 支持分页、评分筛选、平均分、评分分布
- 访客可提交（待审核状态 pending）

---

## 4. JSON-LD 商品数据 ✅

/api/store/seo/product/{slug}?tid=2 返回完整数据：
- slug, name, meta_title, meta_description, og_image
- json_ld: 完整 JSON-LD 结构

---

## 5. 已修复的问题

### 修复：robots.txt Sitemap 参数名

文件：backend/app/api/routers/seo.py 第163行

修复前：
  Sitemap: {base_url}/api/sitemap.xml?tenant_id={tenant_id}

修复后：
  Sitemap: {base_url}/api/sitemap.xml?tid={tenant_id}

验证（2026-05-09）：
  curl -s http://localhost:8000/api/robots.txt?tid=2 | grep Sitemap
  -> Sitemap: http://localhost:8000/api/sitemap.xml?tid=2 ✅

---

## 6. 验证命令

curl -s http://localhost:8000/api/sitemap.xml?tid=2 | grep -c loc   # 期望: 284
curl -s http://localhost:8000/api/sitemap.xml?tid=2 | grep products | wc -l   # 240
curl -s http://localhost:8000/api/sitemap.xml?tid=2 | grep category | wc -l   # 37
curl -s http://localhost:8000/api/sitemap.xml?tid=2 | grep brands | wc -l    # 6
curl -s http://localhost:8000/api/robots.txt?tid=2 | grep Sitemap
curl -s http://localhost:8000/api/store/seo/product/手机配件-110?tid=2

---

## 结论

| 项目 | 状态 |
|------|------|
| sitemap.xml 含商品/分类/品牌（参数正确时）| OK |
| robots.txt 覆盖敏感路径 | OK |
| sitemap 参数名匹配 robots.txt | ✅ 已修复 |
| 评价管理（后台审核）| 真实实现 |
| 前台只展示 approved 评价 | OK |
| JSON-LD 商品数据 | OK |
