From d20c785d3800703e1f8ce2c76aaaedf2d4098ddd Mon Sep 17 00:00:00 2001 From: milky0217 Date: Tue, 26 May 2026 15:29:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E4=BC=9A?= =?UTF-8?q?=E5=91=98=E8=BF=87=E6=9C=9F=E9=80=9A=E7=9F=A5(check=5Fmember=5F?= =?UTF-8?q?expired)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db.rs | 31 ------------------------------- src/main.rs | 3 +-- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/src/db.rs b/src/db.rs index 0f23366..9a077bb 100644 --- a/src/db.rs +++ b/src/db.rs @@ -421,37 +421,6 @@ pub async fn check_member_expiry_soon(pool: &PgPool) -> Result { Ok(affected) } -/// 检查已过期的会员,发送过期通知 -pub async fn check_member_expired(pool: &PgPool) -> Result { - let affected = sqlx::query( - r#" - INSERT INTO notifications (scope, user_id, type, title, content) - SELECT 'user', u.id, 'member_expired', - '会员已过期', - '您的会员已过期,续费后可恢复无限存储额度' - FROM users u - WHERE u.is_member = true - AND u.membership_expires_at IS NOT NULL - AND u.membership_expires_at < NOW() - AND NOT EXISTS ( - SELECT 1 FROM notifications n - WHERE n.user_id = u.id - AND n.type = 'member_expired' - AND n.created_at > NOW() - INTERVAL '1 day' - ) - "#, - ) - .execute(pool) - .await - .map_err(|e| AppError::Database(format!("检查会员过期失败: {}", e)))? - .rows_affected(); - - if affected > 0 { - tracing::info!("已发送 {} 条会员过期通知", affected); - } - Ok(affected) -} - /// 清理超过 24 小时仍未支付的待处理订单 pub async fn cleanup_expired_pending_orders(pool: &PgPool, user_id: Option) -> Result { let affected = if let Some(uid) = user_id { diff --git a/src/main.rs b/src/main.rs index 6a048f1..540e022 100644 --- a/src/main.rs +++ b/src/main.rs @@ -268,9 +268,8 @@ async fn main() -> std::io::Result<()> { Err(e) => tracing::warn!("[定时任务] 扫描待支付订单失败: {}", e), } - // 会员到期提醒 + // 会员到期前 7 天提醒 let _ = db::check_member_expiry_soon(&pool_clone).await; - let _ = db::check_member_expired(&pool_clone).await; } });