Files
along_django/peizhi/xieyi_service.py

57 lines
1.5 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.
"""协议签署校验 — 供接单/派单等接口调用"""
from rest_framework.response import Response
from peizhi.models import XcxXieyi, XcxXieyiQianshu
XIEYI_BLOCK_CODE = 4601
def get_unsigned_xieyi_list(yonghuid: str, shenfen: str):
"""返回未签署当前版本的必签协议列表"""
if not yonghuid or not shenfen:
return []
active = XcxXieyi.objects.filter(
shenfen=shenfen, is_active=True, must_sign=True,
).order_by('sort_order', 'id')
unsigned = []
for xieyi in active:
signed = XcxXieyiQianshu.objects.filter(
yonghuid=yonghuid,
xieyi_id=xieyi.id,
xieyi_version=xieyi.version,
).exists()
if not signed:
unsigned.append(xieyi)
return unsigned
def serialize_unsigned_brief(xieyi_list):
return [
{
'id': x.id,
'title': x.title,
'shenfen': x.shenfen,
'version': x.version,
}
for x in xieyi_list
]
def xieyi_required_response(unsigned_list):
return Response({
'code': XIEYI_BLOCK_CODE,
'msg': '请先阅读并签署用户协议',
'data': {
'all_signed': False,
'unsigned': serialize_unsigned_brief(unsigned_list),
},
})
def check_xieyi_or_response(yonghuid: str, shenfen: str):
"""未签署则返回 Response已签署返回 None"""
unsigned = get_unsigned_xieyi_list(yonghuid, shenfen)
if unsigned:
return xieyi_required_response(unsigned)
return None