fix: 完善订单查询选项 #59

Merged
zhuotianyuan merged 3 commits from zksu/API:main into main 2026-01-22 08:17:22 +00:00
3 changed files with 15 additions and 15 deletions
Showing only changes of commit 75056db42c - Show all commits

View File

@ -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);

View File

@ -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;

11
src/utils/trans.util.ts Normal file
View File

@ -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;
};