Compare commits
3 Commits
a21681da10
...
3750b15298
| Author | SHA1 | Date |
|---|---|---|
|
|
3750b15298 | |
|
|
a74e890d7e | |
|
|
e83745db4f |
|
|
@ -12,4 +12,5 @@ run/
|
||||||
.tsbuildinfo
|
.tsbuildinfo
|
||||||
.tsbuildinfo.*
|
.tsbuildinfo.*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
**/config.prod.ts
|
**/config.prod.ts
|
||||||
|
**/config.local.ts
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
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,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