zksu
/
API
forked from yoone/API
1
0
Fork 0

fix: 修复订单服务中产品属性和组件处理的问题

处理产品属性为空的情况,避免空指针异常
为产品组件查询添加关联关系
在订单销售记录创建时增加对空产品的过滤
添加新的品牌判断逻辑
This commit is contained in:
tikkhun 2026-01-10 15:06:35 +08:00
parent 78d82ffbac
commit 8d0eec06fd
2 changed files with 7 additions and 3 deletions

View File

@ -722,12 +722,14 @@ export class OrderService {
return { return {
product: await this.productModel.findOne({ product: await this.productModel.findOne({
where: { sku: comp.sku }, where: { sku: comp.sku },
relations: ['components','attributes'],
}), }),
quantity: comp.quantity * orderItem.quantity, quantity: comp.quantity * orderItem.quantity,
} }
})) : [{ product, quantity: orderItem.quantity }]; })) : [{ product, quantity: orderItem.quantity }]
const orderSales: OrderSale[] = componentDetails.map(componentDetail => { const orderSales: OrderSale[] = componentDetails.map(componentDetail => {
if(!componentDetail.product) return null
const attrsObj = this.productService.getAttributesObject(product.attributes) const attrsObj = this.productService.getAttributesObject(product.attributes)
const orderSale = plainToClass(OrderSale, { const orderSale = plainToClass(OrderSale, {
orderId: orderItem.orderId, orderId: orderItem.orderId,
@ -740,11 +742,12 @@ export class OrderService {
isPackage: componentDetail.product.type === 'bundle', isPackage: componentDetail.product.type === 'bundle',
isYoone: attrsObj?.['brand']?.name === 'yoone', isYoone: attrsObj?.['brand']?.name === 'yoone',
isZyn: attrsObj?.['brand']?.name === 'zyn', isZyn: attrsObj?.['brand']?.name === 'zyn',
isZex: attrsObj?.['brand']?.name === 'zex',
isYooneNew: attrsObj?.['brand']?.name === 'yoone' && attrsObj?.['version']?.name === 'new', isYooneNew: attrsObj?.['brand']?.name === 'yoone' && attrsObj?.['version']?.name === 'new',
size: this.extractNumberFromString(attrsObj?.['strength']?.name) || null, size: this.extractNumberFromString(attrsObj?.['strength']?.name) || null,
}); });
return orderSale return orderSale
}) }).filter(v => v !== null)
if (orderSales.length > 0) { if (orderSales.length > 0) {
await this.orderSaleModel.save(orderSales); await this.orderSaleModel.save(orderSales);

View File

@ -1537,6 +1537,7 @@ export class ProductService {
return dto; return dto;
} }
getAttributesObject(attributes:DictItem[]){ getAttributesObject(attributes:DictItem[]){
if(!attributes) return {}
const obj:any = {} const obj:any = {}
attributes.forEach(attr=>{ attributes.forEach(attr=>{
obj[attr.dict.name] = attr obj[attr.dict.name] = attr