member_controller.dart 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'dart:math';
  4. import 'package:agile_pay/flutter_pay.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:get/get.dart';
  8. import 'package:injectable/injectable.dart';
  9. import 'package:location/base/base_controller.dart';
  10. import 'package:location/data/bean/goods_bean.dart';
  11. import 'package:location/data/bean/pay_item_bean.dart';
  12. import 'package:location/data/repositories/account_repository.dart';
  13. import 'package:location/data/repositories/member_repository.dart';
  14. import 'package:location/dialog/alipay_qr_code_dialog.dart';
  15. import 'package:location/handler/error_handler.dart';
  16. import 'package:location/module/login/login_page.dart';
  17. import 'package:location/resource/assets.gen.dart';
  18. import 'package:location/utils/async_util.dart';
  19. import 'package:location/utils/common_expand.dart';
  20. import 'package:location/utils/toast_util.dart';
  21. import '../../data/api/response/subscription_check_response.dart';
  22. import '../../data/bean/member_status_info.dart';
  23. import '../../data/bean/wechat_payment_sign_bean.dart';
  24. import '../../data/consts/error_code.dart';
  25. import '../../data/consts/payment_type.dart';
  26. import '../../data/consts/web_url.dart';
  27. import '../../dialog/common_confirm_dialog_impl.dart';
  28. import '../../dialog/loading_dialog.dart';
  29. import '../../dialog/member_retain_dialog.dart';
  30. import '../../dialog/wechat_qr_code_dialog.dart';
  31. import '../../resource/string.gen.dart';
  32. import '../../sdk/wechat/wechat_share_util.dart';
  33. import '../../utils/app_review_service.dart';
  34. import '../../utils/http_handler.dart';
  35. import '../../utils/mmkv_util.dart';
  36. import '../../utils/payment_status_manager.dart';
  37. import '../../widget/animated_switcher_widget.dart';
  38. import '../browser/browser_view.dart';
  39. import '../mine/mine_controller.dart';
  40. import 'member_discount_countdown_widget.dart';
  41. import 'member_evaluate_bean.dart';
  42. import 'member_evaluation_pop_up_dialog.dart';
  43. import 'member_first_week_discount_dialog.dart';
  44. import 'member_fun_bean.dart';
  45. import 'package:apple_pay/apple_pay.dart';
  46. import 'member_page.dart';
  47. import 'member_payment_completed_dialog.dart';
  48. import 'member_user_cancel_pay_dialog.dart';
  49. @injectable
  50. class MemberController extends BaseController implements PaymentStatusCallback {
  51. final AccountRepository accountRepository;
  52. final MemberRepository memberRepository;
  53. final PaymentStatusManager paymentStatusManager;
  54. final switcherController = SwitcherController();
  55. final ScrollController scrollController = ScrollController();
  56. StreamController? _changeStreamController;
  57. final random = Random();
  58. final RxDouble _toolBarOpacity = 0.0.obs;
  59. double get toolBarOpacity => _toolBarOpacity.value;
  60. final List<String> _storeTypes = ['终身会员', '年度会员', '月度会员'];
  61. String? get phone => accountRepository.loginPhoneNum.value;
  62. bool get isLogin => accountRepository.isLogin.value;
  63. MemberStatusInfo? get memberStatusInfo =>
  64. accountRepository.memberStatusInfo.value;
  65. final RxList<GoodsBean> goodsList = <GoodsBean>[].obs;
  66. final Rxn<GoodsBean> _selectedGoods = Rxn<GoodsBean>();
  67. GoodsBean? get selectedGoods => _selectedGoods.value;
  68. final Rxn<PayItemBean> _selectedPayWay = Rxn<PayItemBean>();
  69. PayItemBean? get selectedPayWay => _selectedPayWay.value;
  70. final RxList<PayItemBean> payItemList = <PayItemBean>[].obs;
  71. final RxBool isShowCount = RxBool(true);
  72. CancelableFuture? _memberDataFuture;
  73. ///广告弹窗防抖
  74. bool _isPopBackInProgress = false; // 操作进行中标志
  75. ///检查续订的状态
  76. final Rx<SubscriptionCheckResponse> _checkResponse =
  77. Rx(SubscriptionCheckResponse(outTradeNo: ""));
  78. SubscriptionCheckResponse? get requestCheckResponse => _checkResponse.value;
  79. final List<MemberFunBean> funList = [
  80. MemberFunBean(1, Assets.images.iconMemberFun1.path,
  81. StringName.memberFunName1, StringName.memberFunName1Desc),
  82. MemberFunBean(2, Assets.images.iconMemberFun2.path,
  83. StringName.memberFunName2, StringName.memberFunName2Desc),
  84. // MemberFunBean(3, Assets.images.iconMemberFun3.path,
  85. // StringName.memberFunName3, StringName.memberFunName3Desc),
  86. // MemberFunBean(4, Assets.images.iconMemberFun4.path,
  87. // StringName.memberFunName4, StringName.memberFunName4Desc), //该功能还未开发
  88. MemberFunBean(5, Assets.images.iconMemberFun5.path,
  89. StringName.memberFunName5, StringName.memberFunName5Desc),
  90. MemberFunBean(6, Assets.images.iconMemberFun6.path,
  91. StringName.memberFunName6, StringName.memberFunName6Desc),
  92. ];
  93. final List<MemberEvaluateBean> evaluateList = [
  94. MemberEvaluateBean(1, Assets.images.iconEvaluate1.path, '用户189****7913',
  95. "上班没时间,远程遛娃,非常方便很好用。"),
  96. MemberEvaluateBean(2, Assets.images.iconEvaluate2.path, '用户177****2345',
  97. "这个功能太棒了!尤其是夜间出行时,一键报警让我感觉特别安心。"),
  98. MemberEvaluateBean(3, Assets.images.iconEvaluate3.path, '用户138****6789',
  99. "强烈推荐!我和家人经常用这个功能来共享位置,尤其是旅游时,走散了也不怕。"),
  100. MemberEvaluateBean(4, Assets.images.iconEvaluate4.path, '用户159****3456',
  101. "实时定位非常精准,用来监控孩子的行踪特别方便,再也不用担心他们乱跑了。"),
  102. MemberEvaluateBean(5, Assets.images.iconEvaluate5.path, '用户182****9012',
  103. "用来遛狗也很方便,再也不用担心狗狗跑丢了,真是个好工具!"),
  104. ];
  105. static const String _keMemberPageShowKey = "member_page_show_key";
  106. MemberController(
  107. this.accountRepository, this.memberRepository, this.paymentStatusManager);
  108. @override
  109. void onReady() async {
  110. super.onReady();
  111. _isTherePopUpPrompt();
  112. _startAnimationSwitcher();
  113. scrollController.addListener(() {
  114. double offset = scrollController.offset;
  115. double opacity = offset / 100;
  116. if (opacity > 1) {
  117. opacity = 1;
  118. } else if (opacity < 0) {
  119. opacity = 0;
  120. }
  121. _toolBarOpacity.value = opacity;
  122. });
  123. refreshMemberData();
  124. }
  125. ///是否弹窗提示
  126. void _isTherePopUpPrompt() {
  127. MemberPageType pageType = Get.arguments ?? MemberPageType.universalAccessEnter;
  128. if (pageType == MemberPageType.afeterTrialMemberEnter) {
  129. MemberFirstWeekDiscountDialog.show(
  130. confirmOnTap: () {
  131. onBuyClick();
  132. },
  133. onPrivacyPolicyClick: () {
  134. onPrivacyPolicyClick();
  135. },
  136. onTermOfServiceClick: () {
  137. onTermOfServiceClick();
  138. }
  139. );
  140. }
  141. }
  142. void _startAnimationSwitcher() {
  143. _changeStreamController = AsyncUtil.interval(
  144. (time) => changeSwitcherContent(), Duration(seconds: 3), -1);
  145. }
  146. Future<void> changeSwitcherContent() async {
  147. int userId = random.nextInt(10000);
  148. String userIdStr = userId.toString();
  149. int padLength = 4 - userIdStr.length;
  150. for (int i = 0; i < padLength; i++) {
  151. userIdStr = random.nextInt(10).toString() + userIdStr;
  152. }
  153. bool isHour = random.nextBool();
  154. String secondsOrHour;
  155. if (isHour) {
  156. secondsOrHour = "${1 + random.nextInt(8)}小时";
  157. } else {
  158. secondsOrHour = "${1 + random.nextInt(59)}分钟";
  159. }
  160. int index = random.nextInt(_storeTypes.length);
  161. switcherController.updateWidget(Row(
  162. mainAxisAlignment: MainAxisAlignment.center,
  163. children: [
  164. RichText(
  165. text: TextSpan(
  166. style: TextStyle(fontSize: 11.sp, color: Colors.white,fontWeight: FontWeight.w400),
  167. children: [
  168. TextSpan(text: userIdStr),
  169. TextSpan(text: '用户 '),
  170. TextSpan(text: secondsOrHour),
  171. TextSpan(text: '前购买了'),
  172. TextSpan(
  173. text: _storeTypes[index],
  174. style: TextStyle(color: '#FFC95D'.color)),
  175. ]))
  176. ],
  177. ));
  178. }
  179. String getUserName(String phone) {
  180. if (phone.length > 4) {
  181. phone = phone.substring(phone.length - 4);
  182. }
  183. return '${StringName.mineAccountLoggedDesc}$phone';
  184. }
  185. void back() {
  186. Get.back();
  187. }
  188. void onLoginClick() {
  189. if (accountRepository.isLogin.value) {
  190. return;
  191. }
  192. LoginPage.start();
  193. }
  194. void refreshMemberData() {
  195. _memberDataFuture?.cancel();
  196. _memberDataFuture =
  197. AsyncUtil.retryWithExponentialBackoff(() => _requestMemberData(), 4);
  198. _memberDataFuture?.catchError((error) {
  199. ErrorHandler.toastError(error);
  200. });
  201. }
  202. Future<void> _requestMemberData() {
  203. return memberRepository
  204. .getMemberList(itemListType: Platform.isIOS ? 2 : 0)
  205. .then((response) {
  206. goodsList.clear();
  207. payItemList.clear();
  208. _selectedGoods.value = null;
  209. if (response.goodsList?.isNotEmpty == true) {
  210. goodsList.addAll(response.goodsList!);
  211. _selectedGoods.value = goodsList.first;
  212. }
  213. if (response.payInfoList?.isNotEmpty == true) {
  214. payItemList.addAll(response.payInfoList!);
  215. _selectedPayWay.value = payItemList.first;
  216. }
  217. });
  218. }
  219. void onGoodsItemClick(GoodsBean item) {
  220. _selectedGoods.value = item;
  221. }
  222. void onPrivacyPolicyClick() {
  223. BrowserPage.start(WebUrl.privacyPolicy);
  224. }
  225. void onTermOfServiceClick() {
  226. BrowserPage.start(WebUrl.userAgreement);
  227. }
  228. void onPayWayItemClick(PayItemBean item) {
  229. _selectedPayWay.value = item;
  230. }
  231. void onPopBack() {
  232. if (Platform.isIOS) {
  233. back();
  234. if (accountRepository.memberIsExpired()) {
  235. FocusScope.of(Get.context!).unfocus();
  236. userCancelsPaymentDisplay();
  237. }
  238. } else {
  239. if (accountRepository.memberIsExpired()) {
  240. userCancelsPaymentDisplay();
  241. } else {
  242. back();
  243. }
  244. }
  245. }
  246. ///用户取消支付展示
  247. void userCancelsPaymentDisplay() {
  248. if (_isPopBackInProgress) {
  249. // 如果正在处理返回逻辑,直接跳过
  250. return;
  251. }
  252. _isPopBackInProgress = true; // 锁定状态
  253. //_keMemberPageShowKey
  254. String? memberPageKeyStr = KVUtil.getString(_keMemberPageShowKey, '');
  255. if ((memberPageKeyStr ?? '').isEmpty && (accountRepository.memberStatusInfo.value?.trialed == false)) {
  256. ///永久化存储
  257. KVUtil.putString(_keMemberPageShowKey, _keMemberPageShowKey);
  258. MemberUserCancelPayDialog.show(payClick: () {
  259. //获取会员
  260. MineController attributionController = Get.find<MineController>();
  261. attributionController.onMemberTryOutClick();
  262. _isPopBackInProgress = false;
  263. }, cancelClick: () {
  264. _isPopBackInProgress = false;
  265. if (!Platform.isIOS) {
  266. back();
  267. }
  268. });
  269. } else {
  270. _isPopBackInProgress = false;
  271. }
  272. }
  273. ///支付错误的时候调用
  274. void showRetainDialog() {
  275. if (_isPopBackInProgress) {
  276. // 如果正在处理返回逻辑,直接跳过
  277. return;
  278. }
  279. _isPopBackInProgress = true; // 锁定状态
  280. MemberRetainDialog.show(payClick: () {
  281. onBuyClick();
  282. _isPopBackInProgress = false;
  283. }, cancelClick: () {
  284. _isPopBackInProgress = false;
  285. if (!Platform.isIOS) {
  286. back();
  287. }
  288. });
  289. }
  290. void onBuyClick() {
  291. if (selectedGoods == null) {
  292. ToastUtil.show(StringName.memberPleaseChoiceGoods);
  293. return;
  294. }
  295. if (selectedPayWay == null && !Platform.isIOS) {
  296. ToastUtil.show(StringName.memberPleaseChoicePayment);
  297. return;
  298. }
  299. final buyGoods = selectedGoods!;
  300. final buyPayWay = selectedPayWay!;
  301. int goodsId = buyGoods.id;
  302. int payPlatform = buyPayWay.payPlatform;
  303. int payMethod = buyPayWay.payMethod;
  304. int payWayType =
  305. getPayWayType(payMethod: payMethod, payPlatform: payPlatform);
  306. LoadingDialog.show(StringName.payLoading);
  307. memberRepository
  308. .submitAndRequestPay(
  309. goodsId: goodsId, payPlatform: payPlatform, payMethod: payMethod)
  310. .then((response) {
  311. if (payWayType == PayWayType.paymentWayWechat) {
  312. _onWeChatPay(response.outTradeNo, response.wechatPayPrepayJson!,
  313. payMethod, buyGoods, buyPayWay);
  314. } else if (payWayType == PayWayType.paymentWayWechatScan) {
  315. _onWechatScanPay(response.outTradeNo, response.wechatPayQrcodeUrl!,
  316. buyPayWay, buyGoods);
  317. } else if (payWayType == PayWayType.paymentWayAlipay) {
  318. _onAliPay(response.outTradeNo, response.alipayOrderString!, payMethod,
  319. buyGoods, buyPayWay);
  320. } else if (payWayType == PayWayType.paymentWayAlipayScan) {
  321. _onAliScanPay(response.outTradeNo, response.alipayQrcodeHtml!,
  322. buyPayWay, buyGoods);
  323. } else if (payWayType == PayWayType.paymentWayApple) {
  324. _onApplePay(response.outTradeNo, response.appAccountToken ?? "",
  325. buyPayWay, buyGoods);
  326. } else {
  327. ToastUtil.show(StringName.payNotSupport);
  328. }
  329. }).catchError((error) {
  330. //处理购买失败
  331. showRetainDialog();
  332. if (error is ServerErrorException) {
  333. if (error.code == ErrorCode.payOrderError) {
  334. refreshMemberData();
  335. ToastUtil.show(error.message);
  336. } else if (error.code == ErrorCode.noLoginError) {
  337. ToastUtil.show(StringName.accountNoLogin);
  338. LoginPage.start();
  339. } else {
  340. ToastUtil.show(error.message);
  341. }
  342. } else {
  343. ToastUtil.show(StringName.memberPaymentFailed);
  344. }
  345. }).whenComplete(() {
  346. LoadingDialog.hide();
  347. });
  348. }
  349. ///发起购买请求
  350. Future<void> _onApplePay(String outTradeNo,
  351. String appAccountToken,
  352. PayItemBean payWayInfo,
  353. GoodsBean goodsInfo,) async {
  354. final result = await ApplePay().purchase(
  355. productId: goodsInfo.appleGoodsId ?? "",
  356. appAccountToken: appAccountToken,
  357. );
  358. if (result["success"] == true) {
  359. var receipt = result['receipt'];
  360. print('购买成功: ${result['receipt']}');
  361. checkPaymentStatus(
  362. outTradeNo,
  363. payWayInfo,
  364. goodsInfo,
  365. receiptData: receipt,
  366. );
  367. } else {
  368. LoadingDialog.hide();
  369. ToastUtil.show("支付失败,请稍后重试");
  370. print('购买失败: ${result['error']}');
  371. }
  372. }
  373. void _onAliScanPay(String outTradeNo, String qrHtml, PayItemBean paymentWay,
  374. GoodsBean goodsBean) {
  375. AlipayQrCodeDialog.show(
  376. qrCodeHtml: qrHtml,
  377. loadSuccessCallback: () {
  378. checkPaymentStatus(outTradeNo, paymentWay, goodsBean);
  379. },
  380. onCloseCallback: () async {
  381. //关闭后再持续查询几秒
  382. CustomLoadingDialog.show();
  383. await Future.delayed(Duration(seconds: 4));
  384. paymentStatusManager.removePollingSubscription(outTradeNo);
  385. CustomLoadingDialog.hide();
  386. });
  387. }
  388. void checkPaymentStatus(
  389. String orderNo, PayItemBean paymentWay, GoodsBean goodsBean,
  390. {String? receiptData}) {
  391. paymentStatusManager.registerPaymentSuccessCallback(orderNo, this);
  392. paymentStatusManager.checkPaymentStatus(orderNo, paymentWay, goodsBean,
  393. receiptData: receiptData);
  394. }
  395. void _onWeChatPay(String outTradeNo, String payJson, int payMethod,
  396. GoodsBean buyGoods, PayItemBean buyPayWay) {
  397. final bean = WechatPaymentSignBean.stringToBean(payJson);
  398. final payInfo = WechatPayInfo(
  399. appId: bean.appId,
  400. partnerId: bean.partnerId,
  401. prepayId: bean.prepayId,
  402. package: bean.package,
  403. noncestr: bean.nonceStr,
  404. timestamp: bean.timeStamp,
  405. sign: bean.sign);
  406. requestSdkPay(payInfo, outTradeNo, payMethod, buyGoods, buyPayWay);
  407. }
  408. void _onAliPay(String outTradeNo, String payJson, int payMethod,
  409. GoodsBean buyGoods, PayItemBean buyPayWay) {
  410. final payInfo = AliPayInfo(payJson);
  411. requestSdkPay(payInfo, outTradeNo, payMethod, buyGoods, buyPayWay);
  412. }
  413. void _onWechatScanPay(String outTradeNo, String qrCodeUrl,
  414. PayItemBean paymentWay, GoodsBean goodsBean) {
  415. WechatQrCodeDialog.show(
  416. qrCodeUrl: qrCodeUrl,
  417. loadSuccessCallback: () {
  418. checkPaymentStatus(outTradeNo, paymentWay, goodsBean);
  419. },
  420. onCloseCallback: () async {
  421. //关闭后再持续查询几秒
  422. CustomLoadingDialog.show();
  423. await Future.delayed(Duration(seconds: 4));
  424. paymentStatusManager.removePollingSubscription(outTradeNo);
  425. CustomLoadingDialog.hide();
  426. });
  427. }
  428. ///查询订阅状态
  429. Future<void> _requestCheckRestoreStatus(String? receiptData) async {
  430. memberRepository.subscriptionCheck(3, receiptData ?? "").then((value) {
  431. _checkResponse.value = value;
  432. }).catchError((error) {});
  433. }
  434. /// 点击了恢复订阅
  435. Future<void> clickRecoverSubscribe() async {
  436. PayItemBean? paymentWay = _selectedPayWay.value;
  437. if (paymentWay == null) {
  438. return;
  439. }
  440. int payPlatform = paymentWay.payPlatform;
  441. int payMethod = paymentWay.payMethod;
  442. CustomLoadingDialog.show();
  443. Future.delayed(const Duration(seconds: 20), () {
  444. CustomLoadingDialog.hide();
  445. //ToastUtil.show("没有发现可恢复的记录");
  446. });
  447. final result = await ApplePay().restore();
  448. if (result["success"] == true) {
  449. // CustomLoadingDialog.hide();
  450. var receipt = result['receipt'];
  451. print('查找恢复记录成功: ${result['receipt']}');
  452. checkRestoreStatus(receipt);
  453. } else {
  454. CustomLoadingDialog.hide();
  455. ToastUtil.show("恢复失败");
  456. print('恢复失败: ${result['error']}');
  457. }
  458. // 显示恢复订阅弹窗
  459. // RecoverSubscribeDialog.show("周会员2025年3月6日到期。", () {
  460. // AtmobLog.d(tag, "恢复订阅弹窗 => 点击确认");
  461. // });
  462. }
  463. /// 检查恢复订阅结果
  464. Future<void> checkRestoreStatus(String? receiptData) async {
  465. PayItemBean? paymentWay = _selectedPayWay.value;
  466. if (paymentWay == null) {
  467. // ToastUtil.showToast(StringName.storeChoicePayment.tr);
  468. return;
  469. }
  470. if (receiptData == null) {
  471. return;
  472. }
  473. int payPlatform = paymentWay.payPlatform;
  474. int payMethod = paymentWay.payMethod;
  475. // var code = await storeRepository.resume(payPlatform, payMethod, receiptData);
  476. memberRepository.subscriptionResume(3, receiptData).then((data) async {
  477. CustomLoadingDialog.hide();
  478. ToastUtil.show("恢复成功");
  479. await AccountRepository.getInstance().getMemberStatus();
  480. //accountRepository.refreshMemberStatus();
  481. Get.back();
  482. }).catchError((error) {
  483. CustomLoadingDialog.hide();
  484. ToastUtil.show("恢复失败");
  485. });
  486. // if (code == 0) {
  487. // CustomLoadingDialog.hide();
  488. // ToastUtil.show("Restore success");
  489. // userRepository.getUserInfo();
  490. // Get.back();
  491. // } else {
  492. // CustomLoadingDialog.hide();
  493. // ToastUtil.show("Restore fail");
  494. // }
  495. }
  496. void requestSdkPay(dynamic payInfo, String outTradeNo, int payMethod,
  497. GoodsBean buyGoods, PayItemBean buyPayWay) {
  498. AgilePay.startPay(payInfo, success: (String? result) {
  499. LoadingDialog.show(StringName.payQuerypayState);
  500. checkPaymentStatus(outTradeNo, buyPayWay, buyGoods, receiptData: result);
  501. }, payError: (int error, String? errorMessage) {
  502. debugPrint('zk---payError: $error, $errorMessage');
  503. errorPayToast(error);
  504. errorEventReport(payMethod);
  505. }, error: (int errno, String? error) {
  506. debugPrint('zk---error: $errno, $error');
  507. errorPayToast(errno);
  508. errorEventReport(payMethod);
  509. });
  510. }
  511. void errorEventReport(int payMethod) {
  512. if (payMethod == PayMethod.wechat) {
  513. // EventHandler.report();
  514. } else if (payMethod == PayMethod.alipay) {
  515. // EventHandler.report();
  516. } else if (payMethod == PayMethod.apple) {
  517. // EventHandler.report();
  518. }
  519. }
  520. void errorPayToast(int errno) {
  521. if (errno == AgilePayCode.payCodeNotSupport) {
  522. ToastUtil.show(StringName.payNotSupport);
  523. } else if (errno == AgilePayCode.payCodeCancelError) {
  524. ToastUtil.show(StringName.payUserCancel);
  525. } else if (errno == AgilePayCode.payCodeWxEnvError) {
  526. ToastUtil.show(StringName.payWxEvnError);
  527. } else if (errno == AgilePayCode.payCodeNotConnectStore) {
  528. ToastUtil.show(StringName.payNotConnectStore);
  529. } else {
  530. ToastUtil.show(StringName.payError);
  531. }
  532. }
  533. @override
  534. void onClose() {
  535. super.onClose();
  536. _changeStreamController?.close();
  537. _memberDataFuture?.cancel();
  538. scrollController.dispose();
  539. paymentStatusManager.unregisterPaymentSuccessCallback(this);
  540. }
  541. @override
  542. void onPaymentSuccess(
  543. String orderNo, PayItemBean paymentWay, GoodsBean storeItemBean) {
  544. ///购买成功之后弹出
  545. afterTheFirstPurchasePromptSharingBoxPops();
  546. }
  547. ///第一次购买之后弹出提示分享框
  548. void afterTheFirstPurchasePromptSharingBoxPops() {
  549. paymentStatusManager.onOrderFirstCheck().then((checkReponse) {
  550. //是否展示邀请弹框
  551. if (checkReponse.showInvite || checkReponse.showEvaluate) {
  552. MemberPageType pageType = Get.arguments ?? MemberPageType.universalAccessEnter;
  553. //去分享
  554. if (checkReponse.showInvite && pageType == MemberPageType.addFriendToEnter) {
  555. MemberPaymentCompletedDialog.show(confirmOnTap: () {
  556. WechatShareUtil.shareWebPage().catchError((error) {
  557. ToastUtil.show(error);
  558. });
  559. if (checkReponse.showEvaluate) {
  560. ///是否展示好评领会员弹框
  561. MemberEvaluationPopUpDialog.show(confirmOnTap: () {
  562. AppReviewService.requestAppReview(Get.context!);
  563. onPaySucessShow();
  564. },cancelOnTap: () {
  565. onPaySucessShow();
  566. },days: 1);
  567. } else {
  568. onPaySucessShow();
  569. }
  570. },cancelOnTap: () {
  571. if (checkReponse.showEvaluate) {
  572. ///是否展示好评领会员弹框
  573. MemberEvaluationPopUpDialog.show(confirmOnTap: () {
  574. AppReviewService.requestAppReview(Get.context!);
  575. ///领取会员后请求
  576. memberRepository.memberEvaluate().then((_){
  577. }).catchError((error) {
  578. });;//memberEvaluate
  579. onPaySucessShow();
  580. },cancelOnTap: () {
  581. onPaySucessShow();
  582. },days: 1);
  583. } else {
  584. onPaySucessShow();
  585. }
  586. });
  587. }
  588. else if (checkReponse.showEvaluate) {
  589. ///是否展示好评领会员弹框
  590. MemberEvaluationPopUpDialog.show(confirmOnTap: () {
  591. AppReviewService.requestAppReview(Get.context!);
  592. onPaySucessShow();
  593. },cancelOnTap: () {
  594. onPaySucessShow();
  595. },days: 1);
  596. }
  597. } else {
  598. onPaySucessShow();
  599. }
  600. }).catchError((erro) {
  601. onPaySucessShow();
  602. });
  603. }
  604. ///支付成功之后展示
  605. void onPaySucessShow() {
  606. try {
  607. WechatQrCodeDialog.dismiss();
  608. AlipayQrCodeDialog.dismiss();
  609. CustomLoadingDialog.hide();
  610. LoadingDialog.hide();
  611. } catch (e) {
  612. debugPrint('zk---onPaymentSuccess error: $e');
  613. }
  614. showPaymentSuccessDialog(onConfirm: back, onCancel: back);
  615. }
  616. }