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;
|
site_id: number;
|
||||||
|
|
||||||
@ApiProperty({ description: '原始ID', required: false })
|
@ApiProperty({ description: '原始ID', required: false })
|
||||||
origin_id?: number;
|
origin_id?: string;
|
||||||
|
|
||||||
@ApiProperty({ description: '邮箱' })
|
@ApiProperty({ description: '邮箱' })
|
||||||
email: string;
|
email: string;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export class CustomerService {
|
||||||
site_id: siteId, // 使用站点ID而不是客户ID
|
site_id: siteId, // 使用站点ID而不是客户ID
|
||||||
site_created_at: this.parseDate(siteCustomer.date_created),
|
site_created_at: this.parseDate(siteCustomer.date_created),
|
||||||
site_updated_at: this.parseDate(siteCustomer.date_modified),
|
site_updated_at: this.parseDate(siteCustomer.date_modified),
|
||||||
origin_id: Number(siteCustomer.id),
|
origin_id: String(siteCustomer.id),
|
||||||
email: siteCustomer.email,
|
email: siteCustomer.email,
|
||||||
first_name: siteCustomer.first_name,
|
first_name: siteCustomer.first_name,
|
||||||
last_name: siteCustomer.last_name,
|
last_name: siteCustomer.last_name,
|
||||||
|
|
@ -171,10 +171,7 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import { UnifiedOrderDTO } from '../dto/site-api.dto';
|
import { UnifiedOrderDTO } from '../dto/site-api.dto';
|
||||||
|
import { CustomerService } from './customer.service';
|
||||||
@Provide()
|
@Provide()
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
|
|
||||||
|
|
@ -100,6 +101,9 @@ export class OrderService {
|
||||||
@Inject()
|
@Inject()
|
||||||
siteApiService: SiteApiService;
|
siteApiService: SiteApiService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
customerService: CustomerService;
|
||||||
|
|
||||||
@Logger()
|
@Logger()
|
||||||
logger; // 注入 Logger 实例
|
logger; // 注入 Logger 实例
|
||||||
|
|
||||||
|
|
@ -343,20 +347,33 @@ export class OrderService {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
entity.orderStatus = this.mapOrderStatus(entity.status);
|
entity.orderStatus = this.mapOrderStatus(entity.status);
|
||||||
const customer = await this.customerModel.findOne({
|
await this.customerService.upsertCustomer({
|
||||||
where: { email: order.customer_email },
|
|
||||||
});
|
|
||||||
if (!customer) {
|
|
||||||
// 这里用 customer create
|
|
||||||
await this.customerModel.save({
|
|
||||||
email: order.customer_email,
|
email: order.customer_email,
|
||||||
site_id: siteId,
|
site_id: siteId,
|
||||||
origin_id: String(order.customer_id),
|
origin_id: String(order.customer_id),
|
||||||
billing: order.billing,
|
billing: order.billing,
|
||||||
shipping: order.shipping,
|
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,
|
phone: order?.billing?.phone || order?.shipping?.phone,
|
||||||
|
|
||||||
|
// tags:['fromOrder']
|
||||||
});
|
});
|
||||||
}
|
// 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);
|
return await this.orderModel.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue