Add refund received toggle button and filter options

- Add refund_received column to claude_payment_status table
- API endpoint POST /api/tools/refund-received/{email} to toggle
- Clickable badge in table to mark refund as received/not received
- Filter options: refund received / refund not received

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-06 01:46:45 +08:00
parent 663f99a510
commit d8d651240a
5 changed files with 87 additions and 26 deletions

View File

@@ -105,17 +105,19 @@ class DatabaseManager:
proxy_expire_days INTEGER DEFAULT 30,
proxy_share TEXT DEFAULT 'exclusive',
proxy_purchase_date TEXT DEFAULT '',
refund_received TEXT DEFAULT '0',
checked_at TEXT
)
''')
# 兼容旧表:动态添加缺少的列
for col in ['suspended_time', 'title', 'remark', 'card_number', 'proxy', 'proxy_expire_days', 'proxy_share', 'proxy_purchase_date']:
for col in ['suspended_time', 'title', 'remark', 'card_number', 'proxy', 'proxy_expire_days', 'proxy_share', 'proxy_purchase_date', 'refund_received']:
try:
cursor.execute(f"SELECT {col} FROM claude_payment_status LIMIT 1")
except sqlite3.OperationalError:
defaults = {'title': "DEFAULT ''", 'remark': "DEFAULT ''", 'card_number': "DEFAULT ''", 'proxy': "DEFAULT ''",
'proxy_expire_days': "DEFAULT 30", 'proxy_share': "DEFAULT 'exclusive'", 'proxy_purchase_date': "DEFAULT ''"}
'proxy_expire_days': "DEFAULT 30", 'proxy_share': "DEFAULT 'exclusive'", 'proxy_purchase_date': "DEFAULT ''",
'refund_received': "DEFAULT '0'"}
default = defaults.get(col, '')
cursor.execute(f"ALTER TABLE claude_payment_status ADD COLUMN {col} TEXT {default}")
logger.info(f"已为 claude_payment_status 添加 {col}")
@@ -525,7 +527,7 @@ class DatabaseManager:
cursor = conn.cursor()
checked_at = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 先查已有的 remark/card_number避免被覆盖
cursor.execute('SELECT title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date FROM claude_payment_status WHERE email = ?', (email,))
cursor.execute('SELECT title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, refund_received FROM claude_payment_status WHERE email = ?', (email,))
existing = cursor.fetchone()
old_title = existing['title'] if existing else ''
old_remark = existing['remark'] if existing else ''
@@ -534,10 +536,11 @@ class DatabaseManager:
old_expire = existing['proxy_expire_days'] if existing else 30
old_share = existing['proxy_share'] if existing else 'exclusive'
old_purchase = existing['proxy_purchase_date'] if existing else ''
old_refund_received = existing['refund_received'] if existing else '0'
cursor.execute('''
INSERT OR REPLACE INTO claude_payment_status (email, status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, checked_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (email, status, payment_time, refund_time, suspended_time, old_title or '', old_remark or '', old_card or '', old_proxy or '', old_expire or 30, old_share or 'exclusive', old_purchase or '', checked_at))
INSERT OR REPLACE INTO claude_payment_status (email, status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, refund_received, checked_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (email, status, payment_time, refund_time, suspended_time, old_title or '', old_remark or '', old_card or '', old_proxy or '', old_expire or 30, old_share or 'exclusive', old_purchase or '', old_refund_received or '0', checked_at))
conn.commit()
return True
except Exception as e:
@@ -551,7 +554,7 @@ class DatabaseManager:
def _sync_get():
conn = self.get_connection()
cursor = conn.cursor()
cursor.execute('SELECT status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, checked_at FROM claude_payment_status WHERE email = ?', (email,))
cursor.execute('SELECT status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, refund_received, checked_at FROM claude_payment_status WHERE email = ?', (email,))
row = cursor.fetchone()
if row:
return {
@@ -566,6 +569,7 @@ class DatabaseManager:
'proxy_expire_days': row['proxy_expire_days'] or 30,
'proxy_share': row['proxy_share'] or 'exclusive',
'proxy_purchase_date': row['proxy_purchase_date'] or '',
'refund_received': row['refund_received'] or '0',
'checked_at': row['checked_at']
}
return None
@@ -577,7 +581,7 @@ class DatabaseManager:
def _sync_get():
conn = self.get_connection()
cursor = conn.cursor()
cursor.execute('SELECT email, status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, checked_at FROM claude_payment_status')
cursor.execute('SELECT email, status, payment_time, refund_time, suspended_time, title, remark, card_number, proxy, proxy_expire_days, proxy_share, proxy_purchase_date, refund_received, checked_at FROM claude_payment_status')
rows = cursor.fetchall()
result = {}
for row in rows:
@@ -593,6 +597,7 @@ class DatabaseManager:
'proxy_expire_days': row['proxy_expire_days'] or 30,
'proxy_share': row['proxy_share'] or 'exclusive',
'proxy_purchase_date': row['proxy_purchase_date'] or '',
'refund_received': row['refund_received'] or '0',
'checked_at': row['checked_at']
}
return result
@@ -601,7 +606,7 @@ class DatabaseManager:
async def update_claude_payment_note(self, email: str, **kwargs) -> bool:
"""更新备注、卡号、代理等字段"""
allowed = {'title', 'remark', 'card_number', 'proxy', 'proxy_expire_days', 'proxy_share', 'proxy_purchase_date'}
allowed = {'title', 'remark', 'card_number', 'proxy', 'proxy_expire_days', 'proxy_share', 'proxy_purchase_date', 'refund_received'}
def _sync_update():
try:
conn = self.get_connection()