42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""俱乐部级假单功能开关(config_json.fake_grab_order_enabled)。"""
|
||
import logging
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
CONFIG_KEY = 'fake_grab_order_enabled'
|
||
|
||
|
||
def is_club_fake_grab_enabled(club_id: str) -> bool:
|
||
"""某俱乐部是否对打手侧开启假单池。默认关闭。"""
|
||
cid = (club_id or '').strip()
|
||
if not cid:
|
||
return False
|
||
try:
|
||
from django.conf import settings
|
||
if not getattr(settings, 'FAKE_GRAB_ORDER_POOL_ENABLED', True):
|
||
return False
|
||
except Exception:
|
||
pass
|
||
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 False
|
||
cfg = club.config_json or {}
|
||
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 fake_grab_order_enabled failed club=%s', cid)
|
||
return False
|
||
|
||
|
||
def set_club_fake_grab_enabled(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
|