POST /api/v1/intents/{id}/cancel
取消采购意图。
接口说明
- 需要认证 - 需要提供签名请求头
- 用途 - 取消正在处理的采购意图
- 限制 - 仅能取消 SUBMITTED 和 PROCESSING 状态的意图
- 不可逆 - 取消操作不可撤销
请求头
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
X-App-Id | string | 是 | 应用 ID |
X-Timestamp | string | 是 | 请求时间戳(毫秒) |
X-Signature | string | 是 | 请求签名 |
路径参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | 采购意图 ID |
请求参数
无需请求体。
请求示例
cURL
curl -X POST "https://api.procure-core.com/api/v1/intents/intent_67890/cancel" \
-H "X-App-Id: dev_app_local" \
-H "X-Timestamp: 1708851000000" \
-H "X-Signature: abc123..."TypeScript / JavaScript
import { ProcureClient } from '@procure-core/sdk';
const client = new ProcureClient({
appId: 'your_app_id',
appSecret: 'your_app_secret',
baseURL: 'https://api.procure-core.com'
});
// 取消采购意图
await client.intents.cancel('intent_67890');
console.log('采购意图已取消');Python
from procure_core import ProcureClient
client = ProcureClient(
app_id='your_app_id',
app_secret='your_app_secret',
base_url='https://api.procure-core.com'
)
# 取消采购意图
client.intents.cancel('intent_67890')
print('采购意图已取消')响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
code | number | 状态码,0 表示成功 |
message | string | 响应消息 |
data | object | 更新后的意图信息 |
data 对象结构
| 参数 | 类型 | 说明 |
|---|---|---|
id | string | 采购意图 ID |
status | string | 状态:CANCELLED |
updatedAt | string | 更新时间 |
cancelledAt | string | 取消时间 |
响应示例
成功响应
{
"code": 0,
"message": "操作成功",
"data": {
"id": "intent_67890",
"status": "CANCELLED",
"updatedAt": "2026-02-25T11:30:00.000Z",
"cancelledAt": "2026-02-25T11:30:00.000Z"
}
}错误响应
意图不存在
状态码: 404 Not Found
{
"code": 40401,
"message": "采购意图不存在",
"data": null
}状态不允许取消
状态码: 400 Bad Request
{
"code": 40003,
"message": "当前状态不允许取消",
"data": {
"currentStatus": "COMPLETED",
"reason": "已完成的订单不能取消"
}
}取消失败
状态码: 500 Internal Server Error
{
"code": 50003,
"message": "取消操作失败",
"data": {
"reason": "电商平台订单已发货,无法取消"
}
}使用场景
1. 用户主动取消
// 用户取消订单
async function userCancelIntent(intentId: string) {
try {
const result = await client.intents.cancel(intentId);
console.log('订单已成功取消');
return result;
} catch (error) {
if (error.code === 40003) {
console.error('订单状态不允许取消');
} else if (error.code === 50003) {
console.error('系统取消失败,请联系客服');
}
throw error;
}
}2. 取消前确认
// 取消前确认当前状态
async function safeCancelIntent(intentId: string) {
// 先查询当前状态
const intent = await client.intents.get(intentId);
// 检查是否可以取消
if (!['SUBMITTED', 'PROCESSING'].includes(intent.status)) {
throw new Error(`当前状态 ${intent.status} 不允许取消`);
}
// 执行取消
return await client.intents.cancel(intentId);
}3. 批量取消
// 批量取消多个意图
async function batchCancel(intentIds: string[]) {
const results = [];
for (const intentId of intentIds) {
try {
const result = await client.intents.cancel(intentId);
results.push({ intentId, success: true, data: result });
} catch (error) {
results.push({ intentId, success: false, error: error.message });
}
}
return results;
}4. 超时自动取消
// 超过一定时间未处理,自动取消
async function autoCancelExpired() {
const intents = await client.intents.list({
status: 'SUBMITTED',
sortBy: 'createdAt',
order: 'asc'
});
const now = Date.now();
const expiredThreshold = 24 * 60 * 60 * 1000; // 24小时
for (const intent of intents.data.items) {
const createdTime = new Date(intent.createdAt).getTime();
if (now - createdTime > expiredThreshold) {
try {
await client.intents.cancel(intent.id);
console.log(`已自动取消超时意图: ${intent.id}`);
} catch (error) {
console.error(`取消失败: ${intent.id}`, error);
}
}
}
}取消状态说明
| 原状态 | 是否可取消 | 取消后状态 | 说明 |
|---|---|---|---|
| DRAFT | ❌ 否 | - | 草稿状态直接删除即可 |
| SUBMITTED | ✅ 是 | CANCELLED | 已提交,可以取消 |
| PROCESSING | ✅ 是 | CANCELLED | 处理中,可以尝试取消 |
| COMPLETED | ❌ 否 | - | 已完成,不可取消 |
| FAILED | ❌ 否 | - | 已失败,不需要取消 |
| CANCELLED | ❌ 否 | - | 已取消,不可重复取消 |
取消影响
1. SUBMITTED 状态取消
- ✅ 立即取消成功
- ✅ 不产生任何费用
- ✅ 不影响电商平台
2. PROCESSING 状态取消
- ⚠️ 可能已经下单到电商平台
- ⚠️ 需要同步取消电商平台订单
- ⚠️ 电商平台可能收取手续费
- ⚠️ 取消可能失败(已发货等)
常见错误
| 错误码 | 错误消息 | 解决方案 |
|---|---|---|
| 40401 | 采购意图不存在 | 检查意图 ID 是否正确 |
| 40003 | 当前状态不允许取消 | 检查意图当前状态 |
| 40301 | 无权访问该资源 | 确认该意图属于当前 App |
| 50003 | 取消操作失败 | 查看错误详情或联系客服 |
注意事项
- 不可撤销 - 取消操作不可撤销,请谨慎操作
- 状态限制 - 仅 SUBMITTED 和 PROCESSING 可以取消
- 异步处理 - PROCESSING 状态取消是异步的,可能需要一定时间
- 费用问题 - 已下单的取消可能产生手续费
- 退款时间 - 如已支付,退款需要 1-7 个工作日
- 物流处理 - 如已发货,需要拒收或退货流程
最佳实践
- 及时取消 - 尽早取消可以避免复杂的退款流程
- 状态确认 - 取消前先查询当前状态
- 用户通知 - 取消成功后及时通知用户
- 错误处理 - 妥善处理取消失败的情况
- 日志记录 - 记录取消操作的时间和原因
替代方案
如果意图状态不允许取消:
- DRAFT - 使用 删除接口 直接删除
- COMPLETED - 联系客服处理退货退款
- FAILED - 无需取消,可以直接删除