fix: 修复客户查询条件并优化订单客户信息更新逻辑

修复客户服务中phone查询条件的可选链操作符问题
将订单服务中的客户信息更新逻辑提前到订单检查之前
This commit is contained in:
tikkhun 2026-01-30 10:27:40 +08:00
parent 6b782a9d6e
commit 2cc434bb19
3 changed files with 17 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import {
} from 'typeorm';
import { ApiProperty } from '@midwayjs/swagger';
import { Product } from './product.entity';
// 这个其实是 alias 后面改一下
@Entity('product_site_sku')
export class SiteSku {
@ApiProperty({ description: 'sku'})

View File

@ -371,9 +371,9 @@ export class CustomerService {
const {
page = 1,
per_page = 20,
where ={},
where = {},
} = params;
if (where.phone) {
if (where?.phone) {
where.phone = Like(`%${where.phone}%`);
}

View File

@ -478,6 +478,20 @@ export class OrderService {
const existingOrder = await this.orderModel.findOne({
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) {
// 检查是否可以更新 ERP 状态
@ -494,20 +508,7 @@ export class OrderService {
}
// 如果订单不存在,则映射订单状态
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({
// where: { email: order.customer_email },
// });