数据结构
本文档定义智能采购平台 API 中使用的所有数据结构和数据类型。
采购意图相关
IntentResponseDto
采购意图的完整数据结构。
interface IntentResponseDto {
id: string; // 采购意图唯一标识
userId: string; // 发起用户 ID
platform: Platform; // 电商平台标识
productUrl: string; // 商品原始链接
title: string; // 商品标题
price: number; // 商品单价(元)
quantity: number; // 采购数量
recipientName: string; // 收货人姓名
address: string; // 收货详细地址
phone: string; // 收货人联系电话
status: IntentStatus; // 内部处理状态
remarks?: string | null; // 备注信息(可选)
createdAt: string; // 创建时间(ISO 8601)
updatedAt: string; // 更新时间(ISO 8601)
}字段说明:
| 字段 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|
id | string | 是 | 采购意图唯一标识 | intent_67890 |
userId | string | 是 | 发起用户 ID | user_123 |
platform | enum | 是 | 电商平台:TAOBAO | JD | PDD | TAOBAO |
productUrl | string | 是 | 商品链接 URL | https://item.taobao.com/... |
title | string | 是 | 商品标题 | Apple iPhone 15 Pro 256GB |
price | number | 是 | 商品单价(元) | 8999 |
quantity | number | 是 | 采购数量 | 2 |
recipientName | string | 是 | 收货人姓名 | 张三 |
address | string | 是 | 收货地址 | 北京市朝阳区望京SOHO |
phone | string | 是 | 收货人电话 | 13800138000 |
status | enum | 是 | 处理状态 | SUBMITTED |
remarks | string | 否 | 备注信息 | 急用,请优先处理 |
createdAt | string | 是 | 创建时间 | 2026-02-25T10:00:00Z |
updatedAt | string | 是 | 更新时间 | 2026-02-25T10:00:00Z |
CreateIntentDto
创建采购意图的请求参数。
interface CreateIntentDto {
userId: string; // 发起用户 ID
platform: Platform; // 电商平台标识
productUrl: string; // 商品原始链接
title: string; // 商品标题
price: number; // 商品单价(元)
quantity: number; // 采购数量
recipientName: string; // 收货人姓名
address: string; // 收货详细地址
phone: string; // 收货人联系电话
remarks?: string; // 备注信息(可选)
}验证规则:
userId: 非空字符串,长度 1-100platform: 必须是TAOBAO、JD或PDDproductUrl: 有效的 HTTP/HTTPS URLtitle: 非空字符串,长度 1-500price: 正数,> 0,最多 2 位小数quantity: 正整数,>= 1recipientName: 非空字符串,长度 1-50address: 非空字符串,长度 1-200phone: 11 位手机号或固定电话格式remarks: 可选,最长 500 字符
UpdateIntentDto
更新采购意图的请求参数(所有字段可选)。
interface UpdateIntentDto {
userId?: string;
platform?: Platform;
productUrl?: string;
title?: string;
price?: number;
quantity?: number;
recipientName?: string;
address?: string;
phone?: string;
status?: IntentStatus;
remarks?: string;
}枚举类型
Platform
电商平台标识。
enum Platform {
TAOBAO = 'TAOBAO', // 淘宝
JD = 'JD', // 京东
PDD = 'PDD', // 拼多多
}| 值 | 说明 | 平台 |
|---|---|---|
TAOBAO | 淘宝 | 淘宝网、天猫 |
JD | 京东 | 京东商城 |
PDD | 拼多多 | 拼多多 |
IntentStatus
采购意图处理状态。
enum IntentStatus {
DRAFT = 'DRAFT', // 草稿
SUBMITTED = 'SUBMITTED', // 已提交
PROCESSING = 'PROCESSING', // 处理中
COMPLETED = 'COMPLETED', // 已完成
FAILED = 'FAILED', // 失败
}| 状态 | 说明 | 可执行操作 |
|---|---|---|
DRAFT | 草稿,信息未完整 | 更新、提交、删除 |
SUBMITTED | 已提交,等待处理 | 查询、取消 |
PROCESSING | 正在处理中 | 查询、取消 |
COMPLETED | 已完成 | 查询 |
FAILED | 处理失败 | 查询、重试 |
状态流转图
响应结构
ApiResponse<T>
统一的 API 响应格式。
interface ApiResponse<T> {
code: number; // 业务状态码,0 表示成功
message: string; // 响应消息
data: T | null; // 响应数据
}示例:
{
"code": 0,
"message": "操作成功",
"data": {
"id": "intent_123",
"status": "SUBMITTED"
}
}CreateIntentResponse
创建采购意图的响应。
interface CreateIntentResponse extends ApiResponse<IntentResponseDto> {}IntentDetailResponse
查询意图详情的响应。
interface IntentDetailResponse extends ApiResponse<IntentResponseDto | null> {}IntentListResponse
查询意图列表的响应。
interface IntentListResponse extends ApiResponse<IntentResponseDto[]> {}CancelIntentResponse
取消采购意图的响应。
interface CancelIntentResponse extends ApiResponse<IntentResponseDto> {}分页结构
PaginatedResponse<T>
分页查询的响应结构。
interface PaginatedResponse<T> {
items: T[]; // 当前页数据
total: number; // 总记录数
page: number; // 当前页码
pageSize: number; // 每页数量
totalPages: number; // 总页数
}示例:
{
"code": 0,
"message": "操作成功",
"data": {
"items": [
{ "id": "intent_001", "status": "SUBMITTED" },
{ "id": "intent_002", "status": "PROCESSING" }
],
"total": 45,
"page": 1,
"pageSize": 20,
"totalPages": 3
}
}错误响应结构
ErrorResponse
错误响应的数据结构。
interface ErrorResponse {
code: number; // 错误码
message: string; // 错误消息
data?: ErrorDetail | null; // 错误详情(可选)
}
interface ErrorDetail {
field?: string; // 错误字段
reason?: string; // 错误原因
value?: any; // 错误值
}示例:
{
"code": 40001,
"message": "请求参数错误",
"data": {
"field": "price",
"reason": "价格必须大于0",
"value": -100
}
}日期时间格式
所有日期时间字段均使用 ISO 8601 标准格式。
格式说明
YYYY-MM-DDTHH:mm:ss.sssZYYYY- 4 位年份MM- 2 位月份(01-12)DD- 2 位日期(01-31)T- 日期时间分隔符HH- 2 位小时(00-23)mm- 2 位分钟(00-59)ss- 2 位秒(00-59).sss- 3 位毫秒(可选)Z- UTC 时区标识
示例
// JavaScript/TypeScript
const timestamp = new Date().toISOString();
// "2026-02-25T10:30:00.123Z"
// 解析
const date = new Date('2026-02-25T10:30:00Z');# Python
from datetime import datetime
timestamp = datetime.utcnow().isoformat() + 'Z'
# "2026-02-25T10:30:00.123456Z"
# 解析
date = datetime.fromisoformat('2026-02-25T10:30:00Z')金额格式
所有金额字段使用 人民币元 为单位,保留 2 位小数。
规则
- 类型:
number - 单位:人民币元(CNY)
- 精度:最多 2 位小数
- 范围:0.01 - 999999999.99
示例
{
"price": 8999.00,
"totalAmount": 17998.00,
"discount": 500.50
}联系方式格式
手机号
- 格式:11 位数字,以 1 开头
- 正则:
^1[3-9]\d{9}$ - 示例:
13800138000
固定电话
- 格式:区号(2-4位)+ 号码(7-8位)
- 正则:
^0\d{2,3}-\d{7,8}$ - 示例:
010-12345678
TypeScript 类型定义
完整的 TypeScript 类型定义可以从以下位置获取:
# 下载类型定义
npm install @procure-core/api-typesimport type {
IntentResponseDto,
CreateIntentDto,
Platform,
IntentStatus,
ApiResponse
} from '@procure-core/api-types';