| | |
| | | import UIKit |
| | | import JQTools |
| | | import StoreKit |
| | | import RxSwift |
| | | |
| | | class WalletRechargeVC: BaseVC { |
| | | |
| | |
| | | private let cellH:Double = 35 |
| | | private var productList = Set<String>() |
| | | private var products = [SKProduct]() |
| | | |
| | | private var oldPrice:Double = 0 |
| | | private var timeLoopDisposeBag = DisposeBag() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "疗愈币充值" |
| | |
| | | let h = ceil(4.0 / 4.0) * cellH + floor((4.0 - 1) / 4.0) * 27.0 |
| | | cons_collectionHei.constant = h |
| | | view.layoutIfNeeded() |
| | | |
| | | Services.myWallet().subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | self.oldPrice = m.recharge |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | InPurchaseManager.instance().setProductList(productList) { products in |
| | | self.products = Array(products) |
| | |
| | | sceneDelegate?.needLogin() |
| | | return} |
| | | |
| | | showHUD("正在进行内购买") |
| | | let product = products[selectIndexPath.row] |
| | | InPurchaseManager.purchaseProduct(ID: product.productIdentifier, applicationUsername: userId.string) { model in |
| | | if model.status == 0{ |
| | | //需要后端监听推送后,才会更新金额,可能延迟 |
| | | NotificationCenter.default.post(name: Refreh_PaymentWallet_Noti, object: nil) |
| | | InPurchaseManager.purchaseProduct(ID: product.productIdentifier, applicationUsername: userId.string) {[weak self] result in |
| | | guard let weakSelf = self else { return } |
| | | if result.status == 0{ |
| | | let transactionId = result.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | Services.placeOrderApple(amount: product.price.doubleValue, balanceFlag: .no, orderFrom: 4, transactionIdentifier: transactionId, vipType: nil).subscribe(onNext: { data in |
| | | showHUD("正在查询购买结果") |
| | | let observable = Observable<Int>.interval(RxTimeInterval.seconds(5), scheduler: MainScheduler.instance) |
| | | observable.subscribe { event in |
| | | Services.myWallet().subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | if m.recharge != weakSelf.oldPrice{ |
| | | hiddenHUD() |
| | | alertSuccess(msg: "购买成功") |
| | | weakSelf.timeLoopDisposeBag = DisposeBag() |
| | | NotificationCenter.default.post(name: WithDrawReply_Noti, object: nil) |
| | | DispatchQueue.main.asyncAfter(delay: 1.0) { |
| | | weakSelf.navigationController?.popViewController() |
| | | } |
| | | } |
| | | } |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | }.disposed(by: weakSelf.timeLoopDisposeBag) |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | } |
| | | } errorClouse: { error in |
| | | alertError(msg: error.localizedDescription) |
| | |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_WalletCCell", for: indexPath) as! WalletCCell |
| | | cell.selectAt(indexPath == selectIndexPath) |
| | | let product = products[indexPath.row] |
| | | cell.lable_title.text = product.localizedTitle |
| | | cell.lable_title.text = product.price.stringValue |
| | | |
| | | btn_handle.isEnabled = true |
| | | btn_handle.alpha = 1.0 |