feat: 后台添加商家 + 龙先生 lsx 俱乐部/邀请链种子

支持客服按用户UID开通商家(分俱乐部校验);新增 seed_club_lsx、seed_lsx_invite_data。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-23 21:29:22 +08:00
parent 46d64fbf92
commit cddd231dc2
6 changed files with 313 additions and 1 deletions

View File

@@ -0,0 +1,66 @@
"""一键初始化龙先生电竞(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 = '龙先生电竞'
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}')
else:
self.stdout.write(f'创建俱乐部 {club_id} ...')
call_command(
'create_club',
club_id,
name=name,
wx_appid=wx_appid,
)
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'
)
self.stdout.write(self.style.SUCCESS(
f'龙先生电竞 {club_id} 就绪。请在后台「俱乐部配置」检查支付密钥与 wx_appid。'
))

View File

@@ -0,0 +1,135 @@
"""龙先生电竞(lsx)邀请链种子:自动插入组长+管事(含邀请码),无需先登录小程序。"""
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import transaction
from jituan.models import Club, ClubHuiyuanPrice
from users.business_models import User
from users.models import UserBoss, UserGuanshi, UserZuzhang
from utils.invitationcode_utils import CreateInvitationCode
CLUB_ID = 'lsx'
WX_APPID = 'wx7ff90e9d024fcdb8'
# 固定种子账号可重复执行幂等UID/手机避开 xzj 的 9900001/2
SEED_ZUZHANG = {
'UserUID': '9910001',
'OpenID': 'lsx_seed_openid_zuzhang_v1',
'Phone': '19910000001',
'UserName': 'lsx_seed_zuzhang',
'nickname': '龙先生种子组长',
}
SEED_GUANSHI = {
'UserUID': '9910002',
'OpenID': 'lsx_seed_openid_guanshi_v1',
'Phone': '19910000002',
'UserName': 'lsx_seed_guanshi',
'nickname': '龙先生种子管事',
}
def _ensure_club():
if Club.query.filter(club_id=CLUB_ID).exists():
return
call_command(
'create_club',
CLUB_ID,
name='龙先生电竞',
wx_appid=WX_APPID,
)
def _ensure_user(meta):
user = User.query.filter(UserUID=meta['UserUID']).first()
if not user:
user = User.query.filter(OpenID=meta['OpenID']).first()
if user:
if user.ClubID != CLUB_ID:
user.ClubID = CLUB_ID
user.save(update_fields=['ClubID'])
return user, False
user = User.query.create(
UserUID=meta['UserUID'],
UserName=meta['UserName'],
OpenID=meta['OpenID'],
Phone=meta['Phone'],
ClubID=CLUB_ID,
)
UserBoss.query.create(user=user, nickname=meta['nickname'])
return user, True
def _ensure_zuzhang(user):
if hasattr(user, 'ZuzhangProfile'):
return user.ZuzhangProfile, False
yaoqingma = CreateInvitationCode(str(user.UserUID))
z = UserZuzhang.query.create(
user=user,
yaoqingma=yaoqingma,
zhuangtai=1,
)
return z, True
def _ensure_guanshi(user, zuzhang_uid):
if hasattr(user, 'GuanshiProfile'):
return user.GuanshiProfile, False
yaoqingma = CreateInvitationCode(str(user.UserUID))
g = UserGuanshi.query.create(
user=user,
yaoqingma=yaoqingma,
yaoqingren=zuzhang_uid,
zhuangtai=1,
)
return g, True
class Command(BaseCommand):
help = '插入龙先生电竞种子组长+管事(含邀请码),一条命令即可邀请注册'
def add_arguments(self, parser):
parser.add_argument(
'--force-new-codes',
action='store_true',
help='已存在时重新生成邀请码(慎用)',
)
def handle(self, *args, **options):
with transaction.atomic():
_ensure_club()
zz_user, zz_new = _ensure_user(SEED_ZUZHANG)
zz_profile, zz_profile_new = _ensure_zuzhang(zz_user)
if options.get('force_new_codes') and not zz_profile_new:
zz_profile.yaoqingma = CreateInvitationCode(str(zz_user.UserUID))
zz_profile.save(update_fields=['yaoqingma'])
gs_user, gs_new = _ensure_user(SEED_GUANSHI)
gs_profile, gs_profile_new = _ensure_guanshi(gs_user, zz_user.UserUID)
if options.get('force_new_codes') and not gs_profile_new:
gs_profile.yaoqingma = CreateInvitationCode(str(gs_user.UserUID))
gs_profile.save(update_fields=['yaoqingma'])
price_cnt = ClubHuiyuanPrice.query.filter(club_id=CLUB_ID).count()
self.stdout.write(self.style.SUCCESS('=' * 60))
self.stdout.write(self.style.SUCCESS('龙先生电竞 lsx 邀请链种子数据已就绪'))
self.stdout.write(self.style.SUCCESS('=' * 60))
self.stdout.write(f'club_huiyuan_price 条数: {price_cnt}')
self.stdout.write('')
self.stdout.write('【组长】管事注册用这个邀请码guanshizhuce:')
self.stdout.write(f' UserUID={zz_user.UserUID} Phone={SEED_ZUZHANG["Phone"]}')
self.stdout.write(f' 组长邀请码 inviteCode = {zz_profile.yaoqingma}')
self.stdout.write('')
self.stdout.write('【管事】打手/接单员注册用这个邀请码dashouzhuce:')
self.stdout.write(f' UserUID={gs_user.UserUID} Phone={SEED_GUANSHI["Phone"]}')
self.stdout.write(f' 管事邀请码 inviteCode = {gs_profile.yaoqingma}')
self.stdout.write('')
self.stdout.write('商家:请在后台「商家管理 → 添加商家」按用户UID开通不再用前端邀请码')
self.stdout.write('')
self.stdout.write('新建: 组长=%s 管事=%s' % (
'' if zz_new or zz_profile_new else '否(已存在)',
'' if gs_new or gs_profile_new else '否(已存在)',
))
self.stdout.write(self.style.SUCCESS('=' * 60))

View File

@@ -18,6 +18,7 @@ from backend.view import (
KhgglView,
KefuGetDashouListView,
KefuGetShangjiaListView,
KefuAddShangjiaView,
PopupNoticeListAPIView,
PopupNoticeModifyAPIView,
ShgxgsjView,
@@ -123,6 +124,7 @@ urlpatterns = [
path('houtai/kefuhqdslb', KefuGetDashouListView.as_view(), name='jituan_dashou_list'),
path('houtai/hthqgslb', GetGuanliListView.as_view(), name='jituan_guanshi_list'),
path('houtai/hqsjgllb', KefuGetShangjiaListView.as_view(), name='jituan_shangjia_list'),
path('houtai/tjsj', KefuAddShangjiaView.as_view(), name='jituan_shangjia_add'),
path('houtai/hthqzzlb', GetZuzhangListView.as_view(), name='jituan_zuzhang_list'),
path('houtai/lunbo-list', ClubLunboListView.as_view(), name='jituan_lunbo_list'),
path('houtai/lunbo-manage', ClubLunboManageView.as_view(), name='jituan_lunbo_manage'),