feat: 添加 GET /api/payment/orders 接口,返回用户订单记录

This commit is contained in:
2026-05-07 17:12:31 +08:00
parent a05b46dfe2
commit 228a9f3b3b
4 changed files with 45 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ pub use payment::generate_code;
pub use payment::get_user_quota;
pub use payment::mock_confirm;
pub use payment::sync_order;
pub use payment::get_user_orders;
pub use payment::payment_index;
pub use payment::payment_login_status;
pub use payment::payment_page;

View File

@@ -973,6 +973,28 @@ pub async fn sync_order(
})))
}
/// GET /api/payment/orders — 获取当前用户的订单记录
#[get("/api/payment/orders")]
pub async fn get_user_orders(
pool: web::Data<PgPool>,
claims: web::ReqData<Claims>,
) -> Result<HttpResponse, AppError> {
let orders = db::get_user_orders(pool.get_ref(), claims.user_id).await?;
Ok(HttpResponse::Ok().json(serde_json::json!({
"success": true,
"data": orders.iter().map(|o| serde_json::json!({
"order_no": o.order_no,
"package_type": o.package_type,
"amount": o.amount,
"status": o.status,
"paid_at": o.paid_at,
"expires_at": o.expires_at,
"created_at": o.created_at,
})).collect::<Vec<_>>()
})))
}
/// GET /api/user/quota
#[get("/api/user/quota")]
pub async fn get_user_quota(