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

Compare commits

...

12 Commits

Author SHA1 Message Date
tikkhun 8d12c0ff79 refactor(interface): 移除重复的接口方法声明和注释 2026-01-08 18:40:09 +08:00
tikkhun 56268c9cae refactor(adapter): 清理重复代码并统一订单映射方法命名
移除shopyy和woocommerce适配器中的重复代码
将mapOrder重命名为mapPlatformToUnifiedOrder以保持命名一致性
2026-01-08 18:35:25 +08:00
tikkhun 8bdc438a48 feat(shopyy): 实现全量商品查询功能并优化产品相关逻辑
- 新增ShopyyAllProductQuery类支持全量商品查询参数
- 实现getAllProducts方法支持带条件查询
- 优化getProductBySku方法使用新查询接口
- 公开request方法便于子类调用
- 增加错误日志记录产品查找失败情况
- 修复产品permalink生成逻辑
2026-01-08 18:31:50 +08:00
tikkhun bdc2af3514 fix(sync_shipment): 捕获运单状态更新时的异常并记录日志
添加try-catch块来捕获updateShipmentState过程中可能出现的错误
使用logger记录错误信息以便后续排查
2026-01-08 18:31:31 +08:00
tikkhun 2e62a0cdb2 feat: 增强产品同步功能并优化SKU生成逻辑
添加字典排序字段支持
优化产品同步流程,支持通过SKU同步
重构SKU模板生成逻辑,支持分类属性排序
完善产品导入导出功能,增加分类字段处理
统一产品操作方法,提升代码可维护性
2026-01-08 18:31:31 +08:00
tikkhun f867f256ae refactor(api): 统一接口参数为对象形式并支持多条件查询
重构所有接口方法,将直接传递id参数改为接受where条件对象
支持通过id、sku、email等多条件查询实体
优化产品服务逻辑,支持通过sku直接查询产品
统一各适配器实现,确保接口一致性
2026-01-08 18:31:13 +08:00
tikkhun d549227e03 refactor(interface): 重构站点适配器接口,按功能模块组织方法
重构 ISiteAdapter 接口,将相关方法按功能模块(客户、媒体、订单、产品等)分组
移除废弃的 fulfillOrder 方法
新增多个数据映射方法以支持统一数据格式转换
2026-01-08 18:30:12 +08:00
tikkhun acfee35e73 feat(订单): 添加获取订单总数功能
实现订单总数统计接口,包括:
1. 在ISiteAdapter接口添加countOrders方法
2. 在WooCommerce和Shopyy适配器中实现该方法
3. 添加控制器端点暴露该功能
4. 优化订单查询参数映射逻辑

refactor(Shopyy): 重构搜索参数映射逻辑

将通用的搜索参数映射逻辑提取为独立方法,提高代码复用性
2026-01-08 18:28:15 +08:00
tikkhun 0f81499ccc refactor(api): 统一接口参数为对象形式并支持多条件查询
重构所有接口方法,将直接传递id参数改为接受where条件对象
支持通过id、sku、email等多条件查询实体
优化产品服务逻辑,支持通过sku直接查询产品
统一各适配器实现,确保接口一致性
2026-01-08 18:27:12 +08:00
tikkhun cb2a70d5af refactor(interface): 重构站点适配器接口,按功能模块组织方法
重构 ISiteAdapter 接口,将相关方法按功能模块(客户、媒体、订单、产品等)分组
移除废弃的 fulfillOrder 方法
新增多个数据映射方法以支持统一数据格式转换
2026-01-08 18:26:50 +08:00
tikkhun 1814d9734b feat(订单): 添加获取订单总数功能
实现订单总数统计接口,包括:
1. 在ISiteAdapter接口添加countOrders方法
2. 在WooCommerce和Shopyy适配器中实现该方法
3. 添加控制器端点暴露该功能
4. 优化订单查询参数映射逻辑

refactor(Shopyy): 重构搜索参数映射逻辑

