feat: 客户列表按产品线分组展示 + 产品线筛选

- server.py: /api/customers 增加 product_id 筛选参数 + 返回 product_categories 字段
- index.html: 客户列表按产品线分组渲染(儿童益生菌/女性减肥益生菌/未关联) + 增加产品线筛选下拉
This commit is contained in:
selfrelease
2026-07-15 12:03:10 +08:00
parent 0c12948fa4
commit 96997c3afc
2 changed files with 78 additions and 22 deletions
+10 -2
View File
@@ -243,21 +243,25 @@ def list_salespersons():
def list_customers(
salesperson_id: int | None = Query(None),
intent_level: str | None = Query(None),
product_id: int | None = Query(None),
):
conn = get_conn()
try:
with conn.cursor() as cur:
sql = """
SELECT cu.id, cu.salesperson_id, s.name AS salesperson_name,
SELECT DISTINCT cu.id, cu.salesperson_id, s.name AS salesperson_name,
cu.customer_name, cu.industry, cu.intent_level,
cu.key_needs, cu.stage, cu.last_analysis,
c.display_name AS contact_display_name,
max(m.created_at) AS last_message_at
max(m.created_at) AS last_message_at,
string_agg(DISTINCT p.category, ', ') AS product_categories
FROM customer cu
JOIN salesperson s ON s.id = cu.salesperson_id
JOIN contact c ON c.id = cu.contact_id
LEFT JOIN conversation conv ON conv.contact_id = c.id
LEFT JOIN message m ON m.conversation_id = conv.id
LEFT JOIN deal d ON d.customer_id = cu.id
LEFT JOIN product p ON p.id = d.product_id
"""
conditions = []
params = []
@@ -267,6 +271,9 @@ def list_customers(
if intent_level is not None:
conditions.append("cu.intent_level = %s")
params.append(intent_level)
if product_id is not None:
conditions.append("d.product_id = %s")
params.append(product_id)
if conditions:
sql += " WHERE " + " AND ".join(conditions)
sql += """
@@ -286,6 +293,7 @@ def list_customers(
"last_analysis": r[8].isoformat() if r[8] else None,
"contact_display_name": r[9],
"last_message_at": r[10].isoformat() if r[10] else None,
"product_categories": r[11],
}
for r in cur.fetchall()
]