This commit is contained in:
zlwu committed 2026-08-26 11:10:40 +08:00
1 parent dd1acdc787
commit 4222eaa593
47 files changed
+1054350 -9663

No files matched your search

+5 -2
View File
@@ -474,7 +474,8 @@ def customer_create(
user_id = _user.get("user_id", "") or _user.get("id", "")
dept_id = _user.get("dept_id", "")
if customer_name_exists(db, body.customer_name, tenant_no):
customer_name = (body.customer_name or "").strip()
if customer_name_exists(db, tenant_no, customer_name):
return error_response(400, "客户名称已存在")
obj = create_customer(
@@ -507,7 +508,9 @@ def customer_update(
data = body.model_dump(exclude_unset=True)
customer_id = data.pop("id")
if "customer_name" in data:
if customer_name_exists(db, data["customer_name"], tenant_no, exclude_id=customer_id):
customer_name = (data["customer_name"] or "").strip()
data["customer_name"] = customer_name
if customer_name_exists(db, tenant_no, customer_name, exclude_id=customer_id):
return error_response(400, "客户名称已存在")
obj = update_customer(db, customer_id, user_id=user_id, tenant_no=tenant_no, user_info=user_info, **data)
+13 -2
View File
@@ -463,7 +463,7 @@ def convert_clue(
user_info=None,
) -> dict:
from app.crud.crm.contact import create_contact
from app.crud.crm.customer import check_duplicate_customer, generate_customer_no
from app.crud.crm.customer import check_duplicate_customer, customer_name_exists, generate_customer_no
from app.models.crm_models import CrmCustomer
clue = get_clue(db, clue_id)
@@ -480,6 +480,17 @@ def convert_clue(
name = dup_customers[0].get("customerName") or dup_customers[0].get("customer_name")
raise ValueError(f"该手机号已存在客户记录【{name}】,无法转化")
customer_name = (
customer_data.get("customer_name")
or clue.company
or clue.clue_name
or ""
).strip()
if not customer_name:
raise ValueError("客户名称不能为空")
if customer_name_exists(db, tenant_no, customer_name):
raise ValueError(f"客户名称【{customer_name}】已存在,无法转化")
now = datetime.now()
customer_type = (
customer_data.get("customer_type")
@@ -490,7 +501,7 @@ def convert_clue(
customer = CrmCustomer(
id=generate_uuid(),
customer_no=generate_customer_no(db, tenant_no),
customer_name=customer_data.get("customer_name") or clue.company or clue.clue_name or "",
customer_name=customer_name,
customer_type=customer_type,
mobile=clue.mobile or "",
email=clue.email or "",
+23 -2
View File
@@ -421,8 +421,11 @@ def generate_customer_no(db: Session, tenant_no: str) -> str:
def customer_name_exists(
db: Session, tenant_no: str, name: str, exclude_id: str = None
) -> bool:
normalized = (name or "").strip()
if not normalized:
return False
q = db.query(CrmCustomer).filter(
CrmCustomer.customer_name == name,
CrmCustomer.customer_name == normalized,
CrmCustomer.tenant_no == tenant_no,
CrmCustomer.del_flag == 0,
)
@@ -445,7 +448,9 @@ def check_duplicate_customer(
if mobile:
or_clauses.append(CrmCustomer.mobile == mobile)
if customer_name:
or_clauses.append(CrmCustomer.customer_name == customer_name)
normalized_name = customer_name.strip()
if normalized_name:
or_clauses.append(CrmCustomer.customer_name == normalized_name)
if not or_clauses:
return []
rows = db.query(CrmCustomer).filter(*conditions).filter(or_(*or_clauses)).all()
@@ -461,6 +466,13 @@ def create_customer(
dept_id: str = "",
**kwargs,
) -> CrmCustomer:
customer_name = (kwargs.get("customer_name") or "").strip()
if not customer_name:
raise ValueError("客户名称不能为空")
if customer_name_exists(db, tenant_no, customer_name):
raise ValueError("客户名称已存在")
kwargs["customer_name"] = customer_name
customer_no = kwargs.get("customer_no")
if not customer_no:
customer_no = generate_customer_no(db, tenant_no)
@@ -542,6 +554,15 @@ def update_customer(
raise ValueError("客户不存在")
_ensure_customer_in_scope(db, obj, user_info, obj.tenant_no)
if "customer_name" in kwargs and kwargs.get("customer_name") is not None:
normalized_name = (kwargs.get("customer_name") or "").strip()
if not normalized_name:
raise ValueError("客户名称不能为空")
if normalized_name != (obj.customer_name or "").strip():
if customer_name_exists(db, obj.tenant_no, normalized_name, exclude_id=customer_id):
raise ValueError("客户名称已存在")
kwargs["customer_name"] = normalized_name
# name_pinyin_abbr 单独处理,避免双重赋值
_updatable = (
"customer_name", "short_name", "customer_type", "mobile", "telephone",