member_controller.dart 23 KB

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