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

fix: 将origin_id字段统一转换为字符串类型

修复订单和客户服务中origin_id字段类型不一致的问题,确保所有相关操作中origin_id都作为字符串处理
This commit is contained in:
tikkhun 2025-12-31 14:33:53 +08:00
parent 43e0d8d40d
commit 28fb8e4ce6
6 changed files with 21 additions and 10 deletions

View File

@ -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 ?? ''),
@ -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: [],

View File

@ -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);

View File

@ -28,6 +28,12 @@ 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;

View File

@ -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;

View File

@ -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);

View File

@ -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);