From 526830d9deadbd7170f485317575dce1fe854b27 Mon Sep 17 00:00:00 2001 From: milky0217 Date: Tue, 2 Jun 2026 10:58:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20check-members.sh=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=BA=93=E6=97=A7=E5=AD=97=E6=AE=B5=E5=90=8D?= =?UTF-8?q?(is=5Fpaid/paid=5Fexpires=5Fat)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/check-members.sh | 56 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/scripts/check-members.sh b/scripts/check-members.sh index 16677c1..8ee236d 100755 --- a/scripts/check-members.sh +++ b/scripts/check-members.sh @@ -105,6 +105,33 @@ OVERVIEW=$(psql_exec "$SQL_OVERVIEW") || { IFS='|' read -r total_users total_members active_members expired_members permanent_members expiring_7d expiring_30d <<< "$OVERVIEW" +# 如果新字段名(is_member)查不到,用旧字段名(is_paid)重查 +if [ -z "$total_members" ] || [ "$total_members" = "0" ] && [ "$total_users" != "0" ]; then + SQL_OVERVIEW_OLD=$(cat <<'SQL' +SELECT + COUNT(*) AS total_users, + COUNT(*) FILTER (WHERE is_paid = true) AS total_members, + COUNT(*) FILTER (WHERE is_paid = true AND paid_expires_at > NOW()) AS active_members, + COUNT(*) FILTER (WHERE is_paid = true AND paid_expires_at <= NOW()) AS expired_members, + COUNT(*) FILTER (WHERE is_paid = true AND paid_expires_at IS NULL) AS permanent_members, + COUNT(*) FILTER (WHERE is_paid = true + AND paid_expires_at IS NOT NULL + AND paid_expires_at > NOW() + AND paid_expires_at <= NOW() + INTERVAL '7 days') AS expiring_7d, + COUNT(*) FILTER (WHERE is_paid = true + AND paid_expires_at IS NOT NULL + AND paid_expires_at > NOW() + AND paid_expires_at <= NOW() + INTERVAL '30 days') AS expiring_30d +FROM users; +SQL +) + OVERVIEW=$(psql_exec "$SQL_OVERVIEW_OLD") + IFS='|' read -r total_users total_members active_members expired_members permanent_members expiring_7d expiring_30d <<< "$OVERVIEW" + USE_OLD_COLS=true +else + USE_OLD_COLS=false +fi + # ---- 活跃会员列表 ---- SQL_LIST=$(cat <<'SQL' SELECT @@ -130,7 +157,34 @@ ORDER BY SQL ) -MEMBER_LIST=$(psql_exec "$SQL_LIST") +if [ "$USE_OLD_COLS" = true ]; then + SQL_LIST_OLD=$(cat <<'SQL' +SELECT + id, + COALESCE(openid, 'N/A') AS openid, + COALESCE(nickname, CONCAT('用户 #', id)) AS display_name, + paid_expires_at::date AS expires_on, + CASE + WHEN paid_expires_at IS NULL THEN '永久' + WHEN paid_expires_at <= NOW() THEN '已过期' + ELSE CONCAT('剩 ', EXTRACT(DAY FROM paid_expires_at - NOW()), ' 天') + END AS status, + CASE + WHEN paid_expires_at IS NULL THEN 99999 + WHEN paid_expires_at <= NOW() THEN -1 + ELSE EXTRACT(DAY FROM paid_expires_at - NOW())::int + END AS days_left +FROM users +WHERE is_paid = true +ORDER BY + CASE WHEN paid_expires_at IS NULL THEN 0 ELSE 1 END, + paid_expires_at DESC; +SQL +) + MEMBER_LIST=$(psql_exec "$SQL_LIST_OLD") +else + MEMBER_LIST=$(psql_exec "$SQL_LIST") +fi # ---- 近期到期的活跃会员 ---- SQL_EXPIRING=$(cat <<'SQL'