diff --git a/config/migrations/0009_gonggao_copy_pages.py b/config/migrations/0009_gonggao_copy_pages.py new file mode 100644 index 0000000..e6d00c3 --- /dev/null +++ b/config/migrations/0009_gonggao_copy_pages.py @@ -0,0 +1,27 @@ +from django.db import migrations + + +def copy_gonggao_to_other_pages(apps, schema_editor): + """将 order_pool 公告复制到 accept_order / merchant_home(仅当目标页尚无记录)。""" + Gonggao = apps.get_model('config', 'Gonggao') + for pk in ('accept_order', 'merchant_home'): + for row in Gonggao.objects.filter(page_key='order_pool'): + if Gonggao.objects.filter(club_id=row.club_id, page_key=pk).exists(): + continue + Gonggao.objects.create( + club_id=row.club_id, + page_key=pk, + NoticeType=row.NoticeType, + Content=row.Content or '', + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ('config', '0008_gonggao_page_key'), + ] + + operations = [ + migrations.RunPython(copy_gonggao_to_other_pages, migrations.RunPython.noop), + ] diff --git a/jituan/management/commands/seed_gvsdsdk_permissions.py b/jituan/management/commands/seed_gvsdsdk_permissions.py new file mode 100644 index 0000000..863aa21 --- /dev/null +++ b/jituan/management/commands/seed_gvsdsdk_permissions.py @@ -0,0 +1,43 @@ +"""补齐 gvsdsdk 权限码(可重复执行)。""" +import uuid + +from django.core.management.base import BaseCommand +from django.utils import timezone + +from gvsdsdk.models import Permission + +# (PermCode, PermName, PermDesc, PermCategory) +EXTRA_PERMISSIONS = [ + ( + 'sfbq666', + '身份装饰标签管理', + '管理小程序身份装饰标签(与用户管理-身份装饰标签菜单对应)', + '用户管理', + ), +] + + +class Command(BaseCommand): + help = '写入 gvsdsdk Permission 表缺失的权限码(如 sfbq666)' + + def handle(self, *args, **options): + sample = Permission.objects.filter(PermStatus=1).first() + tenant_uuid = sample.TenantUUID if sample else uuid.UUID('00000000-0000-0000-0000-000000000001').bytes + created = 0 + for code, name, desc, category in EXTRA_PERMISSIONS: + if Permission.objects.filter(PermCode=code).exists(): + self.stdout.write(f' 已存在: {code}') + continue + Permission.objects.create( + PermUUID=uuid.uuid4().bytes, + TenantUUID=tenant_uuid, + PermCode=code, + PermName=name, + PermDesc=desc, + PermCategory=category, + PermStatus=1, + CreateTime=timezone.now(), + ) + created += 1 + self.stdout.write(self.style.SUCCESS(f' 新增权限: {code} - {name}')) + self.stdout.write(self.style.SUCCESS(f'完成,新增 {created} 条权限')) diff --git a/jituan/management/commands/seed_kefu_menu.py b/jituan/management/commands/seed_kefu_menu.py index f48c49d..5571cab 100644 --- a/jituan/management/commands/seed_kefu_menu.py +++ b/jituan/management/commands/seed_kefu_menu.py @@ -46,7 +46,7 @@ MENU_ROWS = [ {'page_id': 'user.zuzhang', 'name': '组长管理', 'path': '/user/zuzhang', 'parent_id': 'user', 'sort_order': 54, 'perm_codes': ['6600a', '6600b', '6600c', '6600d', '6600e']}, {'page_id': 'user.identity-tag', 'name': '身份装饰标签', 'path': '/user/identity-tag', 'parent_id': 'user', 'sort_order': 55, - 'perm_codes': ['sfbq666']}, + 'perm_codes': ['8080a', 'sfbq666']}, # 提现 {'page_id': 'withdraw', 'name': '提现管理', 'path': '', 'parent_id': '', 'sort_order': 60}, {'page_id': 'withdraw.audit', 'name': '提现审核', 'path': '/withdraw/audit', 'parent_id': 'withdraw', 'sort_order': 61, @@ -133,3 +133,8 @@ class Command(BaseCommand): self.stdout.write(self.style.SUCCESS( f'kefu_menu_page 种子完成:新增 {created},更新 {updated},共 {len(MENU_ROWS)} 条' )) + try: + from django.core.management import call_command + call_command('seed_gvsdsdk_permissions') + except Exception as e: + self.stdout.write(self.style.WARNING(f'seed_gvsdsdk_permissions 跳过: {e}')) diff --git a/jituan/services/display_config.py b/jituan/services/display_config.py index 8b1e92d..bb2deb5 100644 --- a/jituan/services/display_config.py +++ b/jituan/services/display_config.py @@ -63,7 +63,8 @@ def get_gonggao_content(request, notice_type=1, page_key=None): club_id = _display_club_id(request) pk = normalize_page_key(page_key, image_type=1) if page_key else LUNBO_PAGE_ORDER_POOL obj = Gonggao.query.filter(club_id=club_id, page_key=pk).first() - if not obj and notice_type: + # 仅旧接口未传 page_key 时,才回退 NoticeType(兼容历史单条公告) + if not obj and notice_type and not page_key: obj = Gonggao.query.filter(club_id=club_id, NoticeType=notice_type).first() return obj.Content if obj and obj.Content else ''