fix: 不再自动创建 lsx 空俱乐部;新增按无 key 路径清理重复配置

cleanup_lsx_empty_club 只删无证书路径的龙先生相关俱乐部,保留已上传 key 的配置。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-23 21:43:12 +08:00
parent cddd231dc2
commit de88e55378
3 changed files with 221 additions and 21 deletions

View File

@@ -26,21 +26,23 @@ class Command(BaseCommand):
club_id = 'lsx'
name = '龙先生电竞'
if Club.query.filter(club_id=club_id).exists():
self.stdout.write(self.style.WARNING(f'俱乐部 {club_id} 已存在,跳过 create_club'))
club = Club.query.filter(club_id=club_id).first()
if club and wx_appid and (club.wx_appid or '') != wx_appid:
club.wx_appid = wx_appid
club.save(update_fields=['wx_appid'])
self.stdout.write(f'已更新 {club_id}.wx_appid = {wx_appid}')
# 俱乐部应由后台「俱乐部配置」创建并上传证书;本命令不再自动 create_club
club = Club.query.filter(club_id=club_id).first()
if club is None:
self.stdout.write(self.style.ERROR(
f'俱乐部 {club_id} 不存在。请先在后台创建并上传支付 key'
f'不要用脚本自动建俱乐部(避免生成无证书空配置)。'
))
return
if wx_appid and (club.wx_appid or '') != wx_appid:
club.wx_appid = wx_appid
club.save(update_fields=['wx_appid'])
self.stdout.write(f'已更新 {club_id}.wx_appid = {wx_appid}')
else:
self.stdout.write(f'创建俱乐部 {club_id} ...')
call_command(
'create_club',
club_id,
name=name,
wx_appid=wx_appid,
)
self.stdout.write(self.style.SUCCESS(
f'俱乐部 {club_id} 已存在name={club.name}),跳过创建。'
))
if options.get('assignments'):
phone = (options.get('phone') or '').strip()
@@ -61,6 +63,18 @@ class Command(BaseCommand):
'python manage.py seed_admin_assignments --phone 手机号 --club-id lsx'
)
keyed = any([
(club.pay_key_path or '').strip(),
(club.pay_cert_path or '').strip(),
(club.private_key_path or '').strip(),
(club.platform_cert_dir or '').strip(),
])
if not keyed:
self.stdout.write(self.style.WARNING(
f'{club_id} 当前无证书路径,请在后台上传 key'
f'若存在重复空俱乐部可用python manage.py cleanup_lsx_empty_club'
))
self.stdout.write(self.style.SUCCESS(
f'龙先生电竞 {club_id} 就绪。请在后台「俱乐部配置」检查支付密钥与 wx_appid'
f'龙先生电竞 {club_id} 检查完成'
))