98 lines
2.6 KiB
Python
98 lines
2.6 KiB
Python
"""利润模拟模型
|
||
|
||
管理利润模拟测算记录
|
||
"""
|
||
|
||
from typing import Optional, List, TYPE_CHECKING
|
||
from decimal import Decimal
|
||
|
||
from sqlalchemy import BigInteger, String, Integer, ForeignKey, DECIMAL
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.models.base import BaseModel
|
||
|
||
if TYPE_CHECKING:
|
||
from app.models.pricing_plan import PricingPlan
|
||
from app.models.user import User
|
||
from app.models.sensitivity_analysis import SensitivityAnalysis
|
||
|
||
|
||
class ProfitSimulation(BaseModel):
|
||
"""利润模拟表"""
|
||
|
||
__tablename__ = "profit_simulations"
|
||
|
||
pricing_plan_id: Mapped[int] = mapped_column(
|
||
BigInteger,
|
||
ForeignKey("pricing_plans.id"),
|
||
nullable=False,
|
||
index=True,
|
||
comment="定价方案ID"
|
||
)
|
||
simulation_name: Mapped[str] = mapped_column(
|
||
String(100),
|
||
nullable=False,
|
||
comment="模拟名称"
|
||
)
|
||
price: Mapped[Decimal] = mapped_column(
|
||
DECIMAL(12, 2),
|
||
nullable=False,
|
||
comment="模拟价格"
|
||
)
|
||
estimated_volume: Mapped[int] = mapped_column(
|
||
Integer,
|
||
nullable=False,
|
||
comment="预估客量"
|
||
)
|
||
period_type: Mapped[str] = mapped_column(
|
||
String(20),
|
||
nullable=False,
|
||
comment="周期类型:daily-日, weekly-周, monthly-月"
|
||
)
|
||
estimated_revenue: Mapped[Decimal] = mapped_column(
|
||
DECIMAL(14, 2),
|
||
nullable=False,
|
||
comment="预估收入"
|
||
)
|
||
estimated_cost: Mapped[Decimal] = mapped_column(
|
||
DECIMAL(14, 2),
|
||
nullable=False,
|
||
comment="预估成本"
|
||
)
|
||
estimated_profit: Mapped[Decimal] = mapped_column(
|
||
DECIMAL(14, 2),
|
||
nullable=False,
|
||
comment="预估利润"
|
||
)
|
||
profit_margin: Mapped[Decimal] = mapped_column(
|
||
DECIMAL(5, 2),
|
||
nullable=False,
|
||
comment="利润率(%)"
|
||
)
|
||
breakeven_volume: Mapped[int] = mapped_column(
|
||
Integer,
|
||
nullable=False,
|
||
comment="盈亏平衡客量"
|
||
)
|
||
created_by: Mapped[Optional[int]] = mapped_column(
|
||
BigInteger,
|
||
ForeignKey("users.id"),
|
||
nullable=True,
|
||
comment="创建人ID"
|
||
)
|
||
|
||
# 关系
|
||
pricing_plan: Mapped["PricingPlan"] = relationship(
|
||
"PricingPlan",
|
||
back_populates="profit_simulations"
|
||
)
|
||
creator: Mapped[Optional["User"]] = relationship(
|
||
"User",
|
||
back_populates="created_profit_simulations"
|
||
)
|
||
sensitivity_analyses: Mapped[List["SensitivityAnalysis"]] = relationship(
|
||
"SensitivityAnalysis",
|
||
back_populates="simulation",
|
||
cascade="all, delete-orphan"
|
||
)
|