Compare commits
2 Commits
8c17b47474
...
5e5ed3b309
| Author | SHA1 | Date |
|---|---|---|
|
|
5e5ed3b309 | |
|
|
590aea0c1c |
|
|
@ -162,6 +162,27 @@ export class LogisticsController {
|
|||
}
|
||||
}
|
||||
|
||||
@ApiOkResponse(
|
||||
{type: BooleanRes}
|
||||
)
|
||||
@Post('/getShipmentLabel/:shipmentId')
|
||||
async getShipmentLabel(
|
||||
@Param('shipmentId') shipmentId: string
|
||||
) {
|
||||
try {
|
||||
const res = await this.logisticsService.getShipmentLabel(shipmentId);
|
||||
|
||||
if (res.data.data[0].status === 'Success') {
|
||||
return successResponse({ content: res.data.data[0].labelContent });
|
||||
} else {
|
||||
return errorResponse(res.data.data[0].errors);
|
||||
}
|
||||
} catch (error) {
|
||||
return errorResponse(error?.message || '创建失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOkResponse()
|
||||
@Post('/getPaymentMethods')
|
||||
async getpaymentmethods() {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ export class StockPoint extends BaseEntity {
|
|||
@Column({ default: false })
|
||||
isB: boolean;
|
||||
|
||||
@Column({ default: 'uniuni' })
|
||||
upStreamName: string;
|
||||
|
||||
@Column()
|
||||
upStreamStockPointId: number;
|
||||
|
||||
@ApiProperty({
|
||||
example: '2022-12-12 11:11:11',
|
||||
description: '创建时间',
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import { CanadaPostService } from './canadaPost.service';
|
|||
import { OrderItem } from '../entity/order_item.entity';
|
||||
import { OrderSale } from '../entity/order_sale.entity';
|
||||
import { UniExpressService } from './uni_express.service';
|
||||
import { StockPoint } from '../entity/stock_point.entity';
|
||||
|
||||
@Provide()
|
||||
export class LogisticsService {
|
||||
|
|
@ -43,6 +44,9 @@ export class LogisticsService {
|
|||
@InjectEntityModel(Order)
|
||||
orderModel: Repository<Order>;
|
||||
|
||||
@InjectEntityModel(StockPoint)
|
||||
stockPointModel: Repository<StockPoint>
|
||||
|
||||
@InjectEntityModel(OrderSale)
|
||||
orderSaleModel: Repository<OrderSale>;
|
||||
|
||||
|
|
@ -188,6 +192,18 @@ export class LogisticsService {
|
|||
return [...rates, ...canadaPostRates];
|
||||
}
|
||||
|
||||
async getShipmentLabel(shipmentId) {
|
||||
try {
|
||||
const shipment:Shipment = await this.shipmentModel.findOneBy({id: shipmentId});
|
||||
if (!shipment) {
|
||||
throw new Error('运单不存在');
|
||||
}
|
||||
return await this.uniExpressService.getLabel(shipment.return_tracking_number);
|
||||
} catch (e) {
|
||||
throw new Error('获取运单失败');
|
||||
}
|
||||
}
|
||||
|
||||
async createShipment(orderId: number, data: ShipmentBookDTO, userId: number) {
|
||||
const order = await this.orderModel.findOneBy({ id: orderId });
|
||||
if (!order) {
|
||||
|
|
@ -200,12 +216,13 @@ export class LogisticsService {
|
|||
throw new Error('订单状态不正确 ');
|
||||
}
|
||||
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,
|
||||
pickup_warehouse: 1, // todo, 可能需要添加
|
||||
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,
|
||||
|
|
@ -224,6 +241,9 @@ export class LogisticsService {
|
|||
weight_uom: `${data.details.packaging_properties.packages[0].measurements.weight.unit}S`, // todo,换成KGS和LBS
|
||||
currency: 'CAD',
|
||||
}
|
||||
console.log('body', reqBody);
|
||||
|
||||
throw new Error('test ');
|
||||
|
||||
// todo: 两个请求做异步 参考promise.all()方法
|
||||
// 获取预估费率
|
||||
|
|
@ -246,9 +266,17 @@ export class LogisticsService {
|
|||
unique_id: resShipmentOrder.data.uni_order_sn,
|
||||
stockPointId: '1', // todo
|
||||
state: resShipmentOrder.data.uni_status_code,
|
||||
return_tracking_number: resShipmentOrder.data.tno,
|
||||
order_id: order.id
|
||||
});
|
||||
order.shipmentId = shipment.id;
|
||||
|
||||
// 同步物流信息到woocommerce
|
||||
const site = this.geSite(order.siteId);
|
||||
await this.wpService.createShipment(site, order.externalOrderId, {
|
||||
tracking_number: shipment.primary_tracking_number,
|
||||
tracking_provider: shipment?.rate?.carrier_name,
|
||||
});
|
||||
}
|
||||
|
||||
await orderRepo.save(order);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,22 @@ export class UniExpressService {
|
|||
}
|
||||
}
|
||||
|
||||
async getLabel(tracking_number: string) {
|
||||
const body = {
|
||||
packageId: tracking_number
|
||||
};
|
||||
const token = await this.getToken();
|
||||
const config: AxiosRequestConfig= {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
url: `${this.url}/orders/printlabel`,
|
||||
data: body
|
||||
};
|
||||
return await axios.request(config);
|
||||
}
|
||||
|
||||
async getOrdersByDate(from: string, to: string, page: number = 1, perPage: number = 100) {
|
||||
try {
|
||||
const token = await this.getToken();
|
||||
|
|
|
|||
Loading…
Reference in New Issue