model.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from sqlalchemy import String, UniqueConstraint, ForeignKey
  2. from sqlalchemy.orm import Mapped, mapped_column
  3. from app.common.enums import PermissionFilterStrategy
  4. from app.core.base_model import PaymentModelMixin, TenantMixin, EnterpriseMixin
  5. class OpenTransferModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  6. __tablename__ = "open_transfer"
  7. __table_args__ = (
  8. UniqueConstraint('third_biz_no', 'tenant_id', name='uq_third_biz_tenant'),
  9. {"comment": "三方转账表"} # 字典必须放在元组的最后
  10. )
  11. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  12. third_biz_no: Mapped[str] = mapped_column(
  13. String(64), nullable=False, index=True, comment="三方订单号"
  14. )
  15. out_biz_no: Mapped[str] = mapped_column(
  16. String(64),
  17. # ForeignKey("pay_transfer.out_biz_no", ondelete="RESTRICT", onupdate="CASCADE"),
  18. nullable=False,
  19. index=True,
  20. comment="平台订单号",
  21. )
  22. class OpenConfModel(PaymentModelMixin, TenantMixin):
  23. __tablename__ = "open_conf"
  24. __table_args__ = (
  25. {"comment": "三方配置表"}
  26. )
  27. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  28. # 支付宝应用配置
  29. app_id: Mapped[str] = mapped_column(
  30. String(64), unique=True, nullable=False, comment="应用ID"
  31. )
  32. # 密钥配置
  33. private_key: Mapped[str] = mapped_column(
  34. String(2048), nullable=True, comment="应用私钥(PKCS8格式)"
  35. )
  36. public_key: Mapped[str] = mapped_column(
  37. String(2048), nullable=True, comment="平台公钥"
  38. )
  39. # 网关配置
  40. gateway_url: Mapped[str] = mapped_column(
  41. String(256), nullable=True, comment="支付宝网关地址"
  42. )
  43. # 签名配置
  44. sign_type: Mapped[str] = mapped_column(
  45. String(32), nullable=True, default="RSA2", comment="签名类型: RSA/RSA2"
  46. )
  47. # 编码配置
  48. charset: Mapped[str] = mapped_column(
  49. String(32), nullable=True,default="UTF-8", comment="字符编码"
  50. )
  51. format: Mapped[str] = mapped_column(
  52. String(32), nullable=True, default="JSON", comment="数据格式"
  53. )
  54. # 回调配置
  55. notify_url: Mapped[str] = mapped_column(
  56. String(512), nullable=True, comment="异步通知地址"
  57. )
  58. return_url: Mapped[str] = mapped_column(
  59. String(512), nullable=True, comment="同步返回地址"
  60. )
  61. # 证书配置(证书模式)
  62. app_cert_sn: Mapped[str] = mapped_column(
  63. String(64), nullable=True, comment="应用证书序列号"
  64. )
  65. alipay_root_cert_sn: Mapped[str] = mapped_column(
  66. String(64), nullable=True, comment="支付宝根证书序列号"
  67. )
  68. # 加密配置
  69. encrypt_key: Mapped[str] = mapped_column(
  70. String(64), nullable=True, comment="AES加密密钥"
  71. )
  72. # 状态配置
  73. status: Mapped[str] = mapped_column(
  74. String(16), nullable=False, default="ENABLED", comment="状态: ENABLED/DISABLED"
  75. )
  76. # 描述
  77. description: Mapped[str] = mapped_column(
  78. String(256), nullable=True, comment="配置描述"
  79. )