"""定价方案模型 管理项目定价方案,支持多种定价策略 """ from typing import Optional, List, TYPE_CHECKING from decimal import Decimal from sqlalchemy import BigInteger, String, Boolean, Text, ForeignKey, DECIMAL from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import BaseModel if TYPE_CHECKING: from app.models.project import Project from app.models.user import User from app.models.profit_simulation import ProfitSimulation class PricingPlan(BaseModel): """定价方案表""" __tablename__ = "pricing_plans" project_id: Mapped[int] = mapped_column( BigInteger, ForeignKey("projects.id"), nullable=False, index=True, comment="项目ID" ) plan_name: Mapped[str] = mapped_column( String(100), nullable=False, comment="方案名称" ) strategy_type: Mapped[str] = mapped_column( String(20), nullable=False, index=True, comment="策略类型:traffic-引流款, profit-利润款, premium-高端款" ) base_cost: Mapped[Decimal] = mapped_column( DECIMAL(12, 2), nullable=False, comment="基础成本" ) target_margin: Mapped[Decimal] = mapped_column( DECIMAL(5, 2), nullable=False, comment="目标毛利率(%)" ) suggested_price: Mapped[Decimal] = mapped_column( DECIMAL(12, 2), nullable=False, comment="建议价格" ) final_price: Mapped[Optional[Decimal]] = mapped_column( DECIMAL(12, 2), nullable=True, comment="最终定价" ) ai_advice: Mapped[Optional[str]] = mapped_column( Text, nullable=True, comment="AI建议内容" ) is_active: Mapped[bool] = mapped_column( Boolean, nullable=False, default=True, comment="是否启用" ) created_by: Mapped[Optional[int]] = mapped_column( BigInteger, ForeignKey("users.id"), nullable=True, comment="创建人ID" ) # 关系 project: Mapped["Project"] = relationship( "Project", back_populates="pricing_plans" ) creator: Mapped[Optional["User"]] = relationship( "User", back_populates="created_pricing_plans" ) profit_simulations: Mapped[List["ProfitSimulation"]] = relationship( "ProfitSimulation", back_populates="pricing_plan", cascade="all, delete-orphan" )