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