fix: bugs-04

This commit is contained in:
2026-03-17 22:39:05 +08:00
parent 143a1b4507
commit cdc2c4ead6
50 changed files with 1694 additions and 1916 deletions

View File

@@ -4,9 +4,13 @@ Identifies transactions that are internal transfers between the victim's
own accounts (e.g. bank -> Alipay -> WeChat) and should NOT be counted
as fraud loss.
"""
from datetime import datetime
from app.models.transaction import TransactionRecord
SELF_KEYWORDS = ["本人", "自己", "余额", "充值", "提现", "银行卡转入", "银行卡充值"]
FEE_TRANSIT_WINDOW_SECONDS = 120
FEE_TOLERANCE_RATIO = 0.02
def is_self_transfer(tx: TransactionRecord, known_self_accounts: list[str]) -> bool:
@@ -33,3 +37,27 @@ def is_self_transfer(tx: TransactionRecord, known_self_accounts: list[str]) -> b
return True
return False
def is_fee_tolerant_transit_pair(tx_a: TransactionRecord, tx_b: TransactionRecord) -> bool:
"""Two-way transfer pattern: opposite direction, close time, similar amount."""
if tx_a.direction.value == tx_b.direction.value:
return False
amount_a = float(tx_a.amount or 0)
amount_b = float(tx_b.amount or 0)
if amount_a <= 0 or amount_b <= 0:
return False
time_a = tx_a.trade_time
time_b = tx_b.trade_time
if not isinstance(time_a, datetime) or not isinstance(time_b, datetime):
return False
if abs((time_a - time_b).total_seconds()) > FEE_TRANSIT_WINDOW_SECONDS:
return False
amount_base = max(amount_a, amount_b)
if amount_base <= 0:
return False
diff_ratio = abs(amount_a - amount_b) / amount_base
return diff_ratio <= FEE_TOLERANCE_RATIO