Compare commits
No commits in common. "3750b15298e2257301676a499fe66de4b27ad0a9" and "a21681da108683a421c923038ed6402b92ace7c0" have entirely different histories.
3750b15298
...
a21681da10
|
|
@ -12,5 +12,4 @@ run/
|
||||||
.tsbuildinfo
|
.tsbuildinfo
|
||||||
.tsbuildinfo.*
|
.tsbuildinfo.*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
**/config.prod.ts
|
**/config.prod.ts
|
||||||
**/config.local.ts
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
import { MidwayConfig } from '@midwayjs/core';
|
|
||||||
export default {
|
|
||||||
koa: {
|
|
||||||
port: 7001,
|
|
||||||
},
|
|
||||||
typeorm: {
|
|
||||||
dataSource: {
|
|
||||||
default: {
|
|
||||||
host: '13.212.62.127',
|
|
||||||
username: 'root',
|
|
||||||
password: 'Yoone!@.2025',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// typeorm: {
|
|
||||||
// dataSource: {
|
|
||||||
// default: {
|
|
||||||
// host: '127.0.0.1',
|
|
||||||
// username: 'root',
|
|
||||||
// password: '123456',
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
cors: {
|
|
||||||
origin: '*', // 允许所有来源跨域请求
|
|
||||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // 允许的 HTTP 方法
|
|
||||||
allowHeaders: ['Content-Type', 'Authorization'], // 允许的自定义请求头
|
|
||||||
credentials: true, // 允许携带凭据(cookies等)
|
|
||||||
},
|
|
||||||
jwt: {
|
|
||||||
secret: 'YOONE2024!@abc',
|
|
||||||
expiresIn: '7d',
|
|
||||||
},
|
|
||||||
wpSite: [
|
|
||||||
{
|
|
||||||
id: '-1',
|
|
||||||
siteName: 'Admin',
|
|
||||||
email: 'tom@yoonevape.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '2',
|
|
||||||
wpApiUrl: 'http://localhost:10004',
|
|
||||||
consumerKey: 'ck_dc9e151e9048c8ed3e27f35ac79d2bf7d6840652',
|
|
||||||
consumerSecret: 'cs_d05d625d7b0ac05c6d765671d8417f41d9477e38',
|
|
||||||
siteName: 'Local',
|
|
||||||
email: 'tom@yoonevape.com',
|
|
||||||
emailPswd: 'lulin91.',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
freightcom: {
|
|
||||||
url: 'https://customer-external-api.ssd-test.freightcom.com',
|
|
||||||
token: '6zGj1qPTL1jIkbLmgaiYc6SwHUIXJ2t25htUF8uuFYiCg8ILCY6xnBEbvrX1p79L',
|
|
||||||
},
|
|
||||||
canadaPost: {
|
|
||||||
url: 'https://ct.soa-gw.canadapost.ca',
|
|
||||||
username: '65d23d3a75d7baf7',
|
|
||||||
password: '56443bb98b68dfdd60f52e',
|
|
||||||
customerNumber: '0006122480',
|
|
||||||
contractId: '0044168528',
|
|
||||||
},
|
|
||||||
} as MidwayConfig;
|
|
||||||
|
|
@ -26,7 +26,6 @@ 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 {
|
||||||
|
|
@ -42,9 +41,6 @@ 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>;
|
||||||
|
|
||||||
|
|
@ -471,70 +467,33 @@ export class LogisticsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTrackingNumber(number: string) {
|
async getTrackingNumber(number: string) {
|
||||||
const orders = await this.orderModel.find({
|
return await this.shipmentModel.find({
|
||||||
where: {
|
where: {
|
||||||
externalOrderId: Like(`%${number}%`),
|
primary_tracking_number: 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(id: string) {
|
async getListByTrackingId(shipment_id: string) {
|
||||||
const qb = `
|
const shipmentItem = await this.shipmentItemModel.find({
|
||||||
SELECT
|
where: {
|
||||||
oi.name,
|
shipment_id,
|
||||||
oi.quantity,
|
},
|
||||||
CASE
|
});
|
||||||
WHEN oi.externalVariationId != 0 THEN v.constitution
|
const orderShipment = await this.orderShipmentModel.find({
|
||||||
ELSE p.constitution
|
where: {
|
||||||
END AS constitution
|
shipment_id,
|
||||||
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
|
const orderItem = await this.orderItem.find({
|
||||||
WHERE oi.orderId=?
|
where: {
|
||||||
`;
|
id: In(orderShipment.map(v => v.order_id)),
|
||||||
const saleItem = await this.orderSaleModel.query(qb, [id]);
|
},
|
||||||
const allSkus = new Set<string>();
|
});
|
||||||
for (const item of saleItem) {
|
return {
|
||||||
if (!item.constitution) continue;
|
shipmentItem,
|
||||||
try {
|
orderItem,
|
||||||
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