feat: 添加PAYMENT_MAINTENANCE_MODE维护模式 + ServiceUnavailable错误
This commit is contained in:
14
src/db.rs
14
src/db.rs
@@ -9,11 +9,14 @@ use crate::error::AppError;
|
||||
|
||||
// 用于插入weather_data的数据
|
||||
pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData, user_id: i32) -> Result<i32, AppError> {
|
||||
// 配额检查:非付费用户数据条数限制
|
||||
let user = get_user_by_id(pool, user_id).await?;
|
||||
let is_paid_active = user.is_paid && user.paid_expires_at.map_or(true, |expires| expires > Utc::now());
|
||||
|
||||
if !is_paid_active {
|
||||
// 维护模式:跳过所有配额检查
|
||||
let is_maintenance = std::env::var("PAYMENT_MAINTENANCE_MODE").ok() == Some("true".to_string());
|
||||
if !is_maintenance {
|
||||
// 配额检查:非付费用户数据条数限制
|
||||
let user = get_user_by_id(pool, user_id).await?;
|
||||
let is_paid_active = user.is_paid && user.paid_expires_at.map_or(true, |expires| expires > Utc::now());
|
||||
|
||||
if !is_paid_active {
|
||||
let current_count = count_user_weather_data(pool, user_id).await?;
|
||||
let limit: i64 = env::var("FREE_USER_DATA_LIMIT")
|
||||
.unwrap_or_else(|_| "20".to_string())
|
||||
@@ -24,6 +27,7 @@ pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData, user
|
||||
return Err(AppError::Forbidden("数据条数已达上限,请升级为付费用户".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 准备插入数据的 SQL 语句
|
||||
let insert_query = r#"
|
||||
|
||||
Reference in New Issue
Block a user