fix: track查询更换后产品
This commit is contained in:
parent
c55eefa3de
commit
96eb7768f3
|
|
@ -247,11 +247,11 @@ export class LogisticsController {
|
|||
}
|
||||
|
||||
@ApiOkResponse()
|
||||
@Post('/getTrackingNumber')
|
||||
async getTrackingNumber(@Query('number') number: string) {
|
||||
@Post('/getOrderList')
|
||||
async getOrderList(@Query('number') number: string) {
|
||||
try {
|
||||
return successResponse(
|
||||
await this.logisticsService.getTrackingNumber(number)
|
||||
await this.logisticsService.getOrderList(number)
|
||||
);
|
||||
} catch (error) {
|
||||
return errorResponse(error?.message || '获取失败');
|
||||
|
|
@ -259,11 +259,11 @@ export class LogisticsController {
|
|||
}
|
||||
|
||||
@ApiOkResponse()
|
||||
@Post('/getListByTrackingId')
|
||||
async getListByTrackingId(@Query('shipment_id') shipment_id: number) {
|
||||
@Post('/getListByOrderId')
|
||||
async getListByOrderId(@Query('id') orderId: number) {
|
||||
try {
|
||||
return successResponse(
|
||||
await this.logisticsService.getListByTrackingId(shipment_id)
|
||||
await this.logisticsService.getListByOrderId(orderId)
|
||||
);
|
||||
} catch (error) {
|
||||
return errorResponse(error?.message || '获取失败');
|
||||
|
|
|
|||
|
|
@ -409,9 +409,11 @@ export class LogisticsService {
|
|||
// 更新产品发货信息
|
||||
this.orderService.updateOrderSales(order.id, sales);
|
||||
|
||||
return { data: {
|
||||
return {
|
||||
data: {
|
||||
shipmentId
|
||||
} };
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
if (resShipmentOrder.status === 'SUCCESS') {
|
||||
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({
|
||||
where: {
|
||||
externalOrderId: Like(`%${number}%`),
|
||||
|
|
@ -568,56 +570,14 @@ export class LogisticsService {
|
|||
}));
|
||||
}
|
||||
|
||||
async getListByTrackingId(id: number) {
|
||||
const qb = `
|
||||
SELECT
|
||||
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>();
|
||||
async getListByOrderId(id: number) {
|
||||
const item = await this.orderItem.find({ where: { orderId: id } });
|
||||
const saleItem = await this.orderSaleModel.find({ where: { orderId: id } });
|
||||
|
||||
if (skuList.length > 0) {
|
||||
const placeholders = skuList.map(() => '?').join(', ');
|
||||
const productRows = await this.orderSaleModel.query(
|
||||
`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;
|
||||
return {
|
||||
item,
|
||||
saleItem
|
||||
};
|
||||
}
|
||||
|
||||
async getList(param: Record<string, any>) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue