"""一键初始化龙先生电竞(lsx)俱乐部(默认不批量给所有客服加任职)。""" from django.core.management import call_command from django.core.management.base import BaseCommand from jituan.models import Club class Command(BaseCommand): help = '创建龙先生电竞俱乐部(lsx);任职请单独 seed_admin_assignments --phone ...' def add_arguments(self, parser): parser.add_argument( '--wx-appid', default='wx7ff90e9d024fcdb8', help='龙先生电竞小程序 appid', ) parser.add_argument( '--assignments', action='store_true', help='同时给 --phone 指定客服加 lsx 任职(需配合 --phone)', ) parser.add_argument( '--phone', type=str, default='', help='与 --assignments 联用:客服手机号', ) def handle(self, *args, **options): wx_appid = (options.get('wx_appid') or '').strip() club_id = 'lsx' name = '龙先生电竞' # 俱乐部应由后台「俱乐部配置」创建并上传证书;本命令不再自动 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(self.style.SUCCESS( f'俱乐部 {club_id} 已存在(name={club.name}),跳过创建。' )) if options.get('assignments'): phone = (options.get('phone') or '').strip() if not phone: self.stdout.write(self.style.WARNING( '未指定 --phone,跳过任职。示例:' 'python manage.py seed_club_lsx --assignments --phone 你的手机号' )) else: call_command( 'seed_admin_assignments', club_id=club_id, phone=phone, ) else: self.stdout.write( '未加任职。需要时在后台「数据范围」配置,或:' '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} 检查完成。' ))