's'
This commit is contained in:
17
app/main.py
17
app/main.py
@@ -9,6 +9,7 @@ import requests
|
|||||||
from fastapi import Request, HTTPException
|
from fastapi import Request, HTTPException
|
||||||
import logging
|
import logging
|
||||||
from pocketbase import PocketBase
|
from pocketbase import PocketBase
|
||||||
|
from pocketbase.client import ListResult # 新增导入(可选,但明确类型)
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ def create_memos_user(user_id: str, password: str = "123456"):
|
|||||||
|
|
||||||
response = requests.post(MEMOS_API, json=memos_data, headers=memos_headers, timeout=10)
|
response = requests.post(MEMOS_API, json=memos_data, headers=memos_headers, timeout=10)
|
||||||
|
|
||||||
if response.status_code in (200, 201): # ← 修复:status_code
|
if response.status_code in (200, 201):
|
||||||
result = response.json()
|
result = response.json()
|
||||||
print(f"memos 用户创建成功: {username}")
|
print(f"memos 用户创建成功: {username}")
|
||||||
logging.info(f"memos 用户创建成功: {username}")
|
logging.info(f"memos 用户创建成功: {username}")
|
||||||
@@ -113,7 +114,6 @@ def create_memos_user(user_id: str, password: str = "123456"):
|
|||||||
return {"success": False, "error": str(e)}
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/payh5")
|
@app.post("/payh5")
|
||||||
async def payh5(item: dict):
|
async def payh5(item: dict):
|
||||||
print('payh5 item:', item)
|
print('payh5 item:', item)
|
||||||
@@ -132,7 +132,7 @@ async def payh5(item: dict):
|
|||||||
"video": "视频解锁",
|
"video": "视频解锁",
|
||||||
"vip": "VIP会员充值",
|
"vip": "VIP会员充值",
|
||||||
}
|
}
|
||||||
name = type_map.get(pay_type, "商品支付") # ← 修复:用 pay_type 匹配(小写一致)
|
name = type_map.get(pay_type, "商品支付")
|
||||||
|
|
||||||
notify_url = "https://api.hackrobot.cn/xorpay_notify"
|
notify_url = "https://api.hackrobot.cn/xorpay_notify"
|
||||||
|
|
||||||
@@ -160,7 +160,6 @@ async def payh5(item: dict):
|
|||||||
"xorpay_url": f"https://xorpay.com/api/cashier/{AID}"
|
"xorpay_url": f"https://xorpay.com/api/cashier/{AID}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 新增:接收前端提交的 meetup 申请表单(存申请字段,支付字段留空)
|
|
||||||
@app.post("/submit_meetup_application")
|
@app.post("/submit_meetup_application")
|
||||||
async def submit_meetup_application(item: dict):
|
async def submit_meetup_application(item: dict):
|
||||||
print('submit_meetup_application item:', item)
|
print('submit_meetup_application item:', item)
|
||||||
@@ -184,7 +183,6 @@ async def submit_meetup_application(item: dict):
|
|||||||
"gradYear": item.get("gradYear", ""),
|
"gradYear": item.get("gradYear", ""),
|
||||||
"phone": item.get("phone", ""),
|
"phone": item.get("phone", ""),
|
||||||
"calculated_age": item.get("calculated_age", 0),
|
"calculated_age": item.get("calculated_age", 0),
|
||||||
# 支付字段留空,等待回调填充
|
|
||||||
"type": "",
|
"type": "",
|
||||||
"order_id": "",
|
"order_id": "",
|
||||||
"amount": 0,
|
"amount": 0,
|
||||||
@@ -199,8 +197,6 @@ async def submit_meetup_application(item: dict):
|
|||||||
logging.error(f"meetup 申请提交失败 - user_id: {user_id}, error: {e}")
|
logging.error(f"meetup 申请提交失败 - user_id: {user_id}, error: {e}")
|
||||||
raise HTTPException(status_code=500, detail="submit failed")
|
raise HTTPException(status_code=500, detail="submit failed")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/xorpay_notify")
|
@app.post("/xorpay_notify")
|
||||||
async def xorpay_notify(request: Request):
|
async def xorpay_notify(request: Request):
|
||||||
form_data = await request.form()
|
form_data = await request.form()
|
||||||
@@ -253,11 +249,10 @@ async def xorpay_notify(request: Request):
|
|||||||
|
|
||||||
if pay_type == "meetup":
|
if pay_type == "meetup":
|
||||||
solan = pb_client.collection("solan")
|
solan = pb_client.collection("solan")
|
||||||
# 查找该 user_id 的待支付记录
|
# 修复bug:pocketbase-py SDK 用 get_list 而非 list
|
||||||
existing = solan.list(filter=f'user_id="{user_id}"', per_page=1)
|
existing: ListResult = solan.get_list(1, 1, {"filter": f'user_id="{user_id}"'})
|
||||||
if existing.items:
|
if existing.items:
|
||||||
record_id = existing.items[0].id
|
record_id = existing.items[0].id
|
||||||
# PATCH 填充支付字段
|
|
||||||
solan.update(record_id, {
|
solan.update(record_id, {
|
||||||
"type": "meetup",
|
"type": "meetup",
|
||||||
"order_id": order_id,
|
"order_id": order_id,
|
||||||
@@ -265,7 +260,6 @@ async def xorpay_notify(request: Request):
|
|||||||
})
|
})
|
||||||
logging.info(f"meetup 支付字段补齐成功 - user_id: {user_id}, record_id: {record_id}")
|
logging.info(f"meetup 支付字段补齐成功 - user_id: {user_id}, record_id: {record_id}")
|
||||||
else:
|
else:
|
||||||
# 兜底:如果没找到申请记录,直接创建完整记录
|
|
||||||
solan.create({
|
solan.create({
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"type": "meetup",
|
"type": "meetup",
|
||||||
@@ -274,7 +268,6 @@ async def xorpay_notify(request: Request):
|
|||||||
})
|
})
|
||||||
logging.info(f"meetup 完整记录创建(兜底) - user_id: {user_id}")
|
logging.info(f"meetup 完整记录创建(兜底) - user_id: {user_id}")
|
||||||
else:
|
else:
|
||||||
# 其他类型仍写入 payments
|
|
||||||
pb_client.collection("payments").create({
|
pb_client.collection("payments").create({
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"type": pay_type,
|
"type": pay_type,
|
||||||
|
|||||||
Reference in New Issue
Block a user