77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
"""俱乐部打手聊天门槛(config_json)。
|
|
|
|
默认与现网一致:不充会员不可聊,但押金达到门槛可聊;进行中订单旁路保留。
|
|
开启 allow_without_member 后:打手无需会员也可聊。
|
|
"""
|
|
import logging
|
|
from decimal import Decimal, InvalidOperation
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
ALLOW_WITHOUT_MEMBER_KEY = 'dashou_chat_allow_without_member'
|
|
YAJIN_THRESHOLD_KEY = 'dashou_chat_yajin_threshold'
|
|
DEFAULT_YAJIN_THRESHOLD = Decimal('5')
|
|
|
|
|
|
def _club(club_id: str):
|
|
cid = (club_id or '').strip()
|
|
if not cid:
|
|
return None
|
|
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()
|
|
return club
|
|
|
|
|
|
def is_dashou_chat_allow_without_member(club_id: str) -> bool:
|
|
"""开启=不充会员也能聊;关闭(默认)=须会员或押金达标等。"""
|
|
club = _club(club_id)
|
|
if not club:
|
|
return False
|
|
try:
|
|
cfg = club.config_json or {}
|
|
raw = cfg.get(ALLOW_WITHOUT_MEMBER_KEY, False)
|
|
if isinstance(raw, str):
|
|
return raw.strip().lower() in ('1', 'true', 'yes', 'on')
|
|
return bool(raw)
|
|
except Exception:
|
|
logger.exception('read dashou_chat_allow_without_member failed club=%s', club_id)
|
|
return False
|
|
|
|
|
|
def get_dashou_chat_yajin_threshold(club_id: str) -> Decimal:
|
|
"""无会员时押金门槛;默认 5(与现网硬编码一致)。"""
|
|
club = _club(club_id)
|
|
if not club:
|
|
return DEFAULT_YAJIN_THRESHOLD
|
|
try:
|
|
cfg = club.config_json or {}
|
|
if YAJIN_THRESHOLD_KEY not in cfg:
|
|
return DEFAULT_YAJIN_THRESHOLD
|
|
return Decimal(str(cfg.get(YAJIN_THRESHOLD_KEY) or DEFAULT_YAJIN_THRESHOLD))
|
|
except (InvalidOperation, TypeError, ValueError):
|
|
return DEFAULT_YAJIN_THRESHOLD
|
|
except Exception:
|
|
logger.exception('read dashou_chat_yajin_threshold failed club=%s', club_id)
|
|
return DEFAULT_YAJIN_THRESHOLD
|
|
|
|
|
|
def set_dashou_chat_allow_without_member(club, enabled: bool) -> None:
|
|
cfg = dict(getattr(club, 'config_json', None) or {})
|
|
cfg[ALLOW_WITHOUT_MEMBER_KEY] = bool(enabled)
|
|
club.config_json = cfg
|
|
|
|
|
|
def set_dashou_chat_yajin_threshold(club, threshold) -> Decimal:
|
|
try:
|
|
val = Decimal(str(threshold))
|
|
except (InvalidOperation, TypeError, ValueError):
|
|
val = DEFAULT_YAJIN_THRESHOLD
|
|
if val < 0:
|
|
val = Decimal('0')
|
|
cfg = dict(getattr(club, 'config_json', None) or {})
|
|
cfg[YAJIN_THRESHOLD_KEY] = float(val)
|
|
club.config_json = cfg
|
|
return val
|