fix: sync-order仅查询状态不确认订单(防止误激活)
This commit is contained in:
@@ -980,7 +980,7 @@ pub async fn mock_confirm(
|
|||||||
|
|
||||||
/// POST /api/payment/sync-order — 根据订单号强制同步会员状态
|
/// POST /api/payment/sync-order — 根据订单号强制同步会员状态
|
||||||
///
|
///
|
||||||
/// 用户支付完成后,若前端会员状态未刷新,可调用此接口同步确认订单并获取最新状态。
|
/// 查询订单和会员的当前最新状态(不执行确认操作,仅查询)
|
||||||
#[post("/api/payment/sync-order")]
|
#[post("/api/payment/sync-order")]
|
||||||
pub async fn sync_order(
|
pub async fn sync_order(
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
@@ -990,12 +990,18 @@ pub async fn sync_order(
|
|||||||
check_payment_maintenance()?;
|
check_payment_maintenance()?;
|
||||||
let user_id = claims.user_id;
|
let user_id = claims.user_id;
|
||||||
|
|
||||||
// 尝试确认订单(幂等),失败时记录日志
|
// 查询订单当前状态(不执行确认,防止误确认未支付订单)
|
||||||
if let Err(e) = db::confirm_payment_order(pool.get_ref(), &body.order_id, user_id).await {
|
let order_status: Option<String> = sqlx::query_scalar(
|
||||||
tracing::warn!("确认订单失败(可能已被异步回调处理): {}", e);
|
r#"SELECT status FROM payment_orders WHERE order_no = $1 AND user_id = $2"#,
|
||||||
}
|
)
|
||||||
|
.bind(&body.order_id)
|
||||||
|
.bind(user_id)
|
||||||
|
.fetch_optional(pool.get_ref())
|
||||||
|
.await
|
||||||
|
.map_err(|e| AppError::Database(format!("查询订单失败: {}", e)))?
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
// 查询最新状态
|
// 查询会员最新状态
|
||||||
let user = sqlx::query_as::<_, (bool, Option<chrono::DateTime<chrono::Utc>>)>(
|
let user = sqlx::query_as::<_, (bool, Option<chrono::DateTime<chrono::Utc>>)>(
|
||||||
r#"SELECT is_paid, paid_expires_at FROM users WHERE id = $1"#,
|
r#"SELECT is_paid, paid_expires_at FROM users WHERE id = $1"#,
|
||||||
)
|
)
|
||||||
@@ -1011,6 +1017,7 @@ pub async fn sync_order(
|
|||||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||||
"success": true,
|
"success": true,
|
||||||
"data": {
|
"data": {
|
||||||
|
"order_status": order_status,
|
||||||
"is_paid": is_paid,
|
"is_paid": is_paid,
|
||||||
"is_paid_active": is_paid_active,
|
"is_paid_active": is_paid_active,
|
||||||
"paid_expires_at": paid_expires_at,
|
"paid_expires_at": paid_expires_at,
|
||||||
|
|||||||
Reference in New Issue
Block a user