35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Float, ForeignKey, Integer, String, Index
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class PaymentOrder(Base, TimestampMixin):
|
|
__tablename__ = "payment_orders"
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
user_id: Mapped[str] = mapped_column(
|
|
String(32), ForeignKey("users.id", ondelete="CASCADE"), index=True
|
|
)
|
|
order_no: Mapped[str] = mapped_column(String(64), unique=True)
|
|
amount: Mapped[float] = mapped_column(Float)
|
|
credits: Mapped[float] = mapped_column(Float)
|
|
payment_method: Mapped[str] = mapped_column(String(16))
|
|
status: Mapped[str] = mapped_column(String(16), default="pending")
|
|
paid_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|
|
trade_no: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
refund_trade_no: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
|
refunded_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|
|
refund_amount: Mapped[float | None] = mapped_column(Float, nullable=True)
|
|
|
|
__table_args__ = (
|
|
Index('idx_payorder_user_status_created', 'user_id', 'status', 'created_at'),
|
|
Index('idx_payorder_status_created', 'status', 'created_at'),
|
|
)
|