Spaces:
Running
Running
提升云端记录数据完整性
Browse files- router_wallet.py +36 -0
router_wallet.py
CHANGED
|
@@ -896,6 +896,42 @@ async def get_sales_stats(account: str, db: Session = Depends(get_db)):
|
|
| 896 |
}
|
| 897 |
}
|
| 898 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 899 |
# ==========================================
|
| 900 |
# 🔄 P7后悔模式:退款API
|
| 901 |
# ==========================================
|
|
|
|
| 896 |
}
|
| 897 |
}
|
| 898 |
|
| 899 |
+
@router.get("/api/wallet/{account}/purchases")
|
| 900 |
+
async def get_purchases(
|
| 901 |
+
account: str,
|
| 902 |
+
current_user: str = Depends(require_auth),
|
| 903 |
+
db: Session = Depends(get_db)
|
| 904 |
+
):
|
| 905 |
+
"""
|
| 906 |
+
📋 获取用户购买记录列表
|
| 907 |
+
- 需要 JWT 鉴权,只能查询自己的购买记录
|
| 908 |
+
- 返回未退款的全部购买记录,按购买时间降序排列
|
| 909 |
+
"""
|
| 910 |
+
# 🔒 权限校验:只能查询自己的购买记录
|
| 911 |
+
if current_user != account:
|
| 912 |
+
raise HTTPException(status_code=403, detail="只能查询自己的购买记录")
|
| 913 |
+
|
| 914 |
+
# 查询未退款的购买记录,按 purchased_at 降序排列
|
| 915 |
+
ownerships = db.query(Ownership).filter(
|
| 916 |
+
Ownership.account == account,
|
| 917 |
+
Ownership.is_refunded == False
|
| 918 |
+
).order_by(Ownership.purchased_at.desc()).all()
|
| 919 |
+
|
| 920 |
+
data = []
|
| 921 |
+
for o in ownerships:
|
| 922 |
+
data.append({
|
| 923 |
+
"item_id": o.item_id,
|
| 924 |
+
"purchased_at": o.purchased_at.isoformat() if o.purchased_at else None,
|
| 925 |
+
"price_paid": o.price_paid or 0,
|
| 926 |
+
"is_refunded": o.is_refunded
|
| 927 |
+
})
|
| 928 |
+
|
| 929 |
+
return {
|
| 930 |
+
"status": "success",
|
| 931 |
+
"data": data,
|
| 932 |
+
"total": len(data)
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
# ==========================================
|
| 936 |
# 🔄 P7后悔模式:退款API
|
| 937 |
# ==========================================
|