Spaces:
Running
Running
优化打赏统计
Browse files- router_wallet.py +33 -0
router_wallet.py
CHANGED
|
@@ -646,6 +646,39 @@ async def get_task_stats(account: str, db: Session = Depends(get_db)):
|
|
| 646 |
}
|
| 647 |
}
|
| 648 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 649 |
# ==========================================
|
| 650 |
# 🔄 P7后悔模式:退款API
|
| 651 |
# ==========================================
|
|
|
|
| 646 |
}
|
| 647 |
}
|
| 648 |
|
| 649 |
+
@router.get("/api/wallet/{account}/tip-stats")
|
| 650 |
+
async def get_tip_stats(account: str, db: Session = Depends(get_db)):
|
| 651 |
+
"""📊 获取用户打赏统计"""
|
| 652 |
+
from sqlalchemy import func as sql_func
|
| 653 |
+
|
| 654 |
+
stats = db.query(
|
| 655 |
+
Transaction.tx_type,
|
| 656 |
+
sql_func.count(Transaction.tx_id).label('count'),
|
| 657 |
+
sql_func.coalesce(sql_func.sum(Transaction.amount), 0).label('total')
|
| 658 |
+
).filter(
|
| 659 |
+
Transaction.account == account,
|
| 660 |
+
Transaction.tx_type.in_(["TIP_OUT", "TIP_IN"])
|
| 661 |
+
).group_by(Transaction.tx_type).all()
|
| 662 |
+
|
| 663 |
+
stats_map = {s.tx_type: {'count': s.count, 'total': int(s.total)} for s in stats}
|
| 664 |
+
|
| 665 |
+
total_tip_in = stats_map.get('TIP_IN', {}).get('total', 0) or 0
|
| 666 |
+
tip_in_count = stats_map.get('TIP_IN', {}).get('count', 0) or 0
|
| 667 |
+
|
| 668 |
+
total_tip_out = abs(stats_map.get('TIP_OUT', {}).get('total', 0) or 0)
|
| 669 |
+
tip_out_count = stats_map.get('TIP_OUT', {}).get('count', 0) or 0
|
| 670 |
+
|
| 671 |
+
return {
|
| 672 |
+
"status": "success",
|
| 673 |
+
"data": {
|
| 674 |
+
"total_tip_in": total_tip_in,
|
| 675 |
+
"tip_in_count": tip_in_count,
|
| 676 |
+
"total_tip_out": total_tip_out,
|
| 677 |
+
"tip_out_count": tip_out_count,
|
| 678 |
+
"net_tips": total_tip_in - total_tip_out
|
| 679 |
+
}
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
# ==========================================
|
| 683 |
# 🔄 P7后悔模式:退款API
|
| 684 |
# ==========================================
|