fix: 修复订单同步时未限制时间范围的问题
修改订单同步逻辑,默认只同步最近7天的订单数据 移除站点服务中不必要的字段解构 扩展WP服务getOrders方法支持参数传递
This commit is contained in:
parent
927857a795
commit
ae34d1fab0
|
|
@ -16,8 +16,8 @@ export class OrderStatisticsParams {
|
|||
keyword?: string;
|
||||
|
||||
@ApiProperty()
|
||||
@Rule(RuleType.string().allow(null))
|
||||
siteId?: string;
|
||||
@Rule(RuleType.number().allow(null))
|
||||
siteId?: number;
|
||||
|
||||
@ApiProperty({
|
||||
enum: ['all', 'first_purchase', 'repeat_purchase'],
|
||||
|
|
|
|||
|
|
@ -104,7 +104,21 @@ export class OrderService {
|
|||
siteService: SiteService;
|
||||
|
||||
async syncOrders(siteId: string) {
|
||||
const orders = await this.wpService.getOrders(siteId); // 调用 WooCommerce API 获取订单
|
||||
//TODO: 临时方案,后续记得调整成前端可控制
|
||||
const daysRange = 7;
|
||||
|
||||
// 获取当前时间和7天前时间
|
||||
const now = new Date();
|
||||
const sevenDaysAgo = new Date();
|
||||
sevenDaysAgo.setDate(now.getDate() - daysRange);
|
||||
|
||||
// 格式化时间为ISO 8601
|
||||
const after = sevenDaysAgo.toISOString();
|
||||
const before = now.toISOString();
|
||||
const orders = await this.wpService.getOrders(siteId,{
|
||||
after: after,
|
||||
before: before,
|
||||
}); // 调用 WooCommerce API 获取订单
|
||||
for (const order of orders) {
|
||||
await this.syncSingleOrder(siteId, order);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export class SiteService {
|
|||
if (!site) return null;
|
||||
if (includeSecret) return site;
|
||||
// 默认不返回密钥,进行字段脱敏
|
||||
const { consumerKey, consumerSecret, ...rest } = site;
|
||||
const { ...rest } = site;
|
||||
return rest;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -186,10 +186,10 @@ export class WPService {
|
|||
const res = await api.get(`orders/${orderId}`);
|
||||
return res.data as Record<string, any>;
|
||||
}
|
||||
async getOrders(siteId: string): Promise<Record<string, any>[]> {
|
||||
async getOrders(siteId: string,params: Record<string, any> = {}): Promise<Record<string, any>[]> {
|
||||
const site = await this.siteService.get(siteId);
|
||||
const api = this.createApi(site, 'wc/v3');
|
||||
return await this.sdkGetAll<Record<string, any>>(api, 'orders');
|
||||
return await this.sdkGetAll<Record<string, any>>(api, 'orders', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue