refactor(logistics): 移除已注释的订单完成处理逻辑
This commit is contained in:
parent
ac17f9f224
commit
fe5d4bf2f0
|
|
@ -377,68 +377,68 @@ export class LogisticsService {
|
|||
// resShipmentOrder = await this.uniExpressService.createShipment(reqBody);
|
||||
|
||||
// // 记录物流信息,并将订单状态转到完成
|
||||
if (resShipmentOrder.status === 'SUCCESS') {
|
||||
order.orderStatus = ErpOrderStatus.COMPLETED;
|
||||
} else {
|
||||
throw new Error('运单生成失败');
|
||||
}
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
let transactionError = undefined;
|
||||
let shipmentId = undefined;
|
||||
await dataSource.transaction(async manager => {
|
||||
const orderRepo = manager.getRepository(Order);
|
||||
const shipmentRepo = manager.getRepository(Shipment);
|
||||
const tracking_provider = 'UniUni'; // todo: id未确定,后写进常数
|
||||
// if (resShipmentOrder.status === 'SUCCESS') {
|
||||
// order.orderStatus = ErpOrderStatus.COMPLETED;
|
||||
// } else {
|
||||
// throw new Error('运单生成失败');
|
||||
// }
|
||||
// const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
// let transactionError = undefined;
|
||||
// let shipmentId = undefined;
|
||||
// await dataSource.transaction(async manager => {
|
||||
// const orderRepo = manager.getRepository(Order);
|
||||
// const shipmentRepo = manager.getRepository(Shipment);
|
||||
// const tracking_provider = 'UniUni'; // todo: id未确定,后写进常数
|
||||
|
||||
// 同步物流信息到woocommerce
|
||||
const site = await this.siteService.get(Number(order.siteId), true);
|
||||
const res = await this.wpService.createShipment(site, order.externalOrderId, {
|
||||
tracking_number: resShipmentOrder.data.tno,
|
||||
tracking_provider: tracking_provider,
|
||||
});
|
||||
// // 同步物流信息到woocommerce
|
||||
// const site = await this.siteService.get(Number(order.siteId), true);
|
||||
// const res = await this.wpService.createShipment(site, order.externalOrderId, {
|
||||
// tracking_number: resShipmentOrder.data.tno,
|
||||
// tracking_provider: tracking_provider,
|
||||
// });
|
||||
|
||||
if (order.orderStatus === ErpOrderStatus.COMPLETED) {
|
||||
const shipment = await shipmentRepo.save({
|
||||
tracking_provider: tracking_provider,
|
||||
tracking_id: res.data.tracking_id,
|
||||
unique_id: resShipmentOrder.data.uni_order_sn,
|
||||
stockPointId: String(data.stockPointId), // todo
|
||||
state: resShipmentOrder.data.uni_status_code,
|
||||
return_tracking_number: resShipmentOrder.data.tno,
|
||||
fee: data.details.shipmentFee,
|
||||
order: order
|
||||
});
|
||||
order.shipmentId = shipment.id;
|
||||
shipmentId = shipment.id;
|
||||
}
|
||||
// if (order.orderStatus === ErpOrderStatus.COMPLETED) {
|
||||
// const shipment = await shipmentRepo.save({
|
||||
// tracking_provider: tracking_provider,
|
||||
// tracking_id: res.data.tracking_id,
|
||||
// unique_id: resShipmentOrder.data.uni_order_sn,
|
||||
// stockPointId: String(data.stockPointId), // todo
|
||||
// state: resShipmentOrder.data.uni_status_code,
|
||||
// return_tracking_number: resShipmentOrder.data.tno,
|
||||
// fee: data.details.shipmentFee,
|
||||
// order: order
|
||||
// });
|
||||
// order.shipmentId = shipment.id;
|
||||
// shipmentId = shipment.id;
|
||||
// }
|
||||
|
||||
// 同步订单状态到woocommerce
|
||||
if (order.status !== OrderStatus.COMPLETED) {
|
||||
await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||
status: OrderStatus.COMPLETED,
|
||||
});
|
||||
order.status = OrderStatus.COMPLETED;
|
||||
}
|
||||
order.orderStatus = ErpOrderStatus.COMPLETED;
|
||||
// // 同步订单状态到woocommerce
|
||||
// if (order.status !== OrderStatus.COMPLETED) {
|
||||
// await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||
// status: OrderStatus.COMPLETED,
|
||||
// });
|
||||
// order.status = OrderStatus.COMPLETED;
|
||||
// }
|
||||
// order.orderStatus = ErpOrderStatus.COMPLETED;
|
||||
|
||||
await orderRepo.save(order);
|
||||
}).catch(error => {
|
||||
transactionError = error
|
||||
});
|
||||
// await orderRepo.save(order);
|
||||
// }).catch(error => {
|
||||
// transactionError = error
|
||||
// });
|
||||
|
||||
if (transactionError !== undefined) {
|
||||
console.log('err', transactionError);
|
||||
throw transactionError;
|
||||
}
|
||||
// if (transactionError !== undefined) {
|
||||
// console.log('err', transactionError);
|
||||
// throw transactionError;
|
||||
// }
|
||||
|
||||
// 更新产品发货信息
|
||||
this.orderService.updateOrderSales(order.id, sales);
|
||||
// // 更新产品发货信息
|
||||
// this.orderService.updateOrderSales(order.id, sales);
|
||||
|
||||
return {
|
||||
data: {
|
||||
shipmentId
|
||||
}
|
||||
};
|
||||
// return {
|
||||
// data: {
|
||||
// shipmentId
|
||||
// }
|
||||
// };
|
||||
} catch (error) {
|
||||
if (resShipmentOrder.status === 'SUCCESS') {
|
||||
await this.uniExpressService.deleteShipment(resShipmentOrder.data.tno);
|
||||
|
|
|
|||
Loading…
Reference in New Issue