dingdanquanliucheng/backend/app/schemas/products.py

157 lines
3.4 KiB
Python
Raw Normal View History

"""
产品模块请求模型
定义产品及产品分类管理相关的请求体数据模型 products 路由使用
包含产品分类的创建/更新产品的创建/更新以及产品规格的更新操作
"""
2026-05-21 14:59:38 +08:00
from pydantic import BaseModel, Field
class CreateCategoryRequest(BaseModel):
"""创建产品分类请求体。被 POST /api/products/categories 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号,数值越小越靠前"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
class UpdateCategoryRequest(BaseModel):
"""更新产品分类请求体。被 PUT /api/products/categories/{id} 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
2026-05-21 14:59:38 +08:00
class ProductSpecificationPayload(BaseModel):
"""产品规格载荷,用于创建产品时携带规格信息。"""
2026-05-21 14:59:38 +08:00
specification: str
"""规格名称(如尺寸、型号等)"""
2026-05-21 14:59:38 +08:00
unit: str
"""计量单位(如个、箱、米等)"""
2026-05-21 14:59:38 +08:00
category_id: int | None = None
"""关联分类 ID"""
2026-05-21 14:59:38 +08:00
cost_price: float = 0
"""成本价"""
2026-05-21 14:59:38 +08:00
sale_price: float = 0
"""销售价"""
2026-05-21 14:59:38 +08:00
status: int = 1
"""状态1-启用0-禁用"""
2026-05-21 14:59:38 +08:00
remark: str | None = None
"""备注信息"""
2026-05-21 14:59:38 +08:00
is_default: bool = False
"""是否为默认规格"""
2026-05-21 14:59:38 +08:00
class CreateProductRequest(BaseModel):
"""创建产品请求体。被 POST /api/products 路由使用。"""
product_name: str
"""产品名称"""
2026-05-21 14:59:38 +08:00
category_id: int | None = None
"""所属分类 ID"""
2026-05-21 14:59:38 +08:00
status: int = 1
"""状态1-启用0-禁用"""
2026-05-21 14:59:38 +08:00
remark: str | None = None
"""备注信息"""
2026-05-21 14:59:38 +08:00
specifications: list[ProductSpecificationPayload] = Field(default_factory=list)
"""产品规格列表,支持创建时同时创建多个规格"""
2026-05-21 14:59:38 +08:00
class UpdateProductRequest(BaseModel):
"""更新产品基本信息请求体。被 PUT /api/products/{id} 路由使用。"""
2026-05-21 14:59:38 +08:00
product_name: str
"""产品名称"""
2026-05-21 14:59:38 +08:00
category_id: int | None = None
"""所属分类 ID"""
2026-05-21 14:59:38 +08:00
status: int = 1
"""状态1-启用0-禁用"""
2026-05-21 14:59:38 +08:00
remark: str | None = None
"""备注信息"""
2026-05-21 14:59:38 +08:00
class UpdateProductSpecificationRequest(BaseModel):
"""更新产品规格请求体。被 PUT /api/products/specifications/{id} 路由使用。"""
specification: str
"""规格名称"""
unit: str
"""计量单位"""
category_id: int | None = None
"""关联分类 ID"""
cost_price: float = 0
"""成本价"""
sale_price: float = 0
"""销售价"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""
2026-05-21 14:59:38 +08:00
is_default: bool = False
"""是否为默认规格"""
class UpdateProductCategoryRequest(BaseModel):
"""更新产品分类请求体。被 PUT /api/products/categories/{id} 路由使用。"""
category_name: str
"""分类名称"""
category_code: str
"""分类编码"""
sort_no: int = 0
"""排序号"""
status: int = 1
"""状态1-启用0-禁用"""
remark: str | None = None
"""备注信息"""