fix(card): 扫码支付等流水不再被算成收入 - #81
Open
yeliqin666 wants to merge 1 commit into
Open
yeliqin666 wants to merge 1 commit into
yeliqin666 wants to merge 1 commit into
Conversation
优先按 typeFrom 判断方向(与官方 ncard 账单页一致),缺失时退回类型关键词, 并补上「二维码支付 / qrCode-payment」;关键词都对不上时按 toAccount 判断钱是否转出。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
TiaoFeng
approved these changes
Sep 24, 2026
TiaoFeng
left a comment
There was a problem hiding this comment.
本人实机验证此 PR 修复了真实存在的“扫码支付流水显示异常”的问题。
结论
没有发现阻塞性问题,倾向支持合并。
JimmyWang0417
left a comment
Collaborator
There was a problem hiding this comment.
补充一个边界问题:题述说 typeFrom 缺失或格式异常时会安全退化,但 _optional_str() 会把 True、1.0 甚至任意对象转换成非空字符串;_signed_amount_cents() 随后把所有非 "1" 的值直接判为支出,因而异常的 typeFrom=True 会覆盖关键词和账户字段,得到错误方向。建议只接受接口约定的字符串/整数值,其他类型返回 None,让它进入既有关键词或账户回退路径,并补一个异常类型的测试。
JimmyWang0417
requested changes
Sep 24, 2026
JimmyWang0417
left a comment
Collaborator
There was a problem hiding this comment.
当前版本暂不支持合并。typeFrom 的异常类型处理仍可能导致错误的金额方向:_optional_str() 会把 True、1.0 等异常值转成非空字符串,随后 _signed_amount_cents() 将所有非 "1" 的值直接判为支出,覆盖关键词和账户字段的回退逻辑。请限制可接受的类型,异常值返回 None,并补充回归测试。
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
校园卡流水里,食堂窗口扫码支付的记录(
icon=qrCode-payment、turnoverType=二维码支付)不含任何已知的支出关键词,于是走进_signed_amount_cents()的默认分支,按正数显示成收入,余额走势和收支统计都跟着错。根因是方向完全靠类型文案关键词猜;学校一加新支付渠道就会漏。改为三级判断:
typeFrom:官方 ncard 账单页前端按"1" === typeFrom显示+,其余一律-,这是权威规则。typeFrom时退回原有关键词匹配(收入优先,保留「消费退款」取正的行为),并把「二维码支付 / qrcode-payment」补进支出关键词。toAccount=0(或等于fromAccount)视为留在卡里,否则视为转出。服务端返回负数时仍原样保留;
typeFrom、toAccount、fromAccount缺失或格式异常时安全退化,不会抛错。验证
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判断方向。本地环境:Windows 11,Python 3.12。
🤖 Generated with Claude Code