将通用的搜索参数映射逻辑提取为独立方法,提高代码复用性
2026-01-08 18:25:35 +08:00
zhuotianyuan 983ba47dbf feat(adapter): 公开映射方法以支持统一接口调用
将各适配器中的私有映射方法改为公开,并在接口中定义统一方法签名
修改webhook控制器以使用适配器映射方法处理订单数据
2026-01-08 10:15:31 +00:00
1 changed files with 43 additions and 54 deletions

View File

@ -12,10 +12,7 @@ import * as crypto from 'crypto';
import { SiteService } from '../service/site.service'; import { SiteService } from '../service/site.service';
import { OrderService } from '../service/order.service'; import { OrderService } from '../service/order.service';
import { SiteApiService } from '../service/site-api.service';
import {
UnifiedOrderDTO,
} from '../dto/site-api.dto';
@Controller('/webhook') @Controller('/webhook')
export class WebhookController { export class WebhookController {
@ -34,6 +31,8 @@ export class WebhookController {
@Inject() @Inject()
private readonly siteService: SiteService; private readonly siteService: SiteService;
@Inject()
private readonly siteApiService: SiteApiService;
// 移除配置中的站点数组,来源统一改为数据库 // 移除配置中的站点数组,来源统一改为数据库
@ -79,7 +78,14 @@ export class WebhookController {
.update(rawBody) .update(rawBody)
.digest('base64'); .digest('base64');
try { try {
if (hash === signature) { if (hash !== signature) {
return {
code: 403,
success: false,
message: 'Webhook verification failed',
};
}
const adapter = await this.siteApiService.getAdapter(siteId);
switch (topic) { switch (topic) {
case 'product.created': case 'product.created':
case 'product.updated': case 'product.updated':
@ -90,7 +96,8 @@ export class WebhookController {
break; break;
case 'order.created': case 'order.created':
case 'order.updated': case 'order.updated':
await this.orderService.syncSingleOrder(siteId, body); const order = adapter.mapPlatformToUnifiedOrder(body)
await this.orderService.syncSingleOrder(siteId, order);
break; break;
case 'order.deleted': case 'order.deleted':
break; break;
@ -102,19 +109,12 @@ export class WebhookController {
break; break;
default: default:
console.log('Unhandled event:', body.event); console.log('Unhandled event:', body.event);
}
return { return {
code: 200, code: 200,
success: true, success: true,
message: 'Webhook processed successfully', message: 'Webhook processed successfully',
}; };
} else {
return {
code: 403,
success: false,
message: 'Webhook verification failed',
};
} }
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@ -130,23 +130,10 @@ export class WebhookController {
@Query('signature') signature: string, @Query('signature') signature: string,
@Headers() header: any @Headers() header: any
) { ) {
console.log(`webhook shoppy`, siteIdStr, body, header)
const topic = header['x-oemsaas-event-type']; const topic = header['x-oemsaas-event-type'];
// const source = header['x-oemsaas-shop-domain']; // const source = header['x-oemsaas-shop-domain'];
const siteId = Number(siteIdStr); const siteId = Number(siteIdStr);
const bodys = new UnifiedOrderDTO();
Object.assign(bodys, body);
// 从数据库获取站点配置
const site = await this.siteService.get(siteId, true);
// if (!site || !source?.includes(site.websiteUrl)) {
if (!site) {
console.log('domain not match');
return {
code: HttpStatus.BAD_REQUEST,
success: false,
message: 'domain not match',
};
}
if (!signature) { if (!signature) {
return { return {
@ -162,6 +149,7 @@ export class WebhookController {
// .createHmac('sha256', this.secret) // .createHmac('sha256', this.secret)
// .update(rawBody) // .update(rawBody)
// .digest('base64'); // .digest('base64');
const adapter = await this.siteApiService.getAdapter(siteId);
try { try {
if (this.secret === signature) { if (this.secret === signature) {
switch (topic) { switch (topic) {
@ -174,7 +162,8 @@ export class WebhookController {
break; break;
case 'orders/create': case 'orders/create':
case 'orders/update': case 'orders/update':
await this.orderService.syncSingleOrder(siteId, bodys); const order = adapter.mapPlatformToUnifiedOrder(body)
await this.orderService.syncSingleOrder(siteId, order);
break; break;
case 'orders/delete': case 'orders/delete':
break; break;