feat: 商品导入修复 brand 字段命名 + 添加 unit 和错误日志

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Sisyphus 2026-06-26 16:24:54 +08:00
parent ae72966766
commit 0a423af4d2

View File

@ -63,7 +63,8 @@ export class ProductService {
const item: any = { const item: any = {
name: p.name, category_id: catId, name: p.name, category_id: catId,
price: p.price > 0 ? p.price : 0.01, price: p.price > 0 ? p.price : 0.01,
brandName: p.brand || '', stock: p.quantity, brand: p.brand || '',
unit: p.unit || '',
sku: p.spec || p.name || '', sku: p.spec || p.name || '',
} }
if (p.imageUrl) item.images = [p.imageUrl] if (p.imageUrl) item.images = [p.imageUrl]
@ -94,6 +95,9 @@ export class ProductService {
const errors: Array<{ sku: string; name: string; error: string }> = items const errors: Array<{ sku: string; name: string; error: string }> = items
.filter(i => i.status === 'failed') .filter(i => i.status === 'failed')
.map(i => ({ sku: i.sku || '', name: i.name || '', error: i.error || '未知错误' })) .map(i => ({ sku: i.sku || '', name: i.name || '', error: i.error || '未知错误' }))
if (errors.length > 0) {
this.logger.warn(`B2B import_products 导入失败详情: ${errors.map(e => `[${e.sku}] ${e.name}: ${e.error}`).join(' | ')}`)
}
this.logger.log(`B2B import_products 完成: 导入 ${imported} 条, 失败 ${errors.length} 条, B2B IDs: ${b2bIds.join(',')}`) this.logger.log(`B2B import_products 完成: 导入 ${imported} 条, 失败 ${errors.length} 条, B2B IDs: ${b2bIds.join(',')}`)
if (b2bIds.length > 0) { if (b2bIds.length > 0) {