# 1 号药城支付落表班次。 from __future__ import annotations from dataclasses import dataclass from settle import MallLine, match_pay_lines # 一次支付落表的计数:写入、状态跳过、订单号重复、对不上。 @dataclass class PaySummary: source_lines: int = 0 inserted: int = 0 skipped_status: int = 0 skipped_dup: int = 0 unmatched: int = 0 unmatched_reasons: dict[str, int] | None = None # 未对上的原因计数缺省为空字典,避免调用方再判 None。 def __post_init__(self) -> None: if self.unmatched_reasons is None: self.unmatched_reasons = {} # 把 1 号药城已支付行写入表 2 的支付行。不对加购行。dry_run 只统计不落库。 def run_yaoex_pay( repo, lines: list[MallLine], *, dry_run: bool = False, ) -> PaySummary: result = match_pay_lines(lines, repo.load_existing_pay_order_nos()) if result.rows and not dry_run: repo.save_pay_rows(result.rows) reasons: dict[str, int] = {} for _line, reason in result.unmatched: reasons[reason] = reasons.get(reason, 0) + 1 return PaySummary( source_lines=len(lines), inserted=len(result.rows), skipped_status=len(result.skipped_status), skipped_dup=len(result.skipped_dup), unmatched=len(result.unmatched), unmatched_reasons=reasons, )