From 728bac58ee408ad3be3b2808f4b097bcdde72aab Mon Sep 17 00:00:00 2001 From: XingQue Date: Tue, 14 Jul 2026 22:48:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E6=94=B6=E6=AC=BE=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=90=8E=E8=B7=B3=E8=BF=87=E8=AF=A5=E5=95=86=E6=88=B7?= =?UTF-8?q?=EF=BC=8C=E5=86=8D=E7=82=B9=E6=94=B6=E6=AC=BE=E5=8F=AF=E6=8D=A2?= =?UTF-8?q?=E5=8F=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- yonghu/tixian_shenhe_services.py | 9 +++++++-- yonghu/tixian_shenhe_views.py | 6 ++++++ yonghu/views.py | 26 ++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/yonghu/tixian_shenhe_services.py b/yonghu/tixian_shenhe_services.py index 9901fd3..9cbbcb1 100644 --- a/yonghu/tixian_shenhe_services.py +++ b/yonghu/tixian_shenhe_services.py @@ -1444,14 +1444,19 @@ def reconcile_shenhe_wechat_bills(shenhe_danhao): ) continue - # 已失败记录:仍问一遍微信,防本地误标 + # 已失败记录:仅当微信实际已到账才复活; + # 勿把 WAIT_USER_CONFIRM 再甩给前端(确认页受限后本地已放弃该户,必须换下一商户) if rec.zhuangtai == 2: wx_data = query_wechat_transfer_bill(rec.tixian_id) if wx_data is None or wx_data.get('_not_found'): continue action, payload = _sync_record_from_wx_query(rec, wx_data) - if action in (RECONCILE_COMPLETED, RECONCILE_WAIT_CONFIRM): + if action == RECONCILE_COMPLETED: return action, payload + logger.warning( + '本地已失败单忽略微信待确认 shenhe=%s bill=%s mch=%s action=%s', + shenhe_danhao, rec.tixian_id, rec.mch_id, action, + ) continue if pending_with_package: diff --git a/yonghu/tixian_shenhe_views.py b/yonghu/tixian_shenhe_views.py index ff74c4b..8411638 100644 --- a/yonghu/tixian_shenhe_views.py +++ b/yonghu/tixian_shenhe_views.py @@ -414,6 +414,12 @@ def process_audit_collect(request): [c.get('MCHID') for c in prefer_cfgs], ) mch_cfgs = prefer_cfgs + elif failed_mchs and not prefer_cfgs: + # 可用商户都失败过:仍按原序再试一轮(例如限额日切后可能恢复) + logger.warning( + '可用商户均曾失败,按原序再试 shenhe=%s failed=%s', + shenhe_danhao, sorted(failed_mchs), + ) _log_wx_collect( '开始轮换', shenhe=shenhe_danhao, diff --git a/yonghu/views.py b/yonghu/views.py index 45d76bb..146e1a0 100644 --- a/yonghu/views.py +++ b/yonghu/views.py @@ -13256,11 +13256,18 @@ class TixianQueRenAutoView(APIView): mark_transfer_success(auto_record, with_accounting=True) return Response({'code': 0, 'msg': '提现成功', 'data': None}) - # 用户取消或失败 + # 用户取消或失败(确认页被微信限额/受限常见) + raw_fail = (request.data.get('fail_reason') or request.data.get('errMsg') or '').strip() + fail_reason = (raw_fail or '用户取消收款')[:500] + abandoned_mch = (auto_record.mch_id or '').strip() auto_record.zhuangtai = 2 - auto_record.fail_reason = '用户取消收款' + auto_record.fail_reason = fail_reason auto_record.save(update_fields=['zhuangtai', 'fail_reason']) release_collect_quota_for_record(auto_record) + logger.error( + '【微信官方收款】确认失败已放弃商户 | bill=%s | mch_id=%s | reason=%s', + tixian_id, abandoned_mch, fail_reason, + ) if is_audit_flow: # 新审核流程:申请时已扣款,取消不退余额,审核单恢复 6 待收款,可再次点收款 @@ -13271,9 +13278,11 @@ class TixianQueRenAutoView(APIView): shenhe_danhao=auto_record.shenhe_danhao, ) audit.tixian_auto_id = None + if hasattr(audit, 'dakuan_mch_id'): + audit.dakuan_mch_id = '' sync_audit_and_jilu_status( audit, 6, - fail_reason='用户取消收款,可重新发起', + fail_reason='确认收款失败,可换其他商户重试', ) except TixianShenheJilu.DoesNotExist: logger.warning(f'确认取消但审核记录不存在: {auto_record.shenhe_danhao}') @@ -13299,7 +13308,16 @@ class TixianQueRenAutoView(APIView): zuzhang.save() decrease_tixian_daily_stat(auto_record.leixing, auto_record.shijidaozhang) - return Response({'code': 0, 'msg': '提现已取消', 'data': None}) + # 告知前端可立刻再调 tixiansq:会跳过刚失败的 mch_id 换下一户 + return Response({ + 'code': 0, + 'msg': '已记录失败,可换商户重试', + 'data': { + 'can_retry_switch': bool(is_audit_flow), + 'abandoned_mch_id': abandoned_mch, + 'fail_reason': fail_reason, + }, + }) except Exception as e: logger.error(f'提现确认异常: {str(e)}', exc_info=True)