| | |
| | | import JQTools |
| | | import StoreKit |
| | | import WebKit |
| | | import SwiftyStoreKit |
| | | import RxSwift |
| | | |
| | | class VIPCenterVC: BaseVC { |
| | | |
| | |
| | | |
| | | private var productList = Set<String>() |
| | | private var products = [SKProduct]() |
| | | private var timeLoopDisposeBag = DisposeBag() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "会员中心" |
| | | |
| | | productList.insert("com.XQMuse.VIP.month.0") |
| | | productList.insert("com.XQMuse.VIP.semester.0") |
| | | productList.insert("com.XQMuse.VIP.year.0") |
| | | productList.insert("com.XQMuse.VIP.year.renewing.0") |
| | | productList.insert("com.XQmuse.Non.renewing.year.1") |
| | | productList.insert("com.XQmuse.Non.renewing.half.year.1") |
| | | productList.insert("com.XQmuse.Non.renewing.month.1") |
| | | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | |
| | | alert(msg: "请先阅读并同意《会员用户协议》");return |
| | | } |
| | | |
| | | showHUD("正在进行内购买") |
| | | guard products.count != 0 else {return} |
| | | let oldVipExpireTime = UserViewModel.getAvatarInfo().vipExpireTime |
| | | |
| | | let product = products[selectIndex] |
| | | let userId = UserViewModel.getAvatarInfo().userId.string |
| | | InPurchaseManager.purchaseProduct(ID: product.productIdentifier, applicationUsername: userId) {[weak self]result in |
| | | guard let weakSelf = self else { return } |
| | | if result.status == 0{ |
| | | hiddenHUD() |
| | | let transactionId = result.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | |
| | | InPurchaseManager.purchaseProduct(ID: product.productIdentifier, applicationUsername: "") { m in |
| | | |
| | | showHUD("正在查询购买结果") |
| | | Services.placeOrderApple(amount: product.price.doubleValue, balanceFlag: .no, orderFrom: 3, transactionIdentifier: transactionId, vipType: weakSelf.selectIndex + 1).subscribe(onNext: { data in |
| | | showHUD("正在查询购买结果") |
| | | let observable = Observable<Int>.interval(RxTimeInterval.seconds(5), scheduler: MainScheduler.instance) |
| | | observable.subscribe { event in |
| | | if event.element == 10{ |
| | | alertError(msg: "订单异常") |
| | | weakSelf.timeLoopDisposeBag = DisposeBag() |
| | | return |
| | | } |
| | | Services.getUserDetail(showProgress: false).subscribe(onNext: {data in |
| | | if data.data?.vipExpireTime != oldVipExpireTime{ |
| | | hiddenHUD() |
| | | alertSuccess(msg: "购买成功") |
| | | weakSelf.timeLoopDisposeBag = DisposeBag() |
| | | NotificationCenter.default.post(name: UpdateUserProfile_Noti, object: nil, userInfo: 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) |
| | | } |
| | |
| | | |
| | | func isSelect(_ state:Bool,product:SKProduct){ |
| | | label_title.text = product.localizedTitle |
| | | let priorDayPrice = product.price.doubleValue / 365.0 |
| | | |
| | | var priorDayPrice:Double = 0 |
| | | switch product.productIdentifier { |
| | | case "com.XQmuse.Non.renewing.year.1": |
| | | priorDayPrice = product.price.doubleValue / 365.0 |
| | | case "com.XQmuse.Non.renewing.half.year.1": |
| | | priorDayPrice = product.price.doubleValue / 180.0 |
| | | case "com.XQmuse.Non.renewing.month.1": |
| | | priorDayPrice = product.price.doubleValue / 30.0 |
| | | default: |
| | | priorDayPrice = product.price.doubleValue |
| | | } |
| | | |
| | | |
| | | |
| | | lable_priorDay.text = String(format:"%@%@/天", product.priceLocale.currencySymbol!,priorDayPrice.jq_formatFloat) |
| | | if state{ |
| | | contentView.backgroundColor = UIColor(hexString: "#A6C586") |