Compare commits
1 Commits
676aa47e6f
...
94767d5120
| Author | SHA1 | Date |
|---|---|---|
|
|
94767d5120 |
|
|
@ -145,7 +145,10 @@ export class LogisticsController {
|
|||
}
|
||||
}
|
||||
|
||||
@Del('deleteShipment/id')
|
||||
@ApiOkResponse({
|
||||
type: BooleanRes,
|
||||
})
|
||||
@Post('/deleteShipment/:id')
|
||||
async deleteShipment(@Param('id') id: number) {
|
||||
try {
|
||||
const res = await this.logisticsService.removeShipment(id);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@ export class Shipment {
|
|||
@Expose()
|
||||
id: string;
|
||||
|
||||
@ApiProperty()
|
||||
@Column({ nullable: true })
|
||||
order_id: number;
|
||||
|
||||
@ApiProperty()
|
||||
@OneToOne(() => Order)
|
||||
@JoinColumn({ name: 'order_id' })
|
||||
|
|
|
|||
|
|
@ -207,13 +207,10 @@ export class LogisticsService {
|
|||
async removeShipment(shipmentId) {
|
||||
try {
|
||||
const shipment:Shipment = await this.shipmentModel.findOneBy({id: shipmentId});
|
||||
const order = shipment.order;
|
||||
// todo 同步到wooccommerce
|
||||
const order:Order = await this.orderModel.findOneBy({id: shipment.order_id});
|
||||
// todo 同步到wooccommerce删除运单信息
|
||||
const site = await this.geSite(order.siteId);
|
||||
await this.wpService.deleteShipment(site, order.externalOrderId, shipment.tracking_id, {
|
||||
tracking_number: shipment.return_tracking_number,
|
||||
tracking_provider: shipment?.tracking_provider,
|
||||
});
|
||||
await this.wpService.deleteShipment(site, order.externalOrderId, shipment.tracking_id);
|
||||
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
let transactionError = undefined;
|
||||
|
|
@ -228,6 +225,18 @@ export class LogisticsService {
|
|||
|
||||
const res = await this.uniExpressService.deleteShipment(shipment.return_tracking_number);
|
||||
console.log('res', res.data);
|
||||
|
||||
// 同步订单状态到woocommerce
|
||||
if (order.status === OrderStatus.COMPLETED) {
|
||||
await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||
status: OrderStatus.PROCESSING,
|
||||
});
|
||||
order.status = OrderStatus.PROCESSING;
|
||||
}
|
||||
order.orderStatus = ErpOrderStatus.PROCESSING;
|
||||
|
||||
await orderRepo.save(order);
|
||||
|
||||
}).catch(error => {
|
||||
transactionError = error;
|
||||
});
|
||||
|
|
@ -330,6 +339,7 @@ export class LogisticsService {
|
|||
}
|
||||
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);
|
||||
|
|
@ -354,10 +364,19 @@ export class LogisticsService {
|
|||
order: order
|
||||
});
|
||||
order.shipmentId = shipment.id;
|
||||
shipmentId = shipment.id;
|
||||
}
|
||||
|
||||
await orderRepo.save(order);
|
||||
// 同步订单状态到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
|
||||
});
|
||||
|
|
@ -368,7 +387,7 @@ export class LogisticsService {
|
|||
}
|
||||
|
||||
return { data: {
|
||||
resShipmentOrder
|
||||
shipmentId
|
||||
} };
|
||||
} catch(error) {
|
||||
if (resShipmentOrder.status === 'SUCCESS') {
|
||||
|
|
@ -460,6 +479,7 @@ export class LogisticsService {
|
|||
}
|
||||
|
||||
async delShipment(id: string, userId: number) {
|
||||
|
||||
const shipment = await this.shipmentModel.findOneBy({ id });
|
||||
if (!shipment) throw new Error('物流不存在');
|
||||
if (shipment.type === ShipmentType.FREIGHTCOM) {
|
||||
|
|
|
|||
|
|
@ -281,13 +281,13 @@ export class WPService {
|
|||
site: WpSite,
|
||||
orderId: string,
|
||||
trackingId: string,
|
||||
data: Record<string, any>
|
||||
): Promise<Boolean> {
|
||||
const { wpApiUrl, consumerKey, consumerSecret } = site;
|
||||
const auth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString(
|
||||
'base64'
|
||||
);
|
||||
|
||||
console.log('del', orderId, trackingId);
|
||||
// 删除接口: DELETE /wp-json/wc-shipment-tracking/v3/orders/<order_id>/shipment-trackings/<tracking_id>
|
||||
const config: AxiosRequestConfig = {
|
||||
method: 'DELETE',
|
||||
|
|
@ -295,7 +295,6 @@ export class WPService {
|
|||
headers: {
|
||||
Authorization: `Basic ${auth}`,
|
||||
},
|
||||
data,
|
||||
};
|
||||
return await axios.request(config);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue