feat: 添加 GET /api/payment/orders 接口,返回用户订单记录
This commit is contained in:
20
src/db.rs
20
src/db.rs
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user