refactor: 移除会员过期通知(check_member_expired)

This commit is contained in:
2026-05-26 15:29:52 +08:00
parent 667231520d
commit d20c785d38
2 changed files with 1 additions and 33 deletions

View File

@@ -421,37 +421,6 @@ pub async fn check_member_expiry_soon(pool: &PgPool) -> Result<u64, AppError> {
Ok(affected)
}
/// 检查已过期的会员,发送过期通知
pub async fn check_member_expired(pool: &PgPool) -> Result<u64, AppError> {
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<i32>) -> Result<u64, AppError> {
let affected = if let Some(uid) = user_id {

View File

@@ -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;
}
});