|
|
@@ -0,0 +1,809 @@
|
|
|
+# PC 后端接口文档
|
|
|
+
|
|
|
+> **Base URL:** `http://localhost:3101/api`
|
|
|
+>
|
|
|
+> **响应格式:** 所有接口统一返回 JSON:
|
|
|
+> ```json
|
|
|
+> { "success": true, "data": { ... }, "error": null } // 成功
|
|
|
+> { "success": false, "data": null, "error": { "message": "...", "code": "ERROR_CODE" } } // 失败
|
|
|
+> ```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 目录
|
|
|
+
|
|
|
+- [快速开始](#快速开始)
|
|
|
+- [项目架构](#项目架构)
|
|
|
+- [通用约定](#通用约定)
|
|
|
+- [1. 健康检查](#1-健康检查)
|
|
|
+- [2. 企微 API 代理](#2-企微-api-代理)
|
|
|
+- [3. 人员管理](#3-人员管理)
|
|
|
+- [4. 小区管理](#4-小区管理)
|
|
|
+- [5. 群管理](#5-群管理)
|
|
|
+- [6. 合规检查](#6-合规检查)
|
|
|
+- [7. 群风控](#7-群风控)
|
|
|
+- [8. 内容运营](#8-内容运营)
|
|
|
+- [9. KOC 与意向客户](#9-koc-与意向客户)
|
|
|
+- [10. 数据看板](#10-数据看板)
|
|
|
+- [11. 经营数据补录](#11-经营数据补录)
|
|
|
+- [12. 统一工作台](#12-统一工作台)
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 快速开始
|
|
|
+
|
|
|
+### 启动服务
|
|
|
+
|
|
|
+```bash
|
|
|
+cd backend
|
|
|
+pnpm install
|
|
|
+pnpm dev
|
|
|
+```
|
|
|
+
|
|
|
+服务启动后访问:
|
|
|
+- PC 端:`http://localhost:3101/api/health`
|
|
|
+- Mobile 端:`http://localhost:3201/api/health`
|
|
|
+
|
|
|
+### 环境变量
|
|
|
+
|
|
|
+复制 `.env.example` 为 `.env`,关键变量:
|
|
|
+
|
|
|
+| 变量 | 说明 | 默认值 |
|
|
|
+|------|------|--------|
|
|
|
+| `PC_PORT` | PC 端端口 | `3101` |
|
|
|
+| `MOBILE_CHAT_PORT` | Mobile 端端口 | `3201` |
|
|
|
+| `QIWEI_BASE_URL` | QiWe 开放平台地址 | `http://manager.qiweapi.com/qiwe` |
|
|
|
+| `QIWEI_TOKEN` | QiWe 租户 Token | 在控制台申请 |
|
|
|
+| `DASHSCOPE_API_KEY` | 阿里云百炼 API Key | — |
|
|
|
+| `DASHSCOPE_APP_ID` | 阿里云百炼 App ID | — |
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 项目架构
|
|
|
+
|
|
|
+```
|
|
|
+backend/src/
|
|
|
+├── index.ts # 总启动器(启动 PC + Mobile)
|
|
|
+├── apps/
|
|
|
+│ ├── pc/ # PC 端(端口 3101,所有模块共享)
|
|
|
+│ │ ├── app.ts # 统一 Express 应用(注册所有路由)
|
|
|
+│ │ ├── health/ # 健康检查
|
|
|
+│ │ ├── qiwei/ # 企微 API 代理 [模块1]
|
|
|
+│ │ ├── staff/ # 人员管理 [模块1]
|
|
|
+│ │ ├── community/ # 小区管理 [模块2]
|
|
|
+│ │ ├── room/ # 群管理 [模块2]
|
|
|
+│ │ ├── compliance/ # 合规检查 [模块4]
|
|
|
+│ │ ├── risk/ # 群风控 [模块5]
|
|
|
+│ │ ├── content/ # 内容运营 [模块6]
|
|
|
+│ │ ├── koc/ # KOC与意向 [模块7]
|
|
|
+│ │ ├── dashboard/ # 数据看板 [模块8]
|
|
|
+│ │ ├── sales/ # 经营数据 [模块9]
|
|
|
+│ │ └── workbench/ # 工作台 [模块10]
|
|
|
+│ └── mobile/
|
|
|
+│ └── chat/ # AI 聊天(端口 3201)
|
|
|
+└── shared/ # 共享层
|
|
|
+ ├── config/env.ts # 环境变量读取
|
|
|
+ ├── errors/app-error.ts # 统一错误类型
|
|
|
+ ├── http/response.ts # 统一响应格式
|
|
|
+ ├── http/error-handler.ts # 错误处理中间件
|
|
|
+ ├── qiwei/client.ts # QiWe API 客户端
|
|
|
+ ├── types/page.ts # 分页类型
|
|
|
+ └── utils/docid.ts # 文档 ID 解析工具
|
|
|
+```
|
|
|
+
|
|
|
+每个业务模块内部统一分为 4 层:
|
|
|
+- `models/` — 数据模型 / DTO 类型定义
|
|
|
+- `services/` — 业务逻辑层
|
|
|
+- `controllers/` — 请求解析 + 调用 service + 响应
|
|
|
+- `routes/` — URL → controller 映射
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 通用约定
|
|
|
+
|
|
|
+### HTTP 方法语义
|
|
|
+
|
|
|
+| 方法 | 语义 |
|
|
|
+|------|------|
|
|
|
+| `GET` | 查询(幂等) |
|
|
|
+| `POST` | 创建 / 触发动作 |
|
|
|
+| `PUT` | 更新整个资源或状态 |
|
|
|
+| `DELETE` | 删除 |
|
|
|
+
|
|
|
+### 分页
|
|
|
+
|
|
|
+分页接口使用 `page` / `pageSize` 查询参数(默认 `page=1, pageSize=20`,上限 100)。
|
|
|
+
|
|
|
+### 错误码
|
|
|
+
|
|
|
+| 错误码 | HTTP 状态 | 说明 |
|
|
|
+|--------|-----------|------|
|
|
|
+| `VALIDATION_ERROR` | 400 | 参数校验不通过 |
|
|
|
+| `NOT_FOUND` | 404 | 资源不存在 |
|
|
|
+| `DUPLICATE` | 409 | 重复数据 |
|
|
|
+| `QIWEI_TOKEN_MISSING` | 500 | 未配置企微 Token |
|
|
|
+| `QIWEI_API_ERROR` | 502 | 企微接口返回错误 |
|
|
|
+| `INTERNAL_ERROR` | 500 | 服务器内部错误 |
|
|
|
+
|
|
|
+### 响应示例
|
|
|
+
|
|
|
+```json
|
|
|
+// 成功
|
|
|
+POST /api/staff
|
|
|
+{
|
|
|
+ "success": true,
|
|
|
+ "data": { "id": 1, "name": "张三", "role": "manager", "storeId": 1, ... },
|
|
|
+ "error": null
|
|
|
+}
|
|
|
+
|
|
|
+// 失败
|
|
|
+POST /api/staff
|
|
|
+{
|
|
|
+ "success": false,
|
|
|
+ "data": null,
|
|
|
+ "error": { "message": "手机号 13800001111 已存在", "code": "STAFF_PHONE_DUPLICATE" }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 1. 健康检查
|
|
|
+
|
|
|
+### `GET /api/health`
|
|
|
+
|
|
|
+返回服务运行状态和已加载模块。
|
|
|
+
|
|
|
+**响应示例:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "status": "ok",
|
|
|
+ "platform": "pc",
|
|
|
+ "timestamp": "2026-05-21T10:30:00.000Z",
|
|
|
+ "modules": ["qiwei", "staff", "community", "room", "compliance", "risk", "content", "koc", "dashboard", "sales", "workbench"]
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 2. 企微 API 代理
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/qiwei/routes/qiwei.routes.ts`
|
|
|
+> **对应规范:** §4 模块1「企微接入与消息基础模块」
|
|
|
+
|
|
|
+### `POST /api/qiwei/proxy`
|
|
|
+
|
|
|
+通用 QiWe API 代理,前端传入 `method` + `params`,后端转发到 QiWe 开放平台。
|
|
|
+
|
|
|
+**Body:**
|
|
|
+```json
|
|
|
+{
|
|
|
+ "method": "/room/getRoomList",
|
|
|
+ "params": { "guid": "a3318ad6-xxxx", "nextStartIndex": 0 }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `GET /api/qiwei/staff/:guid/status`
|
|
|
+
|
|
|
+查询指定人员的企微在线状态。对应 API-05 `/login/checkLogin`。
|
|
|
+
|
|
|
+**Path:** `guid` — 人员设备 GUID
|
|
|
+
|
|
|
+**响应字段:** `userOnlineStatus`(1=在线, 2=离线)、`userId`、`nickname`、`corpName`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `POST /api/qiwei/staff/batch-status`
|
|
|
+
|
|
|
+批量查询人员在线状态。
|
|
|
+
|
|
|
+**Body:**
|
|
|
+```json
|
|
|
+{ "guids": ["guid1", "guid2", "guid3"] }
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `POST /api/qiwei/sync`
|
|
|
+
|
|
|
+触发历史消息同步。对应 API-06 `/msg/syncMsg`。
|
|
|
+
|
|
|
+**Body:**
|
|
|
+```json
|
|
|
+{ "guid": "a3318ad6-xxxx", "msgSeq": 0, "limit": 50 }
|
|
|
+```
|
|
|
+
|
|
|
+**响应:** `{ messages: [...], hasMore: 1, nextSeq: 12345 }`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `POST /api/qiwei/webhook`
|
|
|
+
|
|
|
+接收 QiWe Webhook 推送。对应 API-04 回调。
|
|
|
+**此接口需要公网可达**,通过 API-03 `/client/setCallback` 注册到 QiWe。
|
|
|
+
|
|
|
+处理逻辑:
|
|
|
+1. 解析 `data[]` 中的消息,过滤 `cmd=15000`(普通消息)
|
|
|
+2. 若 `msgType=13`(链接消息),自动解析文档链接 → 登记台账
|
|
|
+3. 同群发现不同 docid → 记录多表异常
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `GET /api/qiwei/messages`
|
|
|
+
|
|
|
+查询已存储的消息列表。
|
|
|
+
|
|
|
+**Query:** `roomId`(可选)、`guid`(可选)、`limit`(默认 50)
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### `GET /api/qiwei/room-docs`
|
|
|
+
|
|
|
+查询群-文档台账列表。**Query:** `roomId`(可选,不传返回全部)
|
|
|
+
|
|
|
+### `GET /api/qiwei/room-doc-anomalies`
|
|
|
+
|
|
|
+查询台账异常记录(多表异常等)。
|
|
|
+
|
|
|
+### `PUT /api/qiwei/room-doc-anomalies/:roomId/resolve`
|
|
|
+
|
|
|
+解决台账异常(人工确认后)。
|
|
|
+
|
|
|
+**Body:**
|
|
|
+```json
|
|
|
+{ "newDocId": "...", "resolution": "keep_new" }
|
|
|
+```
|
|
|
+`resolution`:`keep_new`(以新表为准)/ `keep_old`(保留旧表)
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 3. 人员管理
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/staff/routes/staff.routes.ts`
|
|
|
+> **对应规范:** §4.2「人员企微账号纳入管理」、§4.3「账号是否在线提醒」
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/staff` | 创建人员账号 |
|
|
|
+| `GET` | `/api/staff` | 查询人员列表 |
|
|
|
+| `GET` | `/api/staff/active-guids` | 获取所有启用的 guid |
|
|
|
+| `GET` | `/api/staff/:id` | 查询人员详情 |
|
|
|
+| `PUT` | `/api/staff/:id` | 更新人员信息 |
|
|
|
+| `DELETE` | `/api/staff/:id` | 删除人员 |
|
|
|
+
|
|
|
+### 创建人员
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/staff
|
|
|
+{
|
|
|
+ "name": "张三",
|
|
|
+ "role": "manager",
|
|
|
+ "storeId": 1,
|
|
|
+ "phone": "13800001111"
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+> `role` 可选值:`manager`(店长)、`designer`(设计师)、`operator`(运营)
|
|
|
+>
|
|
|
+> 创建时不绑 guid,人员扫码登录后通过 PUT 回填。
|
|
|
+
|
|
|
+### 查询人员
|
|
|
+
|
|
|
+`GET /api/staff?role=manager&storeId=1&status=1`
|
|
|
+
|
|
|
+### 更新人员(回填 guid、停用等)
|
|
|
+
|
|
|
+```json
|
|
|
+// PUT /api/staff/1
|
|
|
+{ "guid": "a3318ad6-xxxx", "status": 0 }
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 4. 小区管理
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/community/routes/community.routes.ts`
|
|
|
+> **对应规范:** §5.5「录入小区基础档案」、§5.6「维护小区—群—门店对应关系」
|
|
|
+
|
|
|
+### 小区档案
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/communities` | 录入小区 |
|
|
|
+| `GET` | `/api/communities` | 查询小区列表 |
|
|
|
+| `GET` | `/api/communities/:id` | 查询小区详情 |
|
|
|
+| `PUT` | `/api/communities/:id` | 更新小区 |
|
|
|
+| `DELETE` | `/api/communities/:id` | 删除小区 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/communities
|
|
|
+{
|
|
|
+ "name": "万科城市花园",
|
|
|
+ "totalHouseholds": 1200,
|
|
|
+ "avgPrice": 35000,
|
|
|
+ "deliveryYear": 2022,
|
|
|
+ "storeId": 1,
|
|
|
+ "address": "xx路xx号",
|
|
|
+ "remark": ""
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 群-小区绑定
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/community-room-bindings` | 绑定群到小区 |
|
|
|
+| `GET` | `/api/community-room-bindings` | 查询绑定列表 |
|
|
|
+| `GET` | `/api/community-room-bindings/by-room/:roomId` | 按群号查绑定 |
|
|
|
+| `DELETE` | `/api/community-room-bindings/:id` | 解绑 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/community-room-bindings
|
|
|
+{ "communityId": 1, "roomId": "10791082xxxx", "storeId": 1 }
|
|
|
+```
|
|
|
+
|
|
|
+> 一个群只能绑定一个小区,重复绑定返回 409 错误。
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 5. 群管理
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/room/routes/room.routes.ts`
|
|
|
+> **对应规范:** §5.1~§5.7
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/rooms` | 查询群列表 |
|
|
|
+| `POST` | `/api/rooms/sync` | 触发群同步(API-07+API-08) |
|
|
|
+| `GET` | `/api/rooms/:roomId` | 查询群详情 |
|
|
|
+| `POST` | `/api/rooms/member-events/sync` | 同步进退群事件(API-09) |
|
|
|
+| `GET` | `/api/rooms/member-events` | 查询进退群事件 |
|
|
|
+| `GET` | `/api/rooms/health` | 所有群健康度 |
|
|
|
+| `GET` | `/api/rooms/:roomId/health` | 单个群健康度 |
|
|
|
+
|
|
|
+### 触发群同步
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/rooms/sync
|
|
|
+{ "guid": "a3318ad6-xxxx", "nextStartIndex": 0 }
|
|
|
+```
|
|
|
+
|
|
|
+### 同步进退群事件
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/rooms/member-events/sync
|
|
|
+{
|
|
|
+ "guid": "a3318ad6-xxxx",
|
|
|
+ "roomId": "10791082xxxx",
|
|
|
+ "startTime": 1708300000,
|
|
|
+ "endTime": 1708400000
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 群健康度
|
|
|
+
|
|
|
+健康度评分(0-100),扣分/加分规则:
|
|
|
+- 7 日无消息:-30
|
|
|
+- 24h 退群 > 3 人:-20
|
|
|
+- 成员 < 5 人:-15
|
|
|
+- 成员增长趋势:+10
|
|
|
+
|
|
|
+响应:
|
|
|
+```json
|
|
|
+{
|
|
|
+ "roomId": "10791082xxxx",
|
|
|
+ "roomName": "万科业主群",
|
|
|
+ "healthScore": 85,
|
|
|
+ "messageCount7d": 120,
|
|
|
+ "leaveCount24h": 0,
|
|
|
+ "memberTrend": "growing",
|
|
|
+ "detail": "群状态正常"
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 6. 合规检查
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/compliance/routes/compliance.routes.ts`
|
|
|
+> **对应规范:** §7「模块 4:沟通记录合规检查模块」
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/compliance/scan` | 触发合规巡检 |
|
|
|
+| `GET` | `/api/compliance/issues` | 查询合规问题列表 |
|
|
|
+| `GET` | `/api/compliance/issues/:id` | 查询问题详情 |
|
|
|
+| `PUT` | `/api/compliance/issues/:id` | 更新问题状态 |
|
|
|
+| `GET` | `/api/compliance/reports` | 合规汇总报表 |
|
|
|
+
|
|
|
+### 问题类型(`type`)
|
|
|
+
|
|
|
+| type | 含义 | 严重程度 |
|
|
|
+|------|------|----------|
|
|
|
+| `missing_doc` | 缺少沟通记录表 | 高 |
|
|
|
+| `not_pinned` | 记录表未置顶 | 中 |
|
|
|
+| `no_doc_in_notice` | 群公告无文档链接 | 低 |
|
|
|
+| `multi_doc` | 群内存在多张表 | 高 |
|
|
|
+| `stale_doc` | 记录表长期未更新 | 中 |
|
|
|
+| `too_brief` | 内容过于简略 | 低 |
|
|
|
+| `format_error` | 格式不规范 | 中 |
|
|
|
+| `required_empty` | 必填项为空 | 高 |
|
|
|
+| `suspected_miss_log` | 疑似漏记 | 中 |
|
|
|
+
|
|
|
+### 触发巡检
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/compliance/scan
|
|
|
+{ "roomIds": ["10791082xxxx", "10791083xxxx"] }
|
|
|
+```
|
|
|
+
|
|
|
+### 更新问题状态
|
|
|
+
|
|
|
+```json
|
|
|
+// PUT /api/compliance/issues/1
|
|
|
+{ "status": "in_progress", "note": "已通知设计师整改" }
|
|
|
+```
|
|
|
+
|
|
|
+状态流转:`open` → `in_progress` → `resolved` → `closed`
|
|
|
+
|
|
|
+### 合规报表
|
|
|
+
|
|
|
+`GET /api/compliance/reports?totalRooms=156`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 7. 群风控
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/risk/routes/risk.routes.ts`
|
|
|
+> **对应规范:** §8「模块 5:群风控与异常干预模块」
|
|
|
+
|
|
|
+### 风险关键词
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/risk/keywords` | 创建关键词 |
|
|
|
+| `GET` | `/api/risk/keywords` | 查询关键词列表 |
|
|
|
+| `POST` | `/api/risk/keywords/scan` | 扫描消息内容 |
|
|
|
+| `PUT` | `/api/risk/keywords/:id` | 更新关键词 |
|
|
|
+| `DELETE` | `/api/risk/keywords/:id` | 删除关键词 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/risk/keywords
|
|
|
+{
|
|
|
+ "keyword": "退群",
|
|
|
+ "category": "complaint",
|
|
|
+ "severity": 3,
|
|
|
+ "enabled": 1,
|
|
|
+ "remark": "客户投诉敏感词"
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+`category`:`price`(价格敏感)、`competitor`(竞品)、`complaint`(投诉)、`custom`(自定义)
|
|
|
+
|
|
|
+### 消息扫描
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/risk/keywords/scan
|
|
|
+{ "content": "我想退群了", "roomId": "10791082xxxx", "messageId": 12345 }
|
|
|
+```
|
|
|
+
|
|
|
+响应:`{ alerts: [...], hitCount: 1 }`
|
|
|
+
|
|
|
+> 高危预警(severity=3)自动生成工单。
|
|
|
+
|
|
|
+### 预警管理
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/risk/alerts` | 查询预警列表 |
|
|
|
+| `PUT` | `/api/risk/alerts/:id` | 处理预警 |
|
|
|
+
|
|
|
+```json
|
|
|
+// PUT /api/risk/alerts/1
|
|
|
+{ "status": "handled", "handlerId": 1, "note": "已私聊安抚客户" }
|
|
|
+```
|
|
|
+
|
|
|
+### 工单管理
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/risk/work-orders` | 查询工单列表 |
|
|
|
+| `PUT` | `/api/risk/work-orders/:id` | 更新工单状态 |
|
|
|
+
|
|
|
+```json
|
|
|
+// PUT /api/risk/work-orders/1
|
|
|
+{ "status": "completed", "handleRecord": "已完成整改" }
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 8. 内容运营
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/content/routes/content.routes.ts`
|
|
|
+> **对应规范:** §9「模块 6:社群内容与运营执行模块」
|
|
|
+
|
|
|
+### 素材库
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/content/materials` | 创建素材 |
|
|
|
+| `GET` | `/api/content/materials` | 查询素材列表 |
|
|
|
+| `PUT` | `/api/content/materials/:id` | 更新素材 |
|
|
|
+| `DELETE` | `/api/content/materials/:id` | 删除素材 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/content/materials
|
|
|
+{
|
|
|
+ "title": "装修预算话术",
|
|
|
+ "type": "script",
|
|
|
+ "content": "您好,根据您的需求...",
|
|
|
+ "tags": ["预算", "话术"],
|
|
|
+ "creatorId": 1
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+`type`:`script`(话术)、`case`(案例)、`image`(图片)、`video`(视频)、`file`(文件)
|
|
|
+
|
|
|
+### 群发任务
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/content/broadcasts` | 创建群发 |
|
|
|
+| `GET` | `/api/content/broadcasts` | 查询群发列表 |
|
|
|
+| `GET` | `/api/content/broadcasts/:id` | 查群发状态 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/content/broadcasts
|
|
|
+{
|
|
|
+ "guid": "a3318ad6-xxxx",
|
|
|
+ "sendType": 1,
|
|
|
+ "toIdList": ["10791082xxxx"],
|
|
|
+ "msgList": [{ "type": 0, "msgData": { "content": "本周活动" } }]
|
|
|
+}
|
|
|
+```
|
|
|
+`sendType`:0=外部联系人, 1=外部群
|
|
|
+
|
|
|
+### 运营计划
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/content/plans` | 创建运营计划 |
|
|
|
+| `GET` | `/api/content/plans` | 查询计划列表 |
|
|
|
+| `POST` | `/api/content/plans/:planId/items` | 添加计划项 |
|
|
|
+| `GET` | `/api/content/plans/:planId/items` | 查询计划项 |
|
|
|
+| `GET` | `/api/content/plans/:planId/execution` | 检查执行情况 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/content/plans
|
|
|
+{
|
|
|
+ "name": "第22周运营计划",
|
|
|
+ "startDate": "2026-05-25",
|
|
|
+ "endDate": "2026-05-31",
|
|
|
+ "ownerId": 1
|
|
|
+}
|
|
|
+
|
|
|
+// POST /api/content/plans/1/items
|
|
|
+{
|
|
|
+ "content": "发送周末活动预告",
|
|
|
+ "scheduledDate": "2026-05-30",
|
|
|
+ "targetRoomIds": ["10791082xxxx"],
|
|
|
+ "materialId": 1
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 9. KOC 与意向客户
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/koc/routes/koc.routes.ts`
|
|
|
+> **对应规范:** §10「模块 7:拉群、KOC 与意向客户模块」
|
|
|
+
|
|
|
+### 渠道管理
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/channels` | 创建渠道 |
|
|
|
+| `GET` | `/api/channels` | 查询渠道列表 |
|
|
|
+| `PUT` | `/api/channels/:id` | 更新渠道 |
|
|
|
+| `DELETE` | `/api/channels/:id` | 删除渠道 |
|
|
|
+
|
|
|
+### 外部联系人
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/contacts/sync` | 同步联系人(API-17+18) |
|
|
|
+| `GET` | `/api/contacts` | 查询联系人列表 |
|
|
|
+| `GET` | `/api/contacts/:userId` | 查询联系人详情 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/contacts/sync
|
|
|
+{ "guid": "a3318ad6-xxxx", "currentSeq": 0, "limit": 50 }
|
|
|
+```
|
|
|
+
|
|
|
+### KOC 管理
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/koc/candidates` | KOC 候选人列表 |
|
|
|
+| `POST` | `/api/koc/label` | 打 KOC 标签(API-19) |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/koc/label
|
|
|
+{ "userId": "168885xxxx", "guid": "a3318ad6-xxxx", "labelId": "140737xxxx" }
|
|
|
+```
|
|
|
+
|
|
|
+### 意向客户
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/intent-leads/detect` | 识别意向话术 |
|
|
|
+| `GET` | `/api/intent-leads` | 查询意向客户列表 |
|
|
|
+| `PUT` | `/api/intent-leads/:id` | 更新意向客户 |
|
|
|
+| `GET` | `/api/intent-tasks` | 查询跟进待办 |
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/intent-leads/detect
|
|
|
+{ "userId": "168885xxxx", "roomId": "10791082xxxx", "content": "这个方案多少钱?能约看房吗?" }
|
|
|
+```
|
|
|
+
|
|
|
+> 匹配关键词:价格、多少钱、预算、报价、量房、尺寸、面积、方案、设计、风格……
|
|
|
+>
|
|
|
+> 高意向(匹配 ≥3 个词)自动生成跟进待办。
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 10. 数据看板
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/dashboard/routes/dashboard.routes.ts`
|
|
|
+> **对应规范:** §11「模块 8:数据看板与经营复盘模块」
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/dashboard/overview` | 总览看板 |
|
|
|
+| `GET` | `/api/dashboard/community/:communityId` | 小区看板 |
|
|
|
+| `GET` | `/api/dashboard/store/:storeId` | 门店看板 |
|
|
|
+| `GET` | `/api/dashboard/activity/:roomId` | 群活跃度 |
|
|
|
+| `GET` | `/api/dashboard/activity-ranking` | 活跃度排行 |
|
|
|
+| `GET` | `/api/dashboard/reports/weekly` | 周报 |
|
|
|
+| `GET` | `/api/dashboard/reports/monthly` | 月报 |
|
|
|
+
|
|
|
+### 总览看板响应
|
|
|
+
|
|
|
+```json
|
|
|
+{
|
|
|
+ "totalRooms": 156,
|
|
|
+ "totalMembers": 2340,
|
|
|
+ "messageCount7d": 8920,
|
|
|
+ "activeRooms": 142,
|
|
|
+ "complianceRate": 0.85,
|
|
|
+ "openAlerts": 3,
|
|
|
+ "openWorkOrders": 2
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 11. 经营数据补录
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/sales/routes/sales.routes.ts`
|
|
|
+> **对应规范:** §12「模块 9:经营数据手工补录模块」
|
|
|
+
|
|
|
+### 选客数
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/sales/leads` | 录入选客数 |
|
|
|
+| `GET` | `/api/sales/leads` | 查询选客数列表 |
|
|
|
+
|
|
|
+```json
|
|
|
+{ "salespersonId": 1, "recordDate": "2026-05-21", "addCount": 5, "channelId": 1, "remark": "" }
|
|
|
+```
|
|
|
+
|
|
|
+### 订单
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/sales/orders` | 录入订单 |
|
|
|
+| `GET` | `/api/sales/orders` | 查询订单列表 |
|
|
|
+
|
|
|
+```json
|
|
|
+{
|
|
|
+ "salespersonId": 1, "customerId": 1,
|
|
|
+ "amount": 150000, "orderDate": "2026-05-20",
|
|
|
+ "source": "group", "roomId": "10791082xxxx"
|
|
|
+}
|
|
|
+```
|
|
|
+`source`:`group`(群内转化)、`referral`(转介绍)、`walk_in`(自然到店)
|
|
|
+
|
|
|
+### 客户档案
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/sales/customers` | 创建客户档案 |
|
|
|
+| `GET` | `/api/sales/customers` | 查询客户列表 |
|
|
|
+| `GET` | `/api/sales/customers/:id` | 查询客户详情 |
|
|
|
+| `PUT` | `/api/sales/customers/:id` | 更新客户档案 |
|
|
|
+| `POST` | `/api/sales/customers/:customerId/follow-ups` | 添加跟进记录 |
|
|
|
+| `GET` | `/api/sales/customers/:customerId/follow-ups` | 查询跟进记录 |
|
|
|
+
|
|
|
+### 直播数据
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `POST` | `/api/sales/live-stats` | 录入直播数据 |
|
|
|
+| `GET` | `/api/sales/live-stats` | 查询直播数据列表 |
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 12. 统一工作台
|
|
|
+
|
|
|
+> **路由文件:** `apps/pc/workbench/routes/workbench.routes.ts`
|
|
|
+> **对应规范:** §13「模块 10:统一工作台与通知闭环模块」
|
|
|
+
|
|
|
+| 方法 | 路径 | 说明 |
|
|
|
+|------|------|------|
|
|
|
+| `GET` | `/api/workbench` | 工作台首页 |
|
|
|
+| `GET` | `/api/notifications` | 查询通知列表 |
|
|
|
+| `GET` | `/api/notifications/template` | 获取通知模板 |
|
|
|
+| `POST` | `/api/notifications/send` | 发送通知 |
|
|
|
+| `GET` | `/api/audit-logs` | 查询审计日志 |
|
|
|
+
|
|
|
+### 工作台首页
|
|
|
+
|
|
|
+`GET /api/workbench?role=manager`
|
|
|
+
|
|
|
+返回:
|
|
|
+```json
|
|
|
+{
|
|
|
+ "compliancePending": 2,
|
|
|
+ "openAlerts": 3,
|
|
|
+ "openWorkOrders": 2,
|
|
|
+ "opsPending": 1,
|
|
|
+ "intentPending": 4,
|
|
|
+ "newMessagesToday": 156
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+### 发送通知
|
|
|
+
|
|
|
+```json
|
|
|
+// POST /api/notifications/send
|
|
|
+{
|
|
|
+ "type": "compliance",
|
|
|
+ "receiverId": 1,
|
|
|
+ "title": "【整改通知】缺少沟通记录表",
|
|
|
+ "content": "群"万科业主群"尚未登记沟通记录在线文档,请在24小时内完成登记。",
|
|
|
+ "refId": 1
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+通知模板:`GET /api/notifications/template?issueType=missing_doc&roomName=万科业主群`
|
|
|
+
|
|
|
+### 审计日志
|
|
|
+
|
|
|
+`GET /api/audit-logs?action=notify&limit=50`
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## 扩展指南
|
|
|
+
|
|
|
+### 新增接口
|
|
|
+
|
|
|
+1. 确定接口属于哪个模块(如人员管理 → `staff/`)
|
|
|
+2. 在 `models/` 定义类型 → `services/` 写逻辑 → `controllers/` 写 handler → `routes/` 注册路由
|
|
|
+3. 在 `apps/pc/app.ts` 中导入新路由(如果是新模块)
|
|
|
+
|
|
|
+### 新增模块
|
|
|
+
|
|
|
+1. 在 `apps/pc/` 下建目录:`models/`、`services/`、`controllers/`、`routes/`
|
|
|
+2. 在 `apps/pc/app.ts` 中 `import` 并 `app.use('/api', router)`
|
|
|
+3. 完成。不需要新增端口、不需要新增 server.ts
|
|
|
+
|
|
|
+### 当前数据存储说明
|
|
|
+
|
|
|
+所有模块使用内存 `Map` 存储(搜索 `TODO: 替换为数据库`),生产环境需替换为 MySQL/PostgreSQL。
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+> **最后更新:** 2026-05-21
|