-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetails.py
More file actions
43 lines (34 loc) · 1.16 KB
/
details.py
File metadata and controls
43 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from fastapi import APIRouter
from loguru import logger
from .cache import get_plan_cache
router = APIRouter()
@router.get("/plan/{plan_id}")
async def query_details(plan_id: str):
logger.debug(f"plan_id: {plan_id}")
if not plan_id:
logger.error(f"plan_id is required")
return {"ec": 400, "msg": "plan_id is required"}
p = next((p for p in get_plan_cache() if p.plan_id == plan_id), None)
if not p:
logger.error(f"plan_id not found")
return {"ec": 404, "msg": "plan_id not found"}
afdian_info = [s.strip() for s in p.afdian_id.split(",")]
if len(afdian_info) != 2:
logger.error(f"afdian_info is invalid")
return {"ec": 500, "msg": "afdian_info is invalid"}
return {
"ec": 200,
"data": {
"title": p.title,
"type_id": p.type_id,
"price": p.price,
"original_price": p.original_price,
"popular": p.popular,
# "afdian_id": p.afdian_id,
"afdian_info": {
"plan_id": afdian_info[0],
"sku_id": afdian_info[1],
},
"yimapay_id": p.yimapay_id,
},
}