From f331e1b86eb2c0c30f35462a32ca765ccaada2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=8F=91?= Date: Sat, 23 Aug 2025 17:42:02 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E8=8E=B7=E5=8F=96=E8=BF=90=E8=B4=B9?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AD=A3=E7=A1=AE=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/logistics.controller.ts | 4 +-- src/dto/logistics.dto.ts | 44 ++++++++++++++++++++++++++ src/service/logistics.service.ts | 30 +++++------------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/controller/logistics.controller.ts b/src/controller/logistics.controller.ts index 23ef859..f2dfcaa 100644 --- a/src/controller/logistics.controller.ts +++ b/src/controller/logistics.controller.ts @@ -22,7 +22,7 @@ import { errorResponse, successResponse } from '../utils/response.util'; import { LogisticsService } from '../service/logistics.service'; import { ShippingDetailsDTO } from '../dto/freightcom.dto'; import { ShippingAddress } from '../entity/shipping_address.entity'; -import { QueryServiceDTO, ShipmentBookDTO } from '../dto/logistics.dto'; +import { QueryServiceDTO, ShipmentBookDTO, ShipmentFeeBookDTO } from '../dto/logistics.dto'; import { User } from '../decorator/user.decorator'; @Controller('/logistics') @@ -180,7 +180,7 @@ export class LogisticsController { ) @Post('/getShipmentFee') async getShipmentFee( - @Body() data: ShipmentBookDTO + @Body() data: ShipmentFeeBookDTO ) { try { const fee = await this.logisticsService.getShipmentFee(data); diff --git a/src/dto/logistics.dto.ts b/src/dto/logistics.dto.ts index 4533ad7..206884c 100644 --- a/src/dto/logistics.dto.ts +++ b/src/dto/logistics.dto.ts @@ -21,6 +21,50 @@ export class ShipmentBookDTO { orderIds?: number[]; } +export class ShipmentFeeBookDTO { + @ApiProperty() + stockPointId: number; + @ApiProperty() + sender: string; + @ApiProperty() + startPhone: string; + @ApiProperty() + startPostalCode: string; + @ApiProperty() + pickupAddress: string; + // pickupWarehouse: number; // 此处用 stockPointId 到后端解析 + @ApiProperty() + shipperCountryCode: string; + @ApiProperty() + receiver: string; + @ApiProperty() + city: string; + @ApiProperty() + province: string; + @ApiProperty() + country: string; + @ApiProperty() + postalCode: string; + @ApiProperty() + deliveryAddress: string; + @ApiProperty() + receiverPhone: string; + @ApiProperty() + receiverEmail: string; + @ApiProperty() + length: number; + @ApiProperty() + width: number; + @ApiProperty() + height: number; + @ApiProperty() + dimensionUom: string; + @ApiProperty() + weight: number; + @ApiProperty() + weightUom: string; +} + export class PaymentMethodDTO { @ApiProperty() id: string; diff --git a/src/service/logistics.service.ts b/src/service/logistics.service.ts index 9bdbc9b..3cadd75 100644 --- a/src/service/logistics.service.ts +++ b/src/service/logistics.service.ts @@ -8,7 +8,7 @@ import { Order } from '../entity/order.entity'; import { Shipment } from '../entity/shipment.entity'; import { ShipmentItem } from '../entity/shipment_item.entity'; import { OrderShipment } from '../entity/order_shipment.entity'; -import { QueryServiceDTO, ShipmentBookDTO } from '../dto/logistics.dto'; +import { QueryServiceDTO, ShipmentBookDTO, ShipmentFeeBookDTO } from '../dto/logistics.dto'; import { ErpOrderStatus, OrderStatus, @@ -30,6 +30,7 @@ import { OrderSale } from '../entity/order_sale.entity'; import { UniExpressService } from './uni_express.service'; import { StockPoint } from '../entity/stock_point.entity'; import { OrderService } from './order.service'; +import { convertKeysFromCamelToSnake } from '../utils/object-transform.util'; @Provide() export class LogisticsService { @@ -283,34 +284,19 @@ export class LogisticsService { } } - async getShipmentFee(data: ShipmentBookDTO) { + async getShipmentFee(data: ShipmentFeeBookDTO) { try { const stock_point = await this.stockPointModel.findOneBy({ id: data.stockPointId}); const reqBody = { - sender: data.details.origin.contact_name, - start_phone: data.details.origin.phone_number, - start_postal_code: data.details.origin.address.postal_code.replace(/\s/g, ''), - pickup_address: data.details.origin.address.address_line_1, + ...convertKeysFromCamelToSnake(data), pickup_warehouse: stock_point.upStreamStockPointId, - shipper_country_code: data.details.origin.address.country, - receiver: data.details.destination.contact_name, - city: data.details.destination.address.city, - province: data.details.destination.address.region, - country: data.details.destination.address.country, - postal_code: data.details.destination.address.postal_code.replace(/\s/g, ''), - delivery_address: data.details.destination.address.address_line_1, - receiver_phone: data.details.destination.phone_number.number, - receiver_email: data.details.destination.email_addresses, - // item_description: data.sales, // todo: 货品信息 - length: data.details.packaging_properties.packages[0].measurements.cuboid.l, - width: data.details.packaging_properties.packages[0].measurements.cuboid.w, - height: data.details.packaging_properties.packages[0].measurements.cuboid.h, - dimension_uom: data.details.packaging_properties.packages[0].measurements.cuboid.unit, - weight: data.details.packaging_properties.packages[0].measurements.weight.value, - weight_uom: data.details.packaging_properties.packages[0].measurements.weight.unit, currency: 'CAD', + // item_description: data.sales, // todo: 货品信息 } const resShipmentFee = await this.uniExpressService.getRates(reqBody); + if (resShipmentFee.status !== 'SUCCESS') { + throw new Error(resShipmentFee.ret_msg); + } return resShipmentFee.data.totalAfterTax * 100; } catch (e) { throw e; -- 2.40.1