refactor(adapter): 清理重复代码并统一订单映射方法命名
移除shopyy和woocommerce适配器中的重复代码 将mapOrder重命名为mapPlatformToUnifiedOrder以保持命名一致性
This commit is contained in:
parent
8bdc438a48
commit
56268c9cae
|
|
@ -28,10 +28,8 @@ import {
|
||||||
ShopyyCustomer,
|
ShopyyCustomer,
|
||||||
ShopyyOrder,
|
ShopyyOrder,
|
||||||
ShopyyOrderQuery,
|
ShopyyOrderQuery,
|
||||||
ShopyyOrderQuery,
|
|
||||||
ShopyyProduct,
|
ShopyyProduct,
|
||||||
ShopyyProductQuery,
|
ShopyyProductQuery,
|
||||||
ShopyyProductQuery,
|
|
||||||
ShopyyVariant,
|
ShopyyVariant,
|
||||||
ShopyyWebhook,
|
ShopyyWebhook,
|
||||||
} from '../dto/shopyy.dto';
|
} from '../dto/shopyy.dto';
|
||||||
|
|
@ -39,7 +37,6 @@ import {
|
||||||
OrderStatus,
|
OrderStatus,
|
||||||
} from '../enums/base.enum';
|
} from '../enums/base.enum';
|
||||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
||||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
|
||||||
export class ShopyyAdapter implements ISiteAdapter {
|
export class ShopyyAdapter implements ISiteAdapter {
|
||||||
shopyyFinancialStatusMap= {
|
shopyyFinancialStatusMap= {
|
||||||
'200': '待支付',
|
'200': '待支付',
|
||||||
|
|
@ -58,12 +55,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
this.mapPlatformToUnifiedOrder = this.mapPlatformToUnifiedOrder.bind(this);
|
this.mapPlatformToUnifiedOrder = this.mapPlatformToUnifiedOrder.bind(this);
|
||||||
this.mapPlatformToUnifiedMedia = this.mapPlatformToUnifiedMedia.bind(this);
|
this.mapPlatformToUnifiedMedia = this.mapPlatformToUnifiedMedia.bind(this);
|
||||||
// this.mapPlatformToUnifiedSubscription = this.mapPlatformToUnifiedSubscription.bind(this);
|
// this.mapPlatformToUnifiedSubscription = this.mapPlatformToUnifiedSubscription.bind(this);
|
||||||
this.mapPlatformToUnifiedCustomer = this.mapPlatformToUnifiedCustomer.bind(this);
|
|
||||||
this.mapPlatformToUnifiedProduct = this.mapPlatformToUnifiedProduct.bind(this);
|
|
||||||
this.mapPlatformToUnifiedVariation = this.mapPlatformToUnifiedVariation.bind(this);
|
|
||||||
this.mapPlatformToUnifiedOrder = this.mapPlatformToUnifiedOrder.bind(this);
|
|
||||||
this.mapPlatformToUnifiedMedia = this.mapPlatformToUnifiedMedia.bind(this);
|
|
||||||
// this.mapPlatformToUnifiedSubscription = this.mapPlatformToUnifiedSubscription.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 客户映射方法 ==========
|
// ========== 客户映射方法 ==========
|
||||||
|
|
@ -551,13 +542,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
async getOrders(
|
async getOrders(
|
||||||
params: UnifiedSearchParamsDTO
|
params: UnifiedSearchParamsDTO
|
||||||
): Promise<UnifiedPaginationDTO<UnifiedOrderDTO>> {
|
): Promise<UnifiedPaginationDTO<UnifiedOrderDTO>> {
|
||||||
// 转换订单查询参数
|
|
||||||
const normalizedParams = this.mapOrderSearchParams(params);
|
|
||||||
const { items, total, totalPages, page, per_page } = await this.shopyyService.fetchResourcePaged<any>(
|
|
||||||
this.site,
|
|
||||||
'orders',
|
|
||||||
normalizedParams
|
|
||||||
);
|
|
||||||
// 转换订单查询参数
|
// 转换订单查询参数
|
||||||
const normalizedParams = this.mapOrderSearchParams(params);
|
const normalizedParams = this.mapOrderSearchParams(params);
|
||||||
const { items, total, totalPages, page, per_page } = await this.shopyyService.fetchResourcePaged<any>(
|
const { items, total, totalPages, page, per_page } = await this.shopyyService.fetchResourcePaged<any>(
|
||||||
|
|
@ -566,7 +550,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
normalizedParams
|
normalizedParams
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
items: items.map(this.mapPlatformToUnifiedOrder.bind(this)),
|
|
||||||
items: items.map(this.mapPlatformToUnifiedOrder.bind(this)),
|
items: items.map(this.mapPlatformToUnifiedOrder.bind(this)),
|
||||||
total,
|
total,
|
||||||
totalPages,
|
totalPages,
|
||||||
|
|
@ -596,10 +579,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
const requestParams = this.mapCreateOrderParams(data);
|
const requestParams = this.mapCreateOrderParams(data);
|
||||||
const createdOrder = await this.shopyyService.createOrder(this.site, requestParams);
|
const createdOrder = await this.shopyyService.createOrder(this.site, requestParams);
|
||||||
return this.mapPlatformToUnifiedOrder(createdOrder);
|
return this.mapPlatformToUnifiedOrder(createdOrder);
|
||||||
// 使用映射方法转换参数
|
|
||||||
const requestParams = this.mapCreateOrderParams(data);
|
|
||||||
const createdOrder = await this.shopyyService.createOrder(this.site, requestParams);
|
|
||||||
return this.mapPlatformToUnifiedOrder(createdOrder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateOrder(where: {id: string | number}, data: Partial<UnifiedOrderDTO>): Promise<boolean> {
|
async updateOrder(where: {id: string | number}, data: Partial<UnifiedOrderDTO>): Promise<boolean> {
|
||||||
|
|
@ -616,12 +595,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
return await this.shopyyService.getOrderNotes(this.site, orderId);
|
return await this.shopyyService.getOrderNotes(this.site, orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createOrderNote(orderId: string | number, data: any): Promise<any> {
|
|
||||||
return await this.shopyyService.createOrderNote(this.site, orderId, data);
|
|
||||||
async getOrderNotes(orderId: string | number): Promise<any[]> {
|
|
||||||
return await this.shopyyService.getOrderNotes(this.site, orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async createOrderNote(orderId: string | number, data: any): Promise<any> {
|
async createOrderNote(orderId: string | number, data: any): Promise<any> {
|
||||||
return await this.shopyyService.createOrderNote(this.site, orderId, data);
|
return await this.shopyyService.createOrderNote(this.site, orderId, data);
|
||||||
}
|
}
|
||||||
|
|
@ -648,7 +621,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`履行失败: ${error.message}`);
|
throw new Error(`履行失败: ${error.message}`);
|
||||||
throw new Error(`履行失败: ${error.message}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -904,13 +876,8 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProducts(
|
|
||||||
async getProducts(
|
async getProducts(
|
||||||
params: UnifiedSearchParamsDTO
|
params: UnifiedSearchParamsDTO
|
||||||
): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
|
||||||
// 转换搜索参数
|
|
||||||
const requestParams = this.mapProductQuery(params);
|
|
||||||
const response = await this.shopyyService.fetchResourcePaged<ShopyyProduct>(
|
|
||||||
): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
||||||
// 转换搜索参数
|
// 转换搜索参数
|
||||||
const requestParams = this.mapProductQuery(params);
|
const requestParams = this.mapProductQuery(params);
|
||||||
|
|
@ -924,13 +891,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
...item,
|
...item,
|
||||||
permalink: `${this.site.websiteUrl}/products/${item.handle}`,
|
permalink: `${this.site.websiteUrl}/products/${item.handle}`,
|
||||||
})).map(this.mapPlatformToUnifiedProduct.bind(this))
|
})).map(this.mapPlatformToUnifiedProduct.bind(this))
|
||||||
const { items = [], total, totalPages, page, per_page } = response;
|
|
||||||
const finalItems = items.map((item) => ({
|
|
||||||
...item,
|
|
||||||
permalink: `${this.site.websiteUrl}/products/${item.handle}`,
|
|
||||||
})).map(this.mapPlatformToUnifiedProduct.bind(this))
|
|
||||||
return {
|
return {
|
||||||
items: finalItems as UnifiedProductDTO[],
|
|
||||||
items: finalItems as UnifiedProductDTO[],
|
items: finalItems as UnifiedProductDTO[],
|
||||||
total,
|
total,
|
||||||
totalPages,
|
totalPages,
|
||||||
|
|
@ -1122,36 +1083,19 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
|
|
||||||
mapUnifiedToPlatformSubscription(data: Partial<UnifiedSubscriptionDTO>) {
|
mapUnifiedToPlatformSubscription(data: Partial<UnifiedSubscriptionDTO>) {
|
||||||
return data
|
return data
|
||||||
// ========== 订阅映射方法 ==========
|
|
||||||
mapPlatformToUnifiedSubscription(data: any): UnifiedSubscriptionDTO {
|
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mapUnifiedToPlatformSubscription(data: Partial<UnifiedSubscriptionDTO>) {
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSubscriptions(
|
|
||||||
params: UnifiedSearchParamsDTO
|
|
||||||
): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
|
||||||
throw new Error('Shopyy does not support subscriptions.');
|
|
||||||
async getSubscriptions(
|
async getSubscriptions(
|
||||||
params: UnifiedSearchParamsDTO
|
params: UnifiedSearchParamsDTO
|
||||||
): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
||||||
throw new Error('Shopyy does not support subscriptions.');
|
throw new Error('Shopyy does not support subscriptions.');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllSubscriptions(params?: UnifiedSearchParamsDTO): Promise<UnifiedSubscriptionDTO[]> {
|
|
||||||
// Shopyy getAllSubscriptions 暂未实现
|
|
||||||
throw new Error('Shopyy getAllSubscriptions 暂未实现');
|
|
||||||
async getAllSubscriptions(params?: UnifiedSearchParamsDTO): Promise<UnifiedSubscriptionDTO[]> {
|
async getAllSubscriptions(params?: UnifiedSearchParamsDTO): Promise<UnifiedSubscriptionDTO[]> {
|
||||||
// Shopyy getAllSubscriptions 暂未实现
|
// Shopyy getAllSubscriptions 暂未实现
|
||||||
throw new Error('Shopyy getAllSubscriptions 暂未实现');
|
throw new Error('Shopyy getAllSubscriptions 暂未实现');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 产品变体映射方法 ==========
|
|
||||||
mapPlatformToUnifiedVariation(variant: ShopyyVariant): UnifiedProductVariationDTO {
|
|
||||||
// 映射变体
|
|
||||||
// ========== 产品变体映射方法 ==========
|
// ========== 产品变体映射方法 ==========
|
||||||
mapPlatformToUnifiedVariation(variant: ShopyyVariant): UnifiedProductVariationDTO {
|
mapPlatformToUnifiedVariation(variant: ShopyyVariant): UnifiedProductVariationDTO {
|
||||||
// 映射变体
|
// 映射变体
|
||||||
|
|
@ -1314,19 +1258,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 辅助方法 ==========
|
|
||||||
/**
|
|
||||||
* 通用搜索参数转换方法,处理 where 和 orderBy 的转换
|
|
||||||
* 将统一的搜索参数转换为 ShopYY API 所需的参数格式
|
|
||||||
*/
|
|
||||||
mapSearchParams(params: UnifiedSearchParamsDTO): any {
|
|
||||||
// 处理分页参数
|
|
||||||
const page = Number(params.page || 1);
|
|
||||||
const limit = Number(params.per_page ?? 20);
|
|
||||||
|
|
||||||
// 处理 where 条件
|
|
||||||
const query: any = {
|
|
||||||
...(params.where || {}),
|
|
||||||
// ========== 辅助方法 ==========
|
// ========== 辅助方法 ==========
|
||||||
/**
|
/**
|
||||||
* 通用搜索参数转换方法,处理 where 和 orderBy 的转换
|
* 通用搜索参数转换方法,处理 where 和 orderBy 的转换
|
||||||
|
|
@ -1348,14 +1279,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
query.order_by = dir === 'desc' ? 'desc' : 'asc';
|
query.order_by = dir === 'desc' ? 'desc' : 'asc';
|
||||||
query.order_field = field
|
query.order_field = field
|
||||||
}
|
}
|
||||||
return query;
|
|
||||||
limit,
|
|
||||||
}
|
|
||||||
if(params.orderBy){
|
|
||||||
const [field, dir] = Object.entries(params.orderBy)[0];
|
|
||||||
query.order_by = dir === 'desc' ? 'desc' : 'asc';
|
|
||||||
query.order_field = field
|
|
||||||
}
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1378,35 +1301,6 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
[190]: OrderStatus.CANCEL // 190 取消 转为 cancelled
|
[190]: OrderStatus.CANCEL // 190 取消 转为 cancelled
|
||||||
}
|
}
|
||||||
|
|
||||||
shopyyFulfillmentStatusMap = {
|
|
||||||
// 未发货
|
|
||||||
'300': OrderFulfillmentStatus.PENDING,
|
|
||||||
// 部分发货
|
|
||||||
'310': OrderFulfillmentStatus.PARTIALLY_FULFILLED,
|
|
||||||
// 已发货
|
|
||||||
'320': OrderFulfillmentStatus.FULFILLED,
|
|
||||||
// 已取消
|
|
||||||
'330': OrderFulfillmentStatus.CANCELLED,
|
|
||||||
// 确认发货
|
|
||||||
// 映射产品状态: publish -> 1, draft -> 0
|
|
||||||
mapStatus = (status: string) => {
|
|
||||||
return status === 'publish' ? 1 : 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 映射库存状态: instock -> 1, outofstock -> 0
|
|
||||||
mapStockStatus = (stockStatus: string) => {
|
|
||||||
return stockStatus === 'instock' ? 1 : 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
shopyyOrderStatusMap = {//订单状态 100 未完成;110 待处理;180 已完成(确认收货); 190 取消;
|
|
||||||
[100]: OrderStatus.PENDING, // 100 未完成 转为 pending
|
|
||||||
[110]: OrderStatus.PROCESSING, // 110 待处理 转为 processing
|
|
||||||
// 已发货
|
|
||||||
|
|
||||||
[180]: OrderStatus.COMPLETED, // 180 已完成(确认收货) 转为 completed
|
|
||||||
[190]: OrderStatus.CANCEL // 190 取消 转为 cancelled
|
|
||||||
}
|
|
||||||
|
|
||||||
shopyyFulfillmentStatusMap = {
|
shopyyFulfillmentStatusMap = {
|
||||||
// 未发货
|
// 未发货
|
||||||
'300': OrderFulfillmentStatus.PENDING,
|
'300': OrderFulfillmentStatus.PENDING,
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ import {
|
||||||
UnifiedVariationPaginationDTO,
|
UnifiedVariationPaginationDTO,
|
||||||
CreateReviewDTO,
|
CreateReviewDTO,
|
||||||
UpdateReviewDTO,
|
UpdateReviewDTO,
|
||||||
CreateReviewDTO,
|
|
||||||
UpdateReviewDTO,
|
|
||||||
} from '../dto/site-api.dto';
|
} from '../dto/site-api.dto';
|
||||||
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto';
|
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO } from '../dto/api.dto';
|
||||||
import {
|
import {
|
||||||
|
|
@ -34,7 +32,6 @@ import {
|
||||||
import { Site } from '../entity/site.entity';
|
import { Site } from '../entity/site.entity';
|
||||||
import { WPService } from '../service/wp.service';
|
import { WPService } from '../service/wp.service';
|
||||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
||||||
import { BatchOperationDTO, BatchOperationResultDTO } from '../dto/batch.dto';
|
|
||||||
|
|
||||||
export class WooCommerceAdapter implements ISiteAdapter {
|
export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
// 构造函数接收站点配置与服务实例
|
// 构造函数接收站点配置与服务实例
|
||||||
|
|
@ -79,20 +76,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
date_created: item.date_created,
|
date_created: item.date_created,
|
||||||
date_modified: item.date_modified,
|
date_modified: item.date_modified,
|
||||||
raw: item,
|
raw: item,
|
||||||
id: item.id,
|
|
||||||
avatar: item.avatar_url,
|
|
||||||
email: item.email,
|
|
||||||
orders: Number(item.orders ?? 0),
|
|
||||||
total_spend: Number(item.total_spent ?? 0),
|
|
||||||
first_name: item.first_name,
|
|
||||||
last_name: item.last_name,
|
|
||||||
username: item.username,
|
|
||||||
phone: item.billing?.phone || item.shipping?.phone,
|
|
||||||
billing: item.billing,
|
|
||||||
shipping: item.shipping,
|
|
||||||
date_created: item.date_created,
|
|
||||||
date_modified: item.date_modified,
|
|
||||||
raw: item,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -761,40 +744,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
return String(value).split(',').map(v => v.trim()).filter(Boolean);
|
return String(value).split(',').map(v => v.trim()).filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (where.search_fields ?? where.searchFields) mapped.search_fields = toArray(where.search_fields ?? where.searchFields);
|
|
||||||
if (where.after ?? where.date_created_after ?? where.created_after) mapped.after = String(where.after ?? where.date_created_after ?? where.created_after);
|
|
||||||
if (where.before ?? where.date_created_before ?? where.created_before) mapped.before = String(where.before ?? where.date_created_before ?? where.created_before);
|
|
||||||
if (where.modified_after ?? where.date_modified_after) mapped.modified_after = String(where.modified_after ?? where.date_modified_after);
|
|
||||||
if (where.modified_before ?? where.date_modified_before) mapped.modified_before = String(where.modified_before ?? where.date_modified_before);
|
|
||||||
if (where.dates_are_gmt ?? where.datesAreGmt) mapped.dates_are_gmt = Boolean(where.dates_are_gmt ?? where.datesAreGmt);
|
|
||||||
if (where.exclude ?? where.exclude_ids ?? where.excludedIds) mapped.exclude = toArray(where.exclude ?? where.exclude_ids ?? where.excludedIds);
|
|
||||||
if (where.include ?? where.ids) mapped.include = toArray(where.include ?? where.ids);
|
|
||||||
if (where.offset !== undefined) mapped.offset = Number(where.offset);
|
|
||||||
if (where.parent ?? where.parentId) mapped.parent = toArray(where.parent ?? where.parentId);
|
|
||||||
if (where.parent_exclude ?? where.parentExclude) mapped.parent_exclude = toArray(where.parent_exclude ?? where.parentExclude);
|
|
||||||
if (where.slug) mapped.slug = String(where.slug);
|
|
||||||
if (!mapped.status && (where.status || where.include_status || where.exclude_status || where.includeStatus || where.excludeStatus)) {
|
|
||||||
if (where.include_status ?? where.includeStatus) mapped.include_status = String(where.include_status ?? where.includeStatus);
|
|
||||||
if (where.exclude_status ?? where.excludeStatus) mapped.exclude_status = String(where.exclude_status ?? where.excludeStatus);
|
|
||||||
if (where.status) mapped.status = String(where.status);
|
|
||||||
}
|
|
||||||
if (where.type) mapped.type = String(where.type);
|
|
||||||
if (where.include_types ?? where.includeTypes) mapped.include_types = String(where.include_types ?? where.includeTypes);
|
|
||||||
if (where.exclude_types ?? where.excludeTypes) mapped.exclude_types = String(where.exclude_types ?? where.excludeTypes);
|
|
||||||
if (where.sku) mapped.sku = String(where.sku);
|
|
||||||
if (where.featured ?? where.isFeatured) mapped.featured = Boolean(where.featured ?? where.isFeatured);
|
|
||||||
if (where.category ?? where.categoryId) mapped.category = String(where.category ?? where.categoryId);
|
|
||||||
if (where.tag ?? where.tagId) mapped.tag = String(where.tag ?? where.tagId);
|
|
||||||
if (where.shipping_class ?? where.shippingClass) mapped.shipping_class = String(where.shipping_class ?? where.shippingClass);
|
|
||||||
if (where.attribute ?? where.attributeName) mapped.attribute = String(where.attribute ?? where.attributeName);
|
|
||||||
if (where.attribute_term ?? where.attributeTermId ?? where.attributeTerm) mapped.attribute_term = String(where.attribute_term ?? where.attributeTermId ?? where.attributeTerm);
|
|
||||||
if (where.tax_class ?? where.taxClass) mapped.tax_class = String(where.tax_class ?? where.taxClass);
|
|
||||||
if (where.on_sale ?? where.onSale) mapped.on_sale = Boolean(where.on_sale ?? where.onSale);
|
|
||||||
if (where.min_price ?? where.minPrice) mapped.min_price = String(where.min_price ?? where.minPrice);
|
|
||||||
if (where.max_price ?? where.maxPrice) mapped.max_price = String(where.max_price ?? where.maxPrice);
|
|
||||||
if (where.stock_status ?? where.stockStatus) mapped.stock_status = String(where.stock_status ?? where.stockStatus);
|
|
||||||
if (where.virtual !== undefined) mapped.virtual = Boolean(where.virtual);
|
|
||||||
if (where.downloadable !== undefined) mapped.downloadable = Boolean(where.downloadable);
|
|
||||||
if (where.search_fields ?? where.searchFields) mapped.search_fields = toArray(where.search_fields ?? where.searchFields);
|
if (where.search_fields ?? where.searchFields) mapped.search_fields = toArray(where.search_fields ?? where.searchFields);
|
||||||
if (where.after ?? where.date_created_after ?? where.created_after) mapped.after = String(where.after ?? where.date_created_after ?? where.created_after);
|
if (where.after ?? where.date_created_after ?? where.created_after) mapped.after = String(where.after ?? where.date_created_after ?? where.created_after);
|
||||||
if (where.before ?? where.date_created_before ?? where.created_before) mapped.before = String(where.before ?? where.date_created_before ?? where.created_before);
|
if (where.before ?? where.date_created_before ?? where.created_before) mapped.before = String(where.before ?? where.date_created_before ?? where.created_before);
|
||||||
|
|
@ -973,7 +922,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
return this.mapPlatformToUnifiedProduct(product);
|
return this.mapPlatformToUnifiedProduct(product);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProducts(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
|
||||||
async getProducts(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
async getProducts(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedProductDTO>> {
|
||||||
// 获取产品列表并使用统一分页结构返回
|
// 获取产品列表并使用统一分页结构返回
|
||||||
const requestParams = this.mapProductSearchParams(params);
|
const requestParams = this.mapProductSearchParams(params);
|
||||||
|
|
@ -982,11 +930,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
'products',
|
'products',
|
||||||
requestParams
|
requestParams
|
||||||
);
|
);
|
||||||
const { items, total, totalPages, page, per_page } = await this.wpService.fetchResourcePaged<any>(
|
|
||||||
this.site,
|
|
||||||
'products',
|
|
||||||
requestParams
|
|
||||||
);
|
|
||||||
|
|
||||||
// 对于类型为 variable 的产品,需要加载完整的变体数据
|
// 对于类型为 variable 的产品,需要加载完整的变体数据
|
||||||
const productsWithVariations = await Promise.all(
|
const productsWithVariations = await Promise.all(
|
||||||
|
|
@ -1011,7 +954,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: productsWithVariations.map(this.mapPlatformToUnifiedProduct),
|
|
||||||
items: productsWithVariations.map(this.mapPlatformToUnifiedProduct),
|
items: productsWithVariations.map(this.mapPlatformToUnifiedProduct),
|
||||||
total,
|
total,
|
||||||
totalPages,
|
totalPages,
|
||||||
|
|
@ -1112,8 +1054,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 评论操作方法
|
|
||||||
async getReviews(params: UnifiedSearchParamsDTO): Promise<UnifiedReviewPaginationDTO> {
|
|
||||||
// 评论操作方法
|
// 评论操作方法
|
||||||
async getReviews(params: UnifiedSearchParamsDTO): Promise<UnifiedReviewPaginationDTO> {
|
async getReviews(params: UnifiedSearchParamsDTO): Promise<UnifiedReviewPaginationDTO> {
|
||||||
// 获取评论列表并使用统一分页结构返回
|
// 获取评论列表并使用统一分页结构返回
|
||||||
|
|
@ -1123,13 +1063,7 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
'products/reviews',
|
'products/reviews',
|
||||||
requestParams
|
requestParams
|
||||||
);
|
);
|
||||||
const { items, total, totalPages, page, per_page } = await this.wpService.fetchResourcePaged<any>(
|
|
||||||
this.site,
|
|
||||||
'products/reviews',
|
|
||||||
requestParams
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
items: items.map(this.mapPlatformToUnifiedReview.bind(this)),
|
|
||||||
items: items.map(this.mapPlatformToUnifiedReview.bind(this)),
|
items: items.map(this.mapPlatformToUnifiedReview.bind(this)),
|
||||||
total,
|
total,
|
||||||
totalPages,
|
totalPages,
|
||||||
|
|
@ -1143,13 +1077,11 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
const api = this.wpService.createApi(this.site, 'wc/v3');
|
const api = this.wpService.createApi(this.site, 'wc/v3');
|
||||||
const reviews = await this.wpService.sdkGetAll(api, 'products/reviews', params);
|
const reviews = await this.wpService.sdkGetAll(api, 'products/reviews', params);
|
||||||
return reviews.map((review: any) => this.mapPlatformToUnifiedReview(review));
|
return reviews.map((review: any) => this.mapPlatformToUnifiedReview(review));
|
||||||
return reviews.map((review: any) => this.mapPlatformToUnifiedReview(review));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async createReview(data: CreateReviewDTO): Promise<UnifiedReviewDTO> {
|
async createReview(data: CreateReviewDTO): Promise<UnifiedReviewDTO> {
|
||||||
const res = await this.wpService.createReview(this.site, data);
|
const res = await this.wpService.createReview(this.site, data);
|
||||||
return this.mapPlatformToUnifiedReview(res);
|
return this.mapPlatformToUnifiedReview(res);
|
||||||
return this.mapPlatformToUnifiedReview(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateReview(where: Partial<Pick<UnifiedReviewDTO, 'id'>>, data: UpdateReviewDTO): Promise<UnifiedReviewDTO> {
|
async updateReview(where: Partial<Pick<UnifiedReviewDTO, 'id'>>, data: UpdateReviewDTO): Promise<UnifiedReviewDTO> {
|
||||||
|
|
@ -1184,26 +1116,14 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
billing_period: item.billing_period,
|
billing_period: item.billing_period,
|
||||||
billing_interval: item.billing_interval,
|
billing_interval: item.billing_interval,
|
||||||
date_created: item.date_created ?? item.start_date,
|
date_created: item.date_created ?? item.start_date,
|
||||||
status: item.status,
|
|
||||||
customer_id: item.customer_id,
|
|
||||||
billing_period: item.billing_period,
|
|
||||||
billing_interval: item.billing_interval,
|
|
||||||
date_created: item.date_created ?? item.start_date,
|
|
||||||
date_modified: item.date_modified,
|
date_modified: item.date_modified,
|
||||||
start_date: item.start_date,
|
start_date: item.start_date,
|
||||||
next_payment_date: item.next_payment_date,
|
next_payment_date: item.next_payment_date,
|
||||||
line_items: item.line_items,
|
line_items: item.line_items,
|
||||||
start_date: item.start_date,
|
|
||||||
next_payment_date: item.next_payment_date,
|
|
||||||
line_items: item.line_items,
|
|
||||||
raw: item,
|
raw: item,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订阅操作方法
|
|
||||||
async getSubscriptions(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
|
||||||
// 获取订阅列表并映射为统一订阅DTO集合
|
|
||||||
|
|
||||||
// 订阅操作方法
|
// 订阅操作方法
|
||||||
async getSubscriptions(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
async getSubscriptions(params: UnifiedSearchParamsDTO): Promise<UnifiedPaginationDTO<UnifiedSubscriptionDTO>> {
|
||||||
// 获取订阅列表并映射为统一订阅DTO集合
|
// 获取订阅列表并映射为统一订阅DTO集合
|
||||||
|
|
@ -1211,8 +1131,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
this.site,
|
this.site,
|
||||||
'subscriptions',
|
'subscriptions',
|
||||||
params
|
params
|
||||||
'subscriptions',
|
|
||||||
params
|
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
items: items.map(this.mapPlatformToUnifiedSubscription),
|
items: items.map(this.mapPlatformToUnifiedSubscription),
|
||||||
|
|
@ -1231,13 +1149,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
return subscriptions.map((subscription: any) => this.mapPlatformToUnifiedSubscription(subscription));
|
return subscriptions.map((subscription: any) => this.mapPlatformToUnifiedSubscription(subscription));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 变体映射方法 ==========
|
|
||||||
mapPlatformToUnifiedVariation(data: any): UnifiedProductVariationDTO {
|
|
||||||
// 使用mapVariation方法来实现统一的变体映射逻辑
|
|
||||||
return this.mapVariation(data);
|
|
||||||
}
|
|
||||||
mapUnifiedToPlatformVariation(data: Partial<UnifiedProductVariationDTO>) {
|
|
||||||
return data;
|
|
||||||
// ========== 变体映射方法 ==========
|
// ========== 变体映射方法 ==========
|
||||||
mapPlatformToUnifiedVariation(data: any): UnifiedProductVariationDTO {
|
mapPlatformToUnifiedVariation(data: any): UnifiedProductVariationDTO {
|
||||||
// 使用mapVariation方法来实现统一的变体映射逻辑
|
// 使用mapVariation方法来实现统一的变体映射逻辑
|
||||||
|
|
@ -1297,7 +1208,6 @@ export class WooCommerceAdapter implements ISiteAdapter {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 变体操作方法
|
|
||||||
// 变体操作方法
|
// 变体操作方法
|
||||||
// 获取产品变体列表
|
// 获取产品变体列表
|
||||||
async getVariations(productId: string | number, params: UnifiedSearchParamsDTO): Promise<UnifiedVariationPaginationDTO> {
|
async getVariations(productId: string | number, params: UnifiedSearchParamsDTO): Promise<UnifiedVariationPaginationDTO> {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ export class WebhookController {
|
||||||
break;
|
break;
|
||||||
case 'order.created':
|
case 'order.created':
|
||||||
case 'order.updated':
|
case 'order.updated':
|
||||||
const order = adapter.mapOrder(body)
|
const order = adapter.mapPlatformToUnifiedOrder(body)
|
||||||
await this.orderService.syncSingleOrder(siteId, order);
|
await this.orderService.syncSingleOrder(siteId, order);
|
||||||
break;
|
break;
|
||||||
case 'order.deleted':
|
case 'order.deleted':
|
||||||
|
|
@ -162,7 +162,7 @@ export class WebhookController {
|
||||||
break;
|
break;
|
||||||
case 'orders/create':
|
case 'orders/create':
|
||||||
case 'orders/update':
|
case 'orders/update':
|
||||||
const order = adapter.mapOrder(body)
|
const order = adapter.mapPlatformToUnifiedOrder(body)
|
||||||
await this.orderService.syncSingleOrder(siteId, order);
|
await this.orderService.syncSingleOrder(siteId, order);
|
||||||
break;
|
break;
|
||||||
case 'orders/delete':
|
case 'orders/delete':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue