From 636551c4ea9a7284f3969e1f630aebc7380425b8 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 26 Nov 2025 17:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=95=86=E5=93=81=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E9=A1=B5=E9=9D=A2=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/goods_base_controller.dart | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/modules/goods/controllers/goods_base_controller.dart b/lib/modules/goods/controllers/goods_base_controller.dart index 17dd976df..4e0807463 100644 --- a/lib/modules/goods/controllers/goods_base_controller.dart +++ b/lib/modules/goods/controllers/goods_base_controller.dart @@ -99,6 +99,8 @@ abstract class GoodsBaseController extends GetxController { bool ok = false; String failMsg = '支付失败,请重试'; + isPaying.value = true; + _startPayingTimeout(); if (method == _PayMethod.wechat) { ok = await payWechat(item, onResult: (success, msg) { if (!success) failMsg = msg ?? failMsg; @@ -454,9 +456,13 @@ abstract class GoodsBaseController extends GetxController { // 先透传给外部回调 onResult?.call(success, msg); if (success) { + isPaying.value = false; + _cancelPayingTimeout(); await _confirmOrderAndShow(orderId, channel: '微信', initialMessage: msg); } else { + isPaying.value = false; + _cancelPayingTimeout(); _showPayResultDialog(false, msg ?? '支付失败'); } }, @@ -483,9 +489,13 @@ abstract class GoodsBaseController extends GetxController { onResult: (success, msg) async { onResult?.call(success, msg); if (success) { + isPaying.value = false; + _cancelPayingTimeout(); await _confirmOrderAndShow(orderId, channel: '支付宝', initialMessage: msg); } else { + isPaying.value = false; + _cancelPayingTimeout(); _showPayResultDialog(false, msg ?? '支付失败'); } }, @@ -506,9 +516,6 @@ abstract class GoodsBaseController extends GetxController { onResult?.call(false, '创建 Apple 订单失败'); return false; } - isPaying.value = true; - _startPayingTimeout(); - // 使用商品id作为内购的 productId(与后台保持一致) final productId = item.id; // 解析为 App Store 的真实商品ID(支持前缀/映射) @@ -819,7 +826,10 @@ abstract class GoodsBaseController extends GetxController { final host = uri.host; final path = uri.path; if (scheme == 'deepvoiceclient' && host == 'paypal') { + isPaying.value = false; if (path == '/return') { + isPaying.value = false; + _cancelPayingTimeout(); print('[PayPal] 检测到 /return,使用 orderId 回查: $orderId'); await _confirmOrderAndShow( orderId, @@ -829,6 +839,8 @@ abstract class GoodsBaseController extends GetxController { intervalMs: 0, ); } else if (path == '/cancel') { + isPaying.value = false; + _cancelPayingTimeout(); _showPayResultDialog(false, '已取消支付'); } // 一次性监听,处理后即取消 @@ -836,6 +848,8 @@ abstract class GoodsBaseController extends GetxController { _deeplinkSub = null; } }, onError: (e) { + isPaying.value = false; + _cancelPayingTimeout(); // 忽略监听错误,保持现有轮询逻辑 }); return _payService.paypalPay(