Files
smart-project-pricing/后端服务/app/models/pricing_plan.py
2026-01-31 21:33:06 +08:00

95 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""定价方案模型
管理项目定价方案,支持多种定价策略
"""
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"
)