添加报表页面,更新用户管理和注册功能

This commit is contained in:
2025-12-15 21:39:32 +08:00
parent 738eaa5211
commit 9aa28f5b9e
63 changed files with 1018 additions and 403 deletions

View File

@@ -107,8 +107,23 @@ def get_system_stats() -> dict:
cursor.execute("SELECT COUNT(*) as count FROM users WHERE status = 'approved'")
approved_users = cursor.fetchone()["count"]
cursor.execute("SELECT COUNT(*) as count FROM users WHERE status = 'pending'")
pending_users = cursor.fetchone()["count"]
cursor.execute(
"""
SELECT COUNT(*) as count
FROM users
WHERE date(created_at) = date('now', 'localtime')
"""
)
new_users_today = cursor.fetchone()["count"]
cursor.execute(
"""
SELECT COUNT(*) as count
FROM users
WHERE datetime(created_at) >= datetime('now', 'localtime', '-7 days')
"""
)
new_users_7d = cursor.fetchone()["count"]
cursor.execute("SELECT COUNT(*) as count FROM accounts")
total_accounts = cursor.fetchone()["count"]
@@ -125,7 +140,8 @@ def get_system_stats() -> dict:
return {
"total_users": total_users,
"approved_users": approved_users,
"pending_users": pending_users,
"new_users_today": new_users_today,
"new_users_7d": new_users_7d,
"total_accounts": total_accounts,
"vip_users": vip_users,
}

View File

@@ -66,6 +66,9 @@ def migrate_database(conn, target_version: int) -> None:
if current_version < 10:
_migrate_to_v10(conn)
current_version = 10
if current_version < 11:
_migrate_to_v11(conn)
current_version = 11
if current_version != int(target_version):
set_current_version(conn, int(target_version))
@@ -450,3 +453,26 @@ def _migrate_to_v10(conn):
if changed:
conn.commit()
def _migrate_to_v11(conn):
"""迁移到版本11 - 取消注册待审核:历史 pending 用户直接置为 approved"""
cursor = conn.cursor()
now_str = get_cst_now_str()
try:
cursor.execute(
"""
UPDATE users
SET status = 'approved',
approved_at = COALESCE(NULLIF(approved_at, ''), ?)
WHERE status = 'pending'
""",
(now_str,),
)
updated = cursor.rowcount
conn.commit()
if updated:
print(f" ✓ 已将 {updated} 个 pending 用户迁移为 approved")
except sqlite3.OperationalError as e:
print(f" ⚠️ v11 迁移跳过: {e}")

View File

@@ -33,7 +33,7 @@ def ensure_schema(conn) -> None:
email TEXT,
email_verified INTEGER DEFAULT 0,
email_notify_enabled INTEGER DEFAULT 1,
status TEXT DEFAULT 'pending',
status TEXT DEFAULT 'approved',
vip_expire_time TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
approved_at TIMESTAMP

View File

@@ -148,7 +148,7 @@ def get_user_vip_info(user_id):
def create_user(username, password, email=""):
"""创建新用户(待审核状态,赠送默认VIP)"""
"""创建新用户(默认直接通过,赠送默认VIP)"""
cst_tz = pytz.timezone("Asia/Shanghai")
with db_pool.get_db() as conn:
@@ -168,10 +168,10 @@ def create_user(username, password, email=""):
try:
cursor.execute(
"""
INSERT INTO users (username, password_hash, email, status, vip_expire_time, created_at)
VALUES (?, ?, ?, 'pending', ?, ?)
INSERT INTO users (username, password_hash, email, status, vip_expire_time, created_at, approved_at)
VALUES (?, ?, ?, 'approved', ?, ?, ?)
""",
(username, password_hash, email, vip_expire_time, cst_time),
(username, password_hash, email, vip_expire_time, cst_time, cst_time),
)
conn.commit()
return cursor.lastrowid