forked from yoone/API
fix: 修复客户查询条件并优化订单客户信息更新逻辑
修复客户服务中phone查询条件的可选链操作符问题 将订单服务中的客户信息更新逻辑提前到订单检查之前
This commit is contained in:
parent
6b782a9d6e
commit
2cc434bb19
|
|
@ -6,6 +6,7 @@ import {
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { ApiProperty } from '@midwayjs/swagger';
|
import { ApiProperty } from '@midwayjs/swagger';
|
||||||
import { Product } from './product.entity';
|
import { Product } from './product.entity';
|
||||||
|
// 这个其实是 alias 后面改一下
|
||||||
@Entity('product_site_sku')
|
@Entity('product_site_sku')
|
||||||
export class SiteSku {
|
export class SiteSku {
|
||||||
@ApiProperty({ description: 'sku'})
|
@ApiProperty({ description: 'sku'})
|
||||||
|
|
|
||||||
|
|
@ -371,9 +371,9 @@ export class CustomerService {
|
||||||
const {
|
const {
|
||||||
page = 1,
|
page = 1,
|
||||||
per_page = 20,
|
per_page = 20,
|
||||||
where ={},
|
where = {},
|
||||||
} = params;
|
} = params;
|
||||||
if (where.phone) {
|
if (where?.phone) {
|
||||||
where.phone = Like(`%${where.phone}%`);
|
where.phone = Like(`%${where.phone}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,20 @@ export class OrderService {
|
||||||
const existingOrder = await this.orderModel.findOne({
|
const existingOrder = await this.orderModel.findOne({
|
||||||
where: { externalOrderId, siteId: siteId },
|
where: { externalOrderId, siteId: siteId },
|
||||||
});
|
});
|
||||||
|
// 提前不然存在就不更新客户信息了
|
||||||
|
// 创建或更新客户信息
|
||||||
|
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 || order?.billing?.first_name + ' ' + order?.billing?.last_name,
|
||||||
|
phone: order?.billing?.phone || order?.shipping?.phone,
|
||||||
|
// tags:['fromOrder']
|
||||||
|
});
|
||||||
// 如果订单已存在
|
// 如果订单已存在
|
||||||
if (existingOrder) {
|
if (existingOrder) {
|
||||||
// 检查是否可以更新 ERP 状态
|
// 检查是否可以更新 ERP 状态
|
||||||
|
|
@ -494,20 +508,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
// 如果订单不存在,则映射订单状态
|
// 如果订单不存在,则映射订单状态
|
||||||
entity.orderStatus = this.mapOrderStatus(entity.status);
|
entity.orderStatus = this.mapOrderStatus(entity.status);
|
||||||
// 创建或更新客户信息
|
|
||||||
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']
|
|
||||||
});
|
|
||||||
// const customer = await this.customerModel.findOne({
|
// const customer = await this.customerModel.findOne({
|
||||||
// where: { email: order.customer_email },
|
// where: { email: order.customer_email },
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue