model.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. api_key: Mapped[str] = mapped_column(
  23. String(256),
  24. comment="API Key",
  25. index=True,
  26. )
  27. class OpenConfModel(PaymentModelMixin, TenantMixin):
  28. __tablename__ = "open_conf"
  29. __table_args__ = (
  30. {"comment": "三方配置表"}
  31. )
  32. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  33. # 支付宝应用配置
  34. app_id: Mapped[str] = mapped_column(
  35. String(64), unique=True, nullable=False, comment="应用ID"
  36. )
  37. # 密钥配置
  38. private_key: Mapped[str] = mapped_column(
  39. String(2048), nullable=True, comment="应用私钥(PKCS8格式)"
  40. )
  41. public_key: Mapped[str] = mapped_column(
  42. String(2048), nullable=True, comment="平台公钥"
  43. )
  44. # 网关配置
  45. gateway_url: Mapped[str] = mapped_column(
  46. String(256), nullable=True, comment="支付宝网关地址"
  47. )
  48. # 签名配置
  49. sign_type: Mapped[str] = mapped_column(
  50. String(32), nullable=True, default="RSA2", comment="签名类型: RSA/RSA2"
  51. )
  52. # 编码配置
  53. charset: Mapped[str] = mapped_column(
  54. String(32), nullable=True,default="UTF-8", comment="字符编码"
  55. )
  56. format: Mapped[str] = mapped_column(
  57. String(32), nullable=True, default="JSON", comment="数据格式"
  58. )
  59. # 回调配置
  60. notify_url: Mapped[str] = mapped_column(
  61. String(512), nullable=True, comment="异步通知地址"
  62. )
  63. return_url: Mapped[str] = mapped_column(
  64. String(512), nullable=True, comment="同步返回地址"
  65. )
  66. # 证书配置(证书模式)
  67. app_cert_sn: Mapped[str] = mapped_column(
  68. String(64), nullable=True, comment="应用证书序列号"
  69. )
  70. alipay_root_cert_sn: Mapped[str] = mapped_column(
  71. String(64), nullable=True, comment="支付宝根证书序列号"
  72. )
  73. # 加密配置
  74. encrypt_key: Mapped[str] = mapped_column(
  75. String(64), nullable=True, comment="AES加密密钥"
  76. )
  77. # 状态配置
  78. status: Mapped[str] = mapped_column(
  79. String(16), nullable=False, default="ENABLED", comment="状态: ENABLED/DISABLED"
  80. )
  81. # 描述
  82. description: Mapped[str] = mapped_column(
  83. String(256), nullable=True, comment="配置描述"
  84. )