forked from yoone/API
fix: 将origin_id字段统一转换为字符串类型
修复订单和客户服务中origin_id字段类型不一致的问题,确保所有相关操作中origin_id都作为字符串处理
This commit is contained in:
parent
43e0d8d40d
commit
28fb8e4ce6
|
|
@ -14,7 +14,8 @@ import {
|
||||||
UnifiedWebhookPaginationDTO,
|
UnifiedWebhookPaginationDTO,
|
||||||
CreateWebhookDTO,
|
CreateWebhookDTO,
|
||||||
UpdateWebhookDTO,
|
UpdateWebhookDTO,
|
||||||
UnifiedAddressDTO
|
UnifiedAddressDTO,
|
||||||
|
UnifiedShippingLineDTO
|
||||||
} 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 {
|
||||||
|
|
@ -120,6 +121,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
// 映射变体
|
// 映射变体
|
||||||
return {
|
return {
|
||||||
id: variant.id,
|
id: variant.id,
|
||||||
|
name: variant.sku || '',
|
||||||
sku: variant.sku || '',
|
sku: variant.sku || '',
|
||||||
regular_price: String(variant.price ?? ''),
|
regular_price: String(variant.price ?? ''),
|
||||||
sale_price: String(variant.special_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
|
[100]: OrderStatus.PENDING, // 100 未完成 转为 pending
|
||||||
[110]: OrderStatus.PROCESSING, // 110 待处理 转为 processing
|
[110]: OrderStatus.PROCESSING, // 110 待处理 转为 processing
|
||||||
[180]: OrderStatus.COMPLETED, // 180 已完成(确认收货) 转为 completed
|
[180]: OrderStatus.COMPLETED, // 180 已完成(确认收货) 转为 completed
|
||||||
|
|
@ -192,7 +194,7 @@ export class ShopyyAdapter implements ISiteAdapter {
|
||||||
id: item.fulfillments?.[0]?.id || 0,
|
id: item.fulfillments?.[0]?.id || 0,
|
||||||
method_title: item.payment_method || '',
|
method_title: item.payment_method || '',
|
||||||
method_id: 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',
|
total_tax: '0.00',
|
||||||
taxes: [],
|
taxes: [],
|
||||||
meta_data: [],
|
meta_data: [],
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ export class CustomerController {
|
||||||
async createCustomer(@Body() body: CreateCustomerDTO) {
|
async createCustomer(@Body() body: CreateCustomerDTO) {
|
||||||
try {
|
try {
|
||||||
// 调用service层的upsertCustomer方法
|
// 调用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);
|
return successResponse(result.customer);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorResponse(error.message);
|
return errorResponse(error.message);
|
||||||
|
|
@ -190,7 +190,7 @@ export class CustomerController {
|
||||||
@Post('/batch')
|
@Post('/batch')
|
||||||
async batchCreateCustomers(@Body() body: BatchCreateCustomerDTO) {
|
async batchCreateCustomers(@Body() body: BatchCreateCustomerDTO) {
|
||||||
try {
|
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);
|
return successResponse(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return errorResponse(error.message);
|
return errorResponse(error.message);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,13 @@ export class UnifiedSearchParamsDTO<Where=Record<string, any>> {
|
||||||
|
|
||||||
@ApiProperty({ description: '每页数量', example: 20, required: false })
|
@ApiProperty({ description: '每页数量', example: 20, required: false })
|
||||||
per_page?: number;
|
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 })
|
@ApiProperty({ description: '搜索关键词', required: false })
|
||||||
search?: string;
|
search?: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export class CustomerDTO extends Customer{
|
||||||
site_id: number;
|
site_id: number;
|
||||||
|
|
||||||
@ApiProperty({ description: '原始ID', required: false })
|
@ApiProperty({ description: '原始ID', required: false })
|
||||||
origin_id: number;
|
origin_id: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '站点创建时间', required: false })
|
@ApiProperty({ description: '站点创建时间', required: false })
|
||||||
site_created_at: Date;
|
site_created_at: Date;
|
||||||
|
|
@ -124,7 +124,7 @@ export class UpdateCustomerDTO {
|
||||||
site_id?: number;
|
site_id?: number;
|
||||||
|
|
||||||
@ApiProperty({ description: '原始ID', required: false })
|
@ApiProperty({ description: '原始ID', required: false })
|
||||||
origin_id?: number;
|
origin_id?: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '邮箱', required: false })
|
@ApiProperty({ description: '邮箱', required: false })
|
||||||
email?: string;
|
email?: string;
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,10 @@ export class CustomerService {
|
||||||
// 第二步:将站点客户数据转换为客户实体数据
|
// 第二步:将站点客户数据转换为客户实体数据
|
||||||
const customersData = siteCustomers.map(siteCustomer => {
|
const customersData = siteCustomers.map(siteCustomer => {
|
||||||
return this.mapSiteCustomerToCustomer(siteCustomer, siteId);
|
return this.mapSiteCustomerToCustomer(siteCustomer, siteId);
|
||||||
});
|
}).map(customer => ({
|
||||||
|
...customer,
|
||||||
|
origin_id: String(customer.origin_id),
|
||||||
|
}));
|
||||||
|
|
||||||
// 第三步:批量upsert客户数据
|
// 第三步:批量upsert客户数据
|
||||||
const upsertResult = await this.upsertManyCustomers(customersData);
|
const upsertResult = await this.upsertManyCustomers(customersData);
|
||||||
|
|
|
||||||
|
|
@ -347,7 +347,7 @@ export class OrderService {
|
||||||
await this.customerModel.save({
|
await this.customerModel.save({
|
||||||
email: order.customer_email,
|
email: order.customer_email,
|
||||||
site_id: siteId,
|
site_id: siteId,
|
||||||
origin_id: order.customer_id,
|
origin_id: String(order.customer_id),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return await this.orderModel.save(entity);
|
return await this.orderModel.save(entity);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue