API契约:收口业务成功响应 DTO
This commit is contained in:
1 parent
ebce42f9dc
commit
0ca52e43ad
12 files changed
+1020
-233
No files matched your search
+23
-23
@@ -3,8 +3,8 @@ import {
|
||||
LoginResponse, AccountDetail, AccountSummaryResponse, Order, PaginatedResponse,
|
||||
AdminStats, DashboardStats, Card, SystemSettings, ApiResponse, OrderAnalytics,
|
||||
Item, AIReplySettings, ShippingRule, ReplyRule, DefaultReply, AutomationAction, AutomationTriggerType,
|
||||
NotificationChannel, NotificationEventType
|
||||
, AccountTaskSettings, AccountTaskSummary, ChatSession, ChatMessage
|
||||
NotificationChannel, NotificationEventType, AccountTaskSettings, AccountTaskSummary, ChatSession, ChatMessage,
|
||||
CookieSettingsResponse, CookieProfileResponse, ItemPublishResponse, ItemSyncResponse, OrderDTOResponse, OrderDetailResponse, OrderSingleRefreshResponse, OrderBatchResponse, AutomationRuleResponse, AutomationRulePageResponse
|
||||
} from '../types';
|
||||
import { formatLocalDate } from '../dateRange';
|
||||
|
||||
@@ -202,7 +202,7 @@ export const updateAccountAutoConfirm = async (id: string, autoConfirm: boolean)
|
||||
return put(`/cookies/${id}/auto-confirm`, { auto_confirm: autoConfirm });
|
||||
};
|
||||
|
||||
export const updateAccountPauseDuration = async (id: string, pauseDuration: number): Promise<any> => {
|
||||
export const updateAccountPauseDuration = async (id: string, pauseDuration: number): Promise<CookieSettingsResponse> => {
|
||||
return put(`/cookies/${id}/pause-duration`, { pause_duration: pauseDuration });
|
||||
};
|
||||
|
||||
@@ -222,7 +222,7 @@ export interface AccountSettingsUpdate {
|
||||
channel_ids?: number[];
|
||||
}
|
||||
|
||||
export const updateAccountSettings = async (id: string, data: AccountSettingsUpdate): Promise<ApiResponse> => {
|
||||
export const updateAccountSettings = async (id: string, data: AccountSettingsUpdate): Promise<CookieSettingsResponse> => {
|
||||
return put(`/cookies/${id}/settings`, data);
|
||||
};
|
||||
|
||||
@@ -276,7 +276,7 @@ export const cancelPasswordLogin = async (sessionId: string): Promise<ApiRespons
|
||||
return del(`/password-login/cancel/${sessionId}`);
|
||||
};
|
||||
|
||||
export const refreshAccountProfile = async (id: string): Promise<any> => {
|
||||
export const refreshAccountProfile = async (id: string): Promise<CookieProfileResponse> => {
|
||||
return post(`/cookies/${id}/refresh-profile`, {});
|
||||
};
|
||||
|
||||
@@ -314,7 +314,7 @@ export const getOrders = async (
|
||||
if (status && status !== 'all') params.status = status;
|
||||
if (search?.trim()) params.search = search.trim();
|
||||
|
||||
const res = await get<any>('/api/orders', params);
|
||||
const res = await get<PaginatedResponse<Order> & { orders?: Order[] /* 后端兼容的订单列表字段。 */ }>('/api/orders', params);
|
||||
|
||||
// Handle backend response variations
|
||||
const rawOrders = res.orders || res.data || [];
|
||||
@@ -334,11 +334,11 @@ export const getOrders = async (
|
||||
};
|
||||
};
|
||||
|
||||
export const getOrderDetail = async (orderId: string): Promise<{ success: boolean; data?: Order }> => {
|
||||
const result = await get<{ order?: Order; data?: Order }>(`/api/orders/${orderId}`);
|
||||
export const getOrderDetail = async (orderId: string): Promise<{ success: boolean; data?: OrderDTOResponse }> => {
|
||||
const result = await get<OrderDetailResponse>(`/api/orders/${orderId}`);
|
||||
return {
|
||||
success: true,
|
||||
data: result.order || result.data
|
||||
data: result.data
|
||||
};
|
||||
};
|
||||
|
||||
@@ -358,18 +358,18 @@ export const syncOrders = async (cookieId?: string, status?: string): Promise<an
|
||||
return postForm('/api/orders/refresh', formData);
|
||||
};
|
||||
|
||||
export const syncSingleOrder = async (orderId: string): Promise<any> => {
|
||||
export const syncSingleOrder = async (orderId: string): Promise<OrderSingleRefreshResponse> => {
|
||||
return post(`/api/orders/${orderId}/refresh`);
|
||||
};
|
||||
|
||||
export const manualShipOrder = async (orderIds: string[], shipMode: 'status_only' | 'full_delivery'): Promise<any> => {
|
||||
export const manualShipOrder = async (orderIds: string[], shipMode: 'status_only' | 'full_delivery'): Promise<OrderBatchResponse> => {
|
||||
return post('/api/orders/manual-ship', {
|
||||
order_ids: orderIds,
|
||||
ship_mode: shipMode,
|
||||
});
|
||||
}
|
||||
|
||||
export const importOrders = async (data: Partial<Order>[] | FormData): Promise<any> => {
|
||||
export const importOrders = async (data: Partial<Order>[] | FormData): Promise<OrderBatchResponse> => {
|
||||
const isFormData = data instanceof FormData;
|
||||
return isFormData ? postForm('/api/orders/import', data) : post('/api/orders/import', data);
|
||||
}
|
||||
@@ -505,7 +505,7 @@ export const getItems = async (cookieId?: string): Promise<Item[]> => {
|
||||
}));
|
||||
}
|
||||
|
||||
export const syncItemsFromAccount = async (cookieId: string): Promise<any> => {
|
||||
export const syncItemsFromAccount = async (cookieId: string): Promise<ItemSyncResponse> => {
|
||||
return post('/items/get-all-from-account', { cookie_id: cookieId });
|
||||
}
|
||||
|
||||
@@ -528,7 +528,7 @@ export const publishItem = async (form: {
|
||||
postage?: string;
|
||||
images: File[];
|
||||
location?: PublishLocation;
|
||||
}): Promise<any> => {
|
||||
}): Promise<ItemPublishResponse> => {
|
||||
const body = new FormData();
|
||||
body.set('cookie_id', form.cookie_id);
|
||||
body.set('title', form.title);
|
||||
@@ -668,8 +668,8 @@ const normalizeShippingRules = (rules: any[]): ShippingRule[] => rules.map((item
|
||||
}));
|
||||
|
||||
export const getShippingRules = async (): Promise<ShippingRule[]> => {
|
||||
const res = await get<any>('/automation-rules');
|
||||
const rules = Array.isArray(res) ? res : (res.data || res.rules || []);
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/automation-rules');
|
||||
const rules = Array.isArray(res) ? res : (res.data || []);
|
||||
return normalizeShippingRules(rules);
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ export const getShippingRulesPage = async ({
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
}: ShippingRuleListParams = {}): Promise<PaginatedResponse<ShippingRule>> => {
|
||||
const res = await get<any>('/automation-rules', {
|
||||
const res = await get<AutomationRuleResponse[] | AutomationRulePageResponse>('/automation-rules', {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
cookie_id: cookieId || undefined,
|
||||
@@ -698,16 +698,16 @@ export const getShippingRulesPage = async ({
|
||||
enabled,
|
||||
search: search?.trim() || undefined,
|
||||
});
|
||||
const rules = normalizeShippingRules(Array.isArray(res) ? res : (res.data || res.rules || []));
|
||||
const rules = normalizeShippingRules(Array.isArray(res) ? res : (res.data || []));
|
||||
return {
|
||||
success: true,
|
||||
data: rules,
|
||||
total: Number(res.total ?? rules.length),
|
||||
page: Number(res.page ?? page),
|
||||
page_size: Number(res.page_size ?? pageSize),
|
||||
total_pages: Number(res.total_pages ?? (rules.length ? 1 : 0)),
|
||||
total: Number(Array.isArray(res) ? rules.length : (res.total ?? rules.length)),
|
||||
page: Number(Array.isArray(res) ? page : (res.page ?? page)),
|
||||
page_size: Number(Array.isArray(res) ? pageSize : (res.page_size ?? pageSize)),
|
||||
total_pages: Number(Array.isArray(res) ? (rules.length ? 1 : 0) : (res.total_pages ?? (rules.length ? 1 : 0))),
|
||||
trigger_counts: Object.fromEntries(
|
||||
Object.entries(res.trigger_counts || {}).map(([key, value]) => [key, Number(value)]),
|
||||
Object.entries(Array.isArray(res) ? {} : res.trigger_counts || {}).map(([key, value]) => [key, Number(value)]),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -405,3 +405,293 @@ export interface AccountSummaryResponse {
|
||||
/** 最近一次自动擦亮时间。 */
|
||||
last_polish_at: number;
|
||||
}
|
||||
|
||||
/** 账号设置变更接口的具名成功响应。 */
|
||||
export interface CookieSettingsResponse {
|
||||
/** 表示设置是否保存成功。 */
|
||||
success: boolean;
|
||||
/** 暂停结束 Unix 秒。 */
|
||||
paused_until: number;
|
||||
/** 表示账号当前是否暂停。 */
|
||||
paused: boolean;
|
||||
}
|
||||
|
||||
/** 账号资料刷新接口的具名响应。 */
|
||||
export interface CookieProfileResponse {
|
||||
/** 表示资料刷新是否成功。 */
|
||||
success: boolean;
|
||||
/** 账号稳定标识。 */
|
||||
id: string;
|
||||
/** 平台账号昵称。 */
|
||||
nickname: string;
|
||||
/** 平台账号头像地址。 */
|
||||
avatar_url: string;
|
||||
/** 资料刷新错误说明。 */
|
||||
profile_error: string;
|
||||
}
|
||||
|
||||
/** 账号暂停时长查询接口的具名响应。 */
|
||||
export interface PauseDurationResponse {
|
||||
/** 暂停时长,单位为分钟。 */
|
||||
pause_duration: number;
|
||||
/** 暂停结束 Unix 秒。 */
|
||||
paused_until: number;
|
||||
/** 表示账号当前是否暂停。 */
|
||||
paused: boolean;
|
||||
}
|
||||
|
||||
/** 单个本地商品详情接口的具名响应。 */
|
||||
export interface ItemDetailResponse {
|
||||
/** 商品所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 平台商品标识。 */
|
||||
item_id: string;
|
||||
/** 商品标题。 */
|
||||
item_title: string;
|
||||
/** 商品描述。 */
|
||||
item_description: string;
|
||||
/** 商品分类标识。 */
|
||||
item_category: string;
|
||||
/** 商品价格文本。 */
|
||||
item_price: string;
|
||||
/** 商品详情原始 JSON。 */
|
||||
item_detail: string;
|
||||
/** 是否有多规格。 */
|
||||
is_multi_spec: boolean;
|
||||
/** 是否按数量发货。 */
|
||||
multi_quantity_delivery: boolean;
|
||||
}
|
||||
|
||||
/** 商品发布接口的具名成功响应。 */
|
||||
export interface ItemPublishResponse {
|
||||
/** 表示商品是否发布成功。 */
|
||||
success: boolean;
|
||||
/** 发布结果说明。 */
|
||||
message: string;
|
||||
/** 新商品的平台标识。 */
|
||||
item_id: string;
|
||||
/** 新商品的平台详情地址。 */
|
||||
item_url: string;
|
||||
/** 新商品主图地址。 */
|
||||
item_image: string;
|
||||
/** 新商品标题。 */
|
||||
item_title: string;
|
||||
/** 新商品价格文本。 */
|
||||
item_price: string;
|
||||
/** 新商品库存数量。 */
|
||||
quantity: number;
|
||||
/** 新商品分类标识。 */
|
||||
category_id: string;
|
||||
/** 新商品分类名称。 */
|
||||
category_name: string;
|
||||
}
|
||||
|
||||
/** 商品全集同步接口的具名响应。 */
|
||||
export interface ItemSyncResponse {
|
||||
/** 表示同步是否完成。 */
|
||||
success: boolean;
|
||||
/** 同步结果说明。 */
|
||||
message: string;
|
||||
/** 平台返回的商品总数。 */
|
||||
total_count: number;
|
||||
/** 平台商品总页数。 */
|
||||
total_pages: number;
|
||||
/** 本地保存的商品数量。 */
|
||||
saved_count: number;
|
||||
/** 本地删除标记的商品数量。 */
|
||||
deleted_count: number;
|
||||
}
|
||||
|
||||
/** 商品分页同步接口的具名响应。 */
|
||||
export interface ItemPageSyncResponse {
|
||||
/** 表示同步是否完成。 */
|
||||
success: boolean;
|
||||
/** 同步结果说明。 */
|
||||
message: string;
|
||||
/** 当前同步页码。 */
|
||||
page_number: number;
|
||||
/** 当前同步页大小。 */
|
||||
page_size: number;
|
||||
/** 当前页商品数量。 */
|
||||
current_count: number;
|
||||
/** 本地保存的商品数量。 */
|
||||
saved_count: number;
|
||||
}
|
||||
|
||||
/** 订单详情接口返回的原始具名订单 DTO。 */
|
||||
export interface OrderDTOResponse {
|
||||
/** 平台订单标识。 */
|
||||
order_id: string;
|
||||
/** 关联商品标识。 */
|
||||
item_id: string;
|
||||
/** 关联商品标题。 */
|
||||
item_title: string;
|
||||
/** 关联商品图片地址。 */
|
||||
item_image: string;
|
||||
/** 买家平台标识。 */
|
||||
buyer_id: string;
|
||||
/** 商品规格名称。 */
|
||||
spec_name: string;
|
||||
/** 商品规格值。 */
|
||||
spec_value: string;
|
||||
/** 购买数量文本。 */
|
||||
quantity: string;
|
||||
/** 实付金额文本。 */
|
||||
amount: string;
|
||||
/** 归一化订单状态。 */
|
||||
order_status: string;
|
||||
/** 兼容前端使用的订单状态别名。 */
|
||||
status: string;
|
||||
/** 所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 是否议价订单。 */
|
||||
is_bargain: number;
|
||||
/** 是否系统发货。 */
|
||||
system_shipped: boolean;
|
||||
/** 收货人姓名。 */
|
||||
receiver_name: string;
|
||||
/** 收货人电话。 */
|
||||
receiver_phone: string;
|
||||
/** 收货地址。 */
|
||||
receiver_address: string;
|
||||
/** 收货城市。 */
|
||||
receiver_city: string;
|
||||
/** 创建时间。 */
|
||||
created_at: string;
|
||||
/** 更新时间。 */
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
/** 订单详情接口的具名响应。 */
|
||||
export interface OrderDetailResponse extends OrderDTOResponse {
|
||||
/** 表示查询是否完成。 */
|
||||
success: boolean;
|
||||
/** 新版客户端读取的订单对象。 */
|
||||
data: OrderDTOResponse;
|
||||
}
|
||||
|
||||
/** 订单单条刷新返回的远端详情。 */
|
||||
export interface OrderRefreshDetailResponse {
|
||||
/** 购买数量文本。 */
|
||||
quantity: string;
|
||||
/** 商品规格名称。 */
|
||||
spec_name: string;
|
||||
/** 商品规格值。 */
|
||||
spec_value: string;
|
||||
/** 归一化订单状态。 */
|
||||
order_status: string;
|
||||
/** 实付金额文本。 */
|
||||
amount: string;
|
||||
}
|
||||
|
||||
/** 订单单条刷新接口的具名响应。 */
|
||||
export interface OrderSingleRefreshResponse {
|
||||
/** 表示刷新是否完成。 */
|
||||
success: boolean;
|
||||
/** 刷新结果说明。 */
|
||||
message: string;
|
||||
/** 刷新后的订单详情。 */
|
||||
order: OrderRefreshDetailResponse;
|
||||
}
|
||||
|
||||
/** 自动化规则动作的原始具名 DTO。 */
|
||||
export interface AutomationActionResponse {
|
||||
/** 动作稳定标识。 */
|
||||
id: number;
|
||||
/** 动作类型。 */
|
||||
action_type: string;
|
||||
/** 关联卡券组标识。 */
|
||||
card_id: number;
|
||||
/** 关联卡券组名称。 */
|
||||
card_name: string;
|
||||
/** 发送数量。 */
|
||||
delivery_count: number;
|
||||
/** 消息模板。 */
|
||||
message_template: string;
|
||||
/** 延迟秒数。 */
|
||||
delay_seconds: number;
|
||||
/** 扩展配置 JSON。 */
|
||||
config_json: string;
|
||||
/** 是否启用。 */
|
||||
enabled: boolean;
|
||||
/** 执行顺序。 */
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
/** 自动化规则的原始具名 DTO。 */
|
||||
export interface AutomationRuleResponse {
|
||||
/** 规则稳定标识。 */
|
||||
id: number;
|
||||
/** 所属账号标识。 */
|
||||
cookie_id: string;
|
||||
/** 关联商品标识。 */
|
||||
item_id: string;
|
||||
/** 关联商品标题。 */
|
||||
item_title: string;
|
||||
/** 规则名称。 */
|
||||
name: string;
|
||||
/** 触发类型。 */
|
||||
trigger_type: string;
|
||||
/** 是否启用。 */
|
||||
enabled: boolean;
|
||||
/** 规则优先级。 */
|
||||
priority: number;
|
||||
/** 扩展配置 JSON。 */
|
||||
config_json: string;
|
||||
/** 规则动作列表。 */
|
||||
actions: AutomationActionResponse[];
|
||||
/** 创建时间。 */
|
||||
created_at: string;
|
||||
/** 更新时间。 */
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
/** 自动化规则分页接口的具名响应。 */
|
||||
export interface AutomationRulePageResponse {
|
||||
/** 表示查询是否完成。 */
|
||||
success: boolean;
|
||||
/** 当前页规则列表。 */
|
||||
data: AutomationRuleResponse[];
|
||||
/** 规则总数。 */
|
||||
total: number;
|
||||
/** 当前页码。 */
|
||||
page: number;
|
||||
/** 当前页大小。 */
|
||||
page_size: number;
|
||||
/** 总页数。 */
|
||||
total_pages: number;
|
||||
/** 各触发类型规则数量。 */
|
||||
trigger_counts: Record<string, number>;
|
||||
}
|
||||
|
||||
/** 订单批量变更接口的具名响应。 */
|
||||
export interface OrderBatchResponse {
|
||||
/** 表示批量操作是否存在部分失败。 */
|
||||
partial_failure: boolean;
|
||||
/** 批量操作结果说明。 */
|
||||
message: string;
|
||||
/** 订单总数,导入接口提供。 */
|
||||
total?: number;
|
||||
/** 成功处理数量。 */
|
||||
success_count: number;
|
||||
/** 失败处理数量。 */
|
||||
failed_count: number;
|
||||
/** 逐订单兼容结果行。 */
|
||||
results: OrderBatchResult[];
|
||||
}
|
||||
|
||||
/** 订单批量接口的逐订单结果行。 */
|
||||
export interface OrderBatchResult {
|
||||
/** 订单平台标识。 */
|
||||
order_id?: string;
|
||||
/** 表示该订单是否处理成功。 */
|
||||
success?: boolean;
|
||||
/** 该订单处理结果说明。 */
|
||||
message: string;
|
||||
/** 兼容接口可能返回的账号标识。 */
|
||||
cookie_id?: string;
|
||||
/** 兼容接口可能返回的处理阶段。 */
|
||||
stage?: string;
|
||||
/** 允许后端保留尚未结构化的扩展字段。 */
|
||||
[key: string]: unknown;
|
||||
}
|
||||
Reference in new issue
Block a user