div #65
|
|
@ -322,25 +322,25 @@ export class LogisticsService {
|
||||||
let resShipmentFee: any;
|
let resShipmentFee: any;
|
||||||
if (data.shipmentPlatform === 'uniuni') {
|
if (data.shipmentPlatform === 'uniuni') {
|
||||||
resShipmentFee = await this.uniExpressService.getRates(reqBody);
|
resShipmentFee = await this.uniExpressService.getRates(reqBody);
|
||||||
|
|
||||||
if (resShipmentFee.status !== 'SUCCESS') {
|
if (resShipmentFee.status !== 'SUCCESS') {
|
||||||
throw new Error(resShipmentFee.ret_msg);
|
throw new Error(resShipmentFee.ret_msg);
|
||||||
}
|
}
|
||||||
return resShipmentFee.data.totalAfterTax * 100;
|
return resShipmentFee.data.totalAfterTax * 100;
|
||||||
} else if (data.shipmentPlatform === 'freightwaves') {
|
} else if (data.shipmentPlatform === 'freightwaves') {
|
||||||
const fre_reqBody = await this.convertToFreightwavesRateTry(data);
|
const fre_reqBody = await this.convertToFreightwavesRateTry(data);
|
||||||
resShipmentFee = await this.freightwavesService.rateTry(fre_reqBody);
|
resShipmentFee = await this.freightwavesService.rateTry(fre_reqBody);
|
||||||
|
|
||||||
if (resShipmentFee.totalAmount === null) {
|
if (resShipmentFee.totalAmount === null) {
|
||||||
throw new Error(resShipmentFee);
|
throw new Error(resShipmentFee);
|
||||||
}
|
}
|
||||||
return resShipmentFee.totalAmount * 100;
|
return resShipmentFee.totalAmount * 100;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('不支持的运单平台');
|
throw new Error('不支持的运单平台');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,17 +105,17 @@ export class OrderService {
|
||||||
|
|
||||||
async syncOrders(siteId: string) {
|
async syncOrders(siteId: string) {
|
||||||
//TODO: 临时方案,后续记得调整成前端可控制
|
//TODO: 临时方案,后续记得调整成前端可控制
|
||||||
const daysRange = 7;
|
const daysRange = 7;
|
||||||
|
|
||||||
// 获取当前时间和7天前时间
|
// 获取当前时间和7天前时间
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const sevenDaysAgo = new Date();
|
const sevenDaysAgo = new Date();
|
||||||
sevenDaysAgo.setDate(now.getDate() - daysRange);
|
sevenDaysAgo.setDate(now.getDate() - daysRange);
|
||||||
|
|
||||||
// 格式化时间为ISO 8601
|
// 格式化时间为ISO 8601
|
||||||
const after = sevenDaysAgo.toISOString();
|
const after = sevenDaysAgo.toISOString();
|
||||||
const before = now.toISOString();
|
const before = now.toISOString();
|
||||||
const orders = await this.wpService.getOrders(siteId,{
|
const orders = await this.wpService.getOrders(siteId, {
|
||||||
after: after,
|
after: after,
|
||||||
before: before,
|
before: before,
|
||||||
}); // 调用 WooCommerce API 获取订单
|
}); // 调用 WooCommerce API 获取订单
|
||||||
|
|
@ -168,13 +168,13 @@ export class OrderService {
|
||||||
// 更新状态
|
// 更新状态
|
||||||
await this.autoUpdateOrderStatus(siteId, order);
|
await this.autoUpdateOrderStatus(siteId, order);
|
||||||
if (order.status === OrderStatus.AUTO_DRAFT) {
|
if (order.status === OrderStatus.AUTO_DRAFT) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 更新订单
|
// 更新订单
|
||||||
if (existingOrder) {
|
if (existingOrder) {
|
||||||
await this.orderModel.update({ id: existingOrder.id }, { orderStatus: this.mapOrderStatus(order.status) });
|
await this.orderModel.update({ id: existingOrder.id }, { orderStatus: this.mapOrderStatus(order.status) });
|
||||||
}
|
}
|
||||||
const externalOrderId = order.id;
|
const externalOrderId = order.id;
|
||||||
if (
|
if (
|
||||||
existingOrder &&
|
existingOrder &&
|
||||||
existingOrder.orderStatus !== ErpOrderStatus.COMPLETED &&
|
existingOrder.orderStatus !== ErpOrderStatus.COMPLETED &&
|
||||||
|
|
@ -331,7 +331,7 @@ export class OrderService {
|
||||||
externalOrderId: string;
|
externalOrderId: string;
|
||||||
orderItems: Record<string, any>[];
|
orderItems: Record<string, any>[];
|
||||||
}) {
|
}) {
|
||||||
console.log('saveOrderItems params',params)
|
console.log('saveOrderItems params', params)
|
||||||
const { siteId, orderId, externalOrderId, orderItems } = params;
|
const { siteId, orderId, externalOrderId, orderItems } = params;
|
||||||
const currentOrderItems = await this.orderItemModel.find({
|
const currentOrderItems = await this.orderItemModel.find({
|
||||||
where: { siteId, externalOrderId: externalOrderId },
|
where: { siteId, externalOrderId: externalOrderId },
|
||||||
|
|
@ -1358,8 +1358,8 @@ export class OrderService {
|
||||||
const key = it?.externalSubscriptionId
|
const key = it?.externalSubscriptionId
|
||||||
? `sub:${it.externalSubscriptionId}`
|
? `sub:${it.externalSubscriptionId}`
|
||||||
: it?.externalOrderId
|
: it?.externalOrderId
|
||||||
? `ord:${it.externalOrderId}`
|
? `ord:${it.externalOrderId}`
|
||||||
: `id:${it?.id}`;
|
: `id:${it?.id}`;
|
||||||
if (!seen.has(key)) {
|
if (!seen.has(key)) {
|
||||||
seen.add(key);
|
seen.add(key);
|
||||||
relatedList.push(it);
|
relatedList.push(it);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue