feat(service): 新增Wintopay物流服务并优化订单导出和物流处理 #70
|
|
@ -733,14 +733,21 @@ export class OrderService {
|
||||||
if (!orderItem.sku) return;
|
if (!orderItem.sku) return;
|
||||||
|
|
||||||
// 从数据库查询产品,关联查询组件
|
// 从数据库查询产品,关联查询组件
|
||||||
const componentDetails = await this.productService.getComponentDetailFromSiteSku({ sku: orderItem.sku, name: orderItem.name }, site);
|
const productDetail = await this.productService.getComponentDetailFromSiteSku({ sku: orderItem.sku, name: orderItem.name },site);
|
||||||
if(!componentDetails?.length){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const orderSales: OrderSale[] = componentDetails.map(({product, parentProduct, quantity}) => {
|
if (!productDetail || !productDetail.quantity) return;
|
||||||
if (!product) return null
|
const { product, quantity } = productDetail
|
||||||
console.log('product',product)
|
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,
|
||||||
|
}
|
||||||
|
})) : [{ product, quantity }]
|
||||||
|
|
||||||
|
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,
|
||||||
|
|
|
||||||
|
|
@ -1785,33 +1785,24 @@ export class ProductService {
|
||||||
attributes: attributes.length > 0 ? attributes : undefined,
|
attributes: attributes.length > 0 ? attributes : undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 获取库存单品列表
|
isMixedSku(sku: string) {
|
||||||
async getComponentDetailFromSiteSku(siteProduct: { sku: string, name?: string }, site: Site): Promise<{ product: Product,parentProduct?: Product, quantity: number }[]> {
|
const splitSKu = sku.split('-')
|
||||||
|
const last = splitSKu[splitSKu.length - 1]
|
||||||
|
const second = splitSKu[splitSKu.length - 2]
|
||||||
|
// 这里判断 second 是否是数字
|
||||||
|
return sku.includes('-MX-') || sku.includes('-Mixed-') || /^\d+$/.test(second) && /^\d+$/.test(last)
|
||||||
|
}
|
||||||
|
async getComponentDetailFromSiteSku(siteProduct: { sku: string, name: string }, site: Site) {
|
||||||
if (!siteProduct.sku) {
|
if (!siteProduct.sku) {
|
||||||
throw new Error('siteSku 不能为空')
|
throw new Error('siteSku 不能为空')
|
||||||
}
|
}
|
||||||
|
|
||||||
const product = await this.getProductBySiteSku(siteProduct.sku, site)
|
let product = await this.getProductBySiteSku(siteProduct.sku, site)
|
||||||
|
|
||||||
if (!product) return
|
|
||||||
|
|
||||||
if(!product?.components?.length){
|
|
||||||
return [{
|
|
||||||
product,
|
|
||||||
quantity:1
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
return await Promise.all(product.components.map(async comp => {
|
|
||||||
return {
|
return {
|
||||||
product: await this.productModel.findOne({
|
product,
|
||||||
where: { sku: comp.sku },
|
quantity: 1,
|
||||||
relations: ['category', 'attributes', 'attributes.dict', 'components']
|
|
||||||
}),
|
|
||||||
parentProduct: product, // 这里得记录一下他的爸爸用来记录
|
|
||||||
quantity: comp.quantity,
|
|
||||||
}
|
}
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 准备创建产品的 DTO, 处理类型转换和默认值
|
// 准备创建产品的 DTO, 处理类型转换和默认值
|
||||||
|
|
@ -2150,7 +2141,7 @@ export class ProductService {
|
||||||
.leftJoinAndSelect('product.components', 'components')
|
.leftJoinAndSelect('product.components', 'components')
|
||||||
.leftJoinAndSelect('product.siteSkus', 'siteSku')
|
.leftJoinAndSelect('product.siteSkus', 'siteSku')
|
||||||
.where('siteSku.sku LIKE :siteSku', { siteSku: `%${siteSku}%` })
|
.where('siteSku.sku LIKE :siteSku', { siteSku: `%${siteSku}%` })
|
||||||
.orWhere('product.sku = :siteSku', { siteSku })
|
.orWhere('product.sku = :siteSku', { siteSku });
|
||||||
|
|
||||||
if (site) {
|
if (site) {
|
||||||
queryBuilder.orWhere('product.sku = :processedSku', {
|
queryBuilder.orWhere('product.sku = :processedSku', {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue