Compare commits
No commits in common. "75056db42c2c87c37af45e1214be1cebb4eb15dd" and "71b2c249be8561d9287820eb613331a662272365" have entirely different histories.
75056db42c
...
71b2c249be
|
|
@ -523,23 +523,6 @@
|
|||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@faker-js/faker": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-10.2.0.tgz",
|
||||
"integrity": "sha512-rTXwAsIxpCqzUnZvrxVh3L0QA0NzToqWBLAhV+zDV3MIIwiQhAZHMdPCIaj5n/yADu/tyk12wIPgL6YHGXJP+g==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fakerjs"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || ^23.5.0 || >=24.0.0",
|
||||
"npm": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/@hapi/bourne": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/@hapi/bourne/-/bourne-3.0.0.tgz",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import {
|
|||
UnifiedVariationPaginationDTO,
|
||||
CreateReviewDTO,
|
||||
UpdateReviewDTO,
|
||||
FulfillmentDTO,
|
||||
} from '../dto/site-api.dto';
|
||||
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto';
|
||||
import {
|
||||
|
|
@ -30,12 +29,10 @@ import {
|
|||
WooOrderSearchParams,
|
||||
WooProductSearchParams,
|
||||
WpMediaGetListParams,
|
||||
WooFulfillment,
|
||||
} from '../dto/woocommerce.dto';
|
||||
import { Site } from '../entity/site.entity';
|
||||
import { WPService } from '../service/wp.service';
|
||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
||||
import { toArray, toNumber } from '../utils/trans.util';
|
||||
|
||||
export class WooCommerceAdapter implements ISiteAdapter {
|
||||
// 构造函数接收站点配置与服务实例
|
||||
|
|
@ -333,11 +330,22 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
|||
// }
|
||||
const mapped: any = {
|
||||
...(params.search ? { search: params.search } : {}),
|
||||
// ...(orderBy ? { orderBy } : {}),
|
||||
page,
|
||||
per_page,
|
||||
};
|
||||
|
||||
const toArray = (value: any): any[] => {
|
||||
if (Array.isArray(value)) return value;
|
||||
if (value === undefined || value === null) return [];
|
||||
return String(value).split(',').map(v => v.trim()).filter(Boolean);
|
||||
};
|
||||
|
||||
const toNumber = (value: any): number | undefined => {
|
||||
if (value === undefined || value === null || value === '') return undefined;
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n : undefined;
|
||||
};
|
||||
|
||||
// 时间过滤参数
|
||||
if (where.after ?? where.date_created_after ?? where.created_after) mapped.after = String(where.after ?? where.date_created_after ?? where.created_after);
|
||||
|
|
@ -348,7 +356,8 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
|||
|
||||
// 集合过滤参数
|
||||
if (where.exclude) mapped.exclude = toArray(where.exclude);
|
||||
if (where.ids || where.number || where.id || where.include) mapped.include = [...new Set([where.number,where.id,...toArray(where.ids),...toArray(where.include)])].filter(Boolean);
|
||||
if (where.include) mapped.include = toArray(where.include);
|
||||
if (where.ids) mapped.include = toArray(where.ids);
|
||||
if (toNumber(where.offset) !== undefined) mapped.offset = Number(where.offset);
|
||||
if (where.parent ?? where.parentId) mapped.parent = toArray(where.parent ?? where.parentId);
|
||||
if (where.parent_exclude ?? where.parentExclude) mapped.parent_exclude = toArray(where.parent_exclude ?? where.parentExclude);
|
||||
|
|
@ -399,11 +408,13 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
|||
// 包含账单地址与收货地址以及创建与更新时间
|
||||
|
||||
// 映射物流追踪信息,将后端格式转换为前端期望的格式
|
||||
const fulfillments = (item.fulfillments || []).map((track) => ({
|
||||
tracking_id: track.tracking_id,
|
||||
tracking_number: track.tracking_number,
|
||||
shipping_provider: track.tracking_provider,
|
||||
date_created: track.data_sipped,
|
||||
const fulfillments = (item.fulfillments || []).map((track: any) => ({
|
||||
tracking_number: track.tracking_number || '',
|
||||
shipping_provider: track.shipping_provider || '',
|
||||
shipping_method: track.shipping_method || '',
|
||||
status: track.status || '',
|
||||
date_created: track.date_created || '',
|
||||
items: track.items || [],
|
||||
}));
|
||||
|
||||
return {
|
||||
|
|
@ -530,25 +541,54 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
|||
return await this.wpService.getFulfillments(this.site, String(orderId));
|
||||
}
|
||||
|
||||
async createOrderFulfillment(orderId: string | number, data: FulfillmentDTO): Promise<any> {
|
||||
const shipmentData: Partial<WooFulfillment> = {
|
||||
tracking_provider: data.shipping_provider,
|
||||
async createOrderFulfillment(orderId: string | number, data: {
|
||||
tracking_number: string;
|
||||
shipping_provider: string;
|
||||
shipping_method?: string;
|
||||
status?: string;
|
||||
date_created?: string;
|
||||
items?: Array<{
|
||||
order_item_id: number;
|
||||
quantity: number;
|
||||
}>;
|
||||
}): Promise<any> {
|
||||
const shipmentData: any = {
|
||||
shipping_provider: data.shipping_provider,
|
||||
tracking_number: data.tracking_number,
|
||||
data_sipped: data.date_created,
|
||||
// items: data.items,
|
||||
};
|
||||
|
||||
if (data.shipping_method) {
|
||||
shipmentData.shipping_method = data.shipping_method;
|
||||
}
|
||||
|
||||
if (data.status) {
|
||||
shipmentData.status = data.status;
|
||||
}
|
||||
|
||||
if (data.date_created) {
|
||||
shipmentData.date_created = data.date_created;
|
||||
}
|
||||
|
||||
if (data.items) {
|
||||
shipmentData.items = data.items;
|
||||
}
|
||||
|
||||
const response = await this.wpService.createFulfillment(this.site, String(orderId), shipmentData);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: FulfillmentDTO): Promise<any> {
|
||||
const shipmentData: Partial<WooFulfillment> = {
|
||||
tracking_provider: data.shipping_provider,
|
||||
tracking_number: data.tracking_number,
|
||||
data_sipped: data.date_created,
|
||||
// items: data.items,
|
||||
}
|
||||
return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, shipmentData);
|
||||
async updateOrderFulfillment(orderId: string | number, fulfillmentId: string, data: {
|
||||
tracking_number?: string;
|
||||
shipping_provider?: string;
|
||||
shipping_method?: string;
|
||||
status?: string;
|
||||
date_created?: string;
|
||||
items?: Array<{
|
||||
order_item_id: number;
|
||||
quantity: number;
|
||||
}>;
|
||||
}): Promise<any> {
|
||||
return await this.wpService.updateFulfillment(this.site, String(orderId), fulfillmentId, data);
|
||||
}
|
||||
|
||||
async deleteOrderFulfillment(orderId: string | number, fulfillmentId: string): Promise<boolean> {
|
||||
|
|
|
|||
|
|
@ -799,16 +799,14 @@ export class UpdateWebhookDTO {
|
|||
|
||||
|
||||
export class FulfillmentItemDTO {
|
||||
@ApiProperty({ description: '订单项ID' ,required: false})
|
||||
@ApiProperty({ description: '订单项ID' })
|
||||
order_item_id: number;
|
||||
|
||||
@ApiProperty({ description: '数量' ,required:false})
|
||||
@ApiProperty({ description: '数量' })
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
export class FulfillmentDTO {
|
||||
@ApiProperty({ description: '物流id', required: false })
|
||||
tracking_id?: string;
|
||||
@ApiProperty({ description: '物流单号', required: false })
|
||||
tracking_number?: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -370,24 +370,17 @@ export interface WooOrder {
|
|||
date_modified?: string;
|
||||
date_modified_gmt?: string;
|
||||
// 物流追踪信息
|
||||
fulfillments?: WooFulfillment[];
|
||||
}
|
||||
// 这个是一个插件的物流追踪信息
|
||||
// 接口:
|
||||
export interface WooFulfillment {
|
||||
data_sipped: string;
|
||||
tracking_id: string;
|
||||
tracking_link: string;
|
||||
tracking_number: string;
|
||||
tracking_provider: string;
|
||||
}
|
||||
// https://docs.zorem.com/docs/ast-free/developers/adding-tracking-info-to-orders/
|
||||
export interface WooFulfillmentCreateParams {
|
||||
order_id: string;
|
||||
tracking_provider: string;
|
||||
tracking_number: string;
|
||||
date_shipped?: string;
|
||||
status_shipped?: string;
|
||||
fulfillments?: Array<{
|
||||
tracking_number?: string;
|
||||
shipping_provider?: string;
|
||||
shipping_method?: string;
|
||||
status?: string;
|
||||
date_created?: string;
|
||||
items?: Array<{
|
||||
order_item_id?: number;
|
||||
quantity?: number;
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
export interface WooOrderRefund {
|
||||
id?: number;
|
||||
|
|
@ -559,8 +552,7 @@ export interface WooOrderSearchParams {
|
|||
order: string;
|
||||
orderby: string;
|
||||
parant: string[];
|
||||
parent_exclude: string[];
|
||||
status: WooOrderStatusSearchParams[];
|
||||
status: (WooOrderStatusSearchParams)[];
|
||||
customer: number;
|
||||
product: number;
|
||||
dp: number;
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
export const toArray = (value: any): any[] => {
|
||||
if (Array.isArray(value)) return value;
|
||||
if (value === undefined || value === null) return [];
|
||||
return String(value).split(',').map(v => v.trim()).filter(Boolean);
|
||||
};
|
||||
|
||||
export const toNumber = (value: any): number | undefined => {
|
||||
if (value === undefined || value === null || value === '') return undefined;
|
||||
const n = Number(value);
|
||||
return Number.isFinite(n) ? n : undefined;
|
||||
};
|
||||
Loading…
Reference in New Issue