From 1eacee307de305ea3555e6d213ef57ce811ec02a Mon Sep 17 00:00:00 2001 From: zhuotianyuan Date: Thu, 22 Jan 2026 17:06:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=AE=A2=E5=8D=95=E6=9C=8D=E5=8A=A1):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E4=BA=A7=E5=93=81=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 productService 的 getComponentDetailFromSiteSku 方法替代直接查询,简化代码并增加数量检查 --- src/service/order.service.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/service/order.service.ts b/src/service/order.service.ts index 2b9e527..8625380 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -731,13 +731,12 @@ export class OrderService { await this.orderSaleModel.delete(currentOrderSale.map(v => v.id)); } if (!orderItem.sku) return; - // 从数据库查询产品,关联查询组件 - const product = await this.productModel.findOne({ - where: { siteSkus: Like(`%${orderItem.sku}%`) }, - relations: ['components','attributes','attributes.dict'], - }); - if (!product) return; + // 从数据库查询产品,关联查询组件 + const productDetail = await this.productService.getComponentDetailFromSiteSku({ sku: orderItem.sku, name: orderItem.name }); + + if (!productDetail || !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({