← Back to Pull requests

fix(card): 扫码支付等流水不再被算成收入 #81

Open
unknown opened this pull request with 159 lines diff across 1 files
View on GitHub
unknown unknown commented on Sep 22, 2026 13:17 UTC
Author

变更说明

校园卡流水里,食堂窗口扫码支付的记录(icon=qrCode-payment、turnoverType=二维码支付)不含任何已知的支出关键词,于是走进 _signed_amount_cents() 的默认分支,按正数显示成收入,余额走势和收支统计都跟着错。

根因是方向完全靠类型文案关键词猜;学校一加新支付渠道就会漏。改为三级判断:

1. 优先用 typeFrom:官方 ncard 账单页前端按 "1" === typeFrom 显示 +,其余一律 -,这是权威规则。
2. 缺 typeFrom 时退回原有关键词匹配(收入优先,保留「消费退款」取正的行为),并把「二维码支付 / qrcode-payment」补进支出关键词。
3. 关键词也对不上时看钱落到哪:充值 toAccount=0(或等于 fromAccount)视为留在卡里,否则视为转出。

服务端返回负数时仍原样保留;typeFrom、toAccount、fromAccount 缺失或格式异常时安全退化,不会抛错。

验证

  • 每个 bug 修复都新增或更新了可复现旧问题的回归测试。

  • 与已知 Issue 相关的程序错误已有明确的回归测试,并出现在 Actions 日志中。(无对应 Issue)

  • 已运行相关本地测试,并在下方列出无法运行的测试或环境。

  • 合并前 PR Tests / CI Gate 已通过。

  • 平台相关行为已由现有矩阵覆盖,或已在下方解释额外验证范围。
  • 测试证据

    test/card/test_campus_card.py 新增 3 个用例(合成数据,不访问真实接口):

  • test_qrcode_payment_is_expense:扫码支付记为支出;在未修复的代码上得到 +850,失败。

  • test_type_from_decides_direction_before_keywords:typeFrom 优先于关键词,字符串/整数都能识别。

  • test_unknown_type_falls_back_to_destination_account:未知类型按 toAccount 判断方向。
  • uv run --frozen python -m unittest test.card.test_campus_card
    OK
    uv run --frozen python -m test.ci.check_test_contract
    OK: 28 product test modules are covered by 5 domains.
    

    本地环境:Windows 11,Python 3.12。

    🤖 Generated with Claude Code

    Diff: 159 lines (+119 / -40) across 1 files Reviewer: JimmyWang0417 Review duration: 30607m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.33) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.33 · 159 lines diff across 1 files
    0.33
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.304
    Real PR Conversation Timeline
    1 comments
    "Review active on #81"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.4% (LOW) · Higher = larger blast radius
    33.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%