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 || '获取失败');
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ export class LogisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateShipmentStateById(id: number) {
|
async updateShipmentStateById(id: number) {
|
||||||
const shipment:Shipment = await this.shipmentModel.findOneBy({ id : id });
|
const shipment: Shipment = await this.shipmentModel.findOneBy({ id: id });
|
||||||
return this.updateShipmentState(shipment);
|
return this.updateShipmentState(shipment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +219,7 @@ export class LogisticsService {
|
||||||
|
|
||||||
async getShipmentLabel(shipmentId) {
|
async getShipmentLabel(shipmentId) {
|
||||||
try {
|
try {
|
||||||
const shipment:Shipment = await this.shipmentModel.findOneBy({id: shipmentId});
|
const shipment: Shipment = await this.shipmentModel.findOneBy({ id: shipmentId });
|
||||||
if (!shipment) {
|
if (!shipment) {
|
||||||
throw new Error('运单不存在');
|
throw new Error('运单不存在');
|
||||||
}
|
}
|
||||||
|
|
@ -231,11 +231,11 @@ export class LogisticsService {
|
||||||
|
|
||||||
async removeShipment(shipmentId: number) {
|
async removeShipment(shipmentId: number) {
|
||||||
try {
|
try {
|
||||||
const shipment:Shipment = await this.shipmentModel.findOneBy({id: shipmentId});
|
const shipment: Shipment = await this.shipmentModel.findOneBy({ id: shipmentId });
|
||||||
if (shipment.state !== '190') { // todo,写常数
|
if (shipment.state !== '190') { // todo,写常数
|
||||||
throw new Error('订单当前状态无法删除');
|
throw new Error('订单当前状态无法删除');
|
||||||
}
|
}
|
||||||
const order:Order = await this.orderModel.findOneBy({id: shipment.order_id});
|
const order: Order = await this.orderModel.findOneBy({ id: shipment.order_id });
|
||||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||||
let transactionError = undefined;
|
let transactionError = undefined;
|
||||||
await dataSource.transaction(async manager => {
|
await dataSource.transaction(async manager => {
|
||||||
|
|
@ -271,7 +271,7 @@ export class LogisticsService {
|
||||||
}
|
}
|
||||||
order.orderStatus = ErpOrderStatus.PROCESSING;
|
order.orderStatus = ErpOrderStatus.PROCESSING;
|
||||||
this.orderModel.save(order);
|
this.orderModel.save(order);
|
||||||
|
|
||||||
// todo 同步到wooccommerce删除运单信息
|
// todo 同步到wooccommerce删除运单信息
|
||||||
await this.wpService.deleteShipment(site, order.externalOrderId, shipment.tracking_id);
|
await this.wpService.deleteShipment(site, order.externalOrderId, shipment.tracking_id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -287,7 +287,7 @@ export class LogisticsService {
|
||||||
|
|
||||||
async getShipmentFee(data: ShipmentFeeBookDTO) {
|
async getShipmentFee(data: ShipmentFeeBookDTO) {
|
||||||
try {
|
try {
|
||||||
const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId});
|
const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId });
|
||||||
const reqBody = {
|
const reqBody = {
|
||||||
...convertKeysFromCamelToSnake(data),
|
...convertKeysFromCamelToSnake(data),
|
||||||
pickup_warehouse: stock_point.upStreamStockPointId,
|
pickup_warehouse: stock_point.upStreamStockPointId,
|
||||||
|
|
@ -319,7 +319,7 @@ export class LogisticsService {
|
||||||
|
|
||||||
let resShipmentOrder;
|
let resShipmentOrder;
|
||||||
try {
|
try {
|
||||||
const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId});
|
const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId });
|
||||||
const reqBody = {
|
const reqBody = {
|
||||||
sender: data.details.origin.contact_name,
|
sender: data.details.origin.contact_name,
|
||||||
start_phone: data.details.origin.phone_number,
|
start_phone: data.details.origin.phone_number,
|
||||||
|
|
@ -409,10 +409,12 @@ export class LogisticsService {
|
||||||
// 更新产品发货信息
|
// 更新产品发货信息
|
||||||
this.orderService.updateOrderSales(order.id, sales);
|
this.orderService.updateOrderSales(order.id, sales);
|
||||||
|
|
||||||
return { data: {
|
return {
|
||||||
shipmentId
|
data: {
|
||||||
} };
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -469,7 +471,7 @@ export class LogisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShipment(id: number) {
|
async getShipment(id: number) {
|
||||||
const orderShipments:OrderShipment[] = await this.orderShipmentModel.find({
|
const orderShipments: OrderShipment[] = await this.orderShipmentModel.find({
|
||||||
where: { shipment_id: id },
|
where: { shipment_id: id },
|
||||||
});
|
});
|
||||||
if (!orderShipments || orderShipments.length === 0) return;
|
if (!orderShipments || orderShipments.length === 0) return;
|
||||||
|
|
@ -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