Compare commits
3 Commits
0b211628f3
...
6b782a9d6e
| Author | SHA1 | Date |
|---|---|---|
|
|
6b782a9d6e | |
|
|
e94805c640 | |
|
|
d4b267106e |
|
|
@ -996,7 +996,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
private async getProductBySku(sku: string): Promise<UnifiedProductDTO> {
|
private async getProductBySku(sku: string): Promise<UnifiedProductDTO> {
|
||||||
// 使用Shopyy API的搜索功能通过sku查询产品
|
// 使用Shopyy API的搜索功能通过sku查询产品
|
||||||
const response = await this.getAllProducts({ where: { sku } });
|
const response = await this.getAllProducts({ where: { sku } });
|
||||||
console.log('getProductBySku', response)
|
|
||||||
const product = response?.[0]
|
const product = response?.[0]
|
||||||
if (!product) {
|
if (!product) {
|
||||||
throw new Error(`未找到sku为${sku}的产品`);
|
throw new Error(`未找到sku为${sku}的产品`);
|
||||||
|
|
@ -1126,7 +1125,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
// ========== 产品变体映射方法 ==========
|
// ========== 产品变体映射方法 ==========
|
||||||
mapPlatformToUnifiedVariation(variant: ShopyyVariant): UnifiedProductVariationDTO {
|
mapPlatformToUnifiedVariation(variant: ShopyyVariant): UnifiedProductVariationDTO {
|
||||||
// 映射变体
|
// 映射变体
|
||||||
console.log('ivarianttem', variant)
|
|
||||||
return {
|
return {
|
||||||
id: variant.id,
|
id: variant.id,
|
||||||
name: variant.title || '',
|
name: variant.title || '',
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ export class AreaController {
|
||||||
}));
|
}));
|
||||||
return successResponse(countryList, '查询成功');
|
return successResponse(countryList, '查询成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +53,6 @@ export class AreaController {
|
||||||
const newArea = await this.areaService.createArea(area);
|
const newArea = await this.areaService.createArea(area);
|
||||||
return successResponse(newArea, '创建成功');
|
return successResponse(newArea, '创建成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +66,6 @@ export class AreaController {
|
||||||
const updatedArea = await this.areaService.updateArea(id, area);
|
const updatedArea = await this.areaService.updateArea(id, area);
|
||||||
return successResponse(updatedArea, '更新成功');
|
return successResponse(updatedArea, '更新成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +78,6 @@ export class AreaController {
|
||||||
await this.areaService.deleteArea(id);
|
await this.areaService.deleteArea(id);
|
||||||
return successResponse(null, '删除成功');
|
return successResponse(null, '删除成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +91,6 @@ export class AreaController {
|
||||||
const { list, total } = await this.areaService.getAreaList(query);
|
const { list, total } = await this.areaService.getAreaList(query);
|
||||||
return successResponse({ list, total }, '查询成功');
|
return successResponse({ list, total }, '查询成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +106,6 @@ export class AreaController {
|
||||||
}
|
}
|
||||||
return successResponse(area, '查询成功');
|
return successResponse(area, '查询成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse(error?.message || error);
|
return errorResponse(error?.message || error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@ export class OrderController {
|
||||||
const result = await this.orderService.syncOrders(siteId, params);
|
const result = await this.orderService.syncOrders(siteId, params);
|
||||||
return successResponse(result);
|
return successResponse(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
return errorResponse(`同步失败,${error?.message || '未知错误'}`);
|
||||||
return errorResponse('同步失败');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +58,6 @@ export class OrderController {
|
||||||
const result = await this.orderService.syncOrderById(siteId, orderId);
|
const result = await this.orderService.syncOrderById(siteId, orderId);
|
||||||
return successResponse(result);
|
return successResponse(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
return errorResponse('同步失败');
|
return errorResponse('同步失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ export class OrderService {
|
||||||
async syncOrders(siteId: number, params: Record<string, any> = {}): Promise<SyncOperationResult> {
|
async syncOrders(siteId: number, params: Record<string, any> = {}): Promise<SyncOperationResult> {
|
||||||
// 调用 WooCommerce API 获取订单
|
// 调用 WooCommerce API 获取订单
|
||||||
const result = await (await this.siteApiService.getAdapter(siteId)).getAllOrders(params);
|
const result = await (await this.siteApiService.getAdapter(siteId)).getAllOrders(params);
|
||||||
|
this.logger.info('开始进入循环同步订单', result.length, '个订单')
|
||||||
// 初始化同步结果对象
|
// 初始化同步结果对象
|
||||||
const syncResult: SyncOperationResult = {
|
const syncResult: SyncOperationResult = {
|
||||||
total: result.length,
|
total: result.length,
|
||||||
|
|
@ -143,7 +143,6 @@ export class OrderService {
|
||||||
updated: 0,
|
updated: 0,
|
||||||
errors: []
|
errors: []
|
||||||
};
|
};
|
||||||
this.logger.info('开始进入循环同步订单', result.length, '个订单')
|
|
||||||
// 遍历每个订单进行同步
|
// 遍历每个订单进行同步
|
||||||
for (const order of result) {
|
for (const order of result) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -2032,9 +2032,9 @@ export class ProductService {
|
||||||
// 将工作表转换为 JSON 数组
|
// 将工作表转换为 JSON 数组
|
||||||
records = xlsx.utils.sheet_to_json(worksheet);
|
records = xlsx.utils.sheet_to_json(worksheet);
|
||||||
|
|
||||||
console.log('Parsed records count:', records.length);
|
this.logger.debug('Parsed records count:', records.length);
|
||||||
if (records.length > 0) {
|
if (records.length > 0) {
|
||||||
console.log('First record keys:', Object.keys(records[0]));
|
this.logger.debug('First record keys:', Object.keys(records[0]));
|
||||||
}
|
}
|
||||||
return records;
|
return records;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|
@ -2048,6 +2048,7 @@ export class ProductService {
|
||||||
let updated = 0;
|
let updated = 0;
|
||||||
const errors: BatchErrorItem[] = [];
|
const errors: BatchErrorItem[] = [];
|
||||||
const records = await this.getRecordsFromTable(file);
|
const records = await this.getRecordsFromTable(file);
|
||||||
|
this.logger.debug('Total records count:', records.length);
|
||||||
// 逐条处理记录
|
// 逐条处理记录
|
||||||
for (const rec of records) {
|
for (const rec of records) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -2076,7 +2077,7 @@ export class ProductService {
|
||||||
errors.push({ identifier: '' + rec.sku, error: `产品${rec?.sku}导入失败:${e?.message || String(e)}` });
|
errors.push({ identifier: '' + rec.sku, error: `产品${rec?.sku}导入失败:${e?.message || String(e)}` });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.logger.debug(`导入 ${records.length} 条记录,成功创建 ${created} 条,更新 ${updated} 条,失败 ${errors.length} 条,错误详情:${JSON.stringify(errors)}`);
|
this.logger.info(`导入 ${records.length} 条记录,成功创建 ${created} 条,更新 ${updated} 条,失败 ${errors.length} 条,错误详情:${JSON.stringify(errors)}`);
|
||||||
return { total: records.length, processed: records.length - errors.length, created, updated, errors };
|
return { total: records.length, processed: records.length - errors.length, created, updated, errors };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2138,7 +2139,6 @@ export class ProductService {
|
||||||
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据站点SKU查询产品
|
// 根据站点SKU查询产品
|
||||||
async getProductBySiteSku(siteSku: string, site?: Site): Promise<Product> {
|
async getProductBySiteSku(siteSku: string, site?: Site): Promise<Product> {
|
||||||
// 使用查询构建器来正确查询关联表
|
// 使用查询构建器来正确查询关联表
|
||||||
|
|
@ -2150,7 +2150,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