订单号查订单详情
This commit is contained in:
parent
037df80080
commit
e83745db4f
|
|
@ -13,3 +13,4 @@ run/
|
|||
.tsbuildinfo.*
|
||||
yarn.lock
|
||||
**/config.prod.ts
|
||||
**/config.local.ts
|
||||
|
|
@ -26,6 +26,7 @@ import { Product } from '../entity/product.entty';
|
|||
import { ShippingDetailsDTO } from '../dto/freightcom.dto';
|
||||
import { CanadaPostService } from './canadaPost.service';
|
||||
import { OrderItem } from '../entity/order_item.entity';
|
||||
import { OrderSale } from '../entity/order_sale.entity';
|
||||
|
||||
@Provide()
|
||||
export class LogisticsService {
|
||||
|
|
@ -41,6 +42,9 @@ export class LogisticsService {
|
|||
@InjectEntityModel(Order)
|
||||
orderModel: Repository<Order>;
|
||||
|
||||
@InjectEntityModel(OrderSale)
|
||||
orderSaleModel: Repository<OrderSale>;
|
||||
|
||||
@InjectEntityModel(Shipment)
|
||||
shipmentModel: Repository<Shipment>;
|
||||
|
||||
|
|
@ -467,33 +471,70 @@ export class LogisticsService {
|
|||
}
|
||||
|
||||
async getTrackingNumber(number: string) {
|
||||
return await this.shipmentModel.find({
|
||||
const orders = await this.orderModel.find({
|
||||
where: {
|
||||
primary_tracking_number: Like(`%${number}%`),
|
||||
externalOrderId: Like(`%${number}%`),
|
||||
},
|
||||
});
|
||||
|
||||
const siteMap = new Map(this.sites.map(site => [site.id, site.siteName]));
|
||||
|
||||
return orders.map(order => ({
|
||||
...order,
|
||||
siteName: siteMap.get(order.siteId) || '',
|
||||
}));
|
||||
}
|
||||
|
||||
async getListByTrackingId(shipment_id: string) {
|
||||
const shipmentItem = await this.shipmentItemModel.find({
|
||||
where: {
|
||||
shipment_id,
|
||||
},
|
||||
});
|
||||
const orderShipment = await this.orderShipmentModel.find({
|
||||
where: {
|
||||
shipment_id,
|
||||
},
|
||||
});
|
||||
const orderItem = await this.orderItem.find({
|
||||
where: {
|
||||
id: In(orderShipment.map(v => v.order_id)),
|
||||
},
|
||||
});
|
||||
return {
|
||||
shipmentItem,
|
||||
orderItem,
|
||||
};
|
||||
async getListByTrackingId(id: string) {
|
||||
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>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
async getList(param: Record<string, any>) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue