Files
Django/jituan/services/fake_grab_switch.py

37 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""俱乐部级假单功能开关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:
return False
cfg = club.config_json or {}
return bool(cfg.get(CONFIG_KEY))
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