195 lines
6.0 KiB
Python
195 lines
6.0 KiB
Python
"""定价方案 Schema
|
||
|
||
智能定价建议相关的请求和响应模型
|
||
"""
|
||
|
||
from typing import Optional, List, Dict, Any
|
||
from datetime import datetime
|
||
from enum import Enum
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class StrategyType(str, Enum):
|
||
"""定价策略类型"""
|
||
TRAFFIC = "traffic" # 引流款
|
||
PROFIT = "profit" # 利润款
|
||
PREMIUM = "premium" # 高端款
|
||
|
||
|
||
class PricingPlanBase(BaseModel):
|
||
"""定价方案基础字段"""
|
||
|
||
project_id: int = Field(..., description="项目ID")
|
||
plan_name: str = Field(..., min_length=1, max_length=100, description="方案名称")
|
||
strategy_type: StrategyType = Field(..., description="策略类型")
|
||
target_margin: float = Field(..., ge=0, le=100, description="目标毛利率(%)")
|
||
|
||
|
||
class PricingPlanCreate(PricingPlanBase):
|
||
"""创建定价方案请求"""
|
||
pass
|
||
|
||
|
||
class PricingPlanUpdate(BaseModel):
|
||
"""更新定价方案请求"""
|
||
|
||
plan_name: Optional[str] = Field(None, min_length=1, max_length=100, description="方案名称")
|
||
strategy_type: Optional[StrategyType] = Field(None, description="策略类型")
|
||
target_margin: Optional[float] = Field(None, ge=0, le=100, description="目标毛利率(%)")
|
||
final_price: Optional[float] = Field(None, ge=0, description="最终定价")
|
||
is_active: Optional[bool] = Field(None, description="是否启用")
|
||
|
||
|
||
class PricingPlanResponse(BaseModel):
|
||
"""定价方案响应"""
|
||
|
||
id: int
|
||
project_id: int
|
||
project_name: Optional[str] = Field(None, description="项目名称")
|
||
plan_name: str
|
||
strategy_type: str
|
||
base_cost: float
|
||
target_margin: float
|
||
suggested_price: float
|
||
final_price: Optional[float] = None
|
||
ai_advice: Optional[str] = None
|
||
is_active: bool
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
created_by_name: Optional[str] = Field(None, description="创建人姓名")
|
||
|
||
class Config:
|
||
from_attributes = True
|
||
|
||
|
||
class PricingPlanListResponse(BaseModel):
|
||
"""定价方案列表响应"""
|
||
|
||
id: int
|
||
project_id: int
|
||
project_name: Optional[str] = None
|
||
plan_name: str
|
||
strategy_type: str
|
||
base_cost: float
|
||
target_margin: float
|
||
suggested_price: float
|
||
final_price: Optional[float] = None
|
||
is_active: bool
|
||
created_at: datetime
|
||
created_by_name: Optional[str] = None
|
||
|
||
class Config:
|
||
from_attributes = True
|
||
|
||
|
||
class PricingPlanQuery(BaseModel):
|
||
"""定价方案查询参数"""
|
||
|
||
page: int = Field(1, ge=1, description="页码")
|
||
page_size: int = Field(20, ge=1, le=100, description="每页数量")
|
||
project_id: Optional[int] = Field(None, description="项目筛选")
|
||
strategy_type: Optional[StrategyType] = Field(None, description="策略类型筛选")
|
||
is_active: Optional[bool] = Field(None, description="是否启用")
|
||
sort_by: str = Field("created_at", description="排序字段")
|
||
sort_order: str = Field("desc", description="排序方向")
|
||
|
||
|
||
# AI 定价建议相关
|
||
|
||
class GeneratePricingRequest(BaseModel):
|
||
"""生成定价建议请求"""
|
||
|
||
target_margin: float = Field(50, ge=0, le=100, description="目标毛利率(%),默认50")
|
||
strategies: Optional[List[StrategyType]] = Field(None, description="策略类型列表,默认全部")
|
||
stream: bool = Field(False, description="是否流式返回")
|
||
|
||
|
||
class StrategySuggestion(BaseModel):
|
||
"""单个策略的定价建议"""
|
||
|
||
strategy: str = Field(..., description="策略名称")
|
||
suggested_price: float = Field(..., description="建议价格")
|
||
margin: float = Field(..., description="毛利率(%)")
|
||
description: str = Field(..., description="策略说明")
|
||
|
||
|
||
class AIAdvice(BaseModel):
|
||
"""AI 建议内容"""
|
||
|
||
summary: str = Field(..., description="综合建议摘要")
|
||
cost_analysis: str = Field(..., description="成本分析")
|
||
market_analysis: str = Field(..., description="市场分析")
|
||
risk_notes: str = Field(..., description="风险提示")
|
||
recommendations: List[str] = Field(..., description="具体建议列表")
|
||
|
||
|
||
class AIUsage(BaseModel):
|
||
"""AI 调用使用情况"""
|
||
|
||
provider: str = Field(..., description="服务商")
|
||
model: str = Field(..., description="模型")
|
||
tokens: int = Field(..., description="Token 消耗")
|
||
latency_ms: int = Field(..., description="延迟(毫秒)")
|
||
|
||
|
||
class MarketReference(BaseModel):
|
||
"""市场参考数据"""
|
||
|
||
min: float
|
||
max: float
|
||
avg: float
|
||
|
||
|
||
class PricingSuggestions(BaseModel):
|
||
"""定价建议集合"""
|
||
|
||
traffic: Optional[StrategySuggestion] = None
|
||
profit: Optional[StrategySuggestion] = None
|
||
premium: Optional[StrategySuggestion] = None
|
||
|
||
|
||
class GeneratePricingResponse(BaseModel):
|
||
"""生成定价建议响应"""
|
||
|
||
project_id: int
|
||
project_name: str
|
||
cost_base: float = Field(..., description="基础成本")
|
||
market_reference: Optional[MarketReference] = Field(None, description="市场参考")
|
||
pricing_suggestions: PricingSuggestions = Field(..., description="各策略定价建议")
|
||
ai_advice: Optional[AIAdvice] = Field(None, description="AI 建议详情")
|
||
ai_usage: Optional[AIUsage] = Field(None, description="AI 使用统计")
|
||
|
||
|
||
class SimulateStrategyRequest(BaseModel):
|
||
"""模拟定价策略请求"""
|
||
|
||
strategies: List[StrategyType] = Field(..., description="要模拟的策略类型")
|
||
target_margin: float = Field(50, ge=0, le=100, description="目标毛利率(%)")
|
||
|
||
|
||
class StrategySimulationResult(BaseModel):
|
||
"""策略模拟结果"""
|
||
|
||
strategy_type: str
|
||
strategy_name: str
|
||
suggested_price: float
|
||
margin: float
|
||
profit_per_unit: float
|
||
market_position: str = Field(..., description="市场位置描述")
|
||
|
||
|
||
class SimulateStrategyResponse(BaseModel):
|
||
"""模拟定价策略响应"""
|
||
|
||
project_id: int
|
||
project_name: str
|
||
base_cost: float
|
||
results: List[StrategySimulationResult]
|
||
|
||
|
||
class ExportReportRequest(BaseModel):
|
||
"""导出报告请求"""
|
||
|
||
format: str = Field("pdf", description="导出格式:pdf/excel")
|