From 2cc434bb196c5553a32526f7421f192dc1f61cce Mon Sep 17 00:00:00 2001 From: tikkhun Date: Fri, 30 Jan 2026 10:27:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AE=A2=E6=88=B7=E4=BF=A1=E6=81=AF=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复客户服务中phone查询条件的可选链操作符问题 将订单服务中的客户信息更新逻辑提前到订单检查之前 --- src/entity/site-sku.entity.ts | 1 + src/service/customer.service.ts | 4 ++-- src/service/order.service.ts | 27 ++++++++++++++------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/entity/site-sku.entity.ts b/src/entity/site-sku.entity.ts index 03b4ba0..f197caf 100644 --- a/src/entity/site-sku.entity.ts +++ b/src/entity/site-sku.entity.ts @@ -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'}) diff --git a/src/service/customer.service.ts b/src/service/customer.service.ts index 47f430f..8c1a299 100644 --- a/src/service/customer.service.ts +++ b/src/service/customer.service.ts @@ -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}%`); } diff --git a/src/service/order.service.ts b/src/service/order.service.ts index 7f3bc0d..fb3baf1 100644 --- a/src/service/order.service.ts +++ b/src/service/order.service.ts @@ -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 }, // }); -- 2.40.1