forked from yoone/API
fix: 将origin_id类型从number改为string并重构客户创建逻辑
修改customer.dto.ts中的origin_id类型为string,以保持数据类型一致性 重构customer.service.ts中的客户数据映射逻辑,移除冗余的origin_id转换 在order.service.ts中使用customerService处理客户创建,替代直接操作model
This commit is contained in:
parent
70948ef977
commit
99bd7009cc
|
|
@ -73,7 +73,7 @@ export class CreateCustomerDTO {
|
|||
site_id: number;
|
||||
|
||||
@ApiProperty({ description: '原始ID', required: false })
|
||||
origin_id?: number;
|
||||
origin_id?: string;
|
||||
|
||||
@ApiProperty({ description: '邮箱' })
|
||||
email: string;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export class CustomerService {
|
|||
site_id: siteId, // 使用站点ID而不是客户ID
|
||||
site_created_at: this.parseDate(siteCustomer.date_created),
|
||||
site_updated_at: this.parseDate(siteCustomer.date_modified),
|
||||
origin_id: Number(siteCustomer.id),
|
||||
origin_id: String(siteCustomer.id),
|
||||
email: siteCustomer.email,
|
||||
first_name: siteCustomer.first_name,
|
||||
last_name: siteCustomer.last_name,
|
||||
|
|
@ -171,10 +171,7 @@ 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);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { UnifiedOrderDTO } from '../dto/site-api.dto';
|
||||
import { CustomerService } from './customer.service';
|
||||
@Provide()
|
||||
export class OrderService {
|
||||
|
||||
|
|
@ -97,9 +98,12 @@ export class OrderService {
|
|||
@Inject()
|
||||
siteService: SiteService;
|
||||
|
||||
@Inject()
|
||||
@Inject()
|
||||
siteApiService: SiteApiService;
|
||||
|
||||
@Inject()
|
||||
customerService: CustomerService;
|
||||
|
||||
@Logger()
|
||||
logger; // 注入 Logger 实例
|
||||
|
||||
|
|
@ -343,20 +347,33 @@ export class OrderService {
|
|||
return entity;
|
||||
}
|
||||
entity.orderStatus = this.mapOrderStatus(entity.status);
|
||||
const customer = await this.customerModel.findOne({
|
||||
where: { email: order.customer_email },
|
||||
await this.customerService.upsertCustomer({
|
||||
email: order.customer_email,
|
||||
site_id: siteId,
|
||||
origin_id: String(order.customer_id),
|
||||
billing: order.billing,
|
||||
shipping: order.shipping,
|
||||
first_name: order?.billing?.first_name || order?.shipping?.first_name,
|
||||
last_name: order?.billing?.last_name || order?.shipping?.last_name,
|
||||
fullname: order?.billing?.fullname || order?.shipping?.fullname,
|
||||
phone: order?.billing?.phone || order?.shipping?.phone,
|
||||
|
||||
// tags:['fromOrder']
|
||||
});
|
||||
if (!customer) {
|
||||
// 这里用 customer create
|
||||
await this.customerModel.save({
|
||||
email: order.customer_email,
|
||||
site_id: siteId,
|
||||
origin_id: String(order.customer_id),
|
||||
billing: order.billing,
|
||||
shipping: order.shipping,
|
||||
phone: order?.billing?.phone || order?.shipping?.phone,
|
||||
});
|
||||
}
|
||||
// const customer = await this.customerModel.findOne({
|
||||
// where: { email: order.customer_email },
|
||||
// });
|
||||
// if (!customer) {
|
||||
// // 这里用 customer create
|
||||
// await this.customerModel.save({
|
||||
// email: order.customer_email,
|
||||
// site_id: siteId,
|
||||
// origin_id: String(order.customer_id),
|
||||
// billing: order.billing,
|
||||
// shipping: order.shipping,
|
||||
// phone: order?.billing?.phone || order?.shipping?.phone,
|
||||
// });
|
||||
// }
|
||||
return await this.orderModel.save(entity);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue