Add notification system for Claude payment status changes
Detect refund/suspension status changes and generate notifications stored in Redis. Bell icon in navbar shows unread count badge, click to expand dropdown with dismiss per-item or read-all. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
31
mail_api.py
31
mail_api.py
@@ -1166,9 +1166,20 @@ async def _check_claude_payment_for_account(email_addr: str) -> dict:
|
||||
else:
|
||||
status = 'unknown'
|
||||
|
||||
# 查旧状态,状态变化时生成通知
|
||||
old_info = await db_manager.get_claude_payment_status(email_addr)
|
||||
old_status = old_info.get('status') if old_info else None
|
||||
|
||||
# 写入数据库
|
||||
await db_manager.set_claude_payment_status(email_addr, status, payment_time, refund_time, suspended_time)
|
||||
|
||||
# 仅状态变化时创建通知(避免重复检测重复通知)
|
||||
if status != old_status:
|
||||
if status == 'refunded':
|
||||
await cache.add_notification(email_addr, 'refund', f'{email_addr} 已退款')
|
||||
elif status == 'suspended':
|
||||
await cache.add_notification(email_addr, 'suspension', f'{email_addr} 已封号')
|
||||
|
||||
# 如果是支付状态且标题和备注为空,提取收据信息
|
||||
if status == 'paid' and payment_msg:
|
||||
current_info = await db_manager.get_claude_payment_status(email_addr)
|
||||
@@ -1308,6 +1319,26 @@ async def get_claude_payment_status() -> ApiResponse:
|
||||
await cache.set(cache.payment_key(), statuses, TTL_PAYMENT)
|
||||
return ApiResponse(success=True, data=statuses)
|
||||
|
||||
# ============================================================================
|
||||
# 通知系统
|
||||
# ============================================================================
|
||||
|
||||
@app.get("/api/notifications")
|
||||
async def get_notifications():
|
||||
"""获取未读通知列表"""
|
||||
notifications = await cache.get_notifications()
|
||||
return {"success": True, "data": notifications}
|
||||
|
||||
@app.post("/api/notifications/dismiss")
|
||||
async def dismiss_notification(request: Request):
|
||||
"""标记通知已读:传 {id} 移除单条,传 {all:true} 清除全部"""
|
||||
body = await request.json()
|
||||
if body.get('all'):
|
||||
await cache.dismiss_all_notifications()
|
||||
elif body.get('id'):
|
||||
await cache.dismiss_notification(body['id'])
|
||||
return {"success": True}
|
||||
|
||||
# ============================================================================
|
||||
# 命令行入口
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user