fix: track查询更换后产品
This commit is contained in:
parent
c55eefa3de
commit
96eb7768f3
|
|
@ -247,11 +247,11 @@ export class LogisticsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('/getTrackingNumber')
|
@Post('/getOrderList')
|
||||||
async getTrackingNumber(@Query('number') number: string) {
|
async getOrderList(@Query('number') number: string) {
|
||||||
try {
|
try {
|
||||||
return successResponse(
|
return successResponse(
|
||||||
await this.logisticsService.getTrackingNumber(number)
|
await this.logisticsService.getOrderList(number)
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorResponse(error?.message || '获取失败');
|
return errorResponse(error?.message || '获取失败');
|
||||||
|
|
@ -259,11 +259,11 @@ export class LogisticsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@Post('/getListByTrackingId')
|
@Post('/getListByOrderId')
|
||||||
async getListByTrackingId(@Query('shipment_id') shipment_id: number) {
|
async getListByOrderId(@Query('id') orderId: number) {
|
||||||
try {
|
try {
|
||||||
return successResponse(
|
return successResponse(
|
||||||
await this.logisticsService.getListByTrackingId(shipment_id)
|
await this.logisticsService.getListByOrderId(orderId)
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorResponse(error?.message || '获取失败');
|
return errorResponse(error?.message || '获取失败');
|
||||||
|
|
|
||||||
|
|
@ -409,9 +409,11 @@ export class LogisticsService {
|
||||||
// 更新产品发货信息
|
// 更新产品发货信息
|
||||||
this.orderService.updateOrderSales(order.id, sales);
|
this.orderService.updateOrderSales(order.id, sales);
|
||||||
|
|
||||||
return { data: {
|
return {
|
||||||
|
data: {
|
||||||
shipmentId
|
shipmentId
|
||||||
} };
|
}
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (resShipmentOrder.status === 'SUCCESS') {
|
if (resShipmentOrder.status === 'SUCCESS') {
|
||||||
await this.uniExpressService.deleteShipment(resShipmentOrder.data.tno);
|
await this.uniExpressService.deleteShipment(resShipmentOrder.data.tno);
|
||||||
|
|
@ -553,7 +555,7 @@ export class LogisticsService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTrackingNumber(number: string) {
|
async getOrderList(number: string) {
|
||||||
const orders = await this.orderModel.find({
|
const orders = await this.orderModel.find({
|
||||||
where: {
|
where: {
|
||||||
externalOrderId: Like(`%${number}%`),
|
externalOrderId: Like(`%${number}%`),
|
||||||
|
|
@ -568,56 +570,14 @@ export class LogisticsService {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getListByTrackingId(id: number) {
|
async getListByOrderId(id: number) {
|
||||||
const qb = `
|
const item = await this.orderItem.find({ where: { orderId: id } });
|
||||||
SELECT
|
const saleItem = await this.orderSaleModel.find({ where: { orderId: id } });
|
||||||
oi.name,
|
|
||||||
oi.quantity,
|
|
||||||
CASE
|
|
||||||
WHEN oi.externalVariationId != 0 THEN v.constitution
|
|
||||||
ELSE p.constitution
|
|
||||||
END AS constitution
|
|
||||||
FROM order_item oi
|
|
||||||
LEFT JOIN wp_product p ON oi.siteId=p.siteId AND oi.externalProductId=p.externalProductId
|
|
||||||
LEFT JOIN variation v ON oi.siteId=v.siteId AND oi.externalVariationId=v.externalVariationId
|
|
||||||
WHERE oi.orderId=?
|
|
||||||
`;
|
|
||||||
const saleItem = await this.orderSaleModel.query(qb, [id]);
|
|
||||||
const allSkus = new Set<string>();
|
|
||||||
for (const item of saleItem) {
|
|
||||||
if (!item.constitution) continue;
|
|
||||||
try {
|
|
||||||
item.constitution.forEach(c => allSkus.add(c.sku));
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('Invalid constitution JSON:', item.constitution);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(allSkus);
|
|
||||||
const skuList = Array.from(allSkus);
|
|
||||||
let skuNameMap = new Map<string, string>();
|
|
||||||
|
|
||||||
if (skuList.length > 0) {
|
return {
|
||||||
const placeholders = skuList.map(() => '?').join(', ');
|
item,
|
||||||
const productRows = await this.orderSaleModel.query(
|
saleItem
|
||||||
`SELECT sku, name FROM product WHERE sku IN (${placeholders})`,
|
};
|
||||||
skuList
|
|
||||||
);
|
|
||||||
skuNameMap = new Map(productRows.map(p => [p.sku, p.name]));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const item of saleItem) {
|
|
||||||
if (!item.constitution) continue;
|
|
||||||
try {
|
|
||||||
item.constitution = item.constitution.map(c => ({
|
|
||||||
...c,
|
|
||||||
name: skuNameMap.get(c.sku) || null,
|
|
||||||
}));
|
|
||||||
} catch (e) {
|
|
||||||
item.constitution = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return saleItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getList(param: Record<string, any>) {
|
async getList(param: Record<string, any>) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue