From 64baba32b4f1389a6e315afb6e38e56841966a60 Mon Sep 17 00:00:00 2001 From: houhuan Date: Tue, 9 Dec 2025 14:14:53 +0800 Subject: [PATCH] hohoho --- backend/app.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/backend/app.py b/backend/app.py index 977b880..1a8eea7 100644 --- a/backend/app.py +++ b/backend/app.py @@ -566,7 +566,7 @@ def sse_events(): return Response(stream_with_context(event_stream()), mimetype='text/event-stream') def push_feishu(date_str: str, amount: float, reason: str): cfg = load_config() - url = cfg.get("feishu_webhook_url") or cfg.get("webhook_url") + url = cfg.get("feishu_webhook_url") if not url: return shop = cfg.get("shop_name", "益选便利店") @@ -623,11 +623,35 @@ def push_feishu(date_str: str, amount: float, reason: str): body = json.dumps(payload_obj, ensure_ascii=False).encode('utf-8') return requests.post(u, data=body, headers={'Content-Type': 'application/json; charset=utf-8'}, timeout=5) try: - resp = _post_json(url, payload) - ok = (200 <= resp.status_code < 300) - _log(f"飞书推送卡片{'成功' if ok else '失败'}: status={resp.status_code} {resp.text[:200]}") + is_feishu = ('open.feishu.cn' in url) + ok = False + if is_feishu: + resp = _post_json(url, payload) + ok = (200 <= resp.status_code < 300) + _log(f"飞书推送卡片{'成功' if ok else '失败'}: status={resp.status_code} {resp.text[:200]}") + if not ok: + post_payload = { + "msg_type": "post", + "content": { + "post": { + "zh_cn": { + "title": f"{shop} 营业额通知", + "content": [[ + {"tag":"text","text": f"日期:{date_str}\n"}, + {"tag":"text","text": f"今日:¥{amount:.2f}"}, + *( [{"tag":"text","text": f" {arrow} {diff_str} {pct_str}"}] if isinstance(y_amt,(int,float)) else [] ), + ],[ + {"tag":"text","text": f"原因:{reason}"} + ]] + } + } + } + } + resp_post = _post_json(url, post_payload) + ok = (200 <= resp_post.status_code < 300) + _log(f"飞书推送POST{'成功' if ok else '失败'}: status={resp_post.status_code} {resp_post.text[:200]}") if not ok: - text = f"📊 {shop}\n日期:{date_str}\n今日:¥{amount:.2f}" + text = f"{shop}\n日期:{date_str}\n今日:¥{amount:.2f}" if isinstance(y_amt, (int, float)): text += f" {arrow} {diff_str} {pct_str}".strip() text += f"\n原因:{reason}"