model.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. from datetime import datetime
  2. from decimal import Decimal
  3. from sqlalchemy import JSON, DateTime, String, Text, Boolean, Numeric
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from app.core.base_model import PaymentModelMixin, TenantMixin, EnterpriseMixin
  6. from app.common.enums import PermissionFilterStrategy
  7. class AlipayNotifyLogModel(PaymentModelMixin):
  8. """支付宝通知日志模型"""
  9. __tablename__ = "pay_alipay_notify_log"
  10. __table_args__ = {"comment": "支付宝通知日志表"}
  11. notify_id: Mapped[str | None] = mapped_column(
  12. String(50), nullable=False, comment="通知ID"
  13. )
  14. msg_method: Mapped[str] = mapped_column(
  15. String(100), nullable=False, comment="消息接口名称"
  16. )
  17. notify_type: Mapped[str | None] = mapped_column(
  18. String(100), comment="通知类型"
  19. )
  20. message: Mapped[dict] = mapped_column(
  21. JSON, nullable=False, comment="完整的消息数据"
  22. )
  23. verify_result: Mapped[bool] = mapped_column(
  24. Boolean, nullable=False, comment="验签结果"
  25. )
  26. process_result: Mapped[bool | None] = mapped_column(
  27. Boolean, comment="处理结果"
  28. )
  29. error: Mapped[str | None] = mapped_column(
  30. Text, comment="错误信息"
  31. )
  32. received_at: Mapped[datetime] = mapped_column(
  33. DateTime, default=datetime.now, nullable=False, comment="接收时间"
  34. )
  35. class PayBillModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  36. """账单主表"""
  37. __tablename__ = "pay_bill"
  38. __table_args__ = {"comment": "企业码账单表"}
  39. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  40. pay_no: Mapped[str] = mapped_column(
  41. String(64), unique=True, index=True, comment="支付宝账单号"
  42. )
  43. account_id: Mapped[str] = mapped_column(String(64), comment="共同账户ID")
  44. employee_id: Mapped[str] = mapped_column(String(64), comment="员工ID")
  45. consume_type: Mapped[str] = mapped_column(
  46. String(32), comment="账单类型: CONSUME/REFUND/TRANSFER"
  47. )
  48. consume_amount: Mapped[Decimal] = mapped_column(
  49. Numeric(12, 2), comment="账单金额"
  50. )
  51. gmt_biz_create: Mapped[datetime] = mapped_column(
  52. DateTime, comment="账单创建时间"
  53. )
  54. gmt_recieve_pay: Mapped[datetime | None] = mapped_column(
  55. DateTime, comment="支付时间"
  56. )
  57. peer_pay_amount: Mapped[Decimal | None] = mapped_column(
  58. Numeric(12, 2), comment="企业代付金额"
  59. )
  60. notify_reason: Mapped[str] = mapped_column(String(255), comment="通知原因")
  61. notify_msg: Mapped[str | None] = mapped_column(Text, comment="通知描述")
  62. related_pay_no: Mapped[str | None] = mapped_column(
  63. String(64), comment="关联账单号"
  64. )
  65. expense_rule_group_id: Mapped[str | None] = mapped_column(
  66. String(64), comment="费控规则ID"
  67. )
  68. expense_scene_code: Mapped[str | None] = mapped_column(
  69. String(32), comment="费用场景"
  70. )
  71. expense_type: Mapped[str | None] = mapped_column(
  72. String(64), comment="费用类型"
  73. )
  74. status: Mapped[str] = mapped_column(
  75. String(32), default="NEW", comment="状态: NEW/PROCESSED/FAILED"
  76. )
  77. ext_infos: Mapped[dict | None] = mapped_column(JSON, comment="扩展信息")
  78. class PayBillOrderModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  79. """订单明细表"""
  80. __tablename__ = "pay_bill_order"
  81. __table_args__ = {"comment": "账单订单明细表"}
  82. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  83. pay_no: Mapped[str] = mapped_column(
  84. String(64), index=True, comment="关联账单号"
  85. )
  86. order_no: Mapped[str] = mapped_column(
  87. String(64), unique=True, index=True, comment="支付宝订单号"
  88. )
  89. trade_no: Mapped[str | None] = mapped_column(
  90. String(64), comment="支付宝交易号"
  91. )
  92. product_code: Mapped[str | None] = mapped_column(
  93. String(64), comment="产品码"
  94. )
  95. order_title: Mapped[str | None] = mapped_column(
  96. String(255), comment="订单标题"
  97. )
  98. order_amount: Mapped[Decimal | None] = mapped_column(
  99. Numeric(12, 2), comment="订单金额"
  100. )
  101. order_status: Mapped[str | None] = mapped_column(
  102. String(32), comment="订单状态"
  103. )
  104. merchant_name: Mapped[str | None] = mapped_column(
  105. String(255), comment="商户名称"
  106. )
  107. merchant_id: Mapped[str | None] = mapped_column(
  108. String(64), comment="商户ID"
  109. )
  110. shop_name: Mapped[str | None] = mapped_column(
  111. String(255), comment="门店名称"
  112. )
  113. gmt_payment: Mapped[datetime | None] = mapped_column(
  114. DateTime, comment="支付时间"
  115. )
  116. fund_channel: Mapped[str | None] = mapped_column(
  117. String(64), comment="资金渠道"
  118. )
  119. class PayBillVoucherModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  120. """凭证信息表"""
  121. __tablename__ = "pay_bill_voucher"
  122. __table_args__ = {"comment": "账单凭证信息表"}
  123. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  124. pay_no: Mapped[str] = mapped_column(
  125. String(64), index=True, comment="关联账单号"
  126. )
  127. voucher_id: Mapped[str] = mapped_column(
  128. String(64), index=True, comment="凭证ID"
  129. )
  130. voucher_type: Mapped[str | None] = mapped_column(
  131. String(32), comment="凭证类型"
  132. )
  133. voucher_status: Mapped[str | None] = mapped_column(
  134. String(32), comment="凭证状态"
  135. )
  136. invoice_code: Mapped[str | None] = mapped_column(
  137. String(64), comment="发票代码"
  138. )
  139. invoice_no: Mapped[str | None] = mapped_column(
  140. String(64), comment="发票号码"
  141. )
  142. invoice_amount: Mapped[Decimal | None] = mapped_column(
  143. Numeric(12, 2), comment="发票金额"
  144. )
  145. tax_amount: Mapped[Decimal | None] = mapped_column(
  146. Numeric(12, 2), comment="税额"
  147. )
  148. issue_date: Mapped[datetime | None] = mapped_column(
  149. DateTime, comment="开票日期"
  150. )
  151. check_code: Mapped[str | None] = mapped_column(
  152. String(64), comment="校验码"
  153. )
  154. pdf_url: Mapped[str | None] = mapped_column(Text, comment="PDF下载地址")