团队管理设置

This commit is contained in:
2026-06-30 11:31:54 +08:00
parent 152392e3d9
commit 9fb81dcfc1
24 changed files with 1231 additions and 127 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
from app.models.base import Base, TimestampMixin, SoftDeleteMixin, engine, async_session, init_database, close_database
from app.models.user import User
from app.models.team import Team
from app.models.project import Project
from app.models.generation_record import GenerationRecord
from app.models.credit_record import CreditRecord
@@ -33,7 +34,7 @@ from app.models.user_oauth_app import UserOAuthApp
__all__ = [
"Base", "TimestampMixin", "SoftDeleteMixin", "engine", "async_session",
"init_database", "close_database",
"User", "Project", "GenerationRecord", "CreditRecord",
"User", "Team", "Project", "GenerationRecord", "CreditRecord",
"ModelConfig", "SystemConfig", "Notification", "PaymentOrder",
"TokenUsage", "IndustryConfig", "VideoEngine", "CreditRatio",
"MenuConfig", "RechargePackage", "OperationLog",
@@ -16,6 +16,8 @@ class CreditRecord(Base, TimestampMixin):
Index("ix_credit_records_subject_media", "credit_subject", "media_type"),
Index("ix_credit_records_source_module_scene", "source_module", "billing_scene"),
Index("ix_credit_records_user_kind_time", "user_type_snapshot", "frontend_user_kind_snapshot", "created_at"),
Index("ix_credit_records_team_time", "team_id_snapshot", "created_at"),
Index("ix_credit_records_user_kind_team_time", "user_type_snapshot", "frontend_user_kind_snapshot", "team_id_snapshot", "created_at"),
)
id: Mapped[str] = mapped_column(String(32), primary_key=True)
@@ -66,3 +68,6 @@ class CreditRecord(Base, TimestampMixin):
user_type_snapshot: Mapped[str | None] = mapped_column(String(16), nullable=True, index=True)
frontend_user_kind_snapshot: Mapped[str | None] = mapped_column(String(16), nullable=True, index=True)
# 交易流水发生时的团队归属冷备快照;用户后续改团队不影响历史流水展示与筛选。
team_id_snapshot: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
team_name_snapshot: Mapped[str | None] = mapped_column(String(128), nullable=True)
+34
View File
@@ -0,0 +1,34 @@
from sqlalchemy import Index, Integer, String
from sqlalchemy.orm import Mapped, mapped_column
from app.enums.team import TeamStatus
from app.models.base import Base, SoftDeleteMixin, TimestampMixin
class Team(Base, TimestampMixin, SoftDeleteMixin):
__tablename__ = "teams"
__table_args__ = (
Index("ix_teams_status_sort", "status", "sort_order", "created_at"),
Index("ix_teams_code", "code"),
)
id: Mapped[str] = mapped_column(String(32), primary_key=True)
name: Mapped[str] = mapped_column(String(128), nullable=False, index=True, comment="团队名称")
code: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="团队编码")
description: Mapped[str | None] = mapped_column(String(512), nullable=True, comment="团队备注")
status: Mapped[str] = mapped_column(
String(16),
default=TeamStatus.ACTIVE.value,
server_default=TeamStatus.ACTIVE.value,
nullable=False,
index=True,
comment="团队状态:active启用,disabled禁用",
)
sort_order: Mapped[int] = mapped_column(
Integer,
default=0,
server_default="0",
nullable=False,
index=True,
comment="排序值,越小越靠前",
)
+2
View File
@@ -29,6 +29,8 @@ class User(Base, TimestampMixin):
index=True,
nullable=False,
)
# 当前归属团队,仅前台用户有业务意义;不影响 frontend_user_kind 内部/外部设置。
team_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
last_login_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), nullable=True
)