deep-risk/backend/app/models/bank_transaction.py
2025-12-14 20:08:27 +08:00

101 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
银行流水模型
"""
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from sqlalchemy import (
Boolean,
Column,
Date,
DateTime,
String,
Text,
Float,
)
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import BaseModel
if TYPE_CHECKING:
from .streamer import StreamerInfo, McnAgency
class BankTransaction(BaseModel):
"""
银行流水表
"""
__tablename__ = "bank_transaction"
transaction_id: Mapped[str] = mapped_column(
String(50), unique=True, nullable=False, comment="流水ID"
)
account_no: Mapped[str] = mapped_column(
String(50), nullable=False, comment="账号"
)
account_name: Mapped[str] = mapped_column(
String(200), nullable=False, comment="账户名"
)
bank_name: Mapped[str] = mapped_column(
String(200), nullable=False, comment="开户行"
)
transaction_date: Mapped[Date] = mapped_column(
Date, nullable=False, comment="交易日期"
)
transaction_time: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, comment="交易时间"
)
transaction_type: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="交易类型debit-借方支出credit-贷方(收入)",
)
transaction_amount: Mapped[float] = mapped_column(
nullable=False, comment="交易金额"
)
balance: Mapped[float] = mapped_column(
nullable=False, comment="余额"
)
counterparty_account_no: Mapped[Optional[str]] = mapped_column(
String(50), nullable=True, comment="对手方账号"
)
counterparty_account_name: Mapped[Optional[str]] = mapped_column(
String(200), nullable=True, comment="对手方账户名"
)
counterparty_bank_name: Mapped[Optional[str]] = mapped_column(
String(200), nullable=True, comment="对手方开户行"
)
voucher_no: Mapped[Optional[str]] = mapped_column(
String(100), nullable=True, comment="凭证号"
)
transaction_purpose: Mapped[Optional[str]] = mapped_column(
String(500), nullable=True, comment="交易用途"
)
is_cross_border: Mapped[bool] = mapped_column(
default=False, comment="是否跨境"
)
currency: Mapped[str] = mapped_column(
String(10), default="CNY", comment="币种"
)
amount_cny: Mapped[float] = mapped_column(
nullable=False, comment="折算人民币金额"
)
exchange_rate: Mapped[float] = mapped_column(
default=1.0000, comment="汇率"
)
is_large_amount: Mapped[bool] = mapped_column(
default=False, comment="是否大额交易(>20万"
)
is_suspicious: Mapped[bool] = mapped_column(
default=False, comment="是否可疑交易"
)
suspicious_reason: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="可疑原因"
)
is_reconciled: Mapped[bool] = mapped_column(
default=False, comment="是否已对账"
)
reconciled_time: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True), nullable=True, comment="对账时间"
)