feat: 抢单失败返回 fail_type,供前端跳转会员/押金页
This commit is contained in:
@@ -509,7 +509,11 @@ class QiangdanView(APIView):
|
||||
|
||||
dingdan_id = str(dingdan_id).strip()
|
||||
if dingdan_id.upper().startswith('JD'):
|
||||
return Response({'code': 400, 'msg': '您没充值会员或保证金不可接单'})
|
||||
return Response({
|
||||
'code': 400,
|
||||
'msg': '您没充值会员或保证金不可接单',
|
||||
'fail_type': 'huiyuan',
|
||||
})
|
||||
|
||||
try:
|
||||
with transaction.atomic():
|
||||
@@ -545,7 +549,18 @@ class QiangdanView(APIView):
|
||||
|
||||
validation_result = self._validate_order_requirements(order, dashou_profile, request.user.UserUID)
|
||||
if not validation_result['success']:
|
||||
return Response({'code': 400, 'msg': validation_result['message']})
|
||||
payload = {
|
||||
'code': 400,
|
||||
'msg': validation_result['message'],
|
||||
}
|
||||
# 结构化失败类型,供前端跳转会员/押金页(不影响旧客户端)
|
||||
if validation_result.get('fail_type'):
|
||||
payload['fail_type'] = validation_result['fail_type']
|
||||
if validation_result.get('huiyuan_id') is not None:
|
||||
payload['huiyuan_id'] = validation_result['huiyuan_id']
|
||||
if validation_result.get('required_yajin') is not None:
|
||||
payload['required_yajin'] = validation_result['required_yajin']
|
||||
return Response(payload)
|
||||
self._execute_qiangdan(order, dashou_profile, request.user.UserUID)
|
||||
|
||||
# 建聊必须在事务提交后:GoEasy HTTP 不可放在行锁事务里,失败也不回滚抢单
|
||||
@@ -630,6 +645,7 @@ class QiangdanView(APIView):
|
||||
from jituan.services.huiyuan_bundle import (
|
||||
user_has_huiyuan_access_any,
|
||||
resolve_order_membership_ids,
|
||||
normalize_huiyuan_id,
|
||||
)
|
||||
from jituan.services.club_context import resolve_effective_club_id
|
||||
|
||||
@@ -646,13 +662,36 @@ class QiangdanView(APIView):
|
||||
required_ids = resolve_order_membership_ids(order_dict)
|
||||
if user_has_huiyuan_access_any(dashou_yonghuid, required_ids, club_id=club_id):
|
||||
return {'success': True, 'message': '会员验证通过'}
|
||||
return {'success': False, 'message': '未开通对应会员或会员已过期,无法抢此订单'}
|
||||
primary = ''
|
||||
if required_ids:
|
||||
primary = normalize_huiyuan_id(required_ids[0]) or str(required_ids[0])
|
||||
elif order.MembershipID:
|
||||
primary = normalize_huiyuan_id(order.MembershipID) or str(order.MembershipID)
|
||||
return {
|
||||
'success': False,
|
||||
'message': '未开通对应会员或会员已过期,无法抢此订单',
|
||||
'fail_type': 'huiyuan',
|
||||
'huiyuan_id': primary,
|
||||
}
|
||||
|
||||
def _validate_yajin_requirement(self, order, dashou_profile):
|
||||
yajin_required = order.CommissionReq or 0
|
||||
dashou_yajin = dashou_profile.yajin or 0
|
||||
if dashou_yajin < yajin_required:
|
||||
return {'success': False, 'message': f'押金不足,需要{yajin_required}元,当前有{dashou_yajin}元'}
|
||||
try:
|
||||
need = float(yajin_required)
|
||||
except (TypeError, ValueError):
|
||||
need = 0.0
|
||||
try:
|
||||
have = float(dashou_yajin)
|
||||
except (TypeError, ValueError):
|
||||
have = 0.0
|
||||
if have < need:
|
||||
return {
|
||||
'success': False,
|
||||
'message': f'押金不足,需要{need}元,当前有{have}元',
|
||||
'fail_type': 'yajin',
|
||||
'required_yajin': need,
|
||||
}
|
||||
return {'success': True, 'message': '押金验证通过'}
|
||||
|
||||
def _execute_qiangdan(self, order, dashou_profile, dashou_yonghuid):
|
||||
|
||||
Reference in New Issue
Block a user