feat: 俱乐部可关闭强制收集手机号(yhbdsjh 返回无需认证)
This commit is contained in:
@@ -269,6 +269,16 @@ class CheckPhoneAuthView(APIView):
|
||||
except User.DoesNotExist:
|
||||
user = request.user
|
||||
|
||||
# 俱乐部关闭强制收集手机号 → 前端 ensurePhoneAuth 不再跳转认证页
|
||||
try:
|
||||
from jituan.services.club_context import resolve_effective_club_id
|
||||
from jituan.services.force_phone_auth import is_club_force_phone_auth
|
||||
club_id = resolve_effective_club_id(request, user)
|
||||
if not is_club_force_phone_auth(club_id):
|
||||
return Response({'code': 0, 'need_auth': False})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if self._phone_auth_completed(user):
|
||||
return Response({'code': 0, 'need_auth': False})
|
||||
|
||||
|
||||
40
jituan/services/force_phone_auth.py
Normal file
40
jituan/services/force_phone_auth.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""俱乐部是否强制收集手机号(config_json.force_phone_auth)。"""
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_KEY = 'force_phone_auth'
|
||||
|
||||
|
||||
def is_club_force_phone_auth(club_id: str) -> bool:
|
||||
"""
|
||||
是否强制手机号认证。默认 True(与现网一致:门槛用户未认证则 need_auth)。
|
||||
后台关闭后,/peizhi/yhbdsjh 恒返回 need_auth=False,前端不会再强制跳认证页。
|
||||
"""
|
||||
cid = (club_id or '').strip()
|
||||
if not cid:
|
||||
return True
|
||||
try:
|
||||
from jituan.models import Club
|
||||
club = Club.query.filter(club_id=cid).first()
|
||||
if not club and cid != cid.lower():
|
||||
club = Club.query.filter(club_id=cid.lower()).first()
|
||||
if not club:
|
||||
return True
|
||||
cfg = club.config_json or {}
|
||||
if CONFIG_KEY not in cfg:
|
||||
return True
|
||||
raw = cfg.get(CONFIG_KEY)
|
||||
if isinstance(raw, str):
|
||||
return raw.strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
return bool(raw)
|
||||
except Exception:
|
||||
logger.exception('read force_phone_auth failed club=%s', cid)
|
||||
return True
|
||||
|
||||
|
||||
def set_club_force_phone_auth(club, enabled: bool) -> None:
|
||||
"""写入 club.config_json,调用方负责 save。"""
|
||||
cfg = dict(getattr(club, 'config_json', None) or {})
|
||||
cfg[CONFIG_KEY] = bool(enabled)
|
||||
club.config_json = cfg
|
||||
@@ -632,6 +632,7 @@ class ClubManageView(APIView):
|
||||
|
||||
def _serialize(self, club, full=False):
|
||||
from jituan.services.default_invite import get_club_default_dashou_invite
|
||||
from jituan.services.force_phone_auth import is_club_force_phone_auth
|
||||
|
||||
cfg_json = club.config_json or {}
|
||||
base = {
|
||||
@@ -649,6 +650,7 @@ class ClubManageView(APIView):
|
||||
'template_id': club.template_id,
|
||||
'sort_order': club.sort_order,
|
||||
'default_dashou_invite': get_club_default_dashou_invite(club.club_id),
|
||||
'force_phone_auth': is_club_force_phone_auth(club.club_id),
|
||||
}
|
||||
if full:
|
||||
mch_key = self._effective_mch_key(club)
|
||||
@@ -724,6 +726,16 @@ class ClubManageView(APIView):
|
||||
set_club_default_dashou_invite(club, request.data.get('default_dashou_invite'))
|
||||
if 'config_json' not in update_fields:
|
||||
update_fields.append('config_json')
|
||||
if 'force_phone_auth' in request.data:
|
||||
from jituan.services.force_phone_auth import set_club_force_phone_auth
|
||||
raw = request.data.get('force_phone_auth')
|
||||
if isinstance(raw, str):
|
||||
enabled = raw.strip().lower() in ('1', 'true', 'yes', 'on')
|
||||
else:
|
||||
enabled = bool(raw)
|
||||
set_club_force_phone_auth(club, enabled)
|
||||
if 'config_json' not in update_fields:
|
||||
update_fields.append('config_json')
|
||||
if update_fields:
|
||||
club.save(update_fields=update_fields)
|
||||
return Response({
|
||||
|
||||
Reference in New Issue
Block a user