Skip to Content
API 参考数据结构

数据结构

本文档定义智能采购平台 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) }

字段说明:

字段类型必填说明示例
idstring采购意图唯一标识intent_67890
userIdstring发起用户 IDuser_123
platformenum电商平台:TAOBAO | JD | PDDTAOBAO
productUrlstring商品链接 URLhttps://item.taobao.com/...
titlestring商品标题Apple iPhone 15 Pro 256GB
pricenumber商品单价(元)8999
quantitynumber采购数量2
recipientNamestring收货人姓名张三
addressstring收货地址北京市朝阳区望京SOHO
phonestring收货人电话13800138000
statusenum处理状态SUBMITTED
remarksstring备注信息急用,请优先处理
createdAtstring创建时间2026-02-25T10:00:00Z
updatedAtstring更新时间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-100
  • platform: 必须是 TAOBAOJDPDD
  • productUrl: 有效的 HTTP/HTTPS URL
  • title: 非空字符串,长度 1-500
  • price: 正数,> 0,最多 2 位小数
  • quantity: 正整数,>= 1
  • recipientName: 非空字符串,长度 1-50
  • address: 非空字符串,长度 1-200
  • phone: 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.sssZ
  • YYYY - 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-types
import type { IntentResponseDto, CreateIntentDto, Platform, IntentStatus, ApiResponse } from '@procure-core/api-types';

相关文档