84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
class ProductService:
|
|
def list_categories(self) -> dict:
|
|
return {
|
|
"total": 2,
|
|
"page_no": 1,
|
|
"page_size": 20,
|
|
"list": [
|
|
{"category_id": 1, "category_name": "工业品", "category_code": "industry", "status": 1},
|
|
{"category_id": 2, "category_name": "日用品", "category_code": "daily", "status": 1},
|
|
],
|
|
}
|
|
|
|
def create_category(self) -> dict:
|
|
return {
|
|
"category_id": 3,
|
|
"category_name": "新增分类",
|
|
"category_code": "new-category",
|
|
"status": 1,
|
|
}
|
|
|
|
def update_category(self, category_id: int) -> dict:
|
|
return {"category_id": category_id, "updated": True}
|
|
|
|
def list_products(self, filters: dict | None = None) -> dict:
|
|
product_list = [
|
|
{
|
|
"product_id": 2001,
|
|
"product_name": "演示产品A",
|
|
"specification": "10kg",
|
|
"unit": "吨",
|
|
"category_id": 1,
|
|
"category_name": "工业品",
|
|
"cost_price": 60,
|
|
"sale_price": 100,
|
|
"status": 1,
|
|
},
|
|
{
|
|
"product_id": 2002,
|
|
"product_name": "演示产品B",
|
|
"specification": "20kg",
|
|
"unit": "吨",
|
|
"category_id": 1,
|
|
"category_name": "工业品",
|
|
"cost_price": 120,
|
|
"sale_price": 180,
|
|
"status": 1,
|
|
},
|
|
]
|
|
|
|
if filters and filters.get("product_name"):
|
|
product_list = [item for item in product_list if filters["product_name"] in item["product_name"]]
|
|
|
|
return {
|
|
"total": len(product_list),
|
|
"page_no": 1,
|
|
"page_size": 20,
|
|
"list": product_list,
|
|
}
|
|
|
|
def create_product(self) -> dict:
|
|
return {
|
|
"product_id": 2003,
|
|
"product_name": "新建产品",
|
|
"specification": "30kg",
|
|
"unit": "吨",
|
|
"status": 1,
|
|
}
|
|
|
|
def get_product(self, product_id: int) -> dict:
|
|
return {
|
|
"product_id": product_id,
|
|
"product_name": "演示产品A",
|
|
"specification": "10kg",
|
|
"unit": "吨",
|
|
"category_id": 1,
|
|
"category_name": "工业品",
|
|
"cost_price": 60,
|
|
"sale_price": 100,
|
|
"status": 1,
|
|
}
|
|
|
|
|
|
product_service = ProductService()
|