seed_admin_assignments 禁止默认批量;任职角色仅作标签说明
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""为后台客服账号初始化 admin_assignment(数据范围,非功能权限)。"""
|
"""为后台客服账号初始化 admin_assignment(数据范围,非功能权限)。"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
from jituan.constants import CLUB_ID_DEFAULT, DATA_SCOPE_SINGLE, ADMIN_ROLE_LABELS
|
from jituan.constants import CLUB_ID_DEFAULT, DATA_SCOPE_SINGLE, ADMIN_ROLE_LABELS
|
||||||
@@ -19,7 +19,15 @@ class Command(BaseCommand):
|
|||||||
'--club-id', default=CLUB_ID_DEFAULT, help='目标俱乐部 ID,默认 xq',
|
'--club-id', default=CLUB_ID_DEFAULT, help='目标俱乐部 ID,默认 xq',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--role-code', default='CLUB_ADMIN', help='任职角色码',
|
'--role-code', default='CLUB_ADMIN', help='任职角色码(仅展示标签,不控制菜单功能权限)',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--phone', type=str, default='', help='仅给该手机号客服添加任职(推荐)',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--all-kefu',
|
||||||
|
action='store_true',
|
||||||
|
help='给全部客服账号批量添加(慎用,会扫所有有 KefuProfile 的账号)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--dry-run', action='store_true', help='只打印不写入',
|
'--dry-run', action='store_true', help='只打印不写入',
|
||||||
@@ -29,9 +37,24 @@ class Command(BaseCommand):
|
|||||||
club_id = options['club_id']
|
club_id = options['club_id']
|
||||||
role_code = options['role_code']
|
role_code = options['role_code']
|
||||||
dry_run = options['dry_run']
|
dry_run = options['dry_run']
|
||||||
|
target_phone = (options.get('phone') or '').strip()
|
||||||
|
all_kefu = options.get('all_kefu')
|
||||||
|
|
||||||
# UserType 是属性不是 DB 字段,通过 KefuProfile 关联筛选客服账号
|
if not target_phone and not all_kefu:
|
||||||
kefu_users = User.query.filter(KefuProfile__isnull=False).select_related('KefuProfile')
|
raise CommandError(
|
||||||
|
'请指定 --phone 13800138000(只配一个人)或 --all-kefu(批量全部客服)。'
|
||||||
|
'默认不会自动给所有人加任职。'
|
||||||
|
)
|
||||||
|
|
||||||
|
if target_phone:
|
||||||
|
target = User.query.filter(Phone=target_phone).first()
|
||||||
|
if not target:
|
||||||
|
raise CommandError(f'未找到手机号 {target_phone}')
|
||||||
|
kefu_users = [target]
|
||||||
|
else:
|
||||||
|
kefu_users = list(
|
||||||
|
User.query.filter(KefuProfile__isnull=False).select_related('KefuProfile')
|
||||||
|
)
|
||||||
created = 0
|
created = 0
|
||||||
skipped = 0
|
skipped = 0
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
"""一键初始化星之界(xzj)俱乐部及客服数据范围。"""
|
"""一键初始化星之界(xzj)俱乐部(默认不批量给所有客服加任职)。"""
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from jituan.models import Club
|
from jituan.models import Club
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = '创建星之界电竞俱乐部(xzj)并分配客服数据范围(需先 seed_club_xq)'
|
help = '创建星之界电竞俱乐部(xzj);任职请单独 seed_admin_assignments --phone ...'
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--wx-appid', default='wxdefa454152e78a03', help='星之界小程序 appid',
|
'--wx-appid', default='wxdefa454152e78a03', help='星之界小程序 appid',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--skip-assignments', action='store_true', help='跳过客服 admin_assignment',
|
'--assignments',
|
||||||
|
action='store_true',
|
||||||
|
help='同时给 --phone 指定客服加 xzj 任职(需配合 --phone)',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--phone', type=str, default='', help='与 --assignments 联用:客服手机号',
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
@@ -32,15 +37,25 @@ class Command(BaseCommand):
|
|||||||
wx_appid=wx_appid,
|
wx_appid=wx_appid,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not options.get('skip_assignments'):
|
if options.get('assignments'):
|
||||||
self.stdout.write('分配客服数据范围 ...')
|
phone = (options.get('phone') or '').strip()
|
||||||
try:
|
if not phone:
|
||||||
call_command('seed_admin_assignments', club_id=club_id)
|
|
||||||
except Exception as e:
|
|
||||||
self.stdout.write(self.style.WARNING(
|
self.stdout.write(self.style.WARNING(
|
||||||
f'客服数据范围分配失败(可稍后在后台「数据范围」页手动配置): {e}'
|
'未指定 --phone,跳过任职。示例:'
|
||||||
|
'python manage.py seed_club_xzj --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 xzj'
|
||||||
|
)
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS(
|
self.stdout.write(self.style.SUCCESS(
|
||||||
f'星之界 {club_id} 就绪。请在后台「俱乐部配置」检查支付密钥,并在 xzj 视图下单独改轮播/会员价。'
|
f'星之界 {club_id} 就绪。请在后台「俱乐部配置」检查支付密钥。'
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user