Compare commits

..

No commits in common. "00b6ca828e8b0ac275f1e2bc9f11889b3afc1df8" and "ac17f9f224c5d1c0e584f7cd805c7fb1c3fb22b1" have entirely different histories.

4 changed files with 34 additions and 75 deletions

View File

@ -21,7 +21,6 @@ export class ShipmentBookDTO {
orderIds?: number[]; orderIds?: number[];
@ApiProperty() @ApiProperty()
@Rule(RuleType.string())
shipmentPlatform: string; shipmentPlatform: string;
} }

View File

@ -118,8 +118,8 @@ interface RateTryResponseData {
// 创建订单响应数据接口 // 创建订单响应数据接口
interface CreateOrderResponseData { interface CreateOrderResponseData {
msg: string; partnerOrderNumber: string;
data: any; shipOrderId: string;
} }
// 查询订单响应数据接口 // 查询订单响应数据接口
@ -152,8 +152,8 @@ export class FreightwavesService {
// 默认配置 // 默认配置
private config: FreightwavesConfig = { private config: FreightwavesConfig = {
appSecret: 'gELCHguGmdTLo!zfihfM91hae8G@9Sz23Mh6pHrt', appSecret: 'gELCHguGmdTLo!zfihfM91hae8G@9Sz23Mh6pHrt',
apiBaseUrl: 'http://tms.freightwaves.ca:8901/', apiBaseUrl: 'https://tms.freightwaves.ca',
partner: '25072621035200000060' partner: '25072621035200000060',
}; };
// 初始化配置 // 初始化配置

View File

@ -343,6 +343,7 @@ export class LogisticsService {
let resShipmentOrder; let resShipmentOrder;
try { try {
resShipmentOrder = this.mepShipment(data);
// 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,
@ -372,20 +373,11 @@ export class LogisticsService {
// } // }
// } // }
resShipmentOrder =await this.mepShipment(data,order);
// if (data.shipmentPlatform === 'uniuni') {
// // 添加运单 // // 添加运单
// resShipmentOrder = await this.uniExpressService.createShipment(reqBody); // resShipmentOrder = await this.uniExpressService.createShipment(reqBody);
// }
// if (data.shipmentPlatform === 'freightwaves') { // // 记录物流信息,并将订单状态转到完成
// // 添加运单 if (resShipmentOrder.status === 'SUCCESS') {
// resShipmentOrder = await this.freightcomService.createShipment(reqBody);
// }
// 记录物流信息,并将订单状态转到完成
if (resShipmentOrder.status === 'SUCCESS'||resShipmentOrder.code === '00000200') {
order.orderStatus = ErpOrderStatus.COMPLETED; order.orderStatus = ErpOrderStatus.COMPLETED;
} else { } else {
throw new Error('运单生成失败'); throw new Error('运单生成失败');
@ -396,11 +388,11 @@ export class LogisticsService {
await dataSource.transaction(async manager => { await dataSource.transaction(async manager => {
const orderRepo = manager.getRepository(Order); const orderRepo = manager.getRepository(Order);
const shipmentRepo = manager.getRepository(Shipment); const shipmentRepo = manager.getRepository(Shipment);
const tracking_provider = data.shipmentPlatform; // todo: id未确定,后写进常数 const tracking_provider = 'UniUni'; // todo: id未确定后写进常数
// 同步物流信息到woocommerce // 同步物流信息到woocommerce
const site = await this.siteService.get(Number(order.siteId), true); const site = await this.siteService.get(Number(order.siteId), true);
const res = await this.wpService.createFulfillment(site, order.externalOrderId, { const res = await this.wpService.createShipment(site, order.externalOrderId, {
tracking_number: resShipmentOrder.data.tno, tracking_number: resShipmentOrder.data.tno,
tracking_provider: tracking_provider, tracking_provider: tracking_provider,
}); });
@ -421,15 +413,12 @@ export class LogisticsService {
} }
// 同步订单状态到woocommerce // 同步订单状态到woocommerce
if(order.source_type!="shopyy"){
if (order.status !== OrderStatus.COMPLETED) { if (order.status !== OrderStatus.COMPLETED) {
await this.wpService.updateOrder(site, order.externalOrderId, { await this.wpService.updateOrder(site, order.externalOrderId, {
status: OrderStatus.COMPLETED, status: OrderStatus.COMPLETED,
}); });
order.status = OrderStatus.COMPLETED; order.status = OrderStatus.COMPLETED;
} }
}
order.orderStatus = ErpOrderStatus.COMPLETED; order.orderStatus = ErpOrderStatus.COMPLETED;
await orderRepo.save(order); await orderRepo.save(order);
@ -454,7 +443,7 @@ export class LogisticsService {
if (resShipmentOrder.status === 'SUCCESS') { if (resShipmentOrder.status === 'SUCCESS') {
await this.uniExpressService.deleteShipment(resShipmentOrder.data.tno); await this.uniExpressService.deleteShipment(resShipmentOrder.data.tno);
} }
throw new Error(`上游请求错误:${error}`); throw new Error(`上游请求错误${error}`);
} }
} }
@ -681,7 +670,8 @@ export class LogisticsService {
async mepShipment(data: ShipmentBookDTO,order:Order) {
async mepShipment(data: ShipmentBookDTO) {
try { try {
const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId }); const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId });
let resShipmentOrder; let resShipmentOrder;
@ -711,7 +701,7 @@ export class LogisticsService {
weight_uom: data.details.packaging_properties.packages[0].measurements.weight.unit, weight_uom: data.details.packaging_properties.packages[0].measurements.weight.unit,
currency: 'CAD', currency: 'CAD',
custom_field: { custom_field: {
'order_id': order.externalOrderId // todo: 需要获取订单的externalOrderId 'order_id': '' // todo: 需要获取订单的externalOrderId
} }
}; };
@ -721,10 +711,10 @@ export class LogisticsService {
if (data.shipmentPlatform === 'freightwaves') { if (data.shipmentPlatform === 'freightwaves') {
// 根据TMS系统对接说明文档格式化参数 // 根据TMS系统对接说明文档格式化参数
const reqBody: any = { const reqBody = {
shipCompany: 'UPSYYZ7000NEW', shipCompany: '', // 渠道(可以不指定)
partnerOrderNumber: order.externalOrderId , partnerOrderNumber: `order-${Date.now()}`, // 第三方客户订单编号(唯一)
warehouseId: '25072621030107400060', warehouseId: String(stock_point.upStreamStockPointId), // 发货仓库编号(转换为字符串类型)
shipper: { shipper: {
name: data.details.origin.contact_name, // 姓名 name: data.details.origin.contact_name, // 姓名
phone: data.details.origin.phone_number.number, // 电话提取number属性转换为字符串 phone: data.details.origin.phone_number.number, // 电话提取number属性转换为字符串
@ -766,22 +756,22 @@ export class LogisticsService {
weightUnit: (data.details.packaging_properties.packages[0].measurements.weight.unit === 'kg' ? 'KG' : 'LB') as 'KG' | 'LB' // 重量单位LB,KG weightUnit: (data.details.packaging_properties.packages[0].measurements.weight.unit === 'kg' ? 'KG' : 'LB') as 'KG' | 'LB' // 重量单位LB,KG
}, },
currency: 'CAD', // 币种默认CAD currency: 'CAD', // 币种默认CAD
description: '订单编号:'+order.externalOrderId // 包裹描述(确保是字符串类型) description: 'Package' // 包裹描述(确保是字符串类型)
} }
], ],
signService: 0, // 签名服务 0不使用, 1使用 signService: 0 as 0 | 1, // 签名服务 0不使用, 1使用
declaration: { declaration: {
"boxNo": "", //箱子编 boxNo: 'BOX-001', // 箱
"sku": "", //SKU sku: 'DEFAULT-SKU', // SKU
"cnname": "", //中文名称 cnname: '默认商品', // 中文名称
"enname": "", //英文名称 enname: 'Default Product', // 英文名称
"declaredPrice": 1, //申报单价 declaredPrice: 0, // 申报价格
"declaredQty": 1, //申报数量 declaredQty: 1, // 申报数量
"material": "", //材质 material: 'General', // 材质
"intendedUse": "", //用途 intendedUse: 'General use', // 用途
"cweight": 1, //产品单重 cweight: data.details.packaging_properties.packages[0].measurements.weight.value, // 重量
"hsCode": "", //海关编码 hsCode: '39269090', // 海关编码
"battery": "" //电池描述 battery: 'No' // 是否含电池
} }
}; };

View File

@ -403,34 +403,4 @@ export class WPService {
}; };
return await axios.request(config); return await axios.request(config);
} }
async createFulfillment(
site: any,
orderId: string,
data: Record<string, any>
) {
const apiUrl = site.apiUrl;
const { consumerKey, consumerSecret } = site;
const auth = Buffer.from(`${consumerKey}:${consumerSecret}`).toString(
'base64'
);
const config: AxiosRequestConfig = {
method: 'POST',
// 构建 URL,规避多/或少/问题
url: this.buildURL(
apiUrl,
'/wp-json',
'wc-ast/v3/orders',
orderId,
'shipment-trackings'
),
headers: {
Authorization: `Basic ${auth}`,
},
data,
};
return await axios.request(config);
}
} }