修复任职停用;星之界种子邀请链 seed_xzj_invite_data

This commit is contained in:
XingQue
2026-06-24 23:33:25 +08:00
parent 49482830f9
commit d56c85bca9
6 changed files with 349 additions and 20 deletions

View File

@@ -0,0 +1,97 @@
"""admin_assignment 任职 CRUD修复停用不生效、重复插入"""
from django.db.models import Q
from django.utils import timezone
from jituan.constants import DATA_SCOPE_ALL, DATA_SCOPE_SINGLE
from jituan.models import AdminAssignment
def _club_filter(qs, club_id):
if club_id is None:
return qs.filter(Q(club_id__isnull=True) | Q(club_id=''))
return qs.filter(club_id=club_id)
def find_assignment(yonghuid, club_id, role_code):
qs = AdminAssignment.query.filter(yonghuid=yonghuid, role_code=role_code)
return _club_filter(qs, club_id).first()
def find_active_assignment(yonghuid, club_id, role_code):
qs = AdminAssignment.query.filter(yonghuid=yonghuid, role_code=role_code, status=1)
return _club_filter(qs, club_id).first()
def create_or_reactivate_assignment(
yonghuid,
club_id,
role_code,
data_scope,
is_primary,
granted_by,
):
active = find_active_assignment(yonghuid, club_id, role_code)
if active:
return None, '该任职记录已存在且有效'
inactive = find_assignment(yonghuid, club_id, role_code)
if inactive and inactive.status != 1:
AdminAssignment.objects.filter(pk=inactive.id).update(
status=1,
data_scope=data_scope,
is_primary=is_primary,
granted_by=granted_by,
UpdateTime=timezone.now(),
)
return inactive.id, None
row = AdminAssignment.query.create(
yonghuid=yonghuid,
club_id=club_id,
role_code=role_code,
data_scope=data_scope,
is_primary=is_primary,
granted_by=granted_by,
status=1,
)
return row.id, None
def deactivate_assignment(assignment_id):
try:
pk = int(assignment_id)
except (TypeError, ValueError):
return False, '任职 id 无效'
updated = AdminAssignment.objects.filter(pk=pk, status=1).update(
status=0,
UpdateTime=timezone.now(),
)
if updated:
return True, None
exists = AdminAssignment.objects.filter(pk=pk).exists()
if exists:
return True, None
return False, '任职记录不存在'
def dedupe_active_assignments():
"""停用重复的有效任职,每组 (yonghuid, club_id, role_code) 只保留一条。"""
rows = list(
AdminAssignment.query.filter(status=1).order_by('yonghuid', 'club_id', 'role_code', 'id')
)
seen = {}
dup_ids = []
for row in rows:
key = (row.yonghuid, row.club_id or '', row.role_code)
if key in seen:
dup_ids.append(row.id)
else:
seen[key] = row.id
if dup_ids:
AdminAssignment.objects.filter(pk__in=dup_ids).update(
status=0,
UpdateTime=timezone.now(),
)
return len(dup_ids)

View File

@@ -13,24 +13,32 @@ from products.models import Huiyuan
def _format_member(m, price_row=None):
global_jiage = str(m.jiage)
global_guanshifc = str(m.guanshifc)
global_zuzhangfc = str(m.zuzhangfc)
item = {
'huiyuan_id': m.huiyuan_id,
'jieshao': m.jieshao,
'jtjieshao': m.jtjieshao,
'jiage': str(m.jiage),
'guanshifc': str(m.guanshifc),
'zuzhangfc': str(m.zuzhangfc),
'jiage': global_jiage,
'guanshifc': global_guanshifc,
'zuzhangfc': global_zuzhangfc,
'global_jiage': global_jiage,
'global_guanshifc': global_guanshifc,
'global_zuzhangfc': global_zuzhangfc,
'goumai_cishu': m.goumai_cishu,
'CreateTime': m.CreateTime.isoformat() if m.CreateTime else None,
'UpdateTime': m.UpdateTime.isoformat() if m.UpdateTime else None,
'bankuai_id': m.bankuai_id,
'club_enabled': True,
'price_source': 'global',
}
if price_row is not None:
item['jiage'] = str(price_row.jiage)
item['guanshifc'] = str(price_row.guanshifc)
item['zuzhangfc'] = str(price_row.zuzhangfc)
item['club_enabled'] = bool(price_row.is_enabled)
item['price_source'] = 'club'
return item
@@ -40,14 +48,17 @@ def build_member_list_payload(request):
members = Huiyuan.query.all().order_by('-CreateTime')
member_list = []
if scope == DATA_SCOPE_ALL:
for m in members:
member_list.append(_format_member(m))
else:
price_map = {}
if scope != DATA_SCOPE_ALL:
price_map = {
r.huiyuan_id: r
for r in ClubHuiyuanPrice.query.filter(club_id=club_id)
}
if scope == DATA_SCOPE_ALL:
for m in members:
member_list.append(_format_member(m))
else:
for m in members:
row = price_map.get(m.huiyuan_id)
if row is None and club_id != CLUB_ID_DEFAULT:
@@ -60,6 +71,12 @@ def build_member_list_payload(request):
'list': member_list,
'club_id': club_id,
'scope': scope,
'price_note': (
'当前展示俱乐部专属售价club_huiyuan_price与星阙相同说明尚未单独改价'
'在本俱乐部视图下编辑即可覆盖。'
if scope != DATA_SCOPE_ALL else
'集团汇总视图展示全局默认价;切换具体俱乐部可查看/编辑各俱乐部售价。'
),
**list_response_meta(request),
}