Spaces:
Running
Running
Upload 2 files
Browse files- router_tasks.py +7 -7
- router_wallet.py +39 -0
router_tasks.py
CHANGED
|
@@ -476,13 +476,13 @@ async def update_task(task_id: str, update_data: TaskUpdate, current_user: str =
|
|
| 476 |
|
| 477 |
# 📢 如果有接单人,发送通知
|
| 478 |
if task.get("assignee") and changes:
|
| 479 |
-
add_notification(
|
| 480 |
-
|
| 481 |
-
"
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
)
|
| 486 |
|
| 487 |
return {"status": "success"}
|
| 488 |
|
|
|
|
| 476 |
|
| 477 |
# 📢 如果有接单人,发送通知
|
| 478 |
if task.get("assignee") and changes:
|
| 479 |
+
add_notification(task.get("assignee"), {
|
| 480 |
+
"type": "task_updated",
|
| 481 |
+
"from_user": current_user,
|
| 482 |
+
"target_item_id": task_id,
|
| 483 |
+
"target_item_title": task.get("title", ""),
|
| 484 |
+
"content": f"任务《{task.get('title', '')}》已更新:{'、'.join(changes)}"
|
| 485 |
+
})
|
| 486 |
|
| 487 |
return {"status": "success"}
|
| 488 |
|
router_wallet.py
CHANGED
|
@@ -23,6 +23,7 @@ from database_sql import get_db
|
|
| 23 |
from models_sql import Wallet, Transaction, Ownership, Refund
|
| 24 |
from models import RechargeRequest, WithdrawRequest, PurchaseRequest, TipRequest
|
| 25 |
import 数据库连接 as json_db
|
|
|
|
| 26 |
|
| 27 |
# 🔒 P0安全优化:API限流
|
| 28 |
from slowapi import Limiter
|
|
@@ -338,6 +339,16 @@ async def purchase_item(request: Request, req: PurchaseRequest, db: Session = De
|
|
| 338 |
# 📝 P2优化:购买审计日志
|
| 339 |
logger.info(f"PURCHASE | buyer={req.account} | seller={seller_account} | item={req.item_id} | amount={price} | tx={tx_id}")
|
| 340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
# ☁️ 购买成功后返回网盘密码
|
| 342 |
return {
|
| 343 |
"status": "success",
|
|
@@ -401,6 +412,24 @@ async def tip_user(request: Request, req: TipRequest, db: Session = Depends(get_
|
|
| 401 |
# 📝 P2优化:打赏审计日志
|
| 402 |
logger.info(f"TIP | from={req.sender_account} | to={req.target_account} | amount={req.amount} | item={req.item_id or 'N/A'} | anon={req.is_anonymous}")
|
| 403 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
# 🚀 核心新增:记录打赏榜单和月度收益趋势 (写入 JSON 以供高频读取)
|
| 405 |
users_db = json_db.load_data("users.json", default_data={})
|
| 406 |
items_db = json_db.load_data("items.json", default_data=[])
|
|
@@ -808,6 +837,16 @@ async def refund_purchase(request: Request, account: str, item_id: str, db: Sess
|
|
| 808 |
|
| 809 |
logger.info(f"REFUND | buyer={account} | seller={seller_account} | item={item_id} | amount={refund_amount} | ban_until={ban_until.isoformat()}")
|
| 810 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
return {
|
| 812 |
"status": "success",
|
| 813 |
"message": f"退款成功,{refund_amount}积分已退还",
|
|
|
|
| 23 |
from models_sql import Wallet, Transaction, Ownership, Refund
|
| 24 |
from models import RechargeRequest, WithdrawRequest, PurchaseRequest, TipRequest
|
| 25 |
import 数据库连接 as json_db
|
| 26 |
+
from notifications import add_notification
|
| 27 |
|
| 28 |
# 🔒 P0安全优化:API限流
|
| 29 |
from slowapi import Limiter
|
|
|
|
| 339 |
# 📝 P2优化:购买审计日志
|
| 340 |
logger.info(f"PURCHASE | buyer={req.account} | seller={seller_account} | item={req.item_id} | amount={price} | tx={tx_id}")
|
| 341 |
|
| 342 |
+
# 🔔 通知卖家作品被购买
|
| 343 |
+
if seller_account and seller_account != req.account:
|
| 344 |
+
add_notification(seller_account, {
|
| 345 |
+
"type": "purchase",
|
| 346 |
+
"from_user": req.account,
|
| 347 |
+
"target_item_id": req.item_id,
|
| 348 |
+
"target_item_title": item.get("title", ""),
|
| 349 |
+
"content": f"您的作品《{item.get('title', '')}》已被购买"
|
| 350 |
+
})
|
| 351 |
+
|
| 352 |
# ☁️ 购买成功后返回网盘密码
|
| 353 |
return {
|
| 354 |
"status": "success",
|
|
|
|
| 412 |
# 📝 P2优化:打赏审计日志
|
| 413 |
logger.info(f"TIP | from={req.sender_account} | to={req.target_account} | amount={req.amount} | item={req.item_id or 'N/A'} | anon={req.is_anonymous}")
|
| 414 |
|
| 415 |
+
# 🔔 打赏通知(考虑匿名)
|
| 416 |
+
if not req.is_anonymous:
|
| 417 |
+
add_notification(req.target_account, {
|
| 418 |
+
"type": "tip",
|
| 419 |
+
"from_user": req.sender_account,
|
| 420 |
+
"target_item_id": req.item_id or "",
|
| 421 |
+
"target_item_title": "",
|
| 422 |
+
"content": f"您收到来自 {req.sender_account} 的 {req.amount} 积分打赏"
|
| 423 |
+
})
|
| 424 |
+
else:
|
| 425 |
+
add_notification(req.target_account, {
|
| 426 |
+
"type": "tip",
|
| 427 |
+
"from_user": "anonymous",
|
| 428 |
+
"target_item_id": req.item_id or "",
|
| 429 |
+
"target_item_title": "",
|
| 430 |
+
"content": f"您收到了一份 {req.amount} 积分的匿名打赏"
|
| 431 |
+
})
|
| 432 |
+
|
| 433 |
# 🚀 核心新增:记录打赏榜单和月度收益趋势 (写入 JSON 以供高频读取)
|
| 434 |
users_db = json_db.load_data("users.json", default_data={})
|
| 435 |
items_db = json_db.load_data("items.json", default_data=[])
|
|
|
|
| 837 |
|
| 838 |
logger.info(f"REFUND | buyer={account} | seller={seller_account} | item={item_id} | amount={refund_amount} | ban_until={ban_until.isoformat()}")
|
| 839 |
|
| 840 |
+
# 🔔 通知卖家退款
|
| 841 |
+
if seller_account:
|
| 842 |
+
add_notification(seller_account, {
|
| 843 |
+
"type": "refund",
|
| 844 |
+
"from_user": account,
|
| 845 |
+
"target_item_id": item_id,
|
| 846 |
+
"target_item_title": item.get("title", ""),
|
| 847 |
+
"content": f"您的作品《{item.get('title', '')}》已被退款"
|
| 848 |
+
})
|
| 849 |
+
|
| 850 |
return {
|
| 851 |
"status": "success",
|
| 852 |
"message": f"退款成功,{refund_amount}积分已退还",
|