refactor(订单服务): 优化产品详情查询逻辑

使用 productService 的 getComponentDetailFromSiteSku 方法替代直接查询,简化代码并增加数量检查
This commit is contained in:
zhuotianyuan 2026-01-22 17:06:51 +08:00
parent bff03de8b0
commit 1eacee307d
1 changed files with 5 additions and 6 deletions

View File

@ -731,13 +731,12 @@ export class OrderService {
await this.orderSaleModel.delete(currentOrderSale.map(v => v.id)); await this.orderSaleModel.delete(currentOrderSale.map(v => v.id));
} }
if (!orderItem.sku) return; 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 => { const componentDetails: { product: Product, quantity: number }[] = product.components?.length > 0 ? await Promise.all(product.components.map(async comp => {
return { return {
product: await this.productModel.findOne({ product: await this.productModel.findOne({