refactor: is_paid→is_member, paid_expires_at→membership_expires_at 全局重命名
This commit is contained in:
@@ -45,8 +45,8 @@ pub async fn admin_update_user_payment(
|
||||
return Err(AppError::Forbidden("无权限执行此操作".to_string()));
|
||||
}
|
||||
|
||||
// 解析 paid_expires_at
|
||||
let paid_expires_at = match &body.paid_expires_at {
|
||||
// 解析 membership_expires_at
|
||||
let membership_expires_at = match &body.membership_expires_at {
|
||||
Some(date_str) => match DateTime::parse_from_rfc3339(date_str) {
|
||||
Ok(dt) => Some(dt.with_timezone(&Utc)),
|
||||
Err(e) => {
|
||||
@@ -57,12 +57,12 @@ pub async fn admin_update_user_payment(
|
||||
};
|
||||
|
||||
// 更新用户付费状态
|
||||
db::update_user_payment_status(pool.get_ref(), target_user_id, body.is_paid, paid_expires_at).await?;
|
||||
db::update_user_payment_status(pool.get_ref(), target_user_id, body.is_member, membership_expires_at).await?;
|
||||
// 审计日志
|
||||
let _ = db::insert_payment_audit_log(
|
||||
pool.get_ref(), "ADMIN_MANUAL", target_user_id, "admin_revoke",
|
||||
Some(claims.user_id),
|
||||
Some(&format!("管理员手动更新付费状态: is_paid={}, expires_at={:?}", body.is_paid, body.paid_expires_at)),
|
||||
Some(&format!("管理员手动更新付费状态: is_member={}, expires_at={:?}", body.is_member, body.membership_expires_at)),
|
||||
).await;
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
"success": true,
|
||||
|
||||
@@ -498,8 +498,8 @@ pub struct WebLoginConfirmRequest {
|
||||
pub struct WebLoginConfirmResponse {
|
||||
pub success: 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>,
|
||||
}
|
||||
|
||||
#[post("/api/web-login/confirm")]
|
||||
@@ -529,8 +529,8 @@ pub async fn web_login_confirm(
|
||||
return HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -548,12 +548,12 @@ pub async fn web_login_confirm(
|
||||
return HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: false,
|
||||
token: None,
|
||||
is_paid_active: false,
|
||||
paid_expires_at: None,
|
||||
is_active_member: false,
|
||||
membership_expires_at: None,
|
||||
});
|
||||
}
|
||||
|
||||
// 如果已有用户,验证并获取最新 is_paid 信息
|
||||
// 如果已有用户,验证并获取最新 is_member 信息
|
||||
let user_id = if let Some(uid) = existing_user_id {
|
||||
uid
|
||||
} else {
|
||||
@@ -588,16 +588,16 @@ pub async fn web_login_confirm(
|
||||
};
|
||||
|
||||
// 查询付费状态
|
||||
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),
|
||||
@@ -613,12 +613,12 @@ pub async fn web_login_confirm(
|
||||
tracing::warn!("更新登录码 token 失败: {}", e);
|
||||
}
|
||||
|
||||
info!("[WEB LOGIN CONFIRM] user_id={} is_paid={}", user_id, is_paid_active);
|
||||
info!("[WEB LOGIN CONFIRM] user_id={} is_member={}", user_id, is_active_member);
|
||||
HttpResponse::Ok().json(WebLoginConfirmResponse {
|
||||
success: true,
|
||||
token: Some(token),
|
||||
is_paid_active,
|
||||
paid_expires_at,
|
||||
is_active_member,
|
||||
membership_expires_at,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -631,8 +631,8 @@ pub struct AutoConfirmRequest {
|
||||
pub struct AutoConfirmResponse {
|
||||
pub success: 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>,
|
||||
pub payment_url: Option<String>,
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ pub async fn web_login_auto_confirm(
|
||||
};
|
||||
|
||||
let paid_info = 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())
|
||||
@@ -727,9 +727,9 @@ pub async fn web_login_auto_confirm(
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
let (is_paid_active, paid_expires_at): (bool, Option<String>) = match paid_info {
|
||||
Some((is_paid, expires)) => {
|
||||
let active = is_paid && expires.map_or(true, |e| e > Utc::now());
|
||||
let (is_active_member, membership_expires_at): (bool, Option<String>) = match paid_info {
|
||||
Some((is_member, expires)) => {
|
||||
let active = is_member && expires.map_or(true, |e| e > Utc::now());
|
||||
(active, expires.map(|e| e.to_rfc3339()))
|
||||
}
|
||||
None => (false, None),
|
||||
@@ -737,18 +737,18 @@ pub async fn web_login_auto_confirm(
|
||||
|
||||
let base_url = std::env::var("APP_BASE_URL")
|
||||
.unwrap_or_else(|_| "https://dev.xmclassmate.top".to_string());
|
||||
let payment_url = if is_paid_active {
|
||||
let payment_url = if is_active_member {
|
||||
None
|
||||
} else {
|
||||
Some(format!("{}/payment?jwt={}", base_url, token))
|
||||
};
|
||||
|
||||
info!("[WEB LOGIN AUTO-CONFIRM] user_id={} is_paid={}", user_id, is_paid_active);
|
||||
info!("[WEB LOGIN AUTO-CONFIRM] user_id={} is_member={}", user_id, is_active_member);
|
||||
HttpResponse::Ok().json(AutoConfirmResponse {
|
||||
success: true,
|
||||
token: Some(token),
|
||||
is_paid_active,
|
||||
paid_expires_at,
|
||||
is_active_member,
|
||||
membership_expires_at,
|
||||
payment_url,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ pub async fn get_current_user_profile(
|
||||
|
||||
let user = db::get_user_by_id(pool.get_ref(), user_id).await?;
|
||||
let is_maintenance = std::env::var("PAYMENT_MAINTENANCE_MODE").ok() == Some("true".to_string());
|
||||
let is_paid_active = if is_maintenance {
|
||||
let is_active_member = if is_maintenance {
|
||||
true
|
||||
} else {
|
||||
user.is_paid &&
|
||||
user.paid_expires_at.map_or(true, |expires| expires > chrono::Utc::now())
|
||||
user.is_member &&
|
||||
user.membership_expires_at.map_or(true, |expires| expires > chrono::Utc::now())
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok().json(serde_json::json!({
|
||||
@@ -31,10 +31,10 @@ pub async fn get_current_user_profile(
|
||||
"name": user.name,
|
||||
"nickname": user.nickname,
|
||||
"avatarUrl": user.avatar_url,
|
||||
"is_paid": user.is_paid,
|
||||
"is_paid_active": is_paid_active,
|
||||
"is_member": user.is_member,
|
||||
"is_active_member": is_active_member,
|
||||
"is_admin": user.is_admin,
|
||||
"paid_expires_at": user.paid_expires_at
|
||||
"membership_expires_at": user.membership_expires_at
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user