feat(service): 新增Wintopay物流服务并优化订单导出和物流处理 #70

Merged
longbot merged 8 commits from zhuotianyuan/API:main into main 2026-01-30 07:20:08 +00:00
2 changed files with 26 additions and 21 deletions
Showing only changes of commit fe30fabf08 - Show all commits

View File

@ -733,22 +733,13 @@ export class OrderService {
if (!orderItem.sku) return;
// 从数据库查询产品,关联查询组件
const productDetail = await this.productService.getComponentDetailFromSiteSku({ sku: orderItem.sku, name: orderItem.name },site);
if (!productDetail || !productDetail.product || !productDetail.quantity) return;
const { product, quantity } = productDetail
const componentDetails: { product: Product, quantity: number }[] = product.components?.length > 0 ? await Promise.all(product.components.map(async comp => {
return {
product: await this.productModel.findOne({
where: { id: comp.productId },
}),
quantity: comp.quantity * orderItem.quantity,
const componentDetails = await this.productService.getComponentDetailFromSiteSku({ sku: orderItem.sku, name: orderItem.name },orderItem.quantity,site);
if(!componentDetails?.length){
return
}
})) : [{ product, quantity }]
const orderSales: OrderSale[] = componentDetails.map(componentDetail => {
if (!componentDetail.product) return null
const orderSales: OrderSale[] = componentDetails.map(({product, parentProduct, quantity}) => {
if (!product) return null
const attrsObj = this.productService.getAttributesObject(product.attributes)
const orderSale = plainToClass(OrderSale, {
orderId: orderItem.orderId,

View File

@ -1792,17 +1792,31 @@ export class ProductService {
// 这里判断 second 是否是数字
return sku.includes('-MX-') || sku.includes('-Mixed-') || /^\d+$/.test(second) && /^\d+$/.test(last)
}
async getComponentDetailFromSiteSku(siteProduct: { sku: string, name: string }, site: Site) {
async getComponentDetailFromSiteSku(siteProduct: { sku: string, name: string }, quantity: number = 1, site: Site): Promise<{ product: Product,parentProduct?: Product, quantity: number }[]> {
if (!siteProduct.sku) {
throw new Error('siteSku 不能为空')
}
let product = await this.getProductBySiteSku(siteProduct.sku, site)
const product = await this.getProductBySiteSku(siteProduct.sku, site)
return {
if (!product) return
if(!product?.components?.length){
return [{
product,
quantity: 1,
quantity
}]
}
return await Promise.all(product.components.map(async comp => {
return {
product: await this.productModel.findOne({
where: { id: comp.productId },
}),
parentProduct: product, // 这里得记录一下他的爸爸用来记录
quantity: comp.quantity * quantity,
}
}))
}
// 准备创建产品的 DTO, 处理类型转换和默认值