refactor: is_paid→is_member, paid_expires_at→membership_expires_at 全局重命名
This commit is contained in:
@@ -475,8 +475,8 @@ pub async fn payment_index() -> Result<HttpResponse, AppError> {
|
||||
if (resp.ok) {
|
||||
const data = await resp.json();
|
||||
if (data.success) {
|
||||
isPaidActive = data.data.is_paid_active || false;
|
||||
paidExpiresAt = data.data.paid_expires_at || null;
|
||||
isPaidActive = data.data.is_active_member || false;
|
||||
paidExpiresAt = data.data.membership_expires_at || null;
|
||||
}
|
||||
}
|
||||
} catch(e) {}
|
||||
@@ -499,8 +499,8 @@ pub async fn payment_index() -> Result<HttpResponse, AppError> {
|
||||
const data = await resp.json();
|
||||
if (data.success && data.token) {
|
||||
jwt = data.token;
|
||||
isPaidActive = data.is_paid_active || false;
|
||||
paidExpiresAt = data.paid_expires_at;
|
||||
isPaidActive = data.is_active_member || false;
|
||||
paidExpiresAt = data.membership_expires_at;
|
||||
clearInterval(pollTimer);
|
||||
showLoggedIn();
|
||||
}
|
||||
@@ -995,8 +995,8 @@ pub async fn mock_confirm(
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"success": true,
|
||||
"data": {
|
||||
"is_paid_active": true,
|
||||
"paid_expires_at": expires_at,
|
||||
"is_active_member": true,
|
||||
"membership_expires_at": expires_at,
|
||||
}
|
||||
})))
|
||||
}
|
||||
@@ -1026,7 +1026,7 @@ pub async fn sync_order(
|
||||
|
||||
// 查询会员最新状态
|
||||
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_member, membership_expires_at FROM users WHERE id = $1"#,
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_optional(pool.get_ref())
|
||||
@@ -1034,16 +1034,16 @@ pub async fn sync_order(
|
||||
.map_err(|e| AppError::Database(format!("查询用户失败: {}", e)))?
|
||||
.ok_or_else(|| AppError::NotFound("用户不存在".to_string()))?;
|
||||
|
||||
let (is_paid, paid_expires_at) = user;
|
||||
let is_paid_active = is_paid && paid_expires_at.map_or(true, |expires| expires > Utc::now());
|
||||
let (is_member, membership_expires_at) = user;
|
||||
let is_active_member = is_member && membership_expires_at.map_or(true, |expires| expires > Utc::now());
|
||||
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"success": true,
|
||||
"data": {
|
||||
"order_status": order_status,
|
||||
"is_paid": is_paid,
|
||||
"is_paid_active": is_paid_active,
|
||||
"paid_expires_at": paid_expires_at,
|
||||
"is_member": is_member,
|
||||
"is_active_member": is_active_member,
|
||||
"membership_expires_at": membership_expires_at,
|
||||
}
|
||||
})))
|
||||
}
|
||||
@@ -1100,15 +1100,15 @@ pub async fn get_user_quota(
|
||||
|
||||
let is_maintenance = std::env::var("PAYMENT_MAINTENANCE_MODE").ok() == Some("true".to_string());
|
||||
|
||||
let (used, is_paid_active, paid_expires_at, was_paid) =
|
||||
let (used, is_active_member, membership_expires_at, was_member) =
|
||||
db::get_user_quota(pool.get_ref(), user_id).await?;
|
||||
|
||||
// 维护模式使用更高的临时限额,但非会员仍然有限制防止滥用
|
||||
let (limit, unlimited) = if is_maintenance && !is_paid_active {
|
||||
let (limit, unlimited) = if is_maintenance && !is_active_member {
|
||||
let ml: i64 = std::env::var("MAINTENANCE_MODE_DATA_LIMIT")
|
||||
.ok().and_then(|v| v.parse().ok()).unwrap_or(500);
|
||||
(ml, false)
|
||||
} else if is_paid_active {
|
||||
} else if is_active_member {
|
||||
(0, true)
|
||||
} else {
|
||||
let fl: i64 = std::env::var("FREE_USER_DATA_LIMIT")
|
||||
@@ -1116,7 +1116,7 @@ pub async fn get_user_quota(
|
||||
(fl, false)
|
||||
};
|
||||
|
||||
let active = if is_maintenance { true } else { is_paid_active };
|
||||
let active = if is_maintenance { true } else { is_active_member };
|
||||
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"success": true,
|
||||
@@ -1124,9 +1124,9 @@ pub async fn get_user_quota(
|
||||
"used": used,
|
||||
"limit": limit,
|
||||
"unlimited": unlimited,
|
||||
"is_paid_active": active,
|
||||
"paid_expires_at": paid_expires_at,
|
||||
"was_paid": was_paid,
|
||||
"is_active_member": active,
|
||||
"membership_expires_at": membership_expires_at,
|
||||
"was_member": was_member,
|
||||
"maintenance_mode": is_maintenance,
|
||||
}
|
||||
})))
|
||||
@@ -1144,8 +1144,8 @@ pub struct LoginStatusResponse {
|
||||
pub success: bool,
|
||||
pub confirmed: bool,
|
||||
pub token: Option<String>,
|
||||
pub is_paid_active: bool,
|
||||
pub paid_expires_at: Option<String>,
|
||||
pub is_active_member: bool,
|
||||
pub membership_expires_at: Option<String>,
|
||||
}
|
||||
|
||||
// ===== Handler: GET /payment/generate-code — 网页端生成登录码 =====
|
||||
@@ -1212,8 +1212,8 @@ pub async fn payment_login_status(
|
||||
success: false,
|
||||
confirmed: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
}));
|
||||
}
|
||||
};
|
||||
@@ -1231,8 +1231,8 @@ pub async fn payment_login_status(
|
||||
success: false,
|
||||
confirmed: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1243,8 +1243,8 @@ pub async fn payment_login_status(
|
||||
success: true,
|
||||
confirmed: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1252,16 +1252,16 @@ pub async fn payment_login_status(
|
||||
let token = token.unwrap();
|
||||
let user_id = user_id.unwrap();
|
||||
|
||||
let (is_paid_active, paid_expires_at): (bool, Option<String>) =
|
||||
let (is_active_member, membership_expires_at): (bool, Option<String>) =
|
||||
match sqlx::query_as::<_, (bool, Option<chrono::DateTime<chrono::Utc>>)>(
|
||||
"SELECT is_paid, paid_expires_at FROM users WHERE id = $1"
|
||||
"SELECT is_member, membership_expires_at FROM users WHERE id = $1"
|
||||
)
|
||||
.bind(user_id)
|
||||
.fetch_optional(pool.get_ref())
|
||||
.await
|
||||
{
|
||||
Ok(Some((is_paid, expires))) => {
|
||||
let active = is_paid && expires.map_or(true, |e| e > Utc::now());
|
||||
Ok(Some((is_member, expires))) => {
|
||||
let active = is_member && expires.map_or(true, |e| e > Utc::now());
|
||||
(active, expires.map(|e| e.to_rfc3339()))
|
||||
}
|
||||
_ => (false, None),
|
||||
@@ -1278,7 +1278,7 @@ pub async fn payment_login_status(
|
||||
success: true,
|
||||
confirmed: true,
|
||||
token: Some(token),
|
||||
is_paid_active,
|
||||
paid_expires_at,
|
||||
is_active_member,
|
||||
membership_expires_at,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user