mirror of
https://git.oceanpay.cc/danial/kami_apple_exchage.git
synced 2025-12-18 22:29:09 +00:00
- 新增 CODEBUDDY.md、GEMINI.md、GEMINI_CN.md 等项目文档 - 更新 Dockerfile 和其他配置文件 - 优化部分代码结构,如 orders.py、tasks.py 等 - 新增 .dockerignore 文件
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""
|
|
链接相关模型
|
|
"""
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
from sqlalchemy import String, Float, Index
|
|
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
|
from .base import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from .orders import Orders
|
|
|
|
|
|
class Links(BaseModel):
|
|
"""链接数据表"""
|
|
|
|
__tablename__ = "links"
|
|
__table_args__ = (
|
|
Index("ix_links_url", "url"),
|
|
Index("ix_links_amount", "amount"),
|
|
Index("ix_links_url_amount", "url", "amount"), # 组合索引
|
|
)
|
|
|
|
url: Mapped[str] = mapped_column(String(255), nullable=False, comment="链接地址")
|
|
amount: Mapped[float] = mapped_column(Float, nullable=False, comment="金额")
|
|
|
|
# 关系映射
|
|
orders: Mapped[list["Orders"]] = relationship("Orders", back_populates="links")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Links(id={self.id}, url={self.url}, amount={self.amount})>"
|
|
|
|
@property
|
|
def is_valid_amount(self) -> bool:
|
|
"""金额是否有效"""
|
|
return self.amount > 0
|
|
|
|
@property
|
|
def formatted_amount(self) -> str:
|
|
"""格式化金额显示"""
|
|
return f"${self.amount:.2f}"
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
"""转换为字典,包含格式化信息"""
|
|
data = super().to_dict()
|
|
data["is_valid_amount"] = self.is_valid_amount
|
|
data["formatted_amount"] = self.formatted_amount
|
|
return data
|