forked from yoone/API
订单号查订单详情
This commit is contained in:
parent
037df80080
commit
e83745db4f
|
|
@ -12,4 +12,5 @@ run/
|
||||||
.tsbuildinfo
|
.tsbuildinfo
|
||||||
.tsbuildinfo.*
|
.tsbuildinfo.*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
**/config.prod.ts
|
**/config.prod.ts
|
||||||
|
**/config.local.ts
|
||||||
|
|
@ -26,6 +26,7 @@ import { Product } from '../entity/product.entty';
|
||||||
import { ShippingDetailsDTO } from '../dto/freightcom.dto';
|
import { ShippingDetailsDTO } from '../dto/freightcom.dto';
|
||||||
import { CanadaPostService } from './canadaPost.service';
|
import { CanadaPostService } from './canadaPost.service';
|
||||||
import { OrderItem } from '../entity/order_item.entity';
|
import { OrderItem } from '../entity/order_item.entity';
|
||||||
|
import { OrderSale } from '../entity/order_sale.entity';
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
export class LogisticsService {
|
export class LogisticsService {
|
||||||
|
|
@ -41,6 +42,9 @@ export class LogisticsService {
|
||||||
@InjectEntityModel(Order)
|
@InjectEntityModel(Order)
|
||||||
orderModel: Repository<Order>;
|
orderModel: Repository<Order>;
|
||||||
|
|
||||||
|
@InjectEntityModel(OrderSale)
|
||||||
|
orderSaleModel: Repository<OrderSale>;
|
||||||
|
|
||||||
@InjectEntityModel(Shipment)
|
@InjectEntityModel(Shipment)
|
||||||
shipmentModel: Repository<Shipment>;
|
shipmentModel: Repository<Shipment>;
|
||||||
|
|
||||||
|
|
@ -467,33 +471,70 @@ export class LogisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTrackingNumber(number: string) {
|
async getTrackingNumber(number: string) {
|
||||||
return await this.shipmentModel.find({
|
const orders = await this.orderModel.find({
|
||||||
where: {
|
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) {
|
async getListByTrackingId(id: string) {
|
||||||
const shipmentItem = await this.shipmentItemModel.find({
|
const qb = `
|
||||||
where: {
|
SELECT
|
||||||
shipment_id,
|
oi.name,
|
||||||
},
|
oi.quantity,
|
||||||
});
|
CASE
|
||||||
const orderShipment = await this.orderShipmentModel.find({
|
WHEN oi.externalVariationId != 0 THEN v.constitution
|
||||||
where: {
|
ELSE p.constitution
|
||||||
shipment_id,
|
END AS constitution
|
||||||
},
|
FROM order_item oi
|
||||||
});
|
LEFT JOIN wp_product p ON oi.siteId=p.siteId AND oi.externalProductId=p.externalProductId
|
||||||
const orderItem = await this.orderItem.find({
|
LEFT JOIN variation v ON oi.siteId=v.siteId AND oi.externalVariationId=v.externalVariationId
|
||||||
where: {
|
WHERE oi.orderId=?
|
||||||
id: In(orderShipment.map(v => v.order_id)),
|
`;
|
||||||
},
|
const saleItem = await this.orderSaleModel.query(qb, [id]);
|
||||||
});
|
const allSkus = new Set<string>();
|
||||||
return {
|
for (const item of saleItem) {
|
||||||
shipmentItem,
|
if (!item.constitution) continue;
|
||||||
orderItem,
|
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>) {
|
async getList(param: Record<string, any>) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue