feat(inbox): v2 规则引擎完善(help 指令/建单开关/系统回复)并修复拦截日志误写仓库 ID
- functions.js: 拦截/取消拦截波次感知写订单日志 businessId 误用仓库 ID,改为订单 ID (生产订单 JY2026091813795 已发起拦截但订单详情查不到拦截日志的根因) - rules/v2/processor/config/functionSync: 新增 help 指令、create_work_order=0 时跳过 工单登记、系统级回复与无单号提示、白名单范围修正 - after_sale_reply 模型 + 6 个迁移: create_work_order 字段与相关配置种子 - return_unpack: 列表 count 统计修复、分页排序追加主键防重漏行、视频附加 camera_name - methods/system.json + changes + sync 脚本: 接口文档与权限同步
This commit is contained in:
parent
c2a761ca26
commit
806e739267
@ -1,6 +1,6 @@
|
||||
# 站内信 v2 可配置回信引擎 —— HTTP 覆盖测试报告
|
||||
|
||||
> 生成时间:2026-09-16T18:11:52.145Z | 执行方式:真实 HTTP 链路(POST /warehouse?method=inbox.push)
|
||||
> 生成时间:2026-09-17T14:44:55.082Z | 执行方式:真实 HTTP 链路(POST /warehouse?method=inbox.push)
|
||||
|
||||
## 1. 测试环境
|
||||
|
||||
@ -11,10 +11,9 @@
|
||||
| 数据库 | 127.0.0.1:3307/wms(本地库) |
|
||||
| API 应用 | wms_api_app id=3,app_key=APP2025011514315678,warehouse_id=100000 |
|
||||
| 原 callback_url | `http://localhost:6061/push` → 测试期间改为本地 ack 服务(**未自动恢复**) |
|
||||
| 新 v2 测试群 | `httpv2:1789582312145`(首推自动登记后开启 store/after_sales + ai_enabled=1 + template_reply_enabled=1) |
|
||||
| 新 express 测试群 | `httpv2expr:1789582312145`(express/after_sales,开启 v2) |
|
||||
| 存量 v1 对照群 | `test-enter-store-aftersales`(template_reply_enabled=0) |
|
||||
| 存量 ai_enabled=0 群 | `g_st_finance_debug` |
|
||||
| 新 v2 测试群 | `httpv2:1789656295082`(首推自动登记后开启 store/after_sales + ai_enabled=1 + template_reply_enabled=1) |
|
||||
| 新 express 测试群 | `httpv2expr:1789656295082`(express/after_sales,开启 v2) |
|
||||
| 模块优先测试群 | `httpv2aioff:1789656295082`(ai_enabled=0 + template_reply_enabled=1) |
|
||||
|
||||
## 2. 链路
|
||||
|
||||
@ -33,7 +32,7 @@ flowchart LR
|
||||
|
||||
## 3. 用例结果总览
|
||||
|
||||
- 总计:**12** 用例,通过:**12**,失败:**0**
|
||||
- 总计:**11** 用例,通过:**11**,失败:**0**
|
||||
|
||||
| # | 用例 | 内容 | 结果 |
|
||||
|---|---|---|---|
|
||||
@ -47,37 +46,51 @@ flowchart LR
|
||||
| TC08 | 历史消息静默跳过 | `破损 SF1234567890123` | ✅ PASS |
|
||||
| TC09 | 幂等(同 requestId 两次推送) | `破损 SF9999999999999` | ✅ PASS |
|
||||
| TC10 | express 群白名单放行但函数越权拦截(静默) | `破损 SF1234567890123` | ✅ PASS |
|
||||
| TC11 | v1 分叉确认(template_reply_enabled=0 群) | `破损 SF1234567890123` | ✅ PASS |
|
||||
| TC12 | ai_enabled=0 群跳过 | `破损 SF1234567890123` | ✅ PASS |
|
||||
| TC11 | 模块优先(ai_enabled=0 但 template_reply_enabled=1) | `破损 SF1234567890123` | ✅ PASS |
|
||||
|
||||
## 4. 用例明细
|
||||
|
||||
### TC01 破损建单(新 v2 群) ✅ PASS
|
||||
|
||||
- 消息:`破损 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-01-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-01-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 入站消息入库 | ✅ | id=2016 |
|
||||
| v2 命中轨迹写入 ai_thoughts(function=handleStoreFeedback) | ✅ | [object Object] |
|
||||
| 出站回执存在(sys:ack) | ✅ | sys:ack:api:APP2025011514315678:httpv2-01-1789582314626 |
|
||||
| 入站消息入库 | ✅ | id=2118 |
|
||||
| v2 命中轨迹写入 ai_thoughts(function=handleStoreFeedback) | ✅ | [{"round":0,"action":"rule","params":{"keyword":"SF1234567890123","issue_type":"damaged"},"reason":"v2 关键词命中: 破损","function":"handleStoreFeedback","functionResult":{"error":"未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试","success":false}}] |
|
||||
| 出站回执存在(sys:ack) | ✅ | sys:ack:api:APP2025011514315678:httpv2-01-1789656298793 |
|
||||
| 出站 push_status=2(回调 200) | ✅ | push_status=2 |
|
||||
| 本地 ack 服务收到 notify.reply(type=ai) | ✅ | type=ai |
|
||||
| 出站日志 wms_warehouse_log 记录 notify.reply | ✅ | http_status=200 |
|
||||
| 无工单时函数返回可见(出站文案非空) | ✅ | 本地无该运单,函数返回文案: 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 |
|
||||
|
||||
- 入站消息 id=2016,ai_thoughts:
|
||||
- 入站消息 id=2118,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {
|
||||
"keyword": "SF1234567890123",
|
||||
"issue_type": "damaged"
|
||||
},
|
||||
"reason": "v2 关键词命中: 破损",
|
||||
"function": "handleStoreFeedback",
|
||||
"functionResult": {
|
||||
"error": "未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-01-1789582314626` | 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-01-1789656298793` | 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -86,7 +99,7 @@ flowchart LR
|
||||
### TC02 改地址 ✅ PASS
|
||||
|
||||
- 消息:`改地址 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-02-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-02-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
@ -94,17 +107,32 @@ flowchart LR
|
||||
| 出站回执存在 | ✅ | push_status=2 |
|
||||
| 函数已执行(工单或错误文案) | ✅ | \| 未找到当前货主在仓库中的运单「SF1234567890123,1234567890123」,请核实单号后重试 |
|
||||
|
||||
- 入站消息 id=2018,ai_thoughts:
|
||||
- 入站消息 id=2120,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {
|
||||
"keyword": "SF1234567890123,1234567890123",
|
||||
"issue_type": "addr"
|
||||
},
|
||||
"reason": "v2 关键词命中: 改地址",
|
||||
"function": "changeAddr",
|
||||
"functionResult": {
|
||||
"error": "未找到当前货主在仓库中的运单「SF1234567890123,1234567890123」,请核实单号后重试",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-02-1789582314626` | 未找到当前货主在仓库中的运单「SF1234567890123,1234567890123」,请核实单号后重试 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-02-1789656298793` | 未找到当前货主在仓库中的运单「SF1234567890123,1234567890123」,请核实单号后重试 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -113,7 +141,7 @@ flowchart LR
|
||||
### TC03 换快递(express 取号) ✅ PASS
|
||||
|
||||
- 消息:`改快递 SF1234567890123 圆通`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-03-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-03-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
@ -121,17 +149,40 @@ flowchart LR
|
||||
| 取号含 express=圆通 | ✅ | thoughts 含 express 字段 |
|
||||
| 出站回执存在 | ✅ | 未找到订单:SF1234567890123、1234567890123 |
|
||||
|
||||
- 入站消息 id=2020,ai_thoughts:
|
||||
- 入站消息 id=2122,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {
|
||||
"express": "圆通",
|
||||
"keyword": "SF1234567890123,1234567890123"
|
||||
},
|
||||
"reason": "v2 关键词命中: 改快递",
|
||||
"function": "changeExpress",
|
||||
"functionResult": {
|
||||
"data": {
|
||||
"changed": 0,
|
||||
"express": "圆通快递",
|
||||
"message": "未找到订单:SF1234567890123、1234567890123",
|
||||
"allocated": 0,
|
||||
"not_found": 2,
|
||||
"direct_reply": true,
|
||||
"not_in_pending": 0
|
||||
},
|
||||
"success": true
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-03-1789582314626` | 未找到订单:SF1234567890123、1234567890123 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-03-1789656298793` | 未找到订单:SF1234567890123、1234567890123 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -140,24 +191,36 @@ flowchart LR
|
||||
### TC04 拦截 ✅ PASS
|
||||
|
||||
- 消息:`拦截 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-04-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-04-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| v2 命中 interceptWaybill | ✅ | |
|
||||
| 出站回执存在 | ✅ | 请提供运单号 |
|
||||
|
||||
- 入站消息 id=2022,ai_thoughts:
|
||||
- 入站消息 id=2124,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {},
|
||||
"reason": "v2 关键词命中: 拦截",
|
||||
"function": "interceptWaybill",
|
||||
"functionResult": {
|
||||
"error": "请提供运单号",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-04-1789582314626` | 请提供运单号 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-04-1789656298793` | 请提供运单号 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -166,24 +229,36 @@ flowchart LR
|
||||
### TC05 揽收(上门取件) ✅ PASS
|
||||
|
||||
- 消息:`上门取件 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-05-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-05-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| v2 命中 requestPickup | ✅ | |
|
||||
| 出站回执存在 | ✅ | 请提供运单号 |
|
||||
|
||||
- 入站消息 id=2024,ai_thoughts:
|
||||
- 入站消息 id=2126,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {},
|
||||
"reason": "v2 关键词命中: 上门取件",
|
||||
"function": "requestPickup",
|
||||
"functionResult": {
|
||||
"error": "请提供运单号",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-05-1789582314626` | 请提供运单号 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-05-1789656298793` | 请提供运单号 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -192,24 +267,33 @@ flowchart LR
|
||||
### TC06 取号失败引导语 ✅ PASS
|
||||
|
||||
- 消息:`破损`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-06-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-06-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 出站回执为取号引导语 | ✅ | 请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔) |
|
||||
| 未建工单(取号失败不调用函数) | ✅ | |
|
||||
|
||||
- 入站消息 id=2026,ai_thoughts:
|
||||
- 入站消息 id=2128,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {},
|
||||
"reason": "v2 关键词命中: 破损,取号失败-引导提示",
|
||||
"function": "handleStoreFeedback",
|
||||
"functionResult": null
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-06-1789582314626` | 请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔) | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-06-1789656298793` | 请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔) | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -218,7 +302,7 @@ flowchart LR
|
||||
### TC07 v2 未命中静默(模块接管) ✅ PASS
|
||||
|
||||
- 消息:`今天天气怎么样`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-07-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-07-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
@ -226,7 +310,7 @@ flowchart LR
|
||||
| 无 ai_thoughts 轨迹 | ✅ | 空 |
|
||||
| 无新工单 | ✅ | 0 条 |
|
||||
|
||||
- 入站消息 id=2028,ai_thoughts:
|
||||
- 入站消息 id=2130,ai_thoughts:
|
||||
|
||||
```json
|
||||
null
|
||||
@ -235,15 +319,15 @@ null
|
||||
### TC08 历史消息静默跳过 ✅ PASS
|
||||
|
||||
- 消息:`破损 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-08-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-08-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 入站仍入库 | ✅ | id=2029 |
|
||||
| 入站仍入库 | ✅ | id=2131 |
|
||||
| 无出站回执(静默跳过) | ✅ | |
|
||||
| 无新工单 | ✅ | 0 条 |
|
||||
|
||||
- 入站消息 id=2029,ai_thoughts:
|
||||
- 入站消息 id=2131,ai_thoughts:
|
||||
|
||||
```json
|
||||
null
|
||||
@ -252,7 +336,7 @@ null
|
||||
### TC09 幂等(同 requestId 两次推送) ✅ PASS
|
||||
|
||||
- 消息:`破损 SF9999999999999`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-09-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-09-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
@ -260,17 +344,32 @@ null
|
||||
| 入站仅 1 条 | ✅ | 1 -> 1 |
|
||||
| 出站仅 1 条(不重复处理) | ✅ | 出站条数 1 -> 1 |
|
||||
|
||||
- 入站消息 id=2030,ai_thoughts:
|
||||
- 入站消息 id=2132,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {
|
||||
"keyword": "SF9999999999999",
|
||||
"issue_type": "damaged"
|
||||
},
|
||||
"reason": "v2 关键词命中: 破损",
|
||||
"function": "handleStoreFeedback",
|
||||
"functionResult": {
|
||||
"error": "未找到当前货主在仓库中的运单「SF9999999999999」,请核实单号后重试",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-09-1789582314626` | 未找到当前货主在仓库中的运单「SF9999999999999」,请核实单号后重试 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-09-1789656298793` | 未找到当前货主在仓库中的运单「SF9999999999999」,请核实单号后重试 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
@ -279,63 +378,62 @@ null
|
||||
### TC10 express 群白名单放行但函数越权拦截(静默) ✅ PASS
|
||||
|
||||
- 消息:`破损 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-10-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-10-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 入站消息入库 | ✅ | id=2032 |
|
||||
| 入站消息入库 | ✅ | id=2134 |
|
||||
| 无出站回执(静默) | ✅ | |
|
||||
| 白名单行存在(express/after_sales 允许 damage 子类型) | ✅ | 行数=1 |
|
||||
| 函数越权拦截(handleStoreFeedback 仅 store 群可用 → 无轨迹) | ✅ | 无轨迹 |
|
||||
|
||||
- 入站消息 id=2032,ai_thoughts:
|
||||
- 入站消息 id=2134,ai_thoughts:
|
||||
|
||||
```json
|
||||
null
|
||||
```
|
||||
|
||||
### TC11 v1 分叉确认(template_reply_enabled=0 群) ✅ PASS
|
||||
### TC11 模块优先(ai_enabled=0 但 template_reply_enabled=1) ✅ PASS
|
||||
|
||||
- 消息:`破损 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-11-1789582314626`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-11-1789656298793`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 未走 v2 引擎(thoughts 无 v2 轨迹特征) | ✅ | [{"round":0,"action":"rule","params":{"keyword":"SF1234567890123","issue_type":"damaged"},"reason":"关键词规则命中: 破损","function":"handleStoreFeedback","functionResult":{"error":"未找到当前货主在仓库中的运单「SF1234567890 |
|
||||
| 群配置 template_reply_enabled=0 已确认 | ✅ | |
|
||||
| 不依赖 ai_enabled,仍走 v2(轨迹含 v2 关键词命中) | ✅ | [{"round":0,"action":"rule","params":{"keyword":"SF1234567890123","issue_type":"damaged"},"reason":"v2 关键词命中: 破损","function":"handleStoreFeedback","functionResult":{"error":"未找到当前货主在仓库中的运单「SF123456789 |
|
||||
| 出站回执存在 | ✅ | 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 |
|
||||
|
||||
- 入站消息 id=2033,ai_thoughts:
|
||||
- 入站消息 id=2135,ai_thoughts:
|
||||
|
||||
```json
|
||||
[object Object]
|
||||
[
|
||||
{
|
||||
"round": 0,
|
||||
"action": "rule",
|
||||
"params": {
|
||||
"keyword": "SF1234567890123",
|
||||
"issue_type": "damaged"
|
||||
},
|
||||
"reason": "v2 关键词命中: 破损",
|
||||
"function": "handleStoreFeedback",
|
||||
"functionResult": {
|
||||
"error": "未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试",
|
||||
"success": false
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
- 出站回执:
|
||||
|
||||
| ext_id | content | push_status |
|
||||
|---|---|---|
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-11-1789582314626` | 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 | 2 |
|
||||
| `sys:ack:api:APP2025011514315678:httpv2-11-1789656298793` | 未找到当前货主在仓库中的运单「SF1234567890123」,请核实单号后重试 | 2 |
|
||||
|
||||
- 本地 ack 服务收到 notify.reply:type=ai
|
||||
|
||||
- wms_warehouse_log notify.reply 日志:http_status=200
|
||||
|
||||
### TC12 ai_enabled=0 群跳过 ✅ PASS
|
||||
|
||||
- 消息:`破损 SF1234567890123`
|
||||
- ext_id:`api:APP2025011514315678:httpv2-12-1789582314626`
|
||||
|
||||
| 校验项 | 结果 | 详情 |
|
||||
|---|---|---|
|
||||
| 无出站回执 | ✅ | |
|
||||
| 无新工单 | ✅ | 0 条 |
|
||||
|
||||
- 入站消息 id=2035,ai_thoughts:
|
||||
|
||||
```json
|
||||
null
|
||||
```
|
||||
|
||||
## 5. 说明与后续
|
||||
|
||||
1. 测试产生的入站/出站消息、工单等数据**已保留**(未自动清理),可直接在库中核对。
|
||||
|
||||
@ -120,6 +120,8 @@ WHERE group_id = '{测试群ID}' AND warehouse_id = {仓库ID};
|
||||
```
|
||||
|
||||
- `template_reply_enabled=1` 的群在第 6 步自动走 `inbox.v2.rules.handle`(已接入);
|
||||
- **模块优先语义**:`template_reply_enabled=1` 即为模块总开关,开启时不依赖 `ai_enabled`
|
||||
(两个开关同开时也走 v2 不走 v1/AI;`ai_enabled` 只约束未开启模板开关的群);
|
||||
- **模块接管模式**:v2 开启群的未命中消息直接静默,不走 v1 规则、不走 AI 兜底;
|
||||
- 群信息每条消息实时查库(`_loadGroupInfo` 不缓存),SQL 改动对下一条消息立即生效;
|
||||
- v2 配置数据(关键词/白名单/函数/取号/回复)有 300s 缓存,改动后需
|
||||
@ -179,7 +181,7 @@ WHERE app_key = '{测试app_key}';
|
||||
| 6 | 关键词命中 | 长词优先;命中后先过防误判守卫(如"拦截" vs "查物流") |
|
||||
| 7 | 函数越权 | `callFunction` 按群活跃分组校验,越权返回错误(DB 配置只做可见性,代码是最终权威) |
|
||||
| 8 | 取号失败 | 子类型关联了取号规则但未提取到值 → 回复引导语(`no_number_hint` → target 专属 → 默认),**不调用函数** |
|
||||
| 9 | 回复决策 | 回复表 `is_reply=1` → 自定义文案;`is_reply=0` → 静默(函数仍执行);无配置 → 函数返回值兜底 |
|
||||
| 9 | 回复决策 | 回复完全由回复配置控制:`is_reply=1` 且模板渲染非空 → 回复;`is_reply=0` → 静默(函数仍执行);无配置/模板渲染为空 → **默认不回复**(函数已执行,仅不出回执) |
|
||||
| 10 | 快递群 | express 群仅执行函数,**不回信** |
|
||||
| 11 | 出站回执 | 回执 `ext_id='sys:ack:{入站ext_id}'` 唯一,重复处理不重复出站 |
|
||||
| 12 | 缓存 | v2 配置缓存 `inbox:v2:cfg:{warehouseId}` TTL 300s;配置变更后必须 `invalidate`,否则 5 分钟内不生效 |
|
||||
@ -214,7 +216,7 @@ WHERE app_key = '{测试app_key}';
|
||||
| `wms_after_sale_sub_type_group` | 子类型 × 群类型 × 群子类型白名单(`uk(sub_type_id, group_type, sub_group)`) |
|
||||
| `wms_after_sale_sub_type_function` | 子类型 → 处理函数(`function_id` + `sort_order`) |
|
||||
| `wms_after_sale_sub_type_rule` + `wms_inbox_number_rule` | 子类型 → 取号规则(`target/regexp/sort_order`) |
|
||||
| `wms_after_sale_reply` | 仓库级(`warehouse_id` 非空)覆盖系统级;`is_reply=0` 静默、`no_number_hint` 引导语 |
|
||||
| `wms_after_sale_reply` | 仓库级(`warehouse_id` 非空)覆盖系统级;`is_reply=0` 静默、`no_number_hint` 引导语、`create_work_order=0` 函数照常执行但内部跳过工单登记 |
|
||||
|
||||
---
|
||||
|
||||
@ -223,6 +225,7 @@ WHERE app_key = '{测试app_key}';
|
||||
### 6.1 开关与分叉边界
|
||||
|
||||
- **AI 开关**:`ai_enabled != 1` 一律跳过(安全默认,快递群默认关闭);
|
||||
例外:`template_reply_enabled=1` 的群不依赖 AI 开关(模块优先);
|
||||
- **群未绑定**:`group_type` 为空跳过;`store` 群无 `store_id` 归属时主分组不激活(`resolveActiveGroups`);
|
||||
- **v1/v2 分叉**(已接入):`template_reply_enabled=1` 走 `inbox.v2.rules.handle`,
|
||||
否则走 `inbox.rules.handle`(v1 分支原逻辑零改动);
|
||||
@ -238,7 +241,8 @@ WHERE app_key = '{测试app_key}';
|
||||
合并去重 join 逗号 → `keyword`;`express_name→express`;
|
||||
子类型转译 `issue_type`(damage→damaged、change_address→addr、rejected→return、urge→urge 等);
|
||||
- **多函数子类型**:按 `sort_order` 依次执行,任一失败立即返回失败文案;
|
||||
- **回复优先级**:回复表(仓库级 > 系统级)> 函数返回值(`direct_reply.messages` > `data.message` > `error`);
|
||||
- **回复优先级**:回复表(仓库级 > 系统级);模板渲染为空或无配置时**默认不回复**(函数照常执行);
|
||||
`{back_text}` 占位符由 help 函数提供,业务函数无该内容时渲染为空 → 不回复;
|
||||
- **缓存失效**:管理接口增删改配置后必须调用 `ctx.service.inbox.v2.config.invalidate(warehouseId)`;
|
||||
启动时**不清** v2 缓存(防雪崩)。
|
||||
|
||||
@ -275,8 +279,8 @@ SET group_type='store', sub_type='after_sales',
|
||||
WHERE group_id='{测试群ID}' AND warehouse_id={仓库ID};
|
||||
```
|
||||
|
||||
v2 链路的四个开关缺一不可:`group_type` 非空 → `ai_enabled=1` → `template_reply_enabled=1`
|
||||
→ 消息内容命中 v2 关键词。
|
||||
v2 链路只需三个条件(模板开关优先,不依赖 AI 开关):`group_type` 非空 →
|
||||
`template_reply_enabled=1` → 消息内容命中 v2 关键词;`ai_enabled` 开或关都不影响 v2。
|
||||
|
||||
### 7.2 推送消息并核对(HTTP 入口)
|
||||
|
||||
@ -313,8 +317,10 @@ v2 链路的四个开关缺一不可:`group_type` 非空 → `ai_enabled=1`
|
||||
| 揽收 | `上门取件 SF1234567890123` | `requestPickup` + pickup 工单 |
|
||||
| 取号失败 | `破损` | 回复引导语,**不建工单** |
|
||||
| v2 未命中 | `今天天气怎么样` | 模块接管静默:无函数调用、无回执记录 |
|
||||
| 模块优先 | 同破损内容 + `ai_enabled=0`(`template_reply_enabled=1` 不变) | 仍走 v2 并回执(不依赖 AI 开关) |
|
||||
| 历史消息 | 同破损内容 + `sendTime` 为 30 分钟前 | 静默跳过:无回执、无工单 |
|
||||
| 群开关关闭 | 同破损内容 + `template_reply_enabled=0` | 走 v1(不属 v2 测试范围,仅确认分叉生效) |
|
||||
|
||||
> 所有用例的群必须 `template_reply_enabled=1`;**不测** `template_reply_enabled=0` 的 v1 场景。
|
||||
|
||||
### 7.4 边界补充
|
||||
|
||||
|
||||
@ -32,6 +32,12 @@ module.exports = app => {
|
||||
defaultValue: 1,
|
||||
comment: '是否回复:1=命中后回复,0=静默不回复',
|
||||
},
|
||||
create_work_order: {
|
||||
type: TINYINT(1),
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
comment: '是否登记工单:1=执行函数处理(可能建工单,默认),0=仅回复不执行函数',
|
||||
},
|
||||
no_number_hint: {
|
||||
type: STRING(500),
|
||||
allowNull: true,
|
||||
|
||||
@ -20,6 +20,16 @@ function extractLicensePlate(text) {
|
||||
return m ? m[0] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复配置 create_work_order=0 时,v2 引擎注入 ctx.inboxContext.skip_work_order,
|
||||
* 函数照常执行但建单前应跳过工单登记。
|
||||
* @param {Object} ctx Egg 上下文。
|
||||
* @return {boolean} 是否跳过工单登记。
|
||||
*/
|
||||
function shouldSkipWorkOrder(ctx) {
|
||||
return !!(ctx && ctx.inboxContext && ctx.inboxContext.skip_work_order === true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 站内信函数注册表。
|
||||
* 负责注册 AI 可调用的函数(含 handler),支持按分组声明可见性。
|
||||
@ -41,6 +51,58 @@ class InboxFunctionsService extends Service {
|
||||
* 注册内置函数。
|
||||
*/
|
||||
registerBuiltinFunctions() {
|
||||
this.register('help', {
|
||||
description: '帮助指令:枚举当前仓库可见的售后类型与子类型(含关键词),返回可用指令清单(back_text),供回复模板 {back_text} 占位符渲染',
|
||||
params: {},
|
||||
groups: [ GROUP.COMMON ],
|
||||
weight: 0,
|
||||
keywords: [ '指令', '帮助' ],
|
||||
handler: async (params = {}) => {
|
||||
const { ctx } = this;
|
||||
void params;
|
||||
const warehouseId = Number(ctx.inboxContext?.warehouse_id || 0);
|
||||
|
||||
let cfg = null;
|
||||
try {
|
||||
cfg = await ctx.service.inbox.v2.config.load(warehouseId);
|
||||
} catch (e) {
|
||||
ctx.logger.warn(`[inbox functions] help 加载 v2 配置失败: ${e.message}`);
|
||||
}
|
||||
|
||||
// 类型名映射
|
||||
let typeNameMap = {};
|
||||
try {
|
||||
const types = await ctx.model.AfterSaleType.findAll({ attributes: [ 'type', 'name' ], raw: true });
|
||||
typeNameMap = {};
|
||||
for (const t of types) typeNameMap[t.type] = t.name;
|
||||
} catch (e) { /* ignore */ }
|
||||
|
||||
// 关键词按子类型聚合(可见配置)
|
||||
const kwBySubType = {};
|
||||
if (cfg && Array.isArray(cfg.keywords)) {
|
||||
for (const k of cfg.keywords) {
|
||||
if (!kwBySubType[k.sub_type_id]) kwBySubType[k.sub_type_id] = [];
|
||||
kwBySubType[k.sub_type_id].push(k.keyword);
|
||||
}
|
||||
}
|
||||
|
||||
const lines = [];
|
||||
const subTypes = (cfg && cfg.subTypes) ? Object.values(cfg.subTypes) : [];
|
||||
for (const st of subTypes) {
|
||||
const tName = typeNameMap[st.type] || st.type;
|
||||
const kws = kwBySubType[st.id] || [];
|
||||
lines.push(`${tName}:`);
|
||||
lines.push(` ${st.name}:关键词:${kws.length > 0 ? kws.join(',') : '(未配置)'}`);
|
||||
}
|
||||
const backText = lines.length > 0 ? lines.join('\n') : '(当前仓库未配置可用指令)';
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: { back_text: backText },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
this.register('hello', {
|
||||
description: '问候接口,返回欢迎信息。传入 name 参数可个性化问候',
|
||||
params: {
|
||||
@ -979,6 +1041,11 @@ class InboxFunctionsService extends Service {
|
||||
interceptMsgContent ? `原消息: ${interceptMsgContent}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info(`[inbox functions] 拦截: skip_work_order,跳过工单登记 ${e.waybill_code}`);
|
||||
return { success: true, data: { message: '已记录拦截诉求(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
|
||||
await ctx.service.systems.afterSale.create({
|
||||
warehouse_id: warehouseId,
|
||||
after_sale_no: afterSaleNo,
|
||||
@ -1117,7 +1184,7 @@ class InboxFunctionsService extends Service {
|
||||
await logService.createOperationLogs(
|
||||
interceptOrderIds.map(oid => ({
|
||||
businessType: 'order',
|
||||
businessId: String(warehouseId),
|
||||
businessId: String(oid),
|
||||
operationCode: 'ORDER_INTERCEPT_REQUEST',
|
||||
operator: { id: '0', name: groupName || 'AI系统' },
|
||||
extras: { warehouseId, orderId: oid, newInterceptStatus: 'requested' },
|
||||
@ -1400,6 +1467,11 @@ class InboxFunctionsService extends Service {
|
||||
originalText ? `原文: ${originalText}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info(`[inbox functions] 揽收: skip_work_order,跳过工单登记 ${e.waybill_code}`);
|
||||
return { success: true, data: { message: '已记录揽收诉求(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
|
||||
await ctx.service.systems.afterSale.create({
|
||||
warehouse_id: warehouseId,
|
||||
after_sale_no: afterSaleNo,
|
||||
@ -1629,7 +1701,9 @@ class InboxFunctionsService extends Service {
|
||||
const unpackId = Number(unpack.id || 0);
|
||||
if (videos.length > 0) {
|
||||
for (const video of videos) {
|
||||
if (video.video_url) lines.push(String(video.video_url));
|
||||
if (!video.video_url) continue;
|
||||
const cameraName = String(video.camera_name || '').trim();
|
||||
lines.push(cameraName ? `${cameraName}:${video.video_url}` : String(video.video_url));
|
||||
}
|
||||
lines.push('拆包视频保存会有延迟,可以在稍后发送:查退回+运单号,查询');
|
||||
// 视频已可用:推进补录请求状态为 completed(回写视频地址)
|
||||
@ -1829,6 +1903,10 @@ class InboxFunctionsService extends Service {
|
||||
// 第四步:无工单的按拦截规则创建
|
||||
const createdNos = [];
|
||||
if (toCreate.length > 0) {
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info('[inbox functions] 取消拦截: skip_work_order,跳过创建工单');
|
||||
return { success: true, data: { message: '取消拦截信息已登记(本次不创建工单)', skipped_work_order: true } };
|
||||
}
|
||||
const creatorLabel = [ groupName, userName ].filter(Boolean).join('-') || 'AI系统';
|
||||
for (const e of toCreate) {
|
||||
const afterSaleNo = await ctx.service.systemMethods.afterSale.generateAfterSaleNo(warehouseId);
|
||||
@ -1943,7 +2021,7 @@ class InboxFunctionsService extends Service {
|
||||
await logSvc.createOperationLogs(
|
||||
interceptOrderIds.map(oid => ({
|
||||
businessType: 'order',
|
||||
businessId: String(warehouseId),
|
||||
businessId: String(oid),
|
||||
operationCode: 'ORDER_INTERCEPT_REQUEST',
|
||||
operator: { id: '0', name: groupName || 'AI系统' },
|
||||
extras: { warehouseId, orderId: oid, newInterceptStatus: 'requested' },
|
||||
@ -2149,6 +2227,11 @@ class InboxFunctionsService extends Service {
|
||||
msgContent ? `原消息: ${msgContent}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info(`[inbox functions] 问题反馈: skip_work_order,跳过工单登记 ${e.waybill_code}`);
|
||||
return { success: true, data: { message: '已记录问题反馈(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
|
||||
await ctx.service.systems.afterSale.create({
|
||||
warehouse_id: warehouseId,
|
||||
after_sale_no: afterSaleNo,
|
||||
@ -2299,6 +2382,10 @@ class InboxFunctionsService extends Service {
|
||||
for (const r of existingASList) {
|
||||
waybillToAsNo[r.waybill_id] = r.after_sale_no;
|
||||
}
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info('[inbox functions] 改地址/催件: skip_work_order,跳过工单登记');
|
||||
return { success: true, data: { message: '已记录诉求(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
if (toCreate.length > 0) {
|
||||
const creatorLabel = [ groupName, userName ].filter(Boolean).join('-') || 'AI系统';
|
||||
for (const e of toCreate) {
|
||||
@ -2537,6 +2624,10 @@ class InboxFunctionsService extends Service {
|
||||
// 第三步:创建工单(含原文)并映射 waybill_id → 工单号
|
||||
const createdNos = [];
|
||||
const waybillToAsNo = {};
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info('[inbox functions] 核实签收: skip_work_order,跳过工单登记');
|
||||
return { success: true, data: { message: '已记录核实签收诉求(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
if (toCreate.length > 0) {
|
||||
const creatorLabel = [ groupName, userName ].filter(Boolean).join('-') || 'AI系统';
|
||||
for (const e of toCreate) {
|
||||
@ -3303,7 +3394,7 @@ class InboxFunctionsService extends Service {
|
||||
// 第五步:查打包视频
|
||||
const taskIds = packTasks.map(t => t.id);
|
||||
const videos = await ctx.model.PackTaskVideo.findAll({
|
||||
attributes: [ 'id', 'video_url', 'status' ],
|
||||
attributes: [ 'id', 'video_url', 'camera_id', 'status' ],
|
||||
where: {
|
||||
pack_task_id: { [Op.in]: taskIds },
|
||||
deleted_at: null,
|
||||
@ -3345,7 +3436,29 @@ class InboxFunctionsService extends Service {
|
||||
reRecordFailedWbs.push(e.waybill_code);
|
||||
}
|
||||
} else {
|
||||
videoLines.push(`${e.waybill_code}\n${urls.join('\n')}`);
|
||||
// 摄像头名称放链接前(系统设置的自定义名称优先,通道原始名称兜底)
|
||||
const packCameraIds = [ ...new Set(videos.filter(v => v.camera_id).map(v => v.camera_id)) ];
|
||||
const packCameraNameMap = new Map();
|
||||
if (packCameraIds.length > 0) {
|
||||
const packCameras = await ctx.model.Camera.findAll({
|
||||
attributes: [ 'id', 'custom_name', 'channel_name' ],
|
||||
where: { id: { [Op.in]: packCameraIds } },
|
||||
raw: true,
|
||||
});
|
||||
for (const c of packCameras) {
|
||||
packCameraNameMap.set(Number(c.id), String(c.custom_name || c.channel_name || '').trim());
|
||||
}
|
||||
}
|
||||
const displayLines = videos
|
||||
.filter(v => String(v.status || '') !== 'failed')
|
||||
.map(v => {
|
||||
const url = inboxTools.buildVideoUrl(warehouseId, recordingComputerId, v.video_url);
|
||||
if (!url) return '';
|
||||
const cameraName = v.camera_id ? (packCameraNameMap.get(Number(v.camera_id)) || '') : '';
|
||||
return cameraName ? `${cameraName}:${url}` : url;
|
||||
})
|
||||
.filter(Boolean);
|
||||
videoLines.push(`${e.waybill_code}\n${displayLines.join('\n')}`);
|
||||
// 视频已可用:推进补录请求状态为 completed(回写视频地址)
|
||||
for (const task of packTasks) {
|
||||
try {
|
||||
@ -3629,6 +3742,11 @@ class InboxFunctionsService extends Service {
|
||||
feedbackMsgContent ? `原文: ${feedbackMsgContent}` : '',
|
||||
].filter(Boolean).join('\n');
|
||||
|
||||
if (shouldSkipWorkOrder(ctx)) {
|
||||
ctx.logger.info(`[inbox functions] 快递反馈: skip_work_order,跳过工单登记 ${e.waybill_code}`);
|
||||
return { success: true, data: { message: '已记录快递反馈(本次不登记工单)', skipped_work_order: true } };
|
||||
}
|
||||
|
||||
await ctx.service.systems.afterSale.create({
|
||||
warehouse_id: warehouseId,
|
||||
after_sale_no: afterSaleNo,
|
||||
|
||||
@ -213,7 +213,10 @@ class InboxProcessorService extends Service {
|
||||
|
||||
// 5. 群未启用AI → 跳过(ai_enabled != 1 一律跳过,安全默认)
|
||||
// 快递群默认 ai_enabled=0,需手动开启后才会走 AI 处理
|
||||
if (ctx.inboxContext.ai_enabled !== 1) {
|
||||
// v2 例外:模板回信引擎(template_reply_enabled=1)优先于原链路,
|
||||
// 即使 ai_enabled=0 也进入第 6 步走 v2;两开关同开时仍走 v2 不走 v1/AI。
|
||||
const v2Enabled = ctx.inboxContext.template_reply_enabled === 1;
|
||||
if (ctx.inboxContext.ai_enabled !== 1 && !v2Enabled) {
|
||||
ctx.logger.info(`[inbox processor] 群未启用AI自动回复,跳过 AI ext_id=${extId}`);
|
||||
return;
|
||||
}
|
||||
@ -235,7 +238,6 @@ class InboxProcessorService extends Service {
|
||||
// v2 分叉:群开启模板回信引擎(template_reply_enabled=1)时走 v2 可配置引擎,
|
||||
// 模块接管模式——v2 未命中直接静默返回,不再走 v1 规则与 AI 兜底。
|
||||
const text = String(data.content || '').trim();
|
||||
const v2Enabled = ctx.inboxContext.template_reply_enabled === 1;
|
||||
const ruleResult = v2Enabled
|
||||
? await ctx.service.inbox.v2.rules.handle(text)
|
||||
: await ctx.service.inbox.rules.handle(text);
|
||||
|
||||
@ -383,7 +383,7 @@ const STORE_RULES = [
|
||||
tip: '如需催退回,发送:催退回+运单号\n例:催退回 SF123' },
|
||||
{ keys: [ '催件', '催派', '催促', '尽快安排派送', '未中转', '物流停滞' ], fn: 'changeAddr', issueType: 'urge', waybill: true,
|
||||
tip: '如需催件,发送:催件+运单号\n例:催件 SF123' },
|
||||
{ keys: [ '查退回', '是否已退回' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||||
{ keys: [ '查退回', '是否已退回', '查退件', '查件' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||||
tip: '如需查退回,发送:查退回+运单号\n例:查退回 SF123' },
|
||||
{ keys: [ '退回', '拒收' ], fn: 'queryReturn', waybill: true, paramName: 'waybill_code',
|
||||
tip: '如需查退回,发送:查退回+运单号\n例:查退回 SF123' },
|
||||
|
||||
@ -126,9 +126,17 @@ class InboxV2ConfigService extends Service {
|
||||
});
|
||||
const funcIdMap = {};
|
||||
const functionEnabled = {};
|
||||
// 启用状态硬编码:代码注册表中存在的函数即启用(DB is_enabled 仅作展示参考,不再作为启用依据)
|
||||
let registry = null;
|
||||
try {
|
||||
registry = this.ctx.service.inbox.functions.registry;
|
||||
} catch (e) { /* ignore */ }
|
||||
for (const f of funcRows) {
|
||||
funcIdMap[f.id] = f.function_code;
|
||||
if (Number(f.is_enabled) === 1) functionEnabled[f.function_code] = true;
|
||||
const inRegistry = registry instanceof Map && registry.has(f.function_code);
|
||||
if (inRegistry || (registry === null && Number(f.is_enabled) === 1)) {
|
||||
functionEnabled[f.function_code] = true;
|
||||
}
|
||||
}
|
||||
const subTypeFunctions = {};
|
||||
for (const r of funcRelRows) {
|
||||
@ -170,7 +178,7 @@ class InboxV2ConfigService extends Service {
|
||||
// 6. 回复表:仓库级覆盖系统级(同子类型取 warehouse_id 非空者优先)
|
||||
const replyRows = await ctx.model.AfterSaleReply.findAll({
|
||||
where: { ...wh, is_enabled: 1 },
|
||||
attributes: [ 'warehouse_id', 'sub_type_id', 'reply', 'is_reply', 'no_number_hint' ],
|
||||
attributes: [ 'warehouse_id', 'sub_type_id', 'reply', 'is_reply', 'create_work_order', 'no_number_hint' ],
|
||||
raw: true,
|
||||
});
|
||||
const replies = {};
|
||||
@ -182,6 +190,7 @@ class InboxV2ConfigService extends Service {
|
||||
replies[r.sub_type_id] = {
|
||||
reply: String(r.reply || ''),
|
||||
is_reply: Number(r.is_reply) === 1 ? 1 : 0,
|
||||
create_work_order: Number(r.create_work_order) === 0 ? 0 : 1,
|
||||
no_number_hint: r.no_number_hint ? String(r.no_number_hint) : '',
|
||||
warehouse_id: isWh ? r.warehouse_id : null,
|
||||
};
|
||||
|
||||
@ -2,6 +2,41 @@
|
||||
|
||||
const Service = require('egg').Service;
|
||||
|
||||
/**
|
||||
* function_code → 中文名称映射(管理界面展示用)。
|
||||
* 未列出的函数回退到 function_code(英文注册名)。
|
||||
*/
|
||||
const FUNCTION_NAME_MAP = {
|
||||
hello: '问候',
|
||||
help: '帮助',
|
||||
queryPrintBalance: '查询面单余额',
|
||||
createWaybill: '创建运单号',
|
||||
searchStock: '搜索货主商品',
|
||||
searchWarehouseStock: '搜索仓库商品',
|
||||
queryOrder: '查询订单',
|
||||
recallHistory: '回顾对话历史',
|
||||
createOrder: '创建发货单',
|
||||
blockUser: '屏蔽用户',
|
||||
interceptWaybill: '拦截运单',
|
||||
requestPickup: '揽收处理',
|
||||
queryReturn: '查询退回单',
|
||||
cancelIntercept: '取消拦截',
|
||||
handleStoreFeedback: '问题反馈建单',
|
||||
changeAddr: '改地址/催件处理',
|
||||
weishoudao: '核实签收',
|
||||
changeExpress: '改快递',
|
||||
createPostnum: '分配快递号',
|
||||
queryPackVideo: '查询打包视频',
|
||||
queryWeight: '查询重量',
|
||||
handleExpressFeedback: '快递反馈处理',
|
||||
queryWarehouseAddress: '查询仓库地址',
|
||||
listGroups: '查询群列表',
|
||||
openDoor: '开门',
|
||||
registerLicensePlate: '到货登记',
|
||||
departure: '离场登记',
|
||||
enter: '进场登记',
|
||||
};
|
||||
|
||||
/**
|
||||
* 售后函数表同步服务(v2 仓库可配置回信引擎)。
|
||||
*
|
||||
@ -48,7 +83,7 @@ class InboxV2FunctionSyncService extends Service {
|
||||
seen.add(code);
|
||||
rows.push({
|
||||
function_code: code,
|
||||
name: code,
|
||||
name: FUNCTION_NAME_MAP[code] || code,
|
||||
description: (typeof def.description === 'string' ? def.description : '').slice(0, 500) || null,
|
||||
});
|
||||
}
|
||||
@ -65,11 +100,22 @@ class InboxV2FunctionSyncService extends Service {
|
||||
stats.updated = rows.length - stats.created;
|
||||
|
||||
// bulkCreate + updateOnDuplicate:新行插入(is_enabled 默认 1、sort_order 默认 0),
|
||||
// 已有行仅刷新 name/description,不覆盖管理端维护的 is_enabled / sort_order。
|
||||
// 已有行刷新 name/description;启用状态硬编码——注册表存在即启用(is_enabled 同步为 1),
|
||||
// sort_order 由接口配置,不同步覆盖。
|
||||
await ctx.model.AfterSaleFunction.bulkCreate(rows, {
|
||||
updateOnDuplicate: [ 'name', 'description' ],
|
||||
updateOnDuplicate: [ 'name', 'description', 'is_enabled' ],
|
||||
});
|
||||
|
||||
// 代码已删除的函数:保留行但标记下线(is_enabled=0),不删除。
|
||||
if (rows.length > 0) {
|
||||
const codes = rows.map(r => r.function_code);
|
||||
const { Op } = ctx.app.Sequelize;
|
||||
await ctx.model.AfterSaleFunction.update(
|
||||
{ is_enabled: 0 },
|
||||
{ where: { function_code: { [Op.notIn]: codes } } }
|
||||
);
|
||||
}
|
||||
|
||||
stats.ok = true;
|
||||
return stats;
|
||||
} catch (error) {
|
||||
|
||||
@ -130,53 +130,66 @@ class InboxV2RulesService extends Service {
|
||||
};
|
||||
}
|
||||
|
||||
// 2.4 逐函数执行(按 sort_order;任一失败立即以失败出参返回)
|
||||
// 2.4 逐函数执行:函数照常执行;create_work_order=0 时注入 skip_work_order
|
||||
// 标记,由函数内部在建工单前自行跳过登记(其余处理不受影响)。
|
||||
const replyCfgNow = (cfg.replies || {})[cand.sub_type_id];
|
||||
const workOrderSkip = !!replyCfgNow && replyCfgNow.create_work_order === 0;
|
||||
const results = [];
|
||||
let lastFn = null;
|
||||
let lastParams = null;
|
||||
let executed = false;
|
||||
for (const f of fns) {
|
||||
const def = funcSvc.registry.get(f.function_code);
|
||||
if (!def || !groupsSvc.isFunctionAvailable(def, activeGroups)) {
|
||||
ctx.logger.info(
|
||||
`[inbox v2] 函数 ${f.function_code} 当前群不可用,跳过 ` +
|
||||
`groups=${def ? def.groups.join(',') : '-'} active=${activeGroups.join(',')}`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const params = this._buildParams(f.function_code, subType, extracted);
|
||||
const result = await funcSvc.callFunction(f.function_code, params);
|
||||
lastFn = f.function_code;
|
||||
lastParams = params;
|
||||
executed = true;
|
||||
if (workOrderSkip) {
|
||||
ctx.inboxContext.skip_work_order = true;
|
||||
ctx.logger.info(
|
||||
`[inbox v2] 执行 fn=${f.function_code} sub=${subType.type}:${subType.sub_type} ` +
|
||||
`params=${JSON.stringify(params)} success=${!!result.success}`
|
||||
`[inbox v2] 子类型 ${subType.type}:${subType.sub_type} 配置为不登记工单,函数照常执行但跳过建单`
|
||||
);
|
||||
if (!result.success) {
|
||||
const thoughts = [{
|
||||
round: 0,
|
||||
action: 'rule',
|
||||
function: f.function_code,
|
||||
params,
|
||||
reason: `v2 关键词命中: ${cand.keyword}`,
|
||||
functionResult: result,
|
||||
}];
|
||||
return {
|
||||
handled: true,
|
||||
reply: String(result.error || '操作失败,请联系客服处理'),
|
||||
fn: f.function_code,
|
||||
params,
|
||||
result,
|
||||
matchedKey: cand.keyword,
|
||||
thoughts,
|
||||
};
|
||||
}
|
||||
try {
|
||||
for (const f of fns) {
|
||||
const def = funcSvc.registry.get(f.function_code);
|
||||
if (!def || !groupsSvc.isFunctionAvailable(def, activeGroups)) {
|
||||
ctx.logger.info(
|
||||
`[inbox v2] 函数 ${f.function_code} 当前群不可用,跳过 ` +
|
||||
`groups=${def ? def.groups.join(',') : '-'} active=${activeGroups.join(',')}`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const params = this._buildParams(f.function_code, subType, extracted);
|
||||
const result = await funcSvc.callFunction(f.function_code, params);
|
||||
lastFn = f.function_code;
|
||||
lastParams = params;
|
||||
executed = true;
|
||||
ctx.logger.info(
|
||||
`[inbox v2] 执行 fn=${f.function_code} sub=${subType.type}:${subType.sub_type} ` +
|
||||
`params=${JSON.stringify(params)} success=${!!result.success}`
|
||||
);
|
||||
if (!result.success) {
|
||||
const thoughts = [{
|
||||
round: 0,
|
||||
action: 'rule',
|
||||
function: f.function_code,
|
||||
params,
|
||||
reason: `v2 关键词命中: ${cand.keyword}`,
|
||||
functionResult: result,
|
||||
}];
|
||||
return {
|
||||
handled: true,
|
||||
reply: String(result.error || '操作失败,请联系客服处理'),
|
||||
fn: f.function_code,
|
||||
params,
|
||||
result,
|
||||
matchedKey: cand.keyword,
|
||||
thoughts,
|
||||
};
|
||||
}
|
||||
results.push({ fn: f.function_code, params, result });
|
||||
}
|
||||
results.push({ fn: f.function_code, params, result });
|
||||
} finally {
|
||||
if (workOrderSkip) ctx.inboxContext.skip_work_order = false;
|
||||
}
|
||||
if (!executed) continue;
|
||||
|
||||
// 2.5 回复决策:回复表(仓库级覆盖系统级)→ 函数返回值兜底
|
||||
// 2.5 回复决策:完全由回复配置控制(仓库级覆盖系统级)
|
||||
return this._buildOutcome(cfg, cand, subType, results, lastFn, lastParams, text);
|
||||
}
|
||||
|
||||
@ -220,8 +233,10 @@ class InboxV2RulesService extends Service {
|
||||
const rows = (cfg.groupWhitelist || {})[subTypeId];
|
||||
if (!Array.isArray(rows) || rows.length === 0) return false;
|
||||
return rows.some(r => {
|
||||
if (r.group_type === '*') return true; // 全通配:所有群可用(如 help 指令)
|
||||
if (r.group_type !== groupType) return false;
|
||||
if (!groupSubType) return true; // 群未绑子类型:只按主类型放行
|
||||
if (r.sub_group === '*') return true; // 主类型内子类型通配(如 warehouse:*)
|
||||
return r.sub_group === groupSubType;
|
||||
});
|
||||
}
|
||||
@ -318,7 +333,7 @@ class InboxV2RulesService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* 出参构建:回复表决策(仓库级覆盖系统级)→ 函数返回值兜底。
|
||||
* 出参构建:回复决策完全由回复配置控制(仓库级覆盖系统级)。
|
||||
* @param {Object} cfg v2 配置。
|
||||
* @param {Object} cand 命中候选。
|
||||
* @param {Object} subType 子类型记录。
|
||||
@ -329,22 +344,23 @@ class InboxV2RulesService extends Service {
|
||||
* @return {Object} 与 v1 rules.handle 同构的出参。
|
||||
*/
|
||||
_buildOutcome(cfg, cand, subType, results, lastFn, lastParams, text) {
|
||||
const last = results[results.length - 1];
|
||||
const last = results.length > 0 ? results[results.length - 1] : null;
|
||||
const replyCfg = (cfg.replies || {})[cand.sub_type_id];
|
||||
|
||||
// 回复表显式配置:is_reply=0 静默;is_reply=1 用自定义文案(占位符替换)
|
||||
// 回复决策:完全由回复配置控制。
|
||||
// - is_reply=0 → 静默;
|
||||
// - reply 模板渲染非空 → 回复;
|
||||
// - 无回复配置或模板渲染为空 → 不回复(函数已照常执行,仅不出回执)。
|
||||
if (replyCfg && replyCfg.is_reply === 0) {
|
||||
return { handled: true, silent: true };
|
||||
}
|
||||
let reply;
|
||||
let reply = null;
|
||||
if (replyCfg && replyCfg.reply) {
|
||||
reply = this._renderReply(replyCfg.reply, subType, results, text);
|
||||
} else {
|
||||
// 无回复配置:函数返回值兜底(与 v1 buildReply 同构语义)
|
||||
reply = this._buildReplyFromResult(results);
|
||||
const rendered = this._renderReply(replyCfg.reply, subType, results, text, lastParams);
|
||||
if (rendered && String(rendered).trim()) reply = rendered;
|
||||
}
|
||||
|
||||
const thoughts = results.map((r, idx) => ({
|
||||
let thoughts = results.map((r, idx) => ({
|
||||
round: idx,
|
||||
action: 'rule',
|
||||
function: r.fn,
|
||||
@ -352,60 +368,52 @@ class InboxV2RulesService extends Service {
|
||||
reason: `v2 关键词命中: ${cand.keyword}`,
|
||||
functionResult: r.result,
|
||||
}));
|
||||
if (thoughts.length === 0 && lastParams) {
|
||||
// 兜底(一般不可达:fns 全部不可用才出现):记录一条无函数调用的轨迹
|
||||
thoughts = [{
|
||||
round: 0,
|
||||
action: 'rule',
|
||||
function: lastFn,
|
||||
params: lastParams,
|
||||
reason: `v2 关键词命中: ${cand.keyword}(无可用函数)`,
|
||||
functionResult: null,
|
||||
}];
|
||||
}
|
||||
|
||||
return {
|
||||
handled: true,
|
||||
reply,
|
||||
fn: lastFn || last.fn,
|
||||
params: lastParams || last.params,
|
||||
result: last.result,
|
||||
fn: lastFn || (last && last.fn),
|
||||
params: lastParams || (last && last.params),
|
||||
result: last ? last.result : null,
|
||||
matchedKey: cand.keyword,
|
||||
thoughts,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复文案占位符渲染:{sub_type_name}/{keyword}/{express}。
|
||||
* 回复文案占位符渲染:{sub_type_name}/{keyword}/{express}/{back_text}。
|
||||
* {back_text} 取自函数返回的 data.back_text(如 help 函数生成的指令清单)。
|
||||
* @param {string} tpl 模板文案。
|
||||
* @param {Object} subType 子类型记录。
|
||||
* @param {Array} results 函数执行结果。
|
||||
* @param {string} text 消息正文。
|
||||
* @param {Object} [fallbackParams] 未执行函数时的备用参数(create_work_order=0 场景)。
|
||||
* @return {string} 渲染后的文案。
|
||||
*/
|
||||
_renderReply(tpl, subType, results, text) {
|
||||
const last = results[results.length - 1];
|
||||
const params = (last && last.params) || {};
|
||||
_renderReply(tpl, subType, results, text, fallbackParams) {
|
||||
const last = results.length > 0 ? results[results.length - 1] : null;
|
||||
const params = (last && last.params) || fallbackParams || {};
|
||||
const backText = (last && last.result && last.result.data && last.result.data.back_text)
|
||||
? String(last.result.data.back_text)
|
||||
: '';
|
||||
return String(tpl)
|
||||
.replace(/\{sub_type_name\}/g, subType.name || '')
|
||||
.replace(/\{keyword\}/g, String(params.keyword || ''))
|
||||
.replace(/\{express\}/g, String(params.express || ''))
|
||||
.replace(/\{back_text\}/g, backText)
|
||||
.replace(/\{text\}/g, text.slice(0, 200));
|
||||
}
|
||||
|
||||
/**
|
||||
* 无回复配置时,从函数返回值兜底构建回复(direct_reply.messages → data.message → error)。
|
||||
* @param {Array} results 函数执行结果数组。
|
||||
* @return {string|string[]|null} 回复文本。
|
||||
*/
|
||||
_buildReplyFromResult(results) {
|
||||
const replies = [];
|
||||
for (const r of results) {
|
||||
const result = r.result;
|
||||
if (!result || typeof result !== 'object') continue;
|
||||
if (result.success === false) {
|
||||
replies.push(String(result.error || '操作失败,请联系客服处理'));
|
||||
continue;
|
||||
}
|
||||
const data = result.data || {};
|
||||
if (data.direct_reply === true && Array.isArray(data.messages) && data.messages.length > 0) {
|
||||
replies.push(...data.messages.map(m => String(m)));
|
||||
} else if (data.message) {
|
||||
replies.push(String(data.message));
|
||||
}
|
||||
}
|
||||
if (replies.length === 0) return null;
|
||||
return replies.length === 1 ? replies[0] : replies;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InboxV2RulesService;
|
||||
|
||||
@ -53,6 +53,29 @@ class InboxSystemService extends MainService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* v2 可配置回信引擎配置管理子入口,供 /system dispatcher 按 inbox.v2.* 路径访问。
|
||||
* 全部委托给 systems/inbox/v2.js(配置管理系统服务层),本层只做 checkAuth 代理。
|
||||
* @return {Object} v2 配置管理方法集合(type/subType/keyword/numberRule/function/reply/relation)。
|
||||
*/
|
||||
get v2() {
|
||||
const { ctx } = this;
|
||||
const svc = () => ctx.service.systems.inbox.v2;
|
||||
return {
|
||||
type: { ...svc().type, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
subType: { ...svc().subType, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
keyword: { ...svc().keyword, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
numberRule: { ...svc().numberRule, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
function: { ...svc().function, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
reply: { ...svc().reply, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
relation: {
|
||||
function: { ...svc().relation.function, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
rule: { ...svc().relation.rule, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
group: { ...svc().relation.group, checkAuth: (...args) => this.checkAuth(...args) },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成货主绑群码。
|
||||
* 委托给 systems.store.bindCode 执行:校验 StoreWarehouse 合约 → 生成12位随机码 → 缓存300秒。
|
||||
@ -182,7 +205,8 @@ class InboxSystemService extends MainService {
|
||||
|
||||
/**
|
||||
* 修改群信息。
|
||||
* 支持修改 group_type / sub_type / store_id / express_interfaces / system_express_code。
|
||||
* 支持修改 group_type / sub_type / store_id / express_interfaces /
|
||||
* system_express_code / ai_enabled / template_reply_enabled。
|
||||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||||
*
|
||||
* @param {Object} data 请求数据。
|
||||
@ -192,6 +216,8 @@ class InboxSystemService extends MainService {
|
||||
* @param {number} [data.storeId] 关联货主ID。
|
||||
* @param {number[]} [data.expressInterfaces] 快递接口ID数组(仅 express 生效)。
|
||||
* @param {string} [data.systemExpressCode] 系统快递编码(express 时必填)。
|
||||
* @param {number} [data.aiEnabled] 是否启用AI自动回复: 0=关闭 1=开启。
|
||||
* @param {number} [data.templateReplyEnabled] 是否启用模板消息回复: 0=关闭(普通文本回复) 1=开启(模板消息回复)。
|
||||
* @return {Promise<Object>} { message: 操作结果 }。
|
||||
*/
|
||||
async groupUpdate(data = {}) {
|
||||
@ -199,6 +225,7 @@ class InboxSystemService extends MainService {
|
||||
const {
|
||||
id, groupType, subType, storeId,
|
||||
expressInterfaces, systemExpressCode, aiEnabled,
|
||||
templateReplyEnabled,
|
||||
} = data;
|
||||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||||
|
||||
@ -211,6 +238,7 @@ class InboxSystemService extends MainService {
|
||||
expressInterfaces,
|
||||
systemExpressCode,
|
||||
aiEnabled,
|
||||
templateReplyEnabled,
|
||||
});
|
||||
|
||||
return { message: '群信息修改成功' };
|
||||
|
||||
@ -85,6 +85,7 @@ class InboxGroupService extends Service {
|
||||
source_type: { field: 'source_type' },
|
||||
is_blocked: { field: 'is_blocked' },
|
||||
ai_enabled: { field: 'ai_enabled' },
|
||||
template_reply_enabled: { field: 'template_reply_enabled' },
|
||||
system_express_code: { field: 'system_express_code' },
|
||||
},
|
||||
});
|
||||
@ -103,7 +104,8 @@ class InboxGroupService extends Service {
|
||||
attributes: [
|
||||
'id', 'group_name', 'group_id', 'store_id',
|
||||
'group_type', 'sub_type', 'source_type', 'source_extra',
|
||||
'is_blocked', 'ai_enabled', 'express_interfaces', 'system_express_code',
|
||||
'is_blocked', 'ai_enabled', 'template_reply_enabled',
|
||||
'express_interfaces', 'system_express_code',
|
||||
'created_at', 'updated_at',
|
||||
],
|
||||
where,
|
||||
@ -210,7 +212,7 @@ class InboxGroupService extends Service {
|
||||
* @param {string} [data.keyword] 关键词,模糊匹配 group_name / group_id。
|
||||
* @param {string} [data.groupType] 按群类型筛选:store / warehouse / express。
|
||||
* @param {number} [data.limit=20] 返回条数上限,最大 100。
|
||||
* @return {Promise<{list: Array<{id: number, group_id: (string|null), group_name: string, group_type: (string|null), sub_type: (string|null), is_blocked: number}>}>} 群快速列表。
|
||||
* @return {Promise<{list: Array<{id: number, group_id: (string|null), group_name: string, group_type: (string|null), sub_type: (string|null), is_blocked: number, template_reply_enabled: number}>}>} 群快速列表。
|
||||
*/
|
||||
async quickList(data = {}) {
|
||||
const { ctx } = this;
|
||||
@ -250,7 +252,7 @@ class InboxGroupService extends Service {
|
||||
}
|
||||
|
||||
const rows = await InboxGroup.findAll({
|
||||
attributes: [ 'id', 'group_id', 'group_name', 'group_type', 'sub_type', 'is_blocked' ],
|
||||
attributes: [ 'id', 'group_id', 'group_name', 'group_type', 'sub_type', 'is_blocked', 'template_reply_enabled' ],
|
||||
where,
|
||||
order: [[ 'created_at', 'DESC' ]],
|
||||
limit,
|
||||
@ -406,6 +408,8 @@ class InboxGroupService extends Service {
|
||||
* 支持修改 group_type / sub_type / store_id / express_interfaces / system_express_code。
|
||||
* 群类型切为 express 时 system_express_code 必填,
|
||||
* express_interfaces 仅在群类型为 express 时生效(非 express 类型忽略)。
|
||||
* ai_enabled 控制是否 AI 处理,template_reply_enabled 控制命中处理后
|
||||
* 是否以模板消息形式回复(0=普通文本回复,1=模板消息回复),两者独立。
|
||||
*
|
||||
* @param {Object} data 请求数据。
|
||||
* @param {number} data.id 群记录主键ID(必填)。
|
||||
@ -415,6 +419,8 @@ class InboxGroupService extends Service {
|
||||
* @param {number} [data.storeId] 关联货主ID。
|
||||
* @param {number[]} [data.expressInterfaces] 快递接口ID数组。
|
||||
* @param {string} [data.systemExpressCode] 系统快递编码。
|
||||
* @param {number} [data.aiEnabled] 是否启用AI自动回复: 0=关闭 1=开启。
|
||||
* @param {number} [data.templateReplyEnabled] 是否启用模板消息回复: 0=关闭(普通文本回复) 1=开启(模板消息回复)。
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
async update(data = {}) {
|
||||
@ -525,6 +531,10 @@ class InboxGroupService extends Service {
|
||||
if (data.aiEnabled !== undefined) {
|
||||
updateData.ai_enabled = data.aiEnabled === 1 ? 1 : 0;
|
||||
}
|
||||
// 模板消息回复开关(所有群类型均支持,独立于 AI 开关)
|
||||
if (data.templateReplyEnabled !== undefined) {
|
||||
updateData.template_reply_enabled = data.templateReplyEnabled === 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
if (Object.keys(updateData).length === 0) {
|
||||
throw new Error('未提供任何需要修改的字段');
|
||||
@ -539,7 +549,7 @@ class InboxGroupService extends Service {
|
||||
/**
|
||||
* 清空群类型配置。
|
||||
* 将群恢复为"仅保留创建信息"状态:清空 group_type / sub_type / store_id /
|
||||
* express_interfaces / system_express_code,AI 开关重置为关闭。
|
||||
* express_interfaces / system_express_code,AI 开关与模板消息回复开关重置为关闭。
|
||||
* 保留群名称、群ID、仓库、来源信息、屏蔽状态与扩展数据。
|
||||
*
|
||||
* @param {Object} data 请求数据。
|
||||
@ -574,6 +584,7 @@ class InboxGroupService extends Service {
|
||||
express_interfaces: null,
|
||||
system_express_code: null,
|
||||
ai_enabled: 0,
|
||||
template_reply_enabled: 0,
|
||||
},
|
||||
{ where }
|
||||
);
|
||||
|
||||
798
app/service/systems/inbox/v2.js
Normal file
798
app/service/systems/inbox/v2.js
Normal file
@ -0,0 +1,798 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('egg').Service;
|
||||
|
||||
/**
|
||||
* v2 可配置回信引擎 —— 配置管理系统服务层。
|
||||
*
|
||||
* 规则:
|
||||
* - warehouseId 一律从登录上下文 ctx.user.store_id 注入(仓库隔离);
|
||||
* - 系统预设锁定:is_system=1 的主数据只读;系统级子类型(warehouse_id=NULL)
|
||||
* 的关联行只读(群白名单另尊重关联行 is_system 列);
|
||||
* - 关键词属仓库级数据(warehouse_id=当前仓库),可挂在系统级子类型下
|
||||
* (keyword.create/update/delete 不做子类型「仓库自定义」限制);
|
||||
* - 自定义子类型可挂在系统级或本仓库自定义类型下(subType.create 父类型只校验存在性);
|
||||
* - 删除子类型前校验引用(关键词/函数/规则/群/回复),有引用拒绝删除;
|
||||
* - 函数表由代码同步权威:只允许改 is_enabled / sort_order,不允许增删改 code;
|
||||
* - 取号规则为全局资源,仓库侧只读;
|
||||
* - 所有写操作完成后失效该仓库 v2 配置缓存(inbox:v2:cfg:{warehouseId})。
|
||||
*/
|
||||
class InboxV2ConfigManageService extends Service {
|
||||
/** 当前仓库ID(从登录上下文注入)。 */
|
||||
get wid() {
|
||||
return Number(this.ctx.user?.store_id || 0);
|
||||
}
|
||||
|
||||
/** 写操作后失效缓存。 */
|
||||
async _invalidate() {
|
||||
try {
|
||||
await this.ctx.service.inbox.v2.config.invalidate(this.wid);
|
||||
} catch (e) {
|
||||
this.ctx.logger.warn(`[inbox v2 manage] 失效缓存失败: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
_op() {
|
||||
return this.ctx.app.Sequelize.Op;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验子类型是否属于当前仓库可写范围(仓库自定义,warehouse_id=当前仓库)。
|
||||
* @param {number} subTypeId 子类型ID。
|
||||
* @param {string} [label] 错误提示中的实体名称。
|
||||
* @return {Promise<Object>} 子类型记录(raw)。
|
||||
*/
|
||||
async _assertWritableSubType(subTypeId, label = '子类型') {
|
||||
const row = await this.ctx.model.AfterSaleSubType.findOne({
|
||||
where: { id: Number(subTypeId) || 0, warehouse_id: this.wid },
|
||||
attributes: [ 'id', 'warehouse_id', 'is_system' ],
|
||||
raw: true,
|
||||
});
|
||||
if (!row) {
|
||||
throw new Error(`${label}不存在或不是本仓库自定义(系统级只读)`);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取子类型(含系统级+仓库级,用于只读查询)。
|
||||
* @param {number} subTypeId 子类型ID。
|
||||
* @return {Promise<Object|null>} 子类型记录(raw),不存在返回 null。
|
||||
*/
|
||||
async _findSubType(subTypeId) {
|
||||
const Op = this._op();
|
||||
return this.ctx.model.AfterSaleSubType.findOne({
|
||||
where: { id: Number(subTypeId) || 0, [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] },
|
||||
attributes: [ 'id', 'warehouse_id', 'is_system', 'sub_type', 'type' ],
|
||||
raw: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用分页参数。
|
||||
* @param {Object} [params] 请求参数(含 page/pageSize)。
|
||||
* @return {{page: number, pageSize: number}} 归一化分页参数。
|
||||
*/
|
||||
_page(params = {}) {
|
||||
const page = Math.max(1, Number(params.page) || 1);
|
||||
const pageSize = Math.min(200, Math.max(1, Number(params.pageSize) || 20));
|
||||
return { page, pageSize };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 类型 ───────────────────────────
|
||||
|
||||
get type() {
|
||||
const svc = this;
|
||||
return {
|
||||
list: params => svc._typeList(params),
|
||||
create: params => svc._typeCreate(params),
|
||||
update: params => svc._typeUpdate(params),
|
||||
delete: params => svc._typeDelete(params),
|
||||
};
|
||||
}
|
||||
|
||||
async _typeList(params = {}) {
|
||||
const Op = this._op();
|
||||
const { page, pageSize } = this._page(params);
|
||||
const where = { [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] };
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') {
|
||||
where.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
}
|
||||
const { rows, count } = await this.ctx.model.AfterSaleType.findAndCountAll({
|
||||
where, order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]],
|
||||
offset: (page - 1) * pageSize, limit: pageSize, raw: true,
|
||||
});
|
||||
return { list: rows, pagination: { page, pageSize, total: count } };
|
||||
}
|
||||
|
||||
async _typeCreate(params = {}) {
|
||||
const { AfterSaleType } = this.ctx.model;
|
||||
const type = String(params.type || '').trim();
|
||||
const name = String(params.name || '').trim();
|
||||
if (!type || !name) throw new Error('type 与 name 不能为空');
|
||||
if (type.length > 20 || name.length > 50) throw new Error('type(≤20)/name(≤50) 超长');
|
||||
const exist = await AfterSaleType.findOne({
|
||||
where: { type, warehouse_id: this.wid }, raw: true,
|
||||
});
|
||||
if (exist) throw new Error(`类型编码 ${type} 已存在`);
|
||||
const row = await AfterSaleType.create({
|
||||
warehouse_id: this.wid, type, name, is_system: 0, is_enabled: 1,
|
||||
sort_order: Number(params.sortOrder) || 0,
|
||||
});
|
||||
await this._invalidate();
|
||||
return { id: row.id, message: '创建成功' };
|
||||
}
|
||||
|
||||
async _typeUpdate(params = {}) {
|
||||
const { AfterSaleType } = this.ctx.model;
|
||||
const row = await AfterSaleType.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('类型不存在或不是本仓库自定义(系统级只读)');
|
||||
if (row.is_system === 1) throw new Error('系统预设类型不可修改');
|
||||
const patch = {};
|
||||
if (params.name !== undefined) {
|
||||
const name = String(params.name || '').trim();
|
||||
if (!name) throw new Error('name 不能为空');
|
||||
patch.name = name.slice(0, 50);
|
||||
}
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') patch.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
if (params.sortOrder !== undefined) patch.sort_order = Number(params.sortOrder) || 0;
|
||||
if (Object.keys(patch).length === 0) throw new Error('无可更新字段');
|
||||
await AfterSaleType.update(patch, { where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '更新成功' };
|
||||
}
|
||||
|
||||
async _typeDelete(params = {}) {
|
||||
const { AfterSaleType, AfterSaleSubType } = this.ctx.model;
|
||||
const row = await AfterSaleType.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('类型不存在或不是本仓库自定义(系统级只读)');
|
||||
if (row.is_system === 1) throw new Error('系统预设类型不可删除');
|
||||
const subCount = await AfterSaleSubType.count({ where: { type: row.type, warehouse_id: this.wid } });
|
||||
if (subCount > 0) throw new Error(`该类型下还有 ${subCount} 个子类型,请先删除子类型`);
|
||||
await AfterSaleType.destroy({ where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '删除成功' };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 子类型 ───────────────────────────
|
||||
|
||||
get subType() {
|
||||
const svc = this;
|
||||
return {
|
||||
list: params => svc._subTypeList(params),
|
||||
create: params => svc._subTypeCreate(params),
|
||||
update: params => svc._subTypeUpdate(params),
|
||||
delete: params => svc._subTypeDelete(params),
|
||||
};
|
||||
}
|
||||
|
||||
async _subTypeList(params = {}) {
|
||||
const Op = this._op();
|
||||
const { page, pageSize } = this._page(params);
|
||||
const where = { [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] };
|
||||
if (params.type) where.type = String(params.type).trim();
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') {
|
||||
where.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
}
|
||||
const { rows, count } = await this.ctx.model.AfterSaleSubType.findAndCountAll({
|
||||
where, order: [[ 'type', 'ASC' ], [ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]],
|
||||
offset: (page - 1) * pageSize, limit: pageSize, raw: true,
|
||||
});
|
||||
return { list: rows, pagination: { page, pageSize, total: count } };
|
||||
}
|
||||
|
||||
async _subTypeCreate(params = {}) {
|
||||
const { AfterSaleSubType } = this.ctx.model;
|
||||
const type = String(params.type || '').trim();
|
||||
const subType = String(params.subType || '').trim();
|
||||
const name = String(params.name || '').trim();
|
||||
if (!type || !subType || !name) throw new Error('type/subType/name 不能为空');
|
||||
if (subType.length > 50 || name.length > 50) throw new Error('subType/name 超长(≤50)');
|
||||
// 自定义子类型可挂在系统级类型或本仓库自定义类型下:父类型只需存在且可见即可;
|
||||
// 子类型自身始终写 warehouse_id=当前仓库 + is_system=0,因此后续配置全部可写。
|
||||
const Op = this._op();
|
||||
const parent = await this.ctx.model.AfterSaleType.findOne({
|
||||
where: { type, [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] },
|
||||
raw: true,
|
||||
});
|
||||
if (!parent) throw new Error(`类型 ${type} 不存在`);
|
||||
const exist = await AfterSaleSubType.findOne({ where: { type, sub_type: subType, warehouse_id: this.wid }, raw: true });
|
||||
if (exist) throw new Error(`子类型 ${type}:${subType} 已存在`);
|
||||
const row = await AfterSaleSubType.create({
|
||||
warehouse_id: this.wid, type, sub_type: subType, name, is_system: 0, is_enabled: 1,
|
||||
sort_order: Number(params.sortOrder) || 0,
|
||||
});
|
||||
await this._invalidate();
|
||||
return { id: row.id, message: '创建成功' };
|
||||
}
|
||||
|
||||
async _subTypeUpdate(params = {}) {
|
||||
const row = await this._assertWritableSubType(params.id, '子类型');
|
||||
const patch = {};
|
||||
if (params.name !== undefined) {
|
||||
const name = String(params.name || '').trim();
|
||||
if (!name) throw new Error('name 不能为空');
|
||||
patch.name = name.slice(0, 50);
|
||||
}
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') patch.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
if (params.sortOrder !== undefined) patch.sort_order = Number(params.sortOrder) || 0;
|
||||
if (Object.keys(patch).length === 0) throw new Error('无可更新字段');
|
||||
await this.ctx.model.AfterSaleSubType.update(patch, { where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '更新成功' };
|
||||
}
|
||||
|
||||
async _subTypeDelete(params = {}) {
|
||||
const { ctx } = this;
|
||||
const row = await this._assertWritableSubType(params.id, '子类型');
|
||||
// 级联清理关联(关键词/函数关联/取号关联/群白名单/回复),避免逐个手动清理
|
||||
const t = await this.ctx.model.transaction();
|
||||
const counts = {};
|
||||
try {
|
||||
counts.keyword = await ctx.model.AfterSaleKeyword.destroy({ where: { sub_type_id: row.id }, transaction: t });
|
||||
counts.function = await ctx.model.AfterSaleSubTypeFunction.destroy({ where: { sub_type_id: row.id }, transaction: t });
|
||||
counts.rule = await ctx.model.AfterSaleSubTypeRule.destroy({ where: { sub_type_id: row.id }, transaction: t });
|
||||
counts.group = await ctx.model.AfterSaleSubTypeGroup.destroy({ where: { sub_type_id: row.id }, transaction: t });
|
||||
counts.reply = await ctx.model.AfterSaleReply.destroy({ where: { sub_type_id: row.id }, transaction: t });
|
||||
await ctx.model.AfterSaleSubType.destroy({ where: { id: row.id }, transaction: t });
|
||||
await t.commit();
|
||||
} catch (e) {
|
||||
await t.rollback();
|
||||
throw e;
|
||||
}
|
||||
await this._invalidate();
|
||||
return {
|
||||
message: `删除成功(已级联清理:关键词 ${counts.keyword}、函数关联 ${counts.function}、取号关联 ${counts.rule}、群白名单 ${counts.group}、回复 ${counts.reply})`,
|
||||
};
|
||||
}
|
||||
|
||||
// ─────────────────────────── 关键词 ───────────────────────────
|
||||
|
||||
get keyword() {
|
||||
const svc = this;
|
||||
return {
|
||||
list: params => svc._keywordList(params),
|
||||
create: params => svc._keywordCreate(params),
|
||||
update: params => svc._keywordUpdate(params),
|
||||
delete: params => svc._keywordDelete(params),
|
||||
};
|
||||
}
|
||||
|
||||
async _keywordList(params = {}) {
|
||||
const Op = this._op();
|
||||
const { page, pageSize } = this._page(params);
|
||||
const where = { [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] };
|
||||
if (params.subTypeId) where.sub_type_id = Number(params.subTypeId) || 0;
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') {
|
||||
where.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
}
|
||||
const { rows, count } = await this.ctx.model.AfterSaleKeyword.findAndCountAll({
|
||||
where, order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]],
|
||||
offset: (page - 1) * pageSize, limit: pageSize, raw: true,
|
||||
});
|
||||
return { list: rows, pagination: { page, pageSize, total: count } };
|
||||
}
|
||||
|
||||
/**
|
||||
* 同词查重(可见范围:系统级 + 本仓库)。
|
||||
* @param {string} keyword 关键词。
|
||||
* @param {number} [excludeId] 排除自身ID(更新场景)。
|
||||
* @return {Promise<string|null>} 重复时的提示文案(含所在级别与子类型),无重复返回 null。
|
||||
*/
|
||||
async _keywordDupDescribe(keyword, excludeId) {
|
||||
const Op = this._op();
|
||||
const rows = await this.ctx.model.AfterSaleKeyword.findAll({
|
||||
where: {
|
||||
keyword,
|
||||
[Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }],
|
||||
},
|
||||
attributes: [ 'id', 'sub_type_id', 'warehouse_id' ],
|
||||
raw: true,
|
||||
});
|
||||
const dup = rows.find(r => Number(r.id) !== Number(excludeId || 0));
|
||||
if (!dup) return null;
|
||||
const sub = await this.ctx.model.AfterSaleSubType.findOne({
|
||||
where: { id: dup.sub_type_id },
|
||||
attributes: [ 'type', 'sub_type', 'name' ],
|
||||
raw: true,
|
||||
});
|
||||
const level = dup.warehouse_id === null ? '系统级' : '本仓库';
|
||||
const rule = sub ? `${sub.type}:${sub.sub_type}(${sub.name})` : `子类型ID ${dup.sub_type_id}`;
|
||||
return `关键词「${keyword}」已存在于【${level}】${rule}下,不可重复添加`;
|
||||
}
|
||||
|
||||
async _keywordCreate(params = {}) {
|
||||
const { AfterSaleKeyword } = this.ctx.model;
|
||||
const subTypeId = Number(params.subTypeId) || 0;
|
||||
const keyword = String(params.keyword || '').trim();
|
||||
if (!subTypeId || !keyword) throw new Error('subTypeId 与 keyword 不能为空');
|
||||
if (keyword.length > 100) throw new Error('关键词超长(≤100)');
|
||||
// 关键词为仓库级数据(warehouse_id=当前仓库):允许绑定系统级子类型或本仓库自定义子类型,
|
||||
// 只校验子类型存在,不做「仓库自定义」限制(与 keyword.update / keyword.delete 的可写范围对齐)。
|
||||
const subType = await this._findSubType(subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
// 同词查重(系统级+本仓库),重复时提示在哪个规则(子类型)下
|
||||
const dupMsg = await this._keywordDupDescribe(keyword);
|
||||
if (dupMsg) throw new Error(dupMsg);
|
||||
const row = await AfterSaleKeyword.create({
|
||||
warehouse_id: this.wid, sub_type_id: subTypeId, keyword, is_system: 0, is_enabled: 1,
|
||||
sort_order: Number(params.sortOrder) || 0,
|
||||
});
|
||||
await this._invalidate();
|
||||
return { id: row.id, message: '创建成功' };
|
||||
}
|
||||
|
||||
async _keywordUpdate(params = {}) {
|
||||
const { AfterSaleKeyword } = this.ctx.model;
|
||||
const row = await AfterSaleKeyword.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('关键词不存在或不是本仓库自定义(系统级只读)');
|
||||
if (row.is_system === 1) throw new Error('系统预设关键词不可修改');
|
||||
const patch = {};
|
||||
if (params.keyword !== undefined) {
|
||||
const keyword = String(params.keyword || '').trim();
|
||||
if (!keyword) throw new Error('keyword 不能为空');
|
||||
const sliced = keyword.slice(0, 100);
|
||||
// 改词同样查重(排除自身),重复时提示在哪个规则(子类型)下
|
||||
const dupMsg = await this._keywordDupDescribe(sliced, row.id);
|
||||
if (dupMsg) throw new Error(dupMsg);
|
||||
patch.keyword = sliced;
|
||||
}
|
||||
if (params.subTypeId) {
|
||||
await this._assertWritableSubType(params.subTypeId, '子类型');
|
||||
patch.sub_type_id = Number(params.subTypeId);
|
||||
}
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') patch.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
if (params.sortOrder !== undefined) patch.sort_order = Number(params.sortOrder) || 0;
|
||||
if (Object.keys(patch).length === 0) throw new Error('无可更新字段');
|
||||
await AfterSaleKeyword.update(patch, { where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '更新成功' };
|
||||
}
|
||||
|
||||
async _keywordDelete(params = {}) {
|
||||
const { AfterSaleKeyword } = this.ctx.model;
|
||||
const row = await AfterSaleKeyword.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('关键词不存在或不是本仓库自定义(系统级只读)');
|
||||
if (row.is_system === 1) throw new Error('系统预设关键词不可删除');
|
||||
await AfterSaleKeyword.destroy({ where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '删除成功' };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 取号规则(全局只读) ───────────────────────────
|
||||
|
||||
get numberRule() {
|
||||
const svc = this;
|
||||
return { list: params => svc._numberRuleList(params) };
|
||||
}
|
||||
|
||||
async _numberRuleList() {
|
||||
const rows = await this.ctx.model.InboxNumberRule.findAll({
|
||||
order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]], raw: true,
|
||||
});
|
||||
return { list: rows };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 处理函数(代码同步权威,只允许开关/排序) ───────────────────────────
|
||||
|
||||
get function() {
|
||||
const svc = this;
|
||||
return {
|
||||
list: params => svc._functionList(params),
|
||||
update: params => svc._functionUpdate(params),
|
||||
};
|
||||
}
|
||||
|
||||
async _functionList(params = {}) {
|
||||
const Op = this._op();
|
||||
const where = {};
|
||||
if (params.isEnabled !== undefined && params.isEnabled !== null && params.isEnabled !== '') {
|
||||
where.is_enabled = Number(params.isEnabled) === 1 ? 1 : 0;
|
||||
}
|
||||
if (params.keyword) {
|
||||
const like = `%${String(params.keyword).trim()}%`;
|
||||
where[Op.or] = [{ function_code: { [Op.like]: like } }, { name: { [Op.like]: like } }];
|
||||
}
|
||||
const rows = await this.ctx.model.AfterSaleFunction.findAll({
|
||||
where, order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]], raw: true,
|
||||
});
|
||||
// 附上代码注册表中是否存在(便于识别已下线函数)
|
||||
let registry = null;
|
||||
try {
|
||||
registry = this.ctx.service.inbox.functions.registry;
|
||||
} catch (e) { /* ignore */ }
|
||||
return {
|
||||
list: rows.map(r => ({
|
||||
...r,
|
||||
in_registry: registry instanceof Map ? registry.has(r.function_code) : null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
async _functionUpdate(params = {}) {
|
||||
const { AfterSaleFunction } = this.ctx.model;
|
||||
const row = await AfterSaleFunction.findOne({ where: { id: Number(params.id) || 0 }, raw: true });
|
||||
if (!row) throw new Error('函数不存在');
|
||||
const patch = {};
|
||||
// 启用状态硬编码(代码注册表存在即启用),接口只允许调整排序
|
||||
if (params.sortOrder !== undefined) patch.sort_order = Number(params.sortOrder) || 0;
|
||||
if (Object.keys(patch).length === 0) throw new Error('只允许更新 sortOrder(是否启用由代码硬编码,不做接口配置)');
|
||||
await AfterSaleFunction.update(patch, { where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '更新成功' };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 回复 ───────────────────────────
|
||||
|
||||
get reply() {
|
||||
const svc = this;
|
||||
return {
|
||||
create: params => svc._replyCreate(params),
|
||||
update: params => svc._replyUpdate(params),
|
||||
delete: params => svc._replyDelete(params),
|
||||
// 推荐接口:保存(upsert)/ 还原(删除仓库级,回退系统级)
|
||||
save: params => svc._replySave(params),
|
||||
restore: params => svc._replyRestore(params),
|
||||
merged: params => svc._replyMerged(params),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存仓库级回复配置(upsert):按传入字段保存,未传字段保持原值;
|
||||
* 无仓库级配置时按传入字段创建(默认 reply 空、is_reply=1、create_work_order=1)。
|
||||
* 停用即回退系统级语义由 restore 承担,不再提供 isEnabled 开关。
|
||||
* @param {Object} params 请求参数。
|
||||
* @return {Promise<Object>} 保存结果。
|
||||
*/
|
||||
async _replySave(params = {}) {
|
||||
const { AfterSaleReply } = this.ctx.model;
|
||||
const subTypeId = Number(params.subTypeId) || 0;
|
||||
if (!subTypeId) throw new Error('subTypeId 不能为空');
|
||||
const subType = await this._findSubType(subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
|
||||
const patch = {};
|
||||
if (params.reply !== undefined && params.reply !== null) patch.reply = String(params.reply).slice(0, 2000);
|
||||
if (params.isReply !== undefined && params.isReply !== null && params.isReply !== '') patch.is_reply = Number(params.isReply) === 0 ? 0 : 1;
|
||||
if (params.createWorkOrder !== undefined && params.createWorkOrder !== null && params.createWorkOrder !== '') patch.create_work_order = Number(params.createWorkOrder) === 0 ? 0 : 1;
|
||||
if (params.noNumberHint !== undefined && params.noNumberHint !== null) patch.no_number_hint = params.noNumberHint ? String(params.noNumberHint).slice(0, 500) : null;
|
||||
|
||||
const exist = await AfterSaleReply.findOne({
|
||||
where: { warehouse_id: this.wid, sub_type_id: subTypeId },
|
||||
raw: true,
|
||||
});
|
||||
if (exist) {
|
||||
if (Object.keys(patch).length > 0) {
|
||||
await AfterSaleReply.update(patch, { where: { id: exist.id } });
|
||||
}
|
||||
} else {
|
||||
await AfterSaleReply.create({
|
||||
warehouse_id: this.wid,
|
||||
sub_type_id: subTypeId,
|
||||
reply: patch.reply !== undefined ? patch.reply : '',
|
||||
is_reply: patch.is_reply !== undefined ? patch.is_reply : 1,
|
||||
create_work_order: patch.create_work_order !== undefined ? patch.create_work_order : 1,
|
||||
no_number_hint: patch.no_number_hint !== undefined ? patch.no_number_hint : null,
|
||||
is_enabled: 1,
|
||||
});
|
||||
}
|
||||
await this._invalidate();
|
||||
return {
|
||||
id: exist ? exist.id : null,
|
||||
message: exist ? '保存成功' : '创建成功',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原仓库级回复配置:删除仓库级行,回退到系统级配置。
|
||||
* @param {Object} params 请求参数。
|
||||
* @return {Promise<Object>} 还原结果。
|
||||
*/
|
||||
async _replyRestore(params = {}) {
|
||||
const { AfterSaleReply } = this.ctx.model;
|
||||
const subTypeId = Number(params.subTypeId) || 0;
|
||||
if (!subTypeId) throw new Error('subTypeId 不能为空');
|
||||
const row = await AfterSaleReply.findOne({
|
||||
where: { warehouse_id: this.wid, sub_type_id: subTypeId },
|
||||
raw: true,
|
||||
});
|
||||
if (row) {
|
||||
await AfterSaleReply.destroy({ where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '已还原为系统级配置' };
|
||||
}
|
||||
return { message: '本仓库无自定义回复配置,已是系统级配置' };
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复配置(合并后生效配置):以全部有效子类型(系统级+本仓库)为基底,
|
||||
* 每个子类型只返回一条「生效配置」:本仓库有自定义则整行覆盖系统级;
|
||||
* 无任何回复配置行的子类型返回初始值(reply={back_text}、is_reply=1、create_work_order=1、
|
||||
* no_number_hint 按取号规则:express_name→快递提示、有其他规则→运单号提示、无规则→空),
|
||||
* 保证任何仓库都有完整列表。无启用状态字段:停用即回退系统级由 restore 承担。
|
||||
* @param {Object} params 请求参数。
|
||||
* @return {Promise<Object>} { merged, total } 合并后生效配置数组与总数。
|
||||
*/
|
||||
async _replyMerged(params = {}) {
|
||||
const Op = this._op();
|
||||
const wh = { [Op.or]: [{ warehouse_id: null }, { warehouse_id: this.wid }] };
|
||||
// 拉全量(系统级+本仓库级)在内存合并,数据量小
|
||||
const [ rows, subs, ruleRelRows, ruleRows ] = await Promise.all([
|
||||
this.ctx.model.AfterSaleReply.findAll({
|
||||
where: wh,
|
||||
order: [[ 'sub_type_id', 'ASC' ], [ 'warehouse_id', 'ASC' ]],
|
||||
raw: true,
|
||||
}),
|
||||
this.ctx.model.AfterSaleSubType.findAll({
|
||||
where: wh,
|
||||
attributes: [ 'id', 'type', 'sub_type', 'name', 'warehouse_id' ],
|
||||
raw: true,
|
||||
}),
|
||||
this.ctx.model.AfterSaleSubTypeRule.findAll({
|
||||
attributes: [ 'sub_type_id', 'number_rule_id' ],
|
||||
raw: true,
|
||||
}),
|
||||
this.ctx.model.InboxNumberRule.findAll({
|
||||
attributes: [ 'id', 'target' ],
|
||||
raw: true,
|
||||
}),
|
||||
]);
|
||||
const ruleTargets = {};
|
||||
for (const n of ruleRows) ruleTargets[n.id] = n.target;
|
||||
const subTargets = {};
|
||||
for (const rel of ruleRelRows) {
|
||||
const t = ruleTargets[rel.number_rule_id];
|
||||
if (!t) continue;
|
||||
if (!subTargets[rel.sub_type_id]) subTargets[rel.sub_type_id] = [];
|
||||
if (!subTargets[rel.sub_type_id].includes(t)) subTargets[rel.sub_type_id].push(t);
|
||||
}
|
||||
const initialHint = st => {
|
||||
const ts = subTargets[st.id] || [];
|
||||
if (ts.includes('express_name')) {
|
||||
return '请指定目标快递(圆通/中通/申通/顺丰/韵达/极兔/邮政/EMS/京东/德邦)';
|
||||
}
|
||||
return ts.length > 0 ? '请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔)' : '';
|
||||
};
|
||||
const mergedMap = new Map();
|
||||
for (const r of rows) {
|
||||
const isWh = r.warehouse_id !== null && r.warehouse_id !== undefined;
|
||||
const existing = mergedMap.get(r.sub_type_id);
|
||||
if (!existing || (isWh && !existing._wh)) {
|
||||
mergedMap.set(r.sub_type_id, { ...r, _wh: isWh });
|
||||
}
|
||||
}
|
||||
const subMap = {};
|
||||
for (const s of subs) subMap[s.id] = s;
|
||||
const toRow = (st, r) => ({
|
||||
id: r ? r.id : null,
|
||||
sub_type_id: st.id,
|
||||
type: String(st.type || ''),
|
||||
sub_type: String(st.sub_type || ''),
|
||||
sub_type_name: String(st.name || ''),
|
||||
warehouse_id: r ? (r._wh ? r.warehouse_id : null) : (st.warehouse_id === null || st.warehouse_id === undefined ? null : this.wid),
|
||||
is_custom: r ? (r._wh ? 1 : 0) : (st.warehouse_id === null || st.warehouse_id === undefined ? 0 : 1),
|
||||
reply: r ? String(r.reply || '') : '{back_text}',
|
||||
is_reply: r ? (Number(r.is_reply) === 1 ? 1 : 0) : 1,
|
||||
create_work_order: r ? (Number(r.create_work_order) === 0 ? 0 : 1) : 1,
|
||||
no_number_hint: r ? (r.no_number_hint ? String(r.no_number_hint) : '') : initialHint(st),
|
||||
created_at: r ? r.created_at : null,
|
||||
updated_at: r ? r.updated_at : null,
|
||||
});
|
||||
let list = subs.map(st => {
|
||||
const r = mergedMap.get(st.id);
|
||||
return toRow(st, r);
|
||||
});
|
||||
if (params.subTypeId) {
|
||||
const sid = Number(params.subTypeId) || 0;
|
||||
list = list.filter(x => x.sub_type_id === sid);
|
||||
}
|
||||
const total = list.length;
|
||||
return { merged: list, total };
|
||||
}
|
||||
|
||||
async _replyCreate(params = {}) {
|
||||
const { AfterSaleReply } = this.ctx.model;
|
||||
const subTypeId = Number(params.subTypeId) || 0;
|
||||
const reply = String(params.reply || '');
|
||||
if (!subTypeId) throw new Error('subTypeId 不能为空');
|
||||
if (!reply) throw new Error('reply 不能为空');
|
||||
// 允许系统级子类型:仓库级回复的语义就是覆盖系统级配置(读取时仓库级优先)
|
||||
const subType = await this._findSubType(subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
const exist = await AfterSaleReply.findOne({ where: { warehouse_id: this.wid, sub_type_id: subTypeId }, raw: true });
|
||||
if (exist) throw new Error('该子类型已有仓库级回复,请用更新');
|
||||
const row = await AfterSaleReply.create({
|
||||
warehouse_id: this.wid, sub_type_id: subTypeId, reply,
|
||||
is_reply: Number(params.isReply) === 0 ? 0 : 1,
|
||||
create_work_order: Number(params.createWorkOrder) === 0 ? 0 : 1,
|
||||
no_number_hint: params.noNumberHint ? String(params.noNumberHint).slice(0, 500) : null,
|
||||
is_enabled: 1,
|
||||
});
|
||||
await this._invalidate();
|
||||
return { id: row.id, message: '创建成功' };
|
||||
}
|
||||
|
||||
async _replyUpdate(params = {}) {
|
||||
const { AfterSaleReply } = this.ctx.model;
|
||||
const row = await AfterSaleReply.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('回复配置不存在或不是本仓库的(系统级回复只读)');
|
||||
const patch = {};
|
||||
if (params.reply !== undefined) {
|
||||
const reply = String(params.reply || '');
|
||||
if (!reply) throw new Error('reply 不能为空');
|
||||
patch.reply = reply;
|
||||
}
|
||||
if (params.isReply !== undefined && params.isReply !== null && params.isReply !== '') patch.is_reply = Number(params.isReply) === 1 ? 1 : 0;
|
||||
if (params.createWorkOrder !== undefined && params.createWorkOrder !== null && params.createWorkOrder !== '') patch.create_work_order = Number(params.createWorkOrder) === 1 ? 1 : 0;
|
||||
if (params.noNumberHint !== undefined) {
|
||||
patch.no_number_hint = params.noNumberHint ? String(params.noNumberHint).slice(0, 500) : null;
|
||||
}
|
||||
if (Object.keys(patch).length === 0) throw new Error('无可更新字段');
|
||||
await AfterSaleReply.update(patch, { where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '更新成功' };
|
||||
}
|
||||
|
||||
async _replyDelete(params = {}) {
|
||||
const { AfterSaleReply } = this.ctx.model;
|
||||
const row = await AfterSaleReply.findOne({ where: { id: Number(params.id) || 0, warehouse_id: this.wid }, raw: true });
|
||||
if (!row) throw new Error('回复配置不存在或不是本仓库的(系统级回复只读)');
|
||||
await AfterSaleReply.destroy({ where: { id: row.id } });
|
||||
await this._invalidate();
|
||||
return { message: '删除成功' };
|
||||
}
|
||||
|
||||
// ─────────────────────────── 关联关系(set=全量替换,仅本仓库自定义子类型可写) ───────────────────────────
|
||||
|
||||
get relation() {
|
||||
const svc = this;
|
||||
return {
|
||||
function: {
|
||||
list: params => svc._relFunctionList(params),
|
||||
set: params => svc._relFunctionSet(params),
|
||||
},
|
||||
rule: {
|
||||
list: params => svc._relRuleList(params),
|
||||
set: params => svc._relRuleSet(params),
|
||||
},
|
||||
group: {
|
||||
list: params => svc._relGroupList(params),
|
||||
set: params => svc._relGroupSet(params),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async _relFunctionList(params = {}) {
|
||||
const subType = await this._findSubType(params.subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
const rows = await this.ctx.model.AfterSaleSubTypeFunction.findAll({
|
||||
where: { sub_type_id: subType.id },
|
||||
order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]], raw: true,
|
||||
});
|
||||
return { list: rows };
|
||||
}
|
||||
|
||||
async _relFunctionSet(params = {}) {
|
||||
const subType = await this._assertWritableSubType(params.subTypeId, '子类型');
|
||||
const items = Array.isArray(params.items) ? params.items : [];
|
||||
const funcRows = await this.ctx.model.AfterSaleFunction.findAll({ attributes: [ 'id' ], raw: true });
|
||||
const validIds = new Set(funcRows.map(r => r.id));
|
||||
const t = await this.ctx.model.transaction();
|
||||
try {
|
||||
await this.ctx.model.AfterSaleSubTypeFunction.destroy({ where: { sub_type_id: subType.id }, transaction: t });
|
||||
let order = 0;
|
||||
for (const item of items) {
|
||||
const fid = Number(item.functionId) || 0;
|
||||
if (!validIds.has(fid)) continue;
|
||||
await this.ctx.model.AfterSaleSubTypeFunction.create({
|
||||
sub_type_id: subType.id, function_id: fid,
|
||||
sort_order: Number(item.sortOrder) || order,
|
||||
}, { transaction: t });
|
||||
order += 1;
|
||||
}
|
||||
await t.commit();
|
||||
} catch (e) {
|
||||
await t.rollback();
|
||||
throw e;
|
||||
}
|
||||
await this._invalidate();
|
||||
return { message: '关联已更新' };
|
||||
}
|
||||
|
||||
async _relRuleList(params = {}) {
|
||||
const subType = await this._findSubType(params.subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
const rows = await this.ctx.model.AfterSaleSubTypeRule.findAll({
|
||||
where: { sub_type_id: subType.id },
|
||||
order: [[ 'sort_order', 'ASC' ], [ 'id', 'ASC' ]], raw: true,
|
||||
});
|
||||
return { list: rows };
|
||||
}
|
||||
|
||||
async _relRuleSet(params = {}) {
|
||||
const subType = await this._assertWritableSubType(params.subTypeId, '子类型');
|
||||
const items = Array.isArray(params.items) ? params.items : [];
|
||||
const ruleRows = await this.ctx.model.InboxNumberRule.findAll({ attributes: [ 'id' ], raw: true });
|
||||
const validIds = new Set(ruleRows.map(r => r.id));
|
||||
const t = await this.ctx.model.transaction();
|
||||
try {
|
||||
await this.ctx.model.AfterSaleSubTypeRule.destroy({ where: { sub_type_id: subType.id }, transaction: t });
|
||||
let order = 0;
|
||||
for (const item of items) {
|
||||
const rid = Number(item.ruleId) || 0;
|
||||
if (!validIds.has(rid)) continue;
|
||||
await this.ctx.model.AfterSaleSubTypeRule.create({
|
||||
sub_type_id: subType.id, number_rule_id: rid,
|
||||
sort_order: Number(item.sortOrder) || order,
|
||||
}, { transaction: t });
|
||||
order += 1;
|
||||
}
|
||||
await t.commit();
|
||||
} catch (e) {
|
||||
await t.rollback();
|
||||
throw e;
|
||||
}
|
||||
await this._invalidate();
|
||||
return { message: '关联已更新' };
|
||||
}
|
||||
|
||||
async _relGroupList(params = {}) {
|
||||
const subType = await this._findSubType(params.subTypeId);
|
||||
if (!subType) throw new Error('子类型不存在');
|
||||
const rows = await this.ctx.model.AfterSaleSubTypeGroup.findAll({
|
||||
where: { sub_type_id: subType.id },
|
||||
order: [[ 'group_type', 'ASC' ], [ 'sub_group', 'ASC' ], [ 'id', 'ASC' ]], raw: true,
|
||||
});
|
||||
return { list: rows };
|
||||
}
|
||||
|
||||
async _relGroupSet(params = {}) {
|
||||
const subType = await this._assertWritableSubType(params.subTypeId, '子类型');
|
||||
const items = Array.isArray(params.items) ? params.items : [];
|
||||
const { AfterSaleSubTypeGroup } = this.ctx.model;
|
||||
const validTypes = [ 'store', 'warehouse', 'express', '*' ];
|
||||
const t = await this.ctx.model.transaction();
|
||||
try {
|
||||
// 系统预设行(is_system=1)不可删:保留并合并
|
||||
const sysRows = await AfterSaleSubTypeGroup.findAll({
|
||||
where: { sub_type_id: subType.id, is_system: 1 }, raw: true, transaction: t,
|
||||
});
|
||||
await AfterSaleSubTypeGroup.destroy({ where: { sub_type_id: subType.id, is_system: 0 }, transaction: t });
|
||||
const seen = new Set();
|
||||
for (const row of sysRows) {
|
||||
seen.add(`${row.group_type}:${row.sub_group}`);
|
||||
}
|
||||
// 通配覆盖:groupType='*' 覆盖所有具体类型行;主类型内 subGroup='*' 覆盖该主类型其他具体行
|
||||
const norm = items
|
||||
.map(it => ({
|
||||
gt: String(it.groupType || '').trim(),
|
||||
sg: String(it.subGroup || '').trim(),
|
||||
so: Number(it.sortOrder) || 0,
|
||||
}))
|
||||
.filter(x => validTypes.includes(x.gt));
|
||||
const hasWildcardAll = norm.some(x => x.gt === '*');
|
||||
const wildcardTypes = new Set(norm.filter(x => x.gt !== '*' && x.sg === '*').map(x => x.gt));
|
||||
for (const { gt, sg: rawSg, so } of norm) {
|
||||
let sg = rawSg;
|
||||
if (gt === '*') sg = ''; // 全通配时子类型无意义,归一化为空
|
||||
if (hasWildcardAll && gt !== '*') continue; // 有全部时覆盖掉对应类型
|
||||
if (gt !== '*' && wildcardTypes.has(gt) && sg !== '*') continue; // 主类型内通配覆盖具体行
|
||||
const key = `${gt}:${sg}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
await AfterSaleSubTypeGroup.create({
|
||||
sub_type_id: subType.id, group_type: gt, sub_group: sg,
|
||||
is_system: 0, sort_order: so,
|
||||
}, { transaction: t });
|
||||
}
|
||||
await t.commit();
|
||||
} catch (e) {
|
||||
await t.rollback();
|
||||
throw e;
|
||||
}
|
||||
await this._invalidate();
|
||||
return { message: '关联已更新' };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InboxV2ConfigManageService;
|
||||
@ -861,30 +861,37 @@ class ReturnUnpackService extends Service {
|
||||
const queryWhere = this._buildListWhere(where, Op);
|
||||
const order = this._buildListOrder(sort, 'return_unpack');
|
||||
|
||||
const { count, rows } = await ctx.model.ReturnUnpack.findAndCountAll({
|
||||
where: queryWhere,
|
||||
order,
|
||||
offset: (page - 1) * pageSize,
|
||||
limit: pageSize,
|
||||
raw: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.ReturnUnpackVideo,
|
||||
as: 'videos',
|
||||
attributes: [ 'id', 'video_url', 'camera_id', 'status' ],
|
||||
where: { deleted_at: null },
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.Camera,
|
||||
as: 'camera',
|
||||
attributes: [ 'id', 'custom_name', 'channel_name' ],
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
// 性能与准确性:count 与 rows 分离。findAndCountAll 携带 hasMany include(videos)时,
|
||||
// Sequelize 生成的是 COUNT(ReturnUnpack.id) + LEFT JOIN 视频表,等于「主表行 × 命中视频条数」,
|
||||
// 会把 total 放大(生产实测 8483 条拆包单被统计成 16961,与 export 口径对不上),
|
||||
// 拆开后 count 走单表条件(与 exportUnpack 的 total_count 完全一致),性能也更好。
|
||||
const count = await ctx.model.ReturnUnpack.count({ where: queryWhere });
|
||||
const rows = count === 0
|
||||
? []
|
||||
: await ctx.model.ReturnUnpack.findAll({
|
||||
where: queryWhere,
|
||||
order,
|
||||
offset: (page - 1) * pageSize,
|
||||
limit: pageSize,
|
||||
raw: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.ReturnUnpackVideo,
|
||||
as: 'videos',
|
||||
attributes: [ 'id', 'video_url', 'camera_id', 'status' ],
|
||||
where: { deleted_at: null },
|
||||
required: false,
|
||||
include: [
|
||||
{
|
||||
model: ctx.model.Camera,
|
||||
as: 'camera',
|
||||
attributes: [ 'id', 'custom_name', 'channel_name' ],
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const list = [];
|
||||
for (const row of rows) {
|
||||
@ -1644,6 +1651,23 @@ class ReturnUnpackService extends Service {
|
||||
video.video_url = this._buildVideoUrl(warehouseId, recordingComputerId, video.video_url);
|
||||
}
|
||||
|
||||
// 附加摄像头名称(系统设置的自定义名称优先,通道原始名称兜底)
|
||||
const videoCameraIds = [ ...new Set(videos.map(v => v.camera_id).filter(id => id)) ];
|
||||
const cameraNameMap = new Map();
|
||||
if (videoCameraIds.length > 0) {
|
||||
const cameras = await ctx.model.Camera.findAll({
|
||||
attributes: [ 'id', 'custom_name', 'channel_name' ],
|
||||
where: { id: { [Op.in]: videoCameraIds } },
|
||||
raw: true,
|
||||
});
|
||||
for (const camera of cameras) {
|
||||
cameraNameMap.set(Number(camera.id), String(camera.custom_name || camera.channel_name || '').trim());
|
||||
}
|
||||
}
|
||||
for (const video of videos) {
|
||||
video.camera_name = video.camera_id ? (cameraNameMap.get(Number(video.camera_id)) || '') : '';
|
||||
}
|
||||
|
||||
let received = null;
|
||||
if (unpack.return_received_id) {
|
||||
received = await ctx.model.ReturnReceived.findOne({
|
||||
@ -2875,7 +2899,13 @@ class ReturnUnpackService extends Service {
|
||||
const allowed = scene === 'return_unpack_detail' ? detailFields : mainFields;
|
||||
const safeSortField = allowed.has(sortField) ? sortField : 'created_at';
|
||||
|
||||
return [[ safeSortField, sortOrder ]];
|
||||
// 追加主键作为次级排序:排序键可能并列(如 created_at 精确到秒,生产存在同秒多条),
|
||||
// 并列时 MySQL 返回顺序不稳定,list 翻页与 export 的 offset 分页会出现重复/漏行。
|
||||
const order = [[ safeSortField, sortOrder ]];
|
||||
if (safeSortField !== 'id') {
|
||||
order.push([ 'id', sortOrder ]);
|
||||
}
|
||||
return order;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
123
database/migrations/20260918000000-seed-help-instruction.js
Normal file
123
database/migrations/20260918000000-seed-help-instruction.js
Normal file
@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 播种 v2 系统级「帮助 → 指令」链路(幂等,先查后插)。
|
||||
*
|
||||
* - wms_after_sale_type:系统级 type=help(帮助)
|
||||
* - wms_after_sale_sub_type:系统级 type=help / sub_type=instruction(指令)
|
||||
* - wms_after_sale_keyword:系统级关键词「指令」「帮助」→ instruction
|
||||
* - wms_after_sale_function:插入 code=help 函数行(后续启动 sync 会刷新 name/description/is_enabled)
|
||||
* - wms_after_sale_sub_type_function:instruction ↔ help 函数关联
|
||||
* - wms_after_sale_sub_type_group:help 子类型白名单(store.after_sales / warehouse.customer_service / express.after_sales)
|
||||
* - wms_after_sale_reply:系统级回复模板「支持以下命令:\n{back_text}」(仓库可自定义覆盖)
|
||||
*
|
||||
* help 子类型无需取号规则(不关联),help 函数由代码注册表硬编码启用。
|
||||
*/
|
||||
|
||||
const TYPE_TABLE = 'wms_after_sale_type';
|
||||
const SUB_TYPE_TABLE = 'wms_after_sale_sub_type';
|
||||
const KEYWORD_TABLE = 'wms_after_sale_keyword';
|
||||
const FUNCTION_TABLE = 'wms_after_sale_function';
|
||||
const REL_FN_TABLE = 'wms_after_sale_sub_type_function';
|
||||
const REL_GROUP_TABLE = 'wms_after_sale_sub_type_group';
|
||||
const REPLY_TABLE = 'wms_after_sale_reply';
|
||||
|
||||
module.exports = {
|
||||
up: async queryInterface => {
|
||||
const { sequelize } = queryInterface;
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
|
||||
if (!exists(SUB_TYPE_TABLE)) return;
|
||||
|
||||
const q1 = async (sql, replacements) => {
|
||||
const [ rows ] = await sequelize.query(sql, { replacements });
|
||||
return rows && rows.length > 0 ? rows[0] : null;
|
||||
};
|
||||
|
||||
// ─── 1. 系统级类型 help ─────────────────────────────────────
|
||||
if (exists(TYPE_TABLE) && !(await q1('SELECT id FROM `' + TYPE_TABLE + '` WHERE type = :t AND warehouse_id IS NULL LIMIT 1', { t: 'help' }))) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + TYPE_TABLE + '` (warehouse_id, type, name, is_system, is_enabled, sort_order, created_at, updated_at) VALUES (NULL, :t, :n, 1, 1, 100, NOW(), NOW())',
|
||||
{ replacements: { t: 'help', n: '帮助' } }
|
||||
);
|
||||
}
|
||||
|
||||
// ─── 2. 系统级子类型 instruction ────────────────────────────
|
||||
let subId = await q1('SELECT id FROM `' + SUB_TYPE_TABLE + '` WHERE type = :t AND sub_type = :s AND warehouse_id IS NULL LIMIT 1', { t: 'help', s: 'instruction' });
|
||||
if (!subId) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + SUB_TYPE_TABLE + '` (warehouse_id, type, sub_type, name, is_system, is_enabled, sort_order, created_at, updated_at) VALUES (NULL, :t, :s, :n, 1, 1, 0, NOW(), NOW())',
|
||||
{ replacements: { t: 'help', s: 'instruction', n: '指令' } }
|
||||
);
|
||||
subId = await q1('SELECT id FROM `' + SUB_TYPE_TABLE + '` WHERE type = :t AND sub_type = :s AND warehouse_id IS NULL LIMIT 1', { t: 'help', s: 'instruction' });
|
||||
}
|
||||
const instructionId = subId.id;
|
||||
|
||||
// ─── 3. 系统级关键词「指令」「帮助」 ─────────────────────────
|
||||
if (exists(KEYWORD_TABLE)) {
|
||||
let order = 0;
|
||||
for (const kw of [ '指令', '帮助' ]) {
|
||||
const dup = await q1('SELECT id FROM `' + KEYWORD_TABLE + '` WHERE keyword = :k AND warehouse_id IS NULL LIMIT 1', { k: kw });
|
||||
if (!dup) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + KEYWORD_TABLE + '` (warehouse_id, sub_type_id, keyword, is_system, is_enabled, sort_order, created_at, updated_at) VALUES (NULL, :sid, :k, 1, 1, :so, NOW(), NOW())',
|
||||
{ replacements: { sid: instructionId, k: kw, so: order } }
|
||||
);
|
||||
}
|
||||
order += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 4. help 函数行(sync 启动后刷新 name/description/is_enabled) ───
|
||||
let helpFn = null;
|
||||
if (exists(FUNCTION_TABLE)) {
|
||||
helpFn = await q1('SELECT id FROM `' + FUNCTION_TABLE + '` WHERE function_code = :c LIMIT 1', { c: 'help' });
|
||||
if (!helpFn) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + FUNCTION_TABLE + '` (function_code, name, description, is_enabled, sort_order, created_at, updated_at) VALUES (:c, :n, :d, 1, 0, NOW(), NOW())',
|
||||
{ replacements: { c: 'help', n: '帮助', d: '帮助指令:枚举当前仓库可见的售后类型与子类型(含关键词),返回可用指令清单(back_text)' } }
|
||||
);
|
||||
helpFn = await q1('SELECT id FROM `' + FUNCTION_TABLE + '` WHERE function_code = :c LIMIT 1', { c: 'help' });
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 5. instruction ↔ help 函数关联 ─────────────────────────
|
||||
if (exists(REL_FN_TABLE) && helpFn) {
|
||||
const dup = await q1('SELECT id FROM `' + REL_FN_TABLE + '` WHERE sub_type_id = :s AND function_id = :f LIMIT 1', { s: instructionId, f: helpFn.id });
|
||||
if (!dup) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + REL_FN_TABLE + '` (sub_type_id, function_id, sort_order, created_at, updated_at) VALUES (:s, :f, 1, NOW(), NOW())',
|
||||
{ replacements: { s: instructionId, f: helpFn.id } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 6. help 子类型群白名单(三类群均可触发) ────────────────
|
||||
if (exists(REL_GROUP_TABLE)) {
|
||||
for (const [ gt, sg ] of [[ 'store', 'after_sales' ], [ 'warehouse', 'customer_service' ], [ 'express', 'after_sales' ]]) {
|
||||
const dup = await q1('SELECT id FROM `' + REL_GROUP_TABLE + '` WHERE sub_type_id = :s AND group_type = :g AND sub_group = :sg LIMIT 1', { s: instructionId, g: gt, sg });
|
||||
if (!dup) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + REL_GROUP_TABLE + '` (sub_type_id, group_type, sub_group, is_system, sort_order, created_at, updated_at) VALUES (:s, :g, :sg, 1, 0, NOW(), NOW())',
|
||||
{ replacements: { s: instructionId, g: gt, sg } }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 7. 系统级回复模板(仓库可自定义覆盖) ───────────────────
|
||||
if (exists(REPLY_TABLE)) {
|
||||
const dup = await q1('SELECT id FROM `' + REPLY_TABLE + '` WHERE sub_type_id = :s AND warehouse_id IS NULL LIMIT 1', { s: instructionId });
|
||||
if (!dup) {
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + REPLY_TABLE + '` (warehouse_id, sub_type_id, reply, is_reply, no_number_hint, is_enabled, created_at, updated_at) VALUES (NULL, :s, :r, 1, NULL, 1, NOW(), NOW())',
|
||||
{ replacements: { s: instructionId, r: '支持以下命令:\n{back_text}' } }
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(系统预设种子)
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* wms_after_sale_reply 增加 create_work_order 列(幂等)。
|
||||
*
|
||||
* 语义:是否登记工单。1=函数正常创建售后工单(默认);
|
||||
* 0=函数照常执行(符合入参即执行),但函数内部跳过工单登记
|
||||
* (引擎注入 ctx.inboxContext.skip_work_order 标记,建单函数在建单前检查)。
|
||||
*/
|
||||
|
||||
const TABLE = 'wms_after_sale_reply';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = tables.some(t => (typeof t === 'string' ? t : t.tableName) === TABLE);
|
||||
if (!exists) return;
|
||||
|
||||
const columns = await queryInterface.describeTable(TABLE);
|
||||
if (columns.create_work_order) return;
|
||||
|
||||
await queryInterface.addColumn(TABLE, 'create_work_order', {
|
||||
type: Sequelize.TINYINT(1),
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
comment: '是否登记工单:1=函数正常创建工单(默认),0=函数照常执行但内部跳过工单登记',
|
||||
after: 'is_reply',
|
||||
});
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(新列无副作用)
|
||||
},
|
||||
};
|
||||
47
database/migrations/20260918110000-seed-system-reply-all.js
Normal file
47
database/migrations/20260918110000-seed-system-reply-all.js
Normal file
@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 补齐全部系统级子类型的系统级回复配置(幂等,先查后插)。
|
||||
*
|
||||
* - 对每个系统级子类型(warehouse_id IS NULL)补一条系统级回复:
|
||||
* reply='{back_text}'(默认走函数返回内容兜底,help 类占位渲染),
|
||||
* is_reply=1(是否回复统一由回复配置控制)、create_work_order=1、is_enabled=1;
|
||||
* - 已存在回复配置的子类型跳过;
|
||||
* - 仓库自定义子类型不播种(由仓库自行创建仓库级回复)。
|
||||
*/
|
||||
|
||||
const SUB_TYPE_TABLE = 'wms_after_sale_sub_type';
|
||||
const REPLY_TABLE = 'wms_after_sale_reply';
|
||||
|
||||
module.exports = {
|
||||
up: async queryInterface => {
|
||||
const { sequelize } = queryInterface;
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
|
||||
if (!exists(SUB_TYPE_TABLE) || !exists(REPLY_TABLE)) return;
|
||||
|
||||
const [ subRows ] = await sequelize.query(
|
||||
'SELECT id FROM `' + SUB_TYPE_TABLE + '` WHERE warehouse_id IS NULL'
|
||||
);
|
||||
const [ replyRows ] = await sequelize.query(
|
||||
'SELECT sub_type_id FROM `' + REPLY_TABLE + '` WHERE warehouse_id IS NULL'
|
||||
);
|
||||
const hasReply = new Set(replyRows.map(r => Number(r.sub_type_id)));
|
||||
|
||||
let inserted = 0;
|
||||
for (const row of subRows) {
|
||||
const sid = Number(row.id);
|
||||
if (hasReply.has(sid)) continue;
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + REPLY_TABLE + '` (warehouse_id, sub_type_id, reply, is_reply, create_work_order, no_number_hint, is_enabled, created_at, updated_at) VALUES (NULL, :sid, :reply, 1, 1, NULL, 1, NOW(), NOW())',
|
||||
{ replacements: { sid, reply: '{back_text}' } }
|
||||
);
|
||||
inserted += 1;
|
||||
}
|
||||
console.log(`[seed-system-reply-all] inserted=${inserted}`);
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(系统预设种子)
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 补齐系统级回复配置的「取号失败引导语」基础配置(幂等,只填空值行)。
|
||||
*
|
||||
* 现状:系统级回复行 no_number_hint 全部为 NULL,取号失败时依赖代码内置默认值。
|
||||
* 本次把基础引导语写入系统级配置:
|
||||
* - 子类型关联了 target='express_name' 取号规则(如 change_carrier 改快递)→ 快递指定提示;
|
||||
* - 其余子类型 → 默认运单号提示。
|
||||
* 仓库级行不处理(留空时仍走代码兜底)。
|
||||
*/
|
||||
|
||||
const REPLY_TABLE = 'wms_after_sale_reply';
|
||||
const REL_TABLE = 'wms_after_sale_sub_type_rule';
|
||||
const RULE_TABLE = 'wms_inbox_number_rule';
|
||||
|
||||
const HINT_EXPRESS = '请指定目标快递(圆通/中通/申通/顺丰/韵达/极兔/邮政/EMS/京东/德邦)';
|
||||
const HINT_DEFAULT = '请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔)';
|
||||
|
||||
module.exports = {
|
||||
up: async queryInterface => {
|
||||
const { sequelize } = queryInterface;
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
|
||||
if (!exists(REPLY_TABLE)) return;
|
||||
|
||||
// 关联 express_name 取号规则的子类型集合
|
||||
let expressIds = new Set();
|
||||
if (exists(REL_TABLE) && exists(RULE_TABLE)) {
|
||||
const [ relRows ] = await sequelize.query(
|
||||
'SELECT DISTINCT rel.sub_type_id FROM `' + REL_TABLE + '` rel ' +
|
||||
'JOIN `' + RULE_TABLE + '` r ON r.id = rel.number_rule_id WHERE r.target = :t',
|
||||
{ replacements: { t: 'express_name' } }
|
||||
);
|
||||
expressIds = new Set(relRows.map(r => Number(r.sub_type_id)));
|
||||
}
|
||||
|
||||
const [ rows ] = await sequelize.query(
|
||||
'SELECT id, sub_type_id FROM `' + REPLY_TABLE + '` ' +
|
||||
'WHERE warehouse_id IS NULL AND (no_number_hint IS NULL OR no_number_hint = :empty)',
|
||||
{ replacements: { empty: '' } }
|
||||
);
|
||||
|
||||
let updated = 0;
|
||||
for (const row of rows) {
|
||||
const hint = expressIds.has(Number(row.sub_type_id)) ? HINT_EXPRESS : HINT_DEFAULT;
|
||||
await sequelize.query(
|
||||
'UPDATE `' + REPLY_TABLE + '` SET no_number_hint = :hint WHERE id = :id',
|
||||
{ replacements: { hint, id: row.id } }
|
||||
);
|
||||
updated += 1;
|
||||
}
|
||||
console.log(`[seed-system-no-number-hint] updated=${updated}`);
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(系统预设种子)
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 修正系统级「取号失败引导语」范围(幂等,按子类型取号规则重算):
|
||||
* - 子类型关联了 target='express_name' 取号规则(如 change_carrier)→ 快递指定提示;
|
||||
* - 子类型关联了其他取号规则 → 默认运单号提示;
|
||||
* - 子类型无任何取号规则(如 help 指令、无取号环节的类型)→ 清空(取号失败分支不会触发,展示空)。
|
||||
*/
|
||||
|
||||
const REPLY_TABLE = 'wms_after_sale_reply';
|
||||
const REL_TABLE = 'wms_after_sale_sub_type_rule';
|
||||
const RULE_TABLE = 'wms_inbox_number_rule';
|
||||
|
||||
const HINT_EXPRESS = '请指定目标快递(圆通/中通/申通/顺丰/韵达/极兔/邮政/EMS/京东/德邦)';
|
||||
const HINT_DEFAULT = '请提供运单号(发送:指令+运单号,多个单号用逗号或空格分隔)';
|
||||
|
||||
module.exports = {
|
||||
up: async queryInterface => {
|
||||
const { sequelize } = queryInterface;
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
|
||||
if (!exists(REPLY_TABLE)) return;
|
||||
|
||||
let expressIds = new Set();
|
||||
let ruleIds = new Set();
|
||||
if (exists(REL_TABLE) && exists(RULE_TABLE)) {
|
||||
const [ exRows ] = await sequelize.query(
|
||||
'SELECT DISTINCT rel.sub_type_id FROM `' + REL_TABLE + '` rel ' +
|
||||
'JOIN `' + RULE_TABLE + '` r ON r.id = rel.number_rule_id WHERE r.target = :t',
|
||||
{ replacements: { t: 'express_name' } }
|
||||
);
|
||||
expressIds = new Set(exRows.map(r => Number(r.sub_type_id)));
|
||||
const [ anyRows ] = await sequelize.query(
|
||||
'SELECT DISTINCT sub_type_id FROM `' + REL_TABLE + '`'
|
||||
);
|
||||
ruleIds = new Set(anyRows.map(r => Number(r.sub_type_id)));
|
||||
}
|
||||
|
||||
const [ rows ] = await sequelize.query(
|
||||
'SELECT id, sub_type_id FROM `' + REPLY_TABLE + '` WHERE warehouse_id IS NULL'
|
||||
);
|
||||
|
||||
let updated = 0;
|
||||
let cleared = 0;
|
||||
for (const row of rows) {
|
||||
const sid = Number(row.sub_type_id);
|
||||
let hint = null;
|
||||
if (expressIds.has(sid)) hint = HINT_EXPRESS;
|
||||
else if (ruleIds.has(sid)) hint = HINT_DEFAULT;
|
||||
if (hint === null) cleared += 1;
|
||||
await sequelize.query(
|
||||
'UPDATE `' + REPLY_TABLE + '` SET no_number_hint = :hint WHERE id = :id',
|
||||
{ replacements: { hint, id: row.id } }
|
||||
);
|
||||
updated += 1;
|
||||
}
|
||||
console.log(`[fix-no-number-hint-scope] updated=${updated} cleared=${cleared}`);
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(数据修正)
|
||||
},
|
||||
};
|
||||
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* help(指令)子类型群白名单改为通配:所有群都支持(幂等)。
|
||||
*
|
||||
* 原播种为 store.after_sales / warehouse.customer_service / express.after_sales 三条精确白名单,
|
||||
* 其他群子类型(如 store.receiving)无法触发指令。改为 group_type='*' 通配行,
|
||||
* 引擎 _groupAllowed 对 '*' 直接放行;help 函数 groups=[COMMON] 本身所有群可用。
|
||||
*/
|
||||
|
||||
const SUB_TYPE_TABLE = 'wms_after_sale_sub_type';
|
||||
const REL_GROUP_TABLE = 'wms_after_sale_sub_type_group';
|
||||
|
||||
module.exports = {
|
||||
up: async queryInterface => {
|
||||
const { sequelize } = queryInterface;
|
||||
const tables = await queryInterface.showAllTables();
|
||||
const exists = t => tables.some(x => (typeof x === 'string' ? x : x.tableName) === t);
|
||||
if (!exists(SUB_TYPE_TABLE) || !exists(REL_GROUP_TABLE)) return;
|
||||
|
||||
const q1 = async (sql, replacements) => {
|
||||
const [ rows ] = await sequelize.query(sql, { replacements });
|
||||
return rows && rows.length > 0 ? rows[0] : null;
|
||||
};
|
||||
|
||||
const sub = await q1(
|
||||
'SELECT id FROM `' + SUB_TYPE_TABLE + '` WHERE type = :t AND sub_type = :s AND warehouse_id IS NULL LIMIT 1',
|
||||
{ t: 'help', s: 'instruction' }
|
||||
);
|
||||
if (!sub) return;
|
||||
const sid = sub.id;
|
||||
|
||||
const wildcard = await q1(
|
||||
'SELECT id FROM `' + REL_GROUP_TABLE + '` WHERE sub_type_id = :s AND group_type = :g LIMIT 1',
|
||||
{ s: sid, g: '*' }
|
||||
);
|
||||
if (wildcard) {
|
||||
console.log('[help-whitelist-all-groups] 已存在通配白名单,跳过');
|
||||
return;
|
||||
}
|
||||
|
||||
const [ del ] = await sequelize.query(
|
||||
'DELETE FROM `' + REL_GROUP_TABLE + '` WHERE sub_type_id = :s',
|
||||
{ replacements: { s: sid } }
|
||||
);
|
||||
await sequelize.query(
|
||||
'INSERT INTO `' + REL_GROUP_TABLE + '` (sub_type_id, group_type, sub_group, is_system, sort_order, created_at, updated_at) VALUES (:s, :g, :sg, 1, 0, NOW(), NOW())',
|
||||
{ replacements: { s: sid, g: '*', sg: '' } }
|
||||
);
|
||||
console.log(`[help-whitelist-all-groups] deleted=${del.affectedRows || 0} inserted-wildcard=1`);
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// 不回退(语义修正)
|
||||
},
|
||||
};
|
||||
@ -1,4 +1,25 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.09.17-inbox-group-template-reply-switch",
|
||||
"date": "2026-09-17",
|
||||
"type": "enhance",
|
||||
"summary": "enhance: inbox.group 系列接口接入模板消息回复开关 templateReplyEnabled/template_reply_enabled(0=关闭(普通文本回复) / 1=开启(模板消息回复)),默认 0,所有群类型均支持且独立于 aiEnabled。update 新增入参(未传不修改),reset 重置为关闭,list 返回字段与 where 筛选支持、quickList 返回字段同步补全。",
|
||||
"methods": [
|
||||
"inbox.group.update",
|
||||
"inbox.group.reset",
|
||||
"inbox.group.list",
|
||||
"inbox.group.quickList"
|
||||
],
|
||||
"notes": [
|
||||
"字段落位:wms_inbox_group.template_reply_enabled(TINYINT(1) NOT NULL DEFAULT 0,迁移 database/migrations/20260917100000-add-template-reply-enabled-to-inbox-group.js,model app/model/inbox_group.js 已同步)",
|
||||
"语义:ai_enabled 控制是否 AI 处理;template_reply_enabled 控制命中处理后是否以模板消息形式回复(0=普通文本回复,1=模板消息回复),两开关相互独立",
|
||||
"update:data.templateReplyEnabled===1 时写 1,否则写 0,未传不修改;reset:清空配置时 template_reply_enabled 重置为 0;方法层 app/service/systemMethods/inbox.js#groupUpdate 透传",
|
||||
"list:attributes 与 where specialFieldMap 新增 template_reply_enabled(可筛选),返回行沿用 snake_case 风格(template_reply_enabled)与 ai_enabled 相邻",
|
||||
"quickList:轻量字段新增 template_reply_enabled,下拉选择可感知模板回信开关",
|
||||
"消费方:app/service/inbox/processor.js#loadGroupConfig 读取 template_reply_enabled,为 1 的群命中处理后走 inbox.v2.rules 可配置引擎(模板消息回复)",
|
||||
"文档版本 0.3.133 -> 0.3.134,updatedAt 2026-09-17"
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2026.09.16-inbox-push-retry-warehouse-setting",
|
||||
"date": "2026-09-16",
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
{
|
||||
"module": "system",
|
||||
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
|
||||
"version": "0.3.133",
|
||||
"updatedAt": "2026-09-16",
|
||||
"version": "0.3.134",
|
||||
"updatedAt": "2026-09-17",
|
||||
"headers": [
|
||||
{
|
||||
"name": "platform",
|
||||
@ -38980,7 +38980,7 @@
|
||||
"name": "list",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "群记录列表,含id/group_name/group_id/store_id/group_type/sub_type/is_blocked/ai_enabled/express_interfaces(数组)/system_express_code/created_at"
|
||||
"description": "群记录列表,含id/group_name/group_id/store_id/group_type/sub_type/is_blocked/ai_enabled/template_reply_enabled/express_interfaces(数组)/system_express_code/created_at"
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
@ -39040,7 +39040,7 @@
|
||||
},
|
||||
{
|
||||
"method": "inbox.group.update",
|
||||
"description": "修改群信息:群类型/子类型/货主/快递接口/系统快递编码/AI开关。子类型受群类型约束,合法取值见 groupType.list[].subTypes。aiEnabled支持灰度控制,切换为express类型时systemExpressCode必填",
|
||||
"description": "修改群信息:群类型/子类型/货主/快递接口/系统快递编码/AI开关/模板消息回复开关。子类型受群类型约束,合法取值见 groupType.list[].subTypes。aiEnabled支持灰度控制,templateReplyEnabled控制命中处理后是否以模板消息形式回复(独立于aiEnabled),切换为express类型时systemExpressCode必填",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -39168,6 +39168,13 @@
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "是否启用AI自动回复: 0=关闭 1=开启,默认1(所有群类型均支持,用于灰度测试)"
|
||||
},
|
||||
{
|
||||
"name": "templateReplyEnabled",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"source": "body",
|
||||
"description": "是否启用模板消息回复: 0=关闭(普通文本回复) 1=开启(模板消息回复),默认0(所有群类型均支持,独立于aiEnabled;开启后命中处理以模板消息形式回复)"
|
||||
}
|
||||
],
|
||||
"response": [
|
||||
@ -39191,7 +39198,7 @@
|
||||
},
|
||||
{
|
||||
"method": "inbox.group.reset",
|
||||
"description": "清空群类型配置:清空群类型/子类型/货主/快递接口/系统快递编码,AI开关重置关闭,仅保留群创建时信息(群名称/群ID/仓库/来源/屏蔽状态/扩展数据)。入参群记录主键ID",
|
||||
"description": "清空群类型配置:清空群类型/子类型/货主/快递接口/系统快递编码,AI开关与模板消息回复开关重置关闭,仅保留群创建时信息(群名称/群ID/仓库/来源/屏蔽状态/扩展数据)。入参群记录主键ID",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [
|
||||
@ -39356,7 +39363,7 @@
|
||||
"name": "list",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "群快速列表(按创建时间倒序,无分页),每项含 id/group_id/group_name/group_type/sub_type/is_blocked",
|
||||
"description": "群快速列表(按创建时间倒序,无分页),每项含 id/group_id/group_name/group_type/sub_type/is_blocked/template_reply_enabled",
|
||||
"children": [
|
||||
{
|
||||
"name": "id",
|
||||
@ -39393,6 +39400,12 @@
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "是否屏蔽:1=屏蔽 0=正常"
|
||||
},
|
||||
{
|
||||
"name": "template_reply_enabled",
|
||||
"type": "number",
|
||||
"required": true,
|
||||
"description": "是否启用模板消息回复:0=关闭(普通文本回复) 1=开启(模板消息回复)"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -39475,6 +39488,336 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"groupName": "回信引擎配置(v2)",
|
||||
"module": "inbox",
|
||||
"list": [
|
||||
{
|
||||
"method": "inbox.v2.type.list",
|
||||
"description": "售后类型列表(系统级+本仓库自定义,分页);warehouseId 从登录上下文注入",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "启用状态筛选:1/0" },
|
||||
{ "name": "page", "type": "number", "required": false, "source": "body", "description": "页码,默认 1" },
|
||||
{ "name": "pageSize", "type": "number", "required": false, "source": "body", "description": "每页数量,默认 20,最大 200" }
|
||||
],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "类型列表" }, { "name": "pagination", "type": "object", "required": true, "description": "分页信息" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.type.create",
|
||||
"description": "创建仓库自定义售后类型;系统级只读",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "type", "type": "string", "required": true, "source": "body", "description": "类型编码(≤20),仓库内唯一" },
|
||||
{ "name": "name", "type": "string", "required": true, "source": "body", "description": "类型名称(≤50)" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值,默认 0" }
|
||||
],
|
||||
"response": [{ "name": "id", "type": "number", "required": true, "description": "新类型ID" }, { "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.type.update",
|
||||
"description": "更新仓库自定义售后类型(name/isEnabled/sortOrder);系统预设类型拒绝修改",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "id", "type": "number", "required": true, "source": "body", "description": "类型ID" },
|
||||
{ "name": "name", "type": "string", "required": false, "source": "body", "description": "新名称" },
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "1 启用 0 停用" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.type.delete",
|
||||
"description": "删除仓库自定义售后类型(无子类型引用才可删);系统预设类型拒绝删除",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "id", "type": "number", "required": true, "source": "body", "description": "类型ID" }],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.subType.list",
|
||||
"description": "售后子类型列表(系统级+本仓库自定义,分页,可按类型/启用状态筛选)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "type", "type": "string", "required": false, "source": "body", "description": "类型编码筛选" },
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "启用状态筛选:1/0" },
|
||||
{ "name": "page", "type": "number", "required": false, "source": "body", "description": "页码" },
|
||||
{ "name": "pageSize", "type": "number", "required": false, "source": "body", "description": "每页数量" }
|
||||
],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "子类型列表" }, { "name": "pagination", "type": "object", "required": true, "description": "分页信息" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.subType.create",
|
||||
"description": "创建仓库自定义子类型(可挂在系统级类型或本仓库自定义类型下;子类型写入本仓库,后续关键词/函数/取号/白名单/回复均可写)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "type", "type": "string", "required": true, "source": "body", "description": "所属类型编码" },
|
||||
{ "name": "subType", "type": "string", "required": true, "source": "body", "description": "子类型编码(≤50)" },
|
||||
{ "name": "name", "type": "string", "required": true, "source": "body", "description": "子类型名称(≤50)" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "id", "type": "number", "required": true, "description": "新子类型ID" }, { "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.subType.update",
|
||||
"description": "更新仓库自定义子类型(name/isEnabled/sortOrder);系统预设拒绝修改",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "id", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "name", "type": "string", "required": false, "source": "body", "description": "新名称" },
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "1 启用 0 停用" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.subType.delete",
|
||||
"description": "删除仓库自定义子类型,自动级联清理关联(关键词/函数关联/取号关联/群白名单/回复);系统预设拒绝删除",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "id", "type": "number", "required": true, "source": "body", "description": "子类型ID" }],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果(含级联清理统计)" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.keyword.list",
|
||||
"description": "关键词列表(系统级+本仓库自定义,分页,可按子类型/启用状态筛选)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": false, "source": "body", "description": "子类型ID筛选" },
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "启用状态筛选" },
|
||||
{ "name": "page", "type": "number", "required": false, "source": "body", "description": "页码" },
|
||||
{ "name": "pageSize", "type": "number", "required": false, "source": "body", "description": "每页数量" }
|
||||
],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "关键词列表" }, { "name": "pagination", "type": "object", "required": true, "description": "分页信息" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.keyword.create",
|
||||
"description": "创建仓库自定义关键词(关键词为仓库级数据,可绑定系统级或本仓库自定义子类型;同一仓库内关键词唯一);系统预设关键词只读",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "keyword", "type": "string", "required": true, "source": "body", "description": "关键词(≤100),仓库内唯一" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "id", "type": "number", "required": true, "description": "新关键词ID" }, { "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.keyword.update",
|
||||
"description": "更新仓库自定义关键词(keyword/subTypeId/isEnabled/sortOrder);系统预设拒绝修改",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "id", "type": "number", "required": true, "source": "body", "description": "关键词ID" },
|
||||
{ "name": "keyword", "type": "string", "required": false, "source": "body", "description": "新关键词" },
|
||||
{ "name": "subTypeId", "type": "number", "required": false, "source": "body", "description": "新子类型ID" },
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "1 启用 0 停用" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.keyword.delete",
|
||||
"description": "删除仓库自定义关键词;系统预设拒绝删除",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "id", "type": "number", "required": true, "source": "body", "description": "关键词ID" }],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.numberRule.list",
|
||||
"description": "取号规则列表(全局资源只读,含 target/regexp/sort_order,供关联配置选择)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "取号规则列表" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.function.list",
|
||||
"description": "处理函数列表(代码同步权威,含 in_registry 标记与 isEnabled 开关;可按启用状态/关键词筛选)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "isEnabled", "type": "number", "required": false, "source": "body", "description": "启用状态筛选" },
|
||||
{ "name": "keyword", "type": "string", "required": false, "source": "body", "description": "编码/名称模糊搜索" }
|
||||
],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "函数列表(含 in_registry)" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.function.update",
|
||||
"description": "更新函数排序(是否启用由代码硬编码,不做接口配置)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "id", "type": "number", "required": true, "source": "body", "description": "函数ID" },
|
||||
{ "name": "sortOrder", "type": "number", "required": false, "source": "body", "description": "排序值" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.merged",
|
||||
"description": "回复配置合并后生效配置:以全部有效子类型(系统级+本仓库)为基底,每子类型一条、全量返回;本仓库有自定义则返回仓库级并标记 is_custom=1,否则返回系统级(is_custom=0,warehouse_id=null);无回复配置的子类型返回初始值(id=null,reply={back_text},is_reply=1,create_work_order=1);无启用状态字段,停用即回退系统级由 restore 承担",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": false, "source": "body", "description": "子类型ID筛选" }
|
||||
],
|
||||
"response": [
|
||||
{ "name": "merged", "type": "array", "required": true, "description": "合并后生效配置全量列表;元素字段:id/sub_type_id/type/sub_type/sub_type_name/warehouse_id/is_custom(1仓库级 0系统级)/reply/is_reply/create_work_order/no_number_hint/created_at/updated_at" },
|
||||
{ "name": "total", "type": "number", "required": true, "description": "总条数" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.create",
|
||||
"description": "创建仓库级回复配置(每子类型一条,仓库级覆盖系统级;isReply=0 表示命中后静默;createWorkOrder=0 表示函数照常执行但内部跳过工单登记)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "reply", "type": "string", "required": true, "source": "body", "description": "回复文案(支持 {keyword}/{express}/{sub_type_name}/{back_text} 占位符)" },
|
||||
{ "name": "isReply", "type": "number", "required": false, "source": "body", "description": "1 回复 0 静默,默认 1" },
|
||||
{ "name": "createWorkOrder", "type": "number", "required": false, "source": "body", "description": "1 函数正常创建工单(默认) 0 函数照常执行但内部跳过工单登记" },
|
||||
{ "name": "noNumberHint", "type": "string", "required": false, "source": "body", "description": "未取到单据号时的引导语(≤500)" }
|
||||
],
|
||||
"response": [{ "name": "id", "type": "number", "required": true, "description": "新回复ID" }, { "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.update",
|
||||
"description": "更新仓库级回复配置;系统级回复只读",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "id", "type": "number", "required": true, "source": "body", "description": "回复ID" },
|
||||
{ "name": "reply", "type": "string", "required": false, "source": "body", "description": "新回复文案" },
|
||||
{ "name": "isReply", "type": "number", "required": false, "source": "body", "description": "1 回复 0 静默" },
|
||||
{ "name": "createWorkOrder", "type": "number", "required": false, "source": "body", "description": "1 函数正常创建工单 0 函数照常执行但内部跳过工单登记" },
|
||||
{ "name": "noNumberHint", "type": "string", "required": false, "source": "body", "description": "取号失败引导语" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.delete",
|
||||
"description": "删除仓库级回复配置;系统级回复只读",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "id", "type": "number", "required": true, "source": "body", "description": "回复ID" }],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.save",
|
||||
"description": "保存仓库级回复配置(upsert,推荐接口):按传入字段保存,未传字段保持原值;无仓库级配置时按传入字段创建",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "reply", "type": "string", "required": false, "source": "body", "description": "回复文案(≤2000)" },
|
||||
{ "name": "isReply", "type": "number", "required": false, "source": "body", "description": "1 回复 0 静默,默认 1" },
|
||||
{ "name": "createWorkOrder", "type": "number", "required": false, "source": "body", "description": "1 函数正常创建工单 0 函数照常执行但内部跳过工单登记" },
|
||||
{ "name": "noNumberHint", "type": "string", "required": false, "source": "body", "description": "取号失败引导语(≤500)" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.reply.restore",
|
||||
"description": "还原仓库级回复配置:删除仓库级行,回退到系统级配置(幂等,无仓库级配置时返回已是系统级)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" }],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.function.list",
|
||||
"description": "查询子类型的处理函数关联列表(含函数编码/名称,按 sort_order)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" }],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "关联列表" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.function.set",
|
||||
"description": "全量替换子类型的处理函数关联(items=[{functionId,sortOrder}]);仅本仓库自定义子类型可写,系统子类型关联只读",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "items", "type": "array", "required": true, "source": "body", "description": "函数关联数组 [{functionId, sortOrder}]" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.rule.list",
|
||||
"description": "查询子类型的取号规则关联列表(含 target/规则名,按 sort_order)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" }],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "关联列表" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.rule.set",
|
||||
"description": "全量替换子类型的取号规则关联(items=[{ruleId,sortOrder}]);仅本仓库自定义子类型可写",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "items", "type": "array", "required": true, "source": "body", "description": "取号规则关联数组 [{ruleId, sortOrder}]" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.group.list",
|
||||
"description": "查询子类型的群类型白名单关联列表(group_type + sub_group,含 is_system;sub_group='*' 表示主类型内所有子类型通配,group_type='*' 表示所有群)",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" }],
|
||||
"response": [{ "name": "list", "type": "array", "required": true, "description": "白名单关联列表" }]
|
||||
},
|
||||
{
|
||||
"method": "inbox.v2.relation.group.set",
|
||||
"description": "替换子类型的群白名单关联(items=[{groupType,subGroup,sortOrder}],groupType∈store/warehouse/express/'*';subGroup 支持 '*' 通配主类型下所有子类型且覆盖该主类型其他具体行;groupType='*' 表示所有群且覆盖其他具体类型行(subGroup 忽略,归一化为空));系统预设行(is_system=1)保留不可删",
|
||||
"isNeedAuth": true,
|
||||
"isNeedLogin": true,
|
||||
"headers": [{ "name": "Authorization", "type": "string", "required": true, "description": "Bearer token" }],
|
||||
"params": [
|
||||
{ "name": "subTypeId", "type": "number", "required": true, "source": "body", "description": "子类型ID" },
|
||||
{ "name": "items", "type": "array", "required": true, "source": "body", "description": "白名单数组 [{groupType, subGroup, sortOrder}];subGroup='*' 表示该主类型下所有子类型通配,groupType='*' 表示所有群" }
|
||||
],
|
||||
"response": [{ "name": "message", "type": "string", "required": true, "description": "操作结果" }]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"groupName": "店铺快递绑定策略模块",
|
||||
"module": "storeExpressBindingPolicy",
|
||||
|
||||
@ -149,9 +149,10 @@ function buildPermissionDefaults(methodPath, templateRow) {
|
||||
path: methodPath,
|
||||
type: 'api',
|
||||
component: templateRow ? templateRow.component : null,
|
||||
name: templateRow && templateRow.name ? templateRow.name : methodPath,
|
||||
// name/title 一律按 method 路径生成,不继承模板行(历史模板行 title 可能与本接口无关)
|
||||
name: methodPath,
|
||||
redirect: templateRow ? templateRow.redirect : null,
|
||||
meta_title: templateRow && templateRow.meta_title ? templateRow.meta_title : `API:${methodPath}`,
|
||||
meta_title: `API:${methodPath}`,
|
||||
meta_icon: templateRow ? templateRow.meta_icon : null,
|
||||
hidden: templateRow ? Number(templateRow.hidden || 0) : 0,
|
||||
always_show: templateRow ? Number(templateRow.always_show || 0) : 0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user