From bbbf6bc0a6f9c324f84de2ce0b96ffbe8017064b Mon Sep 17 00:00:00 2001 From: zhuotianyuan Date: Mon, 26 Jan 2026 17:28:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(logistics):=20=E4=BF=AE=E5=A4=8D=E8=BF=90?= =?UTF-8?q?=E8=B4=B9=E8=AE=A1=E7=AE=97=E4=B8=AD=E4=B8=8D=E5=90=8C=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=9A=84=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 确保在uniuni和freightwaves平台返回错误状态时抛出异常,并统一返回金额单位为分 --- src/service/logistics.service.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/service/logistics.service.ts b/src/service/logistics.service.ts index 8630deb..620bae3 100644 --- a/src/service/logistics.service.ts +++ b/src/service/logistics.service.ts @@ -32,6 +32,8 @@ import { OrderService } from './order.service'; import { convertKeysFromCamelToSnake } from '../utils/object-transform.util'; import { SiteService } from './site.service'; import { FreightwavesService, RateTryRequest } from './freightwaves.service'; + +@Provide() export class LogisticsService { @InjectEntityModel(Service) serviceModel: Repository; @@ -320,22 +322,30 @@ export class LogisticsService { let resShipmentFee: any; if (data.shipmentPlatform === 'uniuni') { resShipmentFee = await this.uniExpressService.getRates(reqBody); + + if (resShipmentFee.status !== 'SUCCESS') { + throw new Error(resShipmentFee.ret_msg); + } + return resShipmentFee.data.totalAfterTax * 100; } else if (data.shipmentPlatform === 'freightwaves') { const fre_reqBody = await this.convertToFreightwavesRateTry(data); resShipmentFee = await this.freightwavesService.rateTry(fre_reqBody); + + if (resShipmentFee.totalAmount === null) { + throw new Error(resShipmentFee); + } + return resShipmentFee.totalAmount * 100; } else { throw new Error('不支持的运单平台'); } - if (resShipmentFee.status !== 'SUCCESS') { - throw new Error(resShipmentFee.ret_msg); - } - return resShipmentFee.data.totalAfterTax * 100; + + } catch (e) { throw e; } } - + async createShipment(orderId: number, data: ShipmentBookDTO, userId: number) { const order = await this.orderModel.findOneBy({ id: orderId }); const { sales } = data;