model.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. from datetime import datetime
  2. from decimal import Decimal
  3. from sqlalchemy import DateTime, Integer, Numeric, String, Text
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from app.common.enums import PermissionFilterStrategy
  6. from app.core.base_model import PaymentModelMixin, TenantMixin, EnterpriseMixin
  7. from .enums import QuotaStatusEnum
  8. class QuotaModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  9. """额度模型"""
  10. __tablename__ = "pay_expense_quota"
  11. __table_args__ = {"comment": "额度表"}
  12. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  13. employee_id: Mapped[str] = mapped_column(
  14. String(64), index=True, comment="员工ID"
  15. )
  16. institution_id: Mapped[str] = mapped_column(
  17. String(64), index=True, comment="制度ID"
  18. )
  19. out_biz_no: Mapped[str | None] = mapped_column(
  20. String(64), unique=True, index=True, comment="外部业务编号"
  21. )
  22. quota_id: Mapped[str | None] = mapped_column(
  23. String(64), comment="额度ID(支付宝返回)或关联的发放规则ID(issue_rule_id)"
  24. )
  25. total_amount: Mapped[Decimal | None] = mapped_column(
  26. Numeric(12, 2), default=0, comment="总金额"
  27. )
  28. available_amount: Mapped[Decimal | None] = mapped_column(
  29. Numeric(12, 2), default=0, comment="可用金额"
  30. )
  31. valid_from: Mapped[datetime | None] = mapped_column(
  32. DateTime, comment="有效期开始"
  33. )
  34. valid_to: Mapped[datetime | None] = mapped_column(
  35. DateTime, comment="有效期结束"
  36. )
  37. quota_type: Mapped[str | None] = mapped_column(
  38. String(32), default="CAP", comment="额度类型: CAP(余额)/COUPON(点券)/COUNT(次卡)"
  39. )
  40. target_type: Mapped[str | None] = mapped_column(
  41. String(32), comment="额度维度: INSTITUTION(制度)/EXPENSE_TYPE(费用类型)"
  42. )
  43. target_id: Mapped[str | None] = mapped_column(
  44. String(64), comment="额度维度ID"
  45. )
  46. status: Mapped[str] = mapped_column(
  47. String(32),
  48. default=QuotaStatusEnum.QUOTA_ACTIVE.value,
  49. comment="状态: QUOTA_ACTIVE/QUOTA_FROZEN/QUOTA_EXHAUSTED/QUOTA_EXPIRED"
  50. )
  51. class IssueBatchModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  52. """手工发放批次模型"""
  53. __tablename__ = "pay_expense_issue_batch"
  54. __table_args__ = {"comment": "手工发放批次表"}
  55. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  56. issue_batch_id: Mapped[str | None] = mapped_column(
  57. String(64), unique=True, index=True, comment="发放批次ID(支付宝返回)"
  58. )
  59. batch_no: Mapped[str] = mapped_column(
  60. String(64), unique=True, index=True, comment="发放批次号(幂等)"
  61. )
  62. institution_id: Mapped[str] = mapped_column(
  63. String(64), index=True, comment="制度ID"
  64. )
  65. issue_name: Mapped[str] = mapped_column(
  66. String(64), comment="发放名称"
  67. )
  68. quota_type: Mapped[str] = mapped_column(
  69. String(32), default="COUPON", comment="额度类型"
  70. )
  71. share_mode: Mapped[str] = mapped_column(
  72. String(8), default="0", comment="是否可转赠: 0/1"
  73. )
  74. total_count: Mapped[int] = mapped_column(
  75. Integer, default=0, comment="发放总人数"
  76. )
  77. total_amount: Mapped[Decimal | None] = mapped_column(
  78. Numeric(12, 2), default=0, comment="发放总金额"
  79. )
  80. status: Mapped[str] = mapped_column(
  81. String(32), default="ACTIVE", comment="状态: ACTIVE/CANCELLED"
  82. )
  83. effective_start_date: Mapped[datetime | None] = mapped_column(
  84. DateTime, comment="额度有效起始时间"
  85. )
  86. effective_end_date: Mapped[datetime | None] = mapped_column(
  87. DateTime, comment="额度有效结束时间"
  88. )
  89. issue_desc: Mapped[str | None] = mapped_column(
  90. Text, comment="发放说明"
  91. )
  92. class QuotaChangeLogModel(PaymentModelMixin, TenantMixin, EnterpriseMixin):
  93. """额度变更记录表"""
  94. __tablename__ = "pay_expense_quota_change_log"
  95. __table_args__ = {"comment": "额度变更记录表"}
  96. __permission_strategy__ = PermissionFilterStrategy.ENTERPRISE_BASED
  97. quota_id: Mapped[str] = mapped_column(
  98. String(64), index=True, comment="额度ID"
  99. )
  100. employee_id: Mapped[str] = mapped_column(
  101. String(64), comment="员工ID"
  102. )
  103. institution_id: Mapped[str] = mapped_column(
  104. String(64), comment="制度ID"
  105. )
  106. change_type: Mapped[str] = mapped_column(
  107. String(32), comment="变更类型: ISSUE(发放)/ADJUST(调整)/CANCEL(作废)"
  108. )
  109. coupon_name: Mapped[str | None] = mapped_column(
  110. String(128), comment="点券名称"
  111. )
  112. change_amount: Mapped[Decimal] = mapped_column(
  113. Numeric(12, 2), default=0, comment="变更金额(正为增加,负为减少)"
  114. )
  115. before_amount: Mapped[Decimal | None] = mapped_column(
  116. Numeric(12, 2), comment="变更前金额"
  117. )
  118. after_amount: Mapped[Decimal | None] = mapped_column(
  119. Numeric(12, 2), comment="变更后金额"
  120. )
  121. change_desc: Mapped[str | None] = mapped_column(
  122. Text, comment="变更说明"
  123. )