forked from yoone/WEB
1
0
Fork 0

fix(logistics): 修复运费计算中不同平台的错误处理逻辑

确保在uniuni和freightwaves平台返回错误状态时抛出异常,并统一返回金额单位为分
This commit is contained in:
zhuotianyuan 2026-01-26 17:28:14 +08:00
parent 3cd36892f6
commit bbbf6bc0a6
1 changed files with 15 additions and 5 deletions

View File

@ -32,6 +32,8 @@ import { OrderService } from './order.service';
import { convertKeysFromCamelToSnake } from '../utils/object-transform.util'; import { convertKeysFromCamelToSnake } from '../utils/object-transform.util';
import { SiteService } from './site.service'; import { SiteService } from './site.service';
import { FreightwavesService, RateTryRequest } from './freightwaves.service'; import { FreightwavesService, RateTryRequest } from './freightwaves.service';
@Provide()
export class LogisticsService { export class LogisticsService {
@InjectEntityModel(Service) @InjectEntityModel(Service)
serviceModel: Repository<Service>; serviceModel: Repository<Service>;
@ -320,22 +322,30 @@ export class LogisticsService {
let resShipmentFee: any; let resShipmentFee: any;
if (data.shipmentPlatform === 'uniuni') { if (data.shipmentPlatform === 'uniuni') {
resShipmentFee = await this.uniExpressService.getRates(reqBody); 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') { } else if (data.shipmentPlatform === 'freightwaves') {
const fre_reqBody = await this.convertToFreightwavesRateTry(data); const fre_reqBody = await this.convertToFreightwavesRateTry(data);
resShipmentFee = await this.freightwavesService.rateTry(fre_reqBody); resShipmentFee = await this.freightwavesService.rateTry(fre_reqBody);
if (resShipmentFee.totalAmount === null) {
throw new Error(resShipmentFee);
}
return resShipmentFee.totalAmount * 100;
} else { } else {
throw new Error('不支持的运单平台'); throw new Error('不支持的运单平台');
} }
if (resShipmentFee.status !== 'SUCCESS') {
throw new Error(resShipmentFee.ret_msg);
}
return resShipmentFee.data.totalAfterTax * 100;
} catch (e) { } catch (e) {
throw e; throw e;
} }
} }
async createShipment(orderId: number, data: ShipmentBookDTO, userId: number) { async createShipment(orderId: number, data: ShipmentBookDTO, userId: number) {
const order = await this.orderModel.findOneBy({ id: orderId }); const order = await this.orderModel.findOneBy({ id: orderId });
const { sales } = data; const { sales } = data;