feat: 修复产品与站点同步诸多问题 #39
|
|
@ -14,7 +14,8 @@ import {
|
|||
UnifiedWebhookPaginationDTO,
|
||||
CreateWebhookDTO,
|
||||
UpdateWebhookDTO,
|
||||
UnifiedAddressDTO
|
||||
UnifiedAddressDTO,
|
||||
UnifiedShippingLineDTO
|
||||
} from '../dto/site-api.dto';
|
||||
import { UnifiedPaginationDTO, UnifiedSearchParamsDTO, } from '../dto/api.dto';
|
||||
import {
|
||||
|
|
@ -120,6 +121,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
|||
// 映射变体
|
||||
return {
|
||||
id: variant.id,
|
||||
name: variant.sku || '',
|
||||
sku: variant.sku || '',
|
||||
regular_price: String(variant.price ?? ''),
|
||||
sale_price: String(variant.special_price ?? ''),
|
||||
|
|
@ -130,7 +132,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
|||
};
|
||||
}
|
||||
|
||||
shopyyOrderAutoNextStatusMap = {//订单状态 100 未完成;110 待处理;180 已完成(确认收货); 190 取消;
|
||||
shopyyOrderAutoNextStatusMap = {//订单状态 100 未完成;110 待处理;180 已完成(确认收货); 190 取消;
|
||||
[100]: OrderStatus.PENDING, // 100 未完成 转为 pending
|
||||
[110]: OrderStatus.PROCESSING, // 110 待处理 转为 processing
|
||||
[180]: OrderStatus.COMPLETED, // 180 已完成(确认收货) 转为 completed
|
||||
|
|
@ -192,7 +194,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
|||
id: item.fulfillments?.[0]?.id || 0,
|
||||
method_title: item.payment_method || '',
|
||||
method_id: item.payment_method || '',
|
||||
total: item.current_shipping_price.toExponential(2) || '0.00',
|
||||
total: Number(item.current_shipping_price).toExponential(2) || '0.00',
|
||||
total_tax: '0.00',
|
||||
taxes: [],
|
||||
meta_data: [],
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ export class CustomerController {
|
|||
async createCustomer(@Body() body: CreateCustomerDTO) {
|
||||
try {
|
||||
// 调用service层的upsertCustomer方法
|
||||
const result = await this.customerService.upsertCustomer(body);
|
||||
const result = await this.customerService.upsertCustomer({...body, origin_id: String(body.origin_id)});
|
||||
return successResponse(result.customer);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message);
|
||||
|
|
@ -190,7 +190,7 @@ export class CustomerController {
|
|||
@Post('/batch')
|
||||
async batchCreateCustomers(@Body() body: BatchCreateCustomerDTO) {
|
||||
try {
|
||||
const result = await this.customerService.upsertManyCustomers(body.customers);
|
||||
const result = await this.customerService.upsertManyCustomers(body.customers.map(c => ({ ...c, origin_id: String(c.origin_id) })));
|
||||
return successResponse(result);
|
||||
} catch (error) {
|
||||
return errorResponse(error.message);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,13 @@ export class UnifiedSearchParamsDTO<Where=Record<string, any>> {
|
|||
|
||||
@ApiProperty({ description: '每页数量', example: 20, required: false })
|
||||
per_page?: number;
|
||||
|
||||
|
||||
@ApiProperty({ description: '查询时间范围开始', example: '2023-01-01T00:00:00Z', required: false })
|
||||
after?: string;
|
||||
|
||||
@ApiProperty({ description: '查询时间范围结束', example: '2023-01-01T23:59:59Z', required: false })
|
||||
before?: string;
|
||||
|
||||
@ApiProperty({ description: '搜索关键词', required: false })
|
||||
search?: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export class CustomerDTO extends Customer{
|
|||
site_id: number;
|
||||
|
||||
@ApiProperty({ description: '原始ID', required: false })
|
||||
origin_id: number;
|
||||
origin_id: string;
|
||||
|
||||
@ApiProperty({ description: '站点创建时间', required: false })
|
||||
site_created_at: Date;
|
||||
|
|
@ -124,7 +124,7 @@ export class UpdateCustomerDTO {
|
|||
site_id?: number;
|
||||
|
||||
@ApiProperty({ description: '原始ID', required: false })
|
||||
origin_id?: number;
|
||||
origin_id?: string;
|
||||
|
||||
@ApiProperty({ description: '邮箱', required: false })
|
||||
email?: string;
|
||||
|
|
|
|||
|
|
@ -171,7 +171,10 @@ export class CustomerService {
|
|||
// 第二步:将站点客户数据转换为客户实体数据
|
||||
const customersData = siteCustomers.map(siteCustomer => {
|
||||
return this.mapSiteCustomerToCustomer(siteCustomer, siteId);
|
||||
});
|
||||
}).map(customer => ({
|
||||
...customer,
|
||||
origin_id: String(customer.origin_id),
|
||||
}));
|
||||
|
||||
// 第三步:批量upsert客户数据
|
||||
const upsertResult = await this.upsertManyCustomers(customersData);
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ export class OrderService {
|
|||
await this.customerModel.save({
|
||||
email: order.customer_email,
|
||||
site_id: siteId,
|
||||
origin_id: order.customer_id,
|
||||
origin_id: String(order.customer_id),
|
||||
});
|
||||
}
|
||||
return await this.orderModel.save(entity);
|
||||
|
|
|
|||
Loading…
Reference in New Issue