refactor(订单服务): 优化产品详情查询逻辑
使用 productService 的 getComponentDetailFromSiteSku 方法替代直接查询,简化代码并增加数量检查
This commit is contained in:
parent
bff03de8b0
commit
1eacee307d
|
|
@ -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({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue