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

Merged
zksu merged 1 commits from zksu/API:main into main 2026-01-30 03:49:51 +00:00
3 changed files with 17 additions and 15 deletions

View File

@ -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'})

View File

@ -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}%`);
} }

View File

@ -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 },
// }); // });