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

@@ -317,6 +317,26 @@ pub async fn update_user_profile(
// ===== 支付系统 DB 函数 =====
/// 创建待支付订单
pub async fn get_user_orders(
pool: &PgPool,
user_id: i32,
) -> Result<Vec<crate::models::PaymentOrder>, AppError> {
let rows = sqlx::query_as::<_, crate::models::PaymentOrder>(
r#"
SELECT id, user_id, order_no, package_type, amount, status, paid_at, expires_at, created_at
FROM payment_orders
WHERE user_id = $1
ORDER BY created_at DESC
"#,
)
.bind(user_id)
.fetch_all(pool)
.await
.map_err(|e| AppError::Database(format!("查询订单失败: {}", e)))?;
Ok(rows)
}
pub async fn create_payment_order(
pool: &PgPool,
user_id: i32,