团队积分V1
This commit is contained in:
@@ -6,6 +6,7 @@ from decimal import Decimal
|
||||
from sqlalchemy import DateTime, ForeignKey, Index, Numeric, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.enums.credit_balance import CreditScope
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
@@ -16,6 +17,15 @@ class CreditRecordAllocation(Base, TimestampMixin):
|
||||
Index("ix_credit_record_allocations_balance", "credit_balance_id", "created_at"),
|
||||
Index("ix_credit_record_allocations_user_time", "user_id", "created_at"),
|
||||
Index("ix_credit_record_allocations_source_allocation", "source_allocation_id"),
|
||||
Index("ix_credit_record_allocations_team_time", "team_id_snapshot", "created_at", "id"),
|
||||
Index(
|
||||
"ix_credit_record_allocations_team_manager_time",
|
||||
"team_id_snapshot", "team_manager_id_snapshot", "created_at", "id",
|
||||
),
|
||||
Index(
|
||||
"ix_credit_record_allocations_team_period_user",
|
||||
"subscription_period_id_snapshot", "user_id", "allocation_action",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
||||
@@ -26,7 +36,8 @@ class CreditRecordAllocation(Base, TimestampMixin):
|
||||
String(32), ForeignKey("user_credit_balances.id", ondelete="RESTRICT"), nullable=False
|
||||
)
|
||||
user_id: Mapped[str] = mapped_column(
|
||||
String(32), ForeignKey("users.id", ondelete="CASCADE"), nullable=False
|
||||
String(32), ForeignKey("users.id", ondelete="CASCADE"), nullable=False,
|
||||
comment="真实业务消费者;发放类记录为资金所有人",
|
||||
)
|
||||
source_allocation_id: Mapped[str | None] = mapped_column(
|
||||
String(32), ForeignKey("credit_record_allocations.id", ondelete="SET NULL"), nullable=True
|
||||
@@ -36,8 +47,18 @@ class CreditRecordAllocation(Base, TimestampMixin):
|
||||
request_time: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
|
||||
credit_level_snapshot: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
credit_scope_snapshot: Mapped[str] = mapped_column(
|
||||
String(16), nullable=False, default=CreditScope.PERSONAL.value,
|
||||
server_default=CreditScope.PERSONAL.value,
|
||||
)
|
||||
source_type_snapshot: Mapped[str] = mapped_column(String(48), nullable=False)
|
||||
source_id_snapshot: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
team_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
team_manager_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
subscription_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
subscription_period_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
seat_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
|
||||
valid_from_snapshot: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
expires_at_snapshot: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user