51 lines
2.9 KiB
Python
51 lines
2.9 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Index, JSON, Numeric, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class PaymentOrder(Base, TimestampMixin):
|
|
__tablename__ = "payment_orders"
|
|
__table_args__ = (
|
|
Index("idx_payorder_user_status_created", "user_id", "status", "created_at"),
|
|
Index("idx_payorder_status_created", "status", "created_at"),
|
|
)
|
|
|
|
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[Decimal] = mapped_column(Numeric(20, 2), nullable=False)
|
|
credits: Mapped[Decimal] = mapped_column(Numeric(20, 2), nullable=False, default=Decimal("0.00"), server_default="0")
|
|
payment_method: Mapped[str] = mapped_column(String(16))
|
|
status: Mapped[str] = mapped_column(String(32), 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[Decimal | None] = mapped_column(Numeric(20, 2), nullable=True)
|
|
|
|
product_id: Mapped[str | None] = mapped_column(
|
|
String(32), ForeignKey("credit_products.id", ondelete="SET NULL"), nullable=True, index=True
|
|
)
|
|
product_type: Mapped[str | None] = mapped_column(String(24), nullable=True, index=True)
|
|
purchase_scene: Mapped[str | None] = mapped_column(String(24), nullable=True)
|
|
price_type: Mapped[str | None] = mapped_column(String(24), nullable=True)
|
|
product_code_snapshot: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
product_name_snapshot: Mapped[str | None] = mapped_column(String(96), nullable=True)
|
|
product_snapshot_json: Mapped[dict | None] = mapped_column(JSON, nullable=True)
|
|
subscription_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
|
source_subscription_id: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
|
upgrade_period_ids_json: Mapped[list | None] = mapped_column(JSON, nullable=True)
|
|
target_price_snapshot: Mapped[Decimal | None] = mapped_column(Numeric(20, 2), nullable=True)
|
|
deduction_amount_snapshot: Mapped[Decimal | None] = mapped_column(Numeric(20, 2), nullable=True)
|
|
payable_amount_snapshot: Mapped[Decimal | None] = mapped_column(Numeric(20, 2), nullable=True)
|
|
fulfillment_status: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True)
|
|
fulfilled_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|