From a045625d48bea048a1bc44753e30750974ff93e0 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 5 May 2026 11:59:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E5=90=8E=E7=AB=AF=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=B5=B0=E6=9F=A5=E5=8F=91=E7=8E=B0=202=20=E4=B8=AA?= =?UTF-8?q?=20schema=20=E4=B8=8D=E4=B8=80=E8=87=B4=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - coach_service.py:594 _build_task_groups SQL 查 biz.notes.is_pinned 但表无该字段 → UndefinedColumn 抛错 + 事务终止 + 级联 _build_notes / _build_history_months 全部失败(InFailedSqlTransaction) 修复:删除 is_pinned 列,pinned 降级 False(置顶功能未落库, 不影响核心备注展示)。 - customer_service.py:1088 _get_consumption_month_summary SQL 用错 3 个字段(从 v_dwd_assistant_service_log 复制粘贴未适配 v_dwd_settlement_head 字段名差异): sh.tenant_member_id → sh.member_id sh.is_delete = 0 → 删除(view 已过滤已撤销订单) sh.settle_time → sh.create_time → 高频 UndefinedColumn,小程序 customer-records 月度 rechargeTotal 恒返回 0,consumption60D 恒返回 null。 走查覆盖(MCP): - 小程序 customer-records 调 /api/xcx/customers/{id}/consumption-records 修前: rechargeTotal=0, consumption60D=null 修后: rechargeTotal=1009.08, consumption60D=7758.24, daysSinceVisit=31 visitCount=1, consumeTotal=384.02 全部 PASS 发现来源:tmp/20260505_backed_LOG.txt 后端日志 grep ERROR/Traceback 反复出现 UndefinedColumn。 Co-Authored-By: Claude Opus 4.7 (1M context) --- apps/backend/app/services/coach_service.py | 10 ++++++---- apps/backend/app/services/customer_service.py | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/backend/app/services/coach_service.py b/apps/backend/app/services/coach_service.py index bb5d712..4da4500 100644 --- a/apps/backend/app/services/coach_service.py +++ b/apps/backend/app/services/coach_service.py @@ -589,9 +589,11 @@ def _build_task_groups( if task_ids: try: with conn.cursor() as cur: + # 2026-05-05: biz.notes 无 is_pinned 列(SQL 报 UndefinedColumn 触发事务终止 + 级联失败), + # 删除该列,pinned 降级 False(置顶功能未落库,不影响核心备注展示) cur.execute( """ - SELECT task_id, is_pinned, content, created_at + SELECT task_id, content, created_at FROM biz.notes WHERE task_id = ANY(%s) ORDER BY created_at DESC @@ -603,9 +605,9 @@ def _build_task_groups( if tid not in task_notes_map: task_notes_map[tid] = [] task_notes_map[tid].append({ - "pinned": bool(nr[1]), - "text": nr[2] or "", - "date": nr[3].isoformat() if nr[3] else "", + "pinned": False, + "text": nr[1] or "", + "date": nr[2].isoformat() if nr[2] else "", }) except Exception: logger.warning("批量查询任务备注失败", exc_info=True) diff --git a/apps/backend/app/services/customer_service.py b/apps/backend/app/services/customer_service.py index 4d3da71..d3e2238 100644 --- a/apps/backend/app/services/customer_service.py +++ b/apps/backend/app/services/customer_service.py @@ -1085,15 +1085,16 @@ def _get_consumption_month_summary( consume_total = float(row[1]) if row[1] else 0.0 # 充值总额(从 settlement_head 的 recharge_card_amount) + # 2026-05-05: 修字段名,view v_dwd_settlement_head 列名为 member_id / create_time + # (不是 tenant_member_id / settle_time);已撤销订单 view 已过滤,无需 is_delete 条件 cur.execute( """ SELECT COALESCE(SUM(sh.recharge_card_amount), 0) FROM app.v_dwd_settlement_head sh - WHERE sh.tenant_member_id = %s - AND sh.is_delete = 0 + WHERE sh.member_id = %s AND sh.recharge_card_amount > 0 - AND sh.settle_time >= %s::timestamptz - AND sh.settle_time < %s::timestamptz + AND sh.create_time >= %s::timestamptz + AND sh.create_time < %s::timestamptz """, (customer_id, start_date, end_date), )