Merge pull request '【Fix】紧急修复site数据优化产生的连接wp数据异常的bug' (#32) from zhuotianyuan/API:main into main
Reviewed-on: #32
This commit is contained in:
commit
a956c963c0
|
|
@ -16,8 +16,8 @@ export class OrderStatisticsParams {
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@Rule(RuleType.string().allow(null))
|
@Rule(RuleType.number().allow(null))
|
||||||
siteId?: string;
|
siteId?: number;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
enum: ['all', 'first_purchase', 'repeat_purchase'],
|
enum: ['all', 'first_purchase', 'repeat_purchase'],
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,21 @@ export class OrderService {
|
||||||
siteService: SiteService;
|
siteService: SiteService;
|
||||||
|
|
||||||
async syncOrders(siteId: string) {
|
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) {
|
for (const order of orders) {
|
||||||
await this.syncSingleOrder(siteId, order);
|
await this.syncSingleOrder(siteId, order);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class SiteService {
|
||||||
if (!site) return null;
|
if (!site) return null;
|
||||||
if (includeSecret) return site;
|
if (includeSecret) return site;
|
||||||
// 默认不返回密钥,进行字段脱敏
|
// 默认不返回密钥,进行字段脱敏
|
||||||
const { consumerKey, consumerSecret, ...rest } = site;
|
const { ...rest } = site;
|
||||||
return rest;
|
return rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,10 +186,10 @@ export class WPService {
|
||||||
const res = await api.get(`orders/${orderId}`);
|
const res = await api.get(`orders/${orderId}`);
|
||||||
return res.data as Record<string, any>;
|
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 site = await this.siteService.get(siteId);
|
||||||
const api = this.createApi(site, 'wc/v3');
|
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