From c291e95a39e6022461b097bab00a5d3f1ec3e4cd Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 29 Jan 2026 12:33:30 -0600 Subject: [PATCH] 's' --- app/main.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index c735ce7..5919580 100755 --- a/app/main.py +++ b/app/main.py @@ -36,9 +36,15 @@ def get_pb_client(): raise e return client -# 配置日志 -logging.basicConfig(filename='xorpay_notify.log', level=logging.INFO, - format='%(asctime)s - %(message)s') +# 配置日志(添加控制台输出,便于调试) +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(message)s', + handlers=[ + logging.FileHandler('xorpay_notify.log'), + logging.StreamHandler() # 新增:同时输出到控制台 + ] +) # 全局已处理订单 processed_orders = set() @@ -116,7 +122,7 @@ async def payh5(item: dict): pay_type = item.get('type', 'unknown').lower() random_suffix = ''.join(random.choices(string.hexdigits.lower(), k=8)) - timestamp = int(time.time()) # 修正:去掉多余字符 + timestamp = int(time.time()) order_id = f"{user_id}_{pay_type}_order_{timestamp}_{random_suffix}" type_map = { @@ -242,7 +248,12 @@ async def xorpay_notify(request: Request): if pay_type == "meetup": solan = pb_client.collection("solan") - existing = solan.get_list(1, 1, {"filter": f'user_id="{user_id}"'}) + # 修复 filter 语法:添加空格和 '=' 操作符(PocketBase 要求) + # 同时添加 sort 以取最新记录(防止同一 user_id 多条) + existing = solan.get_list(1, 1, { + "filter": f'user_id = "{user_id}"', + "sort": "-created" # 按创建时间倒序,取最新一条 + }) if existing.items: record_id = existing.items[0].id solan.update(record_id, {