forked from yoone/API
1
0
Fork 0

Compare commits

..

No commits in common. "590aea0c1c390e6c33f9dae162e7760dbd0576ad" and "64ea93e3d0d7556e19367884544cea20431ce7ca" have entirely different histories.

4 changed files with 1 additions and 72 deletions

View File

@ -162,27 +162,6 @@ 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() {

View File

@ -48,12 +48,6 @@ 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: '创建时间',

View File

@ -28,7 +28,6 @@ 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 {
@ -44,9 +43,6 @@ export class LogisticsService {
@InjectEntityModel(Order)
orderModel: Repository<Order>;
@InjectEntityModel(StockPoint)
stockPointModel: Repository<StockPoint>
@InjectEntityModel(OrderSale)
orderSaleModel: Repository<OrderSale>;
@ -192,18 +188,6 @@ 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) {
@ -216,13 +200,12 @@ 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: stock_point.upStreamStockPointId,
pickup_warehouse: 1, // todo 可能需要添加
shipper_country_code: data.details.origin.address.country,
receiver: data.details.destination.contact_name,
city: data.details.destination.address.city,
@ -241,9 +224,6 @@ 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()方法
// 获取预估费率
@ -266,17 +246,9 @@ 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);

View File

@ -84,22 +84,6 @@ 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();