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;