Browse Source

上传商品购买页面逻辑代码

weicu
liwei1dao 11 months ago
parent
commit
636551c4ea
  1. 20
      lib/modules/goods/controllers/goods_base_controller.dart

20
lib/modules/goods/controllers/goods_base_controller.dart

@ -99,6 +99,8 @@ abstract class GoodsBaseController extends GetxController {
bool ok = false; bool ok = false;
String failMsg = '支付失败,请重试'; String failMsg = '支付失败,请重试';
isPaying.value = true;
_startPayingTimeout();
if (method == _PayMethod.wechat) { if (method == _PayMethod.wechat) {
ok = await payWechat(item, onResult: (success, msg) { ok = await payWechat(item, onResult: (success, msg) {
if (!success) failMsg = msg ?? failMsg; if (!success) failMsg = msg ?? failMsg;
@ -454,9 +456,13 @@ abstract class GoodsBaseController extends GetxController {
// 先透传给外部回调 // 先透传给外部回调
onResult?.call(success, msg); onResult?.call(success, msg);
if (success) { if (success) {
isPaying.value = false;
_cancelPayingTimeout();
await _confirmOrderAndShow(orderId, await _confirmOrderAndShow(orderId,
channel: '微信', initialMessage: msg); channel: '微信', initialMessage: msg);
} else { } else {
isPaying.value = false;
_cancelPayingTimeout();
_showPayResultDialog(false, msg ?? '支付失败'); _showPayResultDialog(false, msg ?? '支付失败');
} }
}, },
@ -483,9 +489,13 @@ abstract class GoodsBaseController extends GetxController {
onResult: (success, msg) async { onResult: (success, msg) async {
onResult?.call(success, msg); onResult?.call(success, msg);
if (success) { if (success) {
isPaying.value = false;
_cancelPayingTimeout();
await _confirmOrderAndShow(orderId, await _confirmOrderAndShow(orderId,
channel: '支付宝', initialMessage: msg); channel: '支付宝', initialMessage: msg);
} else { } else {
isPaying.value = false;
_cancelPayingTimeout();
_showPayResultDialog(false, msg ?? '支付失败'); _showPayResultDialog(false, msg ?? '支付失败');
} }
}, },
@ -506,9 +516,6 @@ abstract class GoodsBaseController extends GetxController {
onResult?.call(false, '创建 Apple 订单失败'); onResult?.call(false, '创建 Apple 订单失败');
return false; return false;
} }
isPaying.value = true;
_startPayingTimeout();
// 使用商品id作为内购的 productId(与后台保持一致) // 使用商品id作为内购的 productId(与后台保持一致)
final productId = item.id; final productId = item.id;
// 解析为 App Store 的真实商品ID(支持前缀/映射) // 解析为 App Store 的真实商品ID(支持前缀/映射)
@ -819,7 +826,10 @@ abstract class GoodsBaseController extends GetxController {
final host = uri.host; final host = uri.host;
final path = uri.path; final path = uri.path;
if (scheme == 'deepvoiceclient' && host == 'paypal') { if (scheme == 'deepvoiceclient' && host == 'paypal') {
isPaying.value = false;
if (path == '/return') { if (path == '/return') {
isPaying.value = false;
_cancelPayingTimeout();
print('[PayPal] 检测到 /return,使用 orderId 回查: $orderId'); print('[PayPal] 检测到 /return,使用 orderId 回查: $orderId');
await _confirmOrderAndShow( await _confirmOrderAndShow(
orderId, orderId,
@ -829,6 +839,8 @@ abstract class GoodsBaseController extends GetxController {
intervalMs: 0, intervalMs: 0,
); );
} else if (path == '/cancel') { } else if (path == '/cancel') {
isPaying.value = false;
_cancelPayingTimeout();
_showPayResultDialog(false, '已取消支付'); _showPayResultDialog(false, '已取消支付');
} }
// 一次性监听,处理后即取消 // 一次性监听,处理后即取消
@ -836,6 +848,8 @@ abstract class GoodsBaseController extends GetxController {
_deeplinkSub = null; _deeplinkSub = null;
} }
}, onError: (e) { }, onError: (e) {
isPaying.value = false;
_cancelPayingTimeout();
// 忽略监听错误,保持现有轮询逻辑 // 忽略监听错误,保持现有轮询逻辑
}); });
return _payService.paypalPay( return _payService.paypalPay(

Loading…
Cancel
Save