diff --git a/src/adapter/woocommerce.adapter.ts b/src/adapter/woocommerce.adapter.ts index 0246569..f14d7d3 100644 --- a/src/adapter/woocommerce.adapter.ts +++ b/src/adapter/woocommerce.adapter.ts @@ -35,6 +35,7 @@ import { 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 { // 构造函数接收站点配置与服务实例 @@ -332,22 +333,11 @@ 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); @@ -358,9 +348,7 @@ export class WooCommerceAdapter implements ISiteAdapter { // 集合过滤参数 if (where.exclude) mapped.exclude = toArray(where.exclude); - if (where.include) mapped.include = toArray(where.include); - - if (where.ids) mapped.include = toArray(where.ids); + 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 (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); diff --git a/src/dto/woocommerce.dto.ts b/src/dto/woocommerce.dto.ts index 29245b7..c48b85f 100644 --- a/src/dto/woocommerce.dto.ts +++ b/src/dto/woocommerce.dto.ts @@ -559,7 +559,8 @@ export interface WooOrderSearchParams { order: string; orderby: string; parant: string[]; - status: (WooOrderStatusSearchParams)[]; + parent_exclude: string[]; + status: WooOrderStatusSearchParams[]; customer: number; product: number; dp: number; diff --git a/src/utils/trans.util.ts b/src/utils/trans.util.ts new file mode 100644 index 0000000..57063e3 --- /dev/null +++ b/src/utils/trans.util.ts @@ -0,0 +1,11 @@ +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; +}; \ No newline at end of file