优化一下自动提现接口就是user/tixian_shenhe_servers.py,tixian_shenhe_views.py,让文件以及对应的申请,回调,确认接口,让它更好用一点,允许用户多次提现审核,强化收款接口,及时更新数据库中的收款状态,其次,更新了客服提现审核接口,关于大于200元的提现,同意之后直接按驳回处理,微信官方不支持大于200元的提现申请去掉了订单24小时或48小时自动结算的定时任务,将订单广播通知的任务,名称改成和新代码一样
This commit is contained in:
116
users/views.py
116
users/views.py
@@ -65,7 +65,10 @@ from .models import (
|
||||
)
|
||||
from .tixian_shenhe_services import (
|
||||
load_audit_meta_map, refund_balance, sync_audit_and_jilu_status,
|
||||
mark_transfer_success, release_collect_quota_for_record
|
||||
mark_transfer_success, release_collect_quota_for_record,
|
||||
close_audit_wechat_failed, query_wechat_transfer_bill,
|
||||
check_shijidaozhang_within_limit,
|
||||
WX_STATE_FAIL, WX_STATE_SUCCESS, WX_STATE_WAIT, WX_STATE_CANCELING,
|
||||
)
|
||||
from .tixian_shenhe_views import process_audit_collect
|
||||
|
||||
@@ -10046,6 +10049,18 @@ class KefuWithdrawActionView(APIView):
|
||||
raise ValueError(f'用户{req_yonghuid}不存在')
|
||||
|
||||
if action == 1:
|
||||
limit_ok, limit_msg = check_shijidaozhang_within_limit(audit.shijidaozhang)
|
||||
if not limit_ok:
|
||||
sync_audit_and_jilu_status(
|
||||
audit, 5,
|
||||
bhliyou=limit_msg,
|
||||
bo_hui_ren_id=kefu_user.yonghuid,
|
||||
)
|
||||
refund_balance(user, audit.leixing, audit.shijidaozhang)
|
||||
tixian.shenheid = kefu_user.yonghuid
|
||||
tixian.bhliyou = limit_msg
|
||||
tixian.save(update_fields=['shenheid', 'bhliyou', 'update_time'])
|
||||
raise ValueError(f'提现记录{tixian_id}:{limit_msg},已自动驳回并退款')
|
||||
sync_audit_and_jilu_status(audit, 6, shenhe_ren_id=kefu_user.yonghuid)
|
||||
tixian.shenheid = kefu_user.yonghuid
|
||||
tixian.save(update_fields=['shenheid', 'update_time'])
|
||||
@@ -12788,21 +12803,20 @@ class TixianCallbackV3View(APIView):
|
||||
auto_record.zhuangtai = 2
|
||||
auto_record.fail_reason = fail_reason or '微信转账失败'
|
||||
auto_record.save(update_fields=['zhuangtai', 'fail_reason'])
|
||||
release_collect_quota_for_record(auto_record)
|
||||
|
||||
if not auto_record.shenhe_danhao:
|
||||
logger.error('回调失败但打款记录无审核单号 bill=%s', out_bill_no)
|
||||
else:
|
||||
# 申请时已扣款,回调失败不退余额,恢复待收款(6)可重试
|
||||
try:
|
||||
audit = TixianShenheJilu.objects.select_for_update().get(
|
||||
shenhe_danhao=auto_record.shenhe_danhao
|
||||
)
|
||||
audit.tixian_auto_id = None
|
||||
audit.fail_reason = auto_record.fail_reason
|
||||
sync_audit_and_jilu_status(audit, 6, fail_reason=auto_record.fail_reason)
|
||||
close_audit_wechat_failed(
|
||||
audit, None, auto_record.fail_reason,
|
||||
)
|
||||
except TixianShenheJilu.DoesNotExist:
|
||||
logger.warning(f'回调失败但审核记录不存在: {auto_record.shenhe_danhao}')
|
||||
release_collect_quota_for_record(auto_record)
|
||||
|
||||
return Response({'code': 'SUCCESS', 'message': 'ok'})
|
||||
|
||||
@@ -12812,7 +12826,7 @@ class TixianQueRenAutoView(APIView):
|
||||
"""
|
||||
用户确认提现结果
|
||||
POST /yonghu/tixianqr
|
||||
新审核流程:打款记录带 shenhe_danhao 时,确认成功同步审核表+提现记录表为 2;取消不退款(申请已扣),恢复待收款 6 可重试
|
||||
以微信官方查单状态为准:SUCCESS 落库成功;FAIL/CANCELLED 关闭审核单+退款;进行中则提示等待
|
||||
"""
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
@@ -12847,37 +12861,79 @@ class TixianQueRenAutoView(APIView):
|
||||
if auto_record.zhuangtai == 1:
|
||||
return Response({'code': 0, 'msg': '提现成功', 'data': None})
|
||||
|
||||
if auto_record.zhuangtai != 0:
|
||||
return Response({'code': 5, 'msg': '该提现已处理'})
|
||||
wx_data = query_wechat_transfer_bill(tixian_id)
|
||||
if wx_data is None:
|
||||
return Response({'code': 12, 'msg': '系统正在核对微信状态,请稍后再试'})
|
||||
|
||||
mark_transfer_success(auto_record, with_accounting=True)
|
||||
if wx_data.get('_not_found'):
|
||||
return Response({'code': 12, 'msg': '收款处理中,请稍后再试'})
|
||||
|
||||
state = (wx_data.get('state') or '').upper()
|
||||
if state in WX_STATE_SUCCESS:
|
||||
mark_transfer_success(
|
||||
auto_record,
|
||||
wechat_transfer_no=wx_data.get('transfer_bill_no') or wx_data.get('transfer_no'),
|
||||
with_accounting=True,
|
||||
)
|
||||
return Response({'code': 0, 'msg': '提现成功', 'data': None})
|
||||
|
||||
if state in WX_STATE_FAIL:
|
||||
fail_reason = wx_data.get('fail_reason') or wx_data.get('close_reason') or state
|
||||
auto_record.zhuangtai = 2
|
||||
auto_record.fail_reason = str(fail_reason)[:500]
|
||||
auto_record.save(update_fields=['zhuangtai', 'fail_reason'])
|
||||
release_collect_quota_for_record(auto_record)
|
||||
if auto_record.shenhe_danhao:
|
||||
audit = TixianShenheJilu.objects.select_for_update().get(
|
||||
shenhe_danhao=auto_record.shenhe_danhao,
|
||||
)
|
||||
close_audit_wechat_failed(audit, None, auto_record.fail_reason)
|
||||
return Response({'code': 400, 'msg': '微信已确认转账失败,该笔提现已关闭,请联系客服处理'})
|
||||
|
||||
if state in WX_STATE_WAIT or state in WX_STATE_CANCELING:
|
||||
return Response({'code': 12, 'msg': '收款处理中,请在微信中完成或稍后再试'})
|
||||
|
||||
return Response({'code': 12, 'msg': '系统正在核对微信状态,请稍后再试'})
|
||||
|
||||
# 用户报告取消/失败:以微信查单为准,不本地盲目标记
|
||||
if auto_record.zhuangtai == 2:
|
||||
return Response({'code': 0, 'msg': '提现已取消', 'data': None})
|
||||
if auto_record.zhuangtai == 1:
|
||||
return Response({'code': 0, 'msg': '提现成功', 'data': None})
|
||||
|
||||
# 用户取消或失败
|
||||
auto_record.zhuangtai = 2
|
||||
auto_record.fail_reason = '用户取消收款'
|
||||
auto_record.save(update_fields=['zhuangtai', 'fail_reason'])
|
||||
wx_data = query_wechat_transfer_bill(tixian_id)
|
||||
if wx_data is None:
|
||||
return Response({'code': 12, 'msg': '系统正在核对微信状态,请稍后再试,切勿重复操作'})
|
||||
|
||||
if not auto_record.shenhe_danhao:
|
||||
logger.error('确认取消但打款记录无审核单号 bill=%s', tixian_id)
|
||||
return Response({'code': 5, 'msg': '该提现已处理'})
|
||||
if wx_data.get('_not_found'):
|
||||
return Response({'code': 12, 'msg': '收款处理中,请稍后再试'})
|
||||
|
||||
# 申请时已扣款,取消不退余额,审核单恢复 6 待收款,可再次点收款
|
||||
try:
|
||||
audit = TixianShenheJilu.objects.select_for_update().get(
|
||||
shenhe_danhao=auto_record.shenhe_danhao,
|
||||
state = (wx_data.get('state') or '').upper()
|
||||
if state in WX_STATE_SUCCESS:
|
||||
mark_transfer_success(
|
||||
auto_record,
|
||||
wechat_transfer_no=wx_data.get('transfer_bill_no') or wx_data.get('transfer_no'),
|
||||
with_accounting=True,
|
||||
)
|
||||
audit.tixian_auto_id = None
|
||||
sync_audit_and_jilu_status(
|
||||
audit, 6,
|
||||
fail_reason='用户取消收款,可重新发起',
|
||||
)
|
||||
except TixianShenheJilu.DoesNotExist:
|
||||
logger.warning(f'确认取消但审核记录不存在: {auto_record.shenhe_danhao}')
|
||||
release_collect_quota_for_record(auto_record)
|
||||
return Response({'code': 0, 'msg': '提现成功', 'data': None})
|
||||
|
||||
return Response({'code': 0, 'msg': '提现已取消', 'data': None})
|
||||
if state in WX_STATE_FAIL:
|
||||
fail_reason = wx_data.get('fail_reason') or wx_data.get('close_reason') or '用户取消收款'
|
||||
auto_record.zhuangtai = 2
|
||||
auto_record.fail_reason = str(fail_reason)[:500]
|
||||
auto_record.save(update_fields=['zhuangtai', 'fail_reason'])
|
||||
release_collect_quota_for_record(auto_record)
|
||||
if auto_record.shenhe_danhao:
|
||||
audit = TixianShenheJilu.objects.select_for_update().get(
|
||||
shenhe_danhao=auto_record.shenhe_danhao,
|
||||
)
|
||||
close_audit_wechat_failed(audit, None, auto_record.fail_reason)
|
||||
return Response({'code': 0, 'msg': '提现已关闭,请联系客服处理'})
|
||||
|
||||
if state in WX_STATE_WAIT or state in WX_STATE_CANCELING:
|
||||
return Response({'code': 12, 'msg': '收款仍在进行中,请在微信中操作或稍后再试'})
|
||||
|
||||
return Response({'code': 12, 'msg': '系统正在核对微信状态,请稍后再试'})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f'提现确认异常: {str(e)}', exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user