fix: 全支付接口入口拦截小汐支付宝,微信支付路径不动
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -45,6 +45,15 @@ def assert_alipay_allowed_for_club(club_id=None):
|
||||
raise Exception(ALIPAY_DISABLED_MSG)
|
||||
|
||||
|
||||
def alipay_pay_method_block_reason(pay_method, club_id=None):
|
||||
"""支付接口入口:仅 pay_method=alipay 且俱乐部禁用时返回文案;微信/其它一律 None。"""
|
||||
if (pay_method or '').strip().lower() != 'alipay':
|
||||
return None
|
||||
if is_alipay_enabled_for_club(club_id):
|
||||
return None
|
||||
return ALIPAY_DISABLED_MSG
|
||||
|
||||
|
||||
# ==================== 配置读取 ====================
|
||||
|
||||
def get_alipay_config(club_id=None):
|
||||
|
||||
@@ -872,6 +872,10 @@ class CreateOrderView(APIView):
|
||||
|
||||
# 6. 查询利率并计算分成
|
||||
club_id = resolve_club_id_from_request(request)
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, club_id)
|
||||
if _alipay_block:
|
||||
return Response({'code': 99, 'msg': _alipay_block, 'data': None})
|
||||
dashou_lilu = get_commission_rate_object(club_id, '1')
|
||||
|
||||
|
||||
@@ -1234,6 +1238,12 @@ class ContinuePayView(APIView):
|
||||
logger.warning('续付越权 dingdanid=%s uid=%s', dingdanid, current_user.UserUID)
|
||||
return Response({'code': 403, 'msg': '无权操作此订单', 'data': None})
|
||||
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
_club_for_alipay = getattr(dingdan, 'ClubID', None) or resolve_club_id_from_request(request)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, _club_for_alipay)
|
||||
if _alipay_block:
|
||||
return Response({'code': 99, 'msg': _alipay_block, 'data': None})
|
||||
|
||||
# 已进入正常履约/服务流程:不得再拉起支付,也不得改状态
|
||||
if dingdan.Status in (1, 7):
|
||||
return Response({
|
||||
|
||||
@@ -130,6 +130,16 @@ class ShangjiaChongzhi(APIView):
|
||||
'message': f'充值金额必须在{settings.SHANGJIA_CZ_MIN_AMOUNT}-{settings.SHANGJIA_CZ_MAX_AMOUNT}元之间'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, pay_club)
|
||||
if _alipay_block:
|
||||
return Response({
|
||||
'code': 400,
|
||||
'message': _alipay_block,
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 3. 生成订单ID(使用配置的前缀)
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_ns = int(time.time_ns() // 1000) % 1000000
|
||||
@@ -146,7 +156,7 @@ class ShangjiaChongzhi(APIView):
|
||||
jine=jine,
|
||||
leixing=4, # 充值类型:4=商家充值
|
||||
shuoming=settings.SHANGJIA_CZ_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
logger.info(f"创建商家充值订单: 商家{shangjia.nicheng}, 订单{dingdanid}, 金额{jine}元")
|
||||
except Exception as e:
|
||||
@@ -157,7 +167,6 @@ class ShangjiaChongzhi(APIView):
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
# 5. 生成支付参数(支持支付宝/微信)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
@@ -165,7 +174,7 @@ class ShangjiaChongzhi(APIView):
|
||||
dingdanid=dingdanid,
|
||||
jine=jine,
|
||||
subject=settings.SHANGJIA_CZ_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
except Exception as e:
|
||||
chongzhi_jilu.delete()
|
||||
@@ -176,7 +185,6 @@ class ShangjiaChongzhi(APIView):
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
else:
|
||||
try:
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
pay_openid, _ = get_payment_openid(request, club_id=pay_club)
|
||||
if not pay_openid:
|
||||
chongzhi_jilu.delete()
|
||||
|
||||
@@ -125,6 +125,15 @@ class HuiyuanGoumai(APIView):
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
from jituan.services.member_recharge import validate_member_purchase
|
||||
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, club_id)
|
||||
if _alipay_block:
|
||||
return Response({
|
||||
'code': 400,
|
||||
'message': _alipay_block,
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
ok, err_msg, club_price, purchase_days = validate_member_purchase(
|
||||
request.user.UserUID, huiyuanid, club_id, is_trial,
|
||||
)
|
||||
@@ -165,7 +174,6 @@ class HuiyuanGoumai(APIView):
|
||||
f"金额{jine}元, 天数{purchase_days}")
|
||||
|
||||
# 7. 生成支付参数(支持支付宝/微信)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
|
||||
@@ -111,6 +111,17 @@ class JifenBuchong(APIView):
|
||||
'message': '积分已满,无需补充'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, pay_club)
|
||||
if _alipay_block:
|
||||
return Response({
|
||||
'code': 400,
|
||||
'message': _alipay_block,
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 4. 生成订单ID(前缀CzJF表示积分充值)
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_ns = int(time.time_ns() // 1000) % 1000000
|
||||
@@ -127,13 +138,12 @@ class JifenBuchong(APIView):
|
||||
jine=jine,
|
||||
leixing=3, # 充值类型:3=积分
|
||||
shuoming=settings.JIFEN_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
|
||||
logger.info(f"创建积分充值订单: 用户{request.user.UserUID}, 订单{dingdanid}, 金额{jine}元")
|
||||
|
||||
# 6. 生成支付参数(支持支付宝/微信)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
@@ -141,7 +151,7 @@ class JifenBuchong(APIView):
|
||||
dingdanid=dingdanid,
|
||||
jine=jine,
|
||||
subject=settings.JIFEN_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
except Exception as e:
|
||||
chongzhi_jilu.delete()
|
||||
@@ -152,7 +162,6 @@ class JifenBuchong(APIView):
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
else:
|
||||
try:
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
pay_openid, _ = get_payment_openid(request, club_id=pay_club)
|
||||
if not pay_openid:
|
||||
chongzhi_jilu.delete()
|
||||
|
||||
@@ -126,6 +126,17 @@ class YajinGoumai(APIView):
|
||||
'message': '充值金额必须在1-10000元之间'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, pay_club)
|
||||
if _alipay_block:
|
||||
return Response({
|
||||
'code': 400,
|
||||
'message': _alipay_block,
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# 3. 生成订单ID(使用你提供的算法,前缀改为CzYJ)
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_ns = int(time.time_ns() // 1000) % 1000000
|
||||
@@ -141,13 +152,12 @@ class YajinGoumai(APIView):
|
||||
jine=jine,
|
||||
leixing=2, # 充值类型:2=押金
|
||||
shuoming=settings.YAJIN_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
|
||||
logger.info(f"创建押金充值订单: 用户{request.user.UserUID}, 订单{dingdanid}, 金额{jine}元")
|
||||
|
||||
# 5. 生成支付参数(支持支付宝/微信)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
@@ -155,7 +165,7 @@ class YajinGoumai(APIView):
|
||||
dingdanid=dingdanid,
|
||||
jine=jine,
|
||||
subject=settings.YAJIN_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, request.user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
except Exception as e:
|
||||
chongzhi_jilu.delete()
|
||||
@@ -166,7 +176,6 @@ class YajinGoumai(APIView):
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
else:
|
||||
try:
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
pay_openid, _ = get_payment_openid(request, club_id=pay_club)
|
||||
if not pay_openid:
|
||||
chongzhi_jilu.delete()
|
||||
|
||||
@@ -222,6 +222,10 @@ class ZhuanpanGoumai(APIView):
|
||||
return Response({'code': 400, 'message': '请填写游戏昵称'}, status=400)
|
||||
|
||||
club_id = resolve_club_id_for_write(request, request.user)
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, club_id)
|
||||
if _alipay_block:
|
||||
return Response({'code': 400, 'message': _alipay_block}, status=400)
|
||||
huodong = None
|
||||
if huodong_id:
|
||||
huodong = ZhuanpanHuodong.query.filter(
|
||||
|
||||
@@ -122,6 +122,18 @@ class FaKuanPayView(APIView):
|
||||
|
||||
jine = float(fadan.FineAmount)
|
||||
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, pay_club)
|
||||
if _alipay_block:
|
||||
return Response({
|
||||
'code': 400,
|
||||
'message': _alipay_block,
|
||||
'msg': _alipay_block,
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_ns = int(time.time_ns() // 1000) % 1000000
|
||||
random_num = random.randint(0, 99)
|
||||
@@ -144,9 +156,6 @@ class FaKuanPayView(APIView):
|
||||
# 生成支付参数(支持支付宝/微信)
|
||||
# 支付必须用「当前小程序/打手写入俱乐部」的 AppID+openid;
|
||||
# 与罚单 ClubID(申请人俱乐部)混用会导致部分人 openid/appid 不一致而下单失败。
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
pay_club = resolve_club_id_for_write(request, request.user)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
@@ -623,6 +632,14 @@ class KaohePayView(APIView):
|
||||
logger.warning(f"费用为0,应使用免费申请接口,tag_id={tag_id}, cishu={new_cishu}")
|
||||
return Response({'code': 400, 'message': '本次费用为0,请直接使用免费申请接口'})
|
||||
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
from jituan.services.alipay_pay import alipay_pay_method_block_reason
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
pay_club = resolve_club_id_for_write(request, user)
|
||||
_alipay_block = alipay_pay_method_block_reason(pay_method, pay_club)
|
||||
if _alipay_block:
|
||||
return Response({'code': 400, 'message': _alipay_block})
|
||||
|
||||
# 7. 生成订单ID
|
||||
timestamp_ms = int(time.time() * 1000)
|
||||
timestamp_ns = int(time.time_ns() // 1000) % 1000000
|
||||
@@ -631,7 +648,6 @@ class KaohePayView(APIView):
|
||||
logger.info(f"生成订单ID: {dingdanid}")
|
||||
|
||||
# 8. 创建支付订单(Czjilu)
|
||||
from jituan.services.club_write import resolve_club_id_for_write
|
||||
order = Czjilu.query.create(
|
||||
dingdan_id=dingdanid,
|
||||
zhuangtai=9, # 未支付
|
||||
@@ -639,7 +655,7 @@ class KaohePayView(APIView):
|
||||
jine=float(fee),
|
||||
leixing=5, # 5-考核支付
|
||||
shuoming=settings.KAOHE_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
logger.info(f"创建支付订单成功: {dingdanid}")
|
||||
|
||||
@@ -669,7 +685,6 @@ class KaohePayView(APIView):
|
||||
logger.info(f"attach内容: {attach_str},长度: {len(attach_str.encode('utf-8'))}字节")
|
||||
|
||||
# 11. 生成支付参数(支持支付宝/微信)
|
||||
pay_method = (request.data.get('pay_method') or request.data.get('payMethod') or 'wechat').lower()
|
||||
if pay_method == 'alipay':
|
||||
try:
|
||||
from jituan.services.alipay_pay import generate_alipay_czjilu_pay_params
|
||||
@@ -677,7 +692,7 @@ class KaohePayView(APIView):
|
||||
dingdanid=dingdanid,
|
||||
jine=float(fee),
|
||||
subject=settings.KAOHE_PAY_DESCRIPTION,
|
||||
club_id=resolve_club_id_for_write(request, user),
|
||||
club_id=pay_club,
|
||||
)
|
||||
logger.info(f"支付宝支付参数生成成功: {dingdanid}")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user