仅商户整户额度可换号,并支持后台用户绑定固定收款商户。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
@@ -88,6 +88,62 @@ def list_enabled_wx_cfgs() -> List[Dict]:
|
||||
return []
|
||||
|
||||
|
||||
def get_bound_mch_id(yonghuid: str) -> Optional[str]:
|
||||
"""启用中的用户绑定商户号;无绑定返回 None。"""
|
||||
yonghuid = str(yonghuid or '').strip()
|
||||
if not yonghuid:
|
||||
return None
|
||||
from peizhi.models import UserWechatMchBind
|
||||
|
||||
row = (
|
||||
UserWechatMchBind.objects.filter(yonghuid=yonghuid, enabled=True)
|
||||
.only('mch_id')
|
||||
.first()
|
||||
)
|
||||
if not row:
|
||||
return None
|
||||
return (row.mch_id or '').strip() or None
|
||||
|
||||
|
||||
def list_wx_cfgs_for_collect(yonghuid: str) -> Tuple[List[Dict], Optional[str], bool]:
|
||||
"""
|
||||
收款选户:
|
||||
- 有启用绑定 → 仅返回该一户配置;证书不全/不存在则报错,绝不偷偷落到默认户
|
||||
- 无绑定 → list_enabled_wx_cfgs()
|
||||
返回 (cfgs, err_msg, is_user_bound)
|
||||
"""
|
||||
bound_mch = get_bound_mch_id(yonghuid)
|
||||
if not bound_mch:
|
||||
cfgs = list_enabled_wx_cfgs()
|
||||
return cfgs, None, False
|
||||
|
||||
cfg = get_wx_cfg_by_mch_id(bound_mch)
|
||||
if not cfg or not wx_cfg_is_complete(cfg):
|
||||
logger.error(
|
||||
'用户绑定商户不可用 yonghuid=%s mch_id=%s',
|
||||
yonghuid, bound_mch,
|
||||
)
|
||||
return [], (
|
||||
f'该用户已绑定商户号 {bound_mch},但配置不完整或未启用,'
|
||||
f'请在后台检查证书/启用状态或改绑'
|
||||
), True
|
||||
|
||||
# 绑定户若在配置表被停用:get_wx_cfg_by_mch_id 仍可能因私钥完整返回 cfg,
|
||||
# 强制要求绑定目标在启用列表或行本身 enabled
|
||||
from peizhi.models import WechatPayMchConfig
|
||||
row = WechatPayMchConfig.objects.filter(mch_id=bound_mch).first()
|
||||
if row is not None and not row.enabled:
|
||||
return [], (
|
||||
f'该用户已绑定商户号 {bound_mch},但该商户已停用,请后台改绑或重新启用'
|
||||
), True
|
||||
|
||||
logger.warning(
|
||||
'收款使用用户绑定商户 yonghuid=%s mch_id=%s(强制单户,不轮换)',
|
||||
yonghuid, bound_mch,
|
||||
)
|
||||
return [cfg], None, True
|
||||
|
||||
|
||||
def list_wx_cfgs_for_callback() -> List[Dict]:
|
||||
"""
|
||||
回调验签/解密:包含已停用商户。
|
||||
|
||||
Reference in New Issue
Block a user