Files
along_django/utils/fadan_utils.py

51 lines
2.1 KiB
Python
Raw Permalink 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.
# utils/fadan_utils.py
from dingdan.models import Fadan
import logging
logger = logging.getLogger('xiaochengxu')
def check_fadan_qiangdan_eligible(yonghuid: str, action_type: int) -> tuple:
"""
通用罚单资格检查。
参数:
yonghuid : 被检查的用户 yonghuid
action_type : 1 = 抢单, 2 = 提现
返回:
(is_eligible: bool, message: str)
True 允许操作False 返回拦截原因。
"""
try:
if action_type == 1:
# 抢单:仅当存在“影响抢单”且“未解决”的罚单时拦截(待缴纳或申诉中)
blocked = Fadan.objects.filter(
beichufa_id=yonghuid,
yingxiang_qiangdan=1,
zhuangtai__in=[1, 3] # 1=待缴纳, 3=申诉中
).exists()
if blocked:
logger.info(f"用户 {yonghuid} 抢单被拦截:存在未解决的影响抢单罚单")
return (False, "您有未缴纳或申诉中的罚单,请先处理后再抢单")
return (True, "无罚单限制")
elif action_type == 2:
# 提现:只要存在任意未解决的罚单(待缴纳/申诉中),不论是否影响抢单,一律禁止提现
blocked = Fadan.objects.filter(
beichufa_id=yonghuid,
zhuangtai__in=[1, 3] # 1=待缴纳, 3=申诉中
).exists()
if blocked:
logger.info(f"用户 {yonghuid} 提现被拦截:存在未解决的罚单")
return (False, "您有未处理完的罚单,需全部完成或驳回后方可提现")
return (True, "罚单状态正常,可提现")
else:
logger.warning(f"未知的检查类型: {action_type}")
return (False, "罚单查询系统异常(无效的检查类型)")
except Exception as e:
logger.error(f"检查用户 {yonghuid} 罚单状态异常: {e}", exc_info=True)
# 安全起见,异常时禁止操作
return (False, "罚单查询系统繁忙,请稍后重试")