Major Features: - ✅ Multi-tenant architecture (tenant isolation) - ✅ Employee CRUD with lifecycle management (onboarding/offboarding) - ✅ Department tree structure with email domain management - ✅ Company info management (single-record editing) - ✅ System functions CRUD (permission management) - ✅ Email account management (multi-account per employee) - ✅ Keycloak SSO integration (auth.lab.taipei) - ✅ Redis session storage (10.1.0.254:6379) - Solves Cookie 4KB limitation - Cross-system session sharing - Sliding expiration (8 hours) - Automatic token refresh Technical Stack: Backend: - FastAPI + SQLAlchemy - PostgreSQL 16 (10.1.0.20:5433) - Keycloak Admin API integration - Docker Mailserver integration (SSH) - Alembic migrations Frontend: - Next.js 14 (App Router) - NextAuth 4 with Keycloak Provider - Redis session storage (ioredis) - Tailwind CSS Infrastructure: - Redis 7 (10.1.0.254:6379) - Session + Cache - Keycloak 26.1.0 (auth.lab.taipei) - Docker Mailserver (10.1.0.254) Architecture Highlights: - Session管理由 Keycloak + Redis 統一控制 - 支援多系統 (HR/WebMail/Calendar/Drive/Office) 共享 session - Token 自動刷新,異質服務整合 - 未來可無縫遷移到雲端 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""
|
|
付款記錄 Model
|
|
記錄所有付款交易
|
|
"""
|
|
from datetime import datetime
|
|
from sqlalchemy import Column, Integer, String, DateTime, Numeric, ForeignKey, Text
|
|
from sqlalchemy.orm import relationship
|
|
import enum
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class PaymentStatus(str, enum.Enum):
|
|
"""付款狀態"""
|
|
SUCCESS = "success" # 成功
|
|
FAILED = "failed" # 失敗
|
|
PENDING = "pending" # 處理中
|
|
REFUNDED = "refunded" # 已退款
|
|
|
|
|
|
class Payment(Base):
|
|
"""付款記錄表"""
|
|
|
|
__tablename__ = "payments"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
invoice_id = Column(Integer, ForeignKey("invoices.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
tenant_id = Column(Integer, ForeignKey("organizes.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
|
|
# 付款資訊
|
|
amount = Column(Numeric(10, 2), nullable=False, comment="付款金額")
|
|
payment_method = Column(String(20), nullable=False, comment="付款方式 (credit_card/wire_transfer/cash)")
|
|
transaction_id = Column(String(100), nullable=True, comment="金流交易編號")
|
|
status = Column(String(20), default=PaymentStatus.PENDING, nullable=False, comment="狀態")
|
|
|
|
# 時間記錄
|
|
paid_at = Column(DateTime, default=datetime.utcnow, nullable=False, comment="付款時間")
|
|
|
|
# 備註
|
|
notes = Column(Text, nullable=True, comment="備註")
|
|
|
|
# 關聯
|
|
invoice = relationship("Invoice", back_populates="payments")
|
|
|
|
def __repr__(self):
|
|
return f"<Payment NT$ {self.amount} - {self.status}>"
|
|
|
|
@property
|
|
def is_success(self) -> bool:
|
|
"""是否付款成功"""
|
|
return self.status == PaymentStatus.SUCCESS
|