| | |
| | | |
| | | class VIPCenterVC: BaseVC { |
| | | |
| | | private var btn_vip:UIButton! |
| | | private var webView:WKWebView! |
| | | private var inpurchaseManager = InPurchaseManager.instance() |
| | | private var products = Set<SKProduct>() |
| | | private var btn_vip:UIButton! |
| | | private var webView:WKWebView! |
| | | private var inpurchaseManager = InPurchaseManager.instance() |
| | | private var products = Set<SKProduct>() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | yy_popBlock = {[weak self] () in |
| | | guard let weakSelf = self else { return } |
| | | var toVC:UIViewController? |
| | | for subVC in weakSelf.navigationController?.viewControllers ?? []{ |
| | | if subVC.isKind(of: HomeListenVC.self){ |
| | | toVC = subVC;break |
| | | } |
| | | } |
| | | yy_popBlock = {[weak self] () in |
| | | guard let weakSelf = self else { return } |
| | | var toVC:UIViewController? |
| | | for subVC in weakSelf.navigationController?.viewControllers ?? []{ |
| | | if subVC.isKind(of: HomeListenV2VC.self){ |
| | | toVC = subVC;break |
| | | } |
| | | } |
| | | |
| | | if toVC != nil{ |
| | | weakSelf.navigationController?.popToViewController(toVC!, animated: true) |
| | | }else{ |
| | | weakSelf.navigationController?.popViewController(animated: true) |
| | | } |
| | | } |
| | | if toVC != nil{ |
| | | weakSelf.navigationController?.popToViewController(toVC!, animated: true) |
| | | }else{ |
| | | weakSelf.navigationController?.popViewController(animated: true) |
| | | } |
| | | } |
| | | |
| | | Services.vipInfo().subscribe(onNext: {data in |
| | | if let model = data.data?.first{ |
| | | self.webView.loadHTMLString(model.info.jq_wrapHtml(edge: UIEdgeInsets(top: 0, left: 10, bottom: 3, right: 0)), baseURL: nil) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | Services.vipInfo().subscribe(onNext: {data in |
| | | if let model = data.data?.first{ |
| | | self.webView.loadHTMLString(model.info.jq_wrapHtml(edge: UIEdgeInsets(top: 0, left: 10, bottom: 3, right: 0)), baseURL: nil) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | inpurchaseManager.test1() |
| | | inpurchaseManager.setProductList([ProductMemberID]) {[weak self] m in |
| | | self?.products = m |
| | | } |
| | | } |
| | | inpurchaseManager.test1() |
| | | inpurchaseManager.setProductList([ProductMemberID]) {[weak self] m in |
| | | self?.products = m |
| | | } |
| | | } |
| | | |
| | | override func setUI() { |
| | | override func setUI() { |
| | | |
| | | view.backgroundColor = .white |
| | | webView = WKWebView(frame: .zero) |
| | | view.addSubview(webView) |
| | | webView.snp.makeConstraints { make in |
| | | make.left.right.top.equalToSuperview() |
| | | make.bottom.equalToSuperview().offset(-150) |
| | | } |
| | | view.backgroundColor = .white |
| | | webView = WKWebView(frame: .zero) |
| | | view.addSubview(webView) |
| | | webView.snp.makeConstraints { make in |
| | | make.left.right.top.equalToSuperview() |
| | | make.bottom.equalToSuperview().offset(-150) |
| | | } |
| | | |
| | | |
| | | btn_vip = UIButton(type: .custom) |
| | | btn_vip.setTitle("成为会员", for: .normal) |
| | | btn_vip.setTitleColor(.white, for: .normal) |
| | | btn_vip.backgroundColor = UIColor(hexStr: "#41A2EB") |
| | | btn_vip.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) |
| | | btn_vip.addTarget(self, action: #selector(becomeVIPAction), for: .touchUpInside) |
| | | btn_vip.jq_cornerRadius = 8 |
| | | view.addSubview(btn_vip) |
| | | btn_vip.snp.makeConstraints { make in |
| | | make.width.equalTo(316) |
| | | make.height.equalTo(49) |
| | | make.bottom.equalTo(-91) |
| | | make.centerX.equalToSuperview() |
| | | } |
| | | } |
| | | btn_vip = UIButton(type: .custom) |
| | | btn_vip.setTitle("成为会员", for: .normal) |
| | | btn_vip.setTitleColor(.white, for: .normal) |
| | | btn_vip.backgroundColor = UIColor(hexStr: "#41A2EB") |
| | | btn_vip.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium) |
| | | btn_vip.addTarget(self, action: #selector(becomeVIPAction), for: .touchUpInside) |
| | | btn_vip.jq_cornerRadius = 8 |
| | | view.addSubview(btn_vip) |
| | | btn_vip.snp.makeConstraints { make in |
| | | make.width.equalTo(316) |
| | | make.height.equalTo(49) |
| | | make.bottom.equalTo(-91) |
| | | make.centerX.equalToSuperview() |
| | | } |
| | | } |
| | | |
| | | @objc func becomeVIPAction(){ |
| | | #if DEBUG |
| | | toPay() |
| | | #else |
| | | ParentVerifiyView.show {[unowned self] in |
| | | self.toPay() |
| | | } |
| | | #endif |
| | | } |
| | | @objc func becomeVIPAction(){ |
| | | #if DEBUG |
| | | toPay() |
| | | #else |
| | | ParentVerifiyView.show {[unowned self] in |
| | | self.toPay() |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | private func toPay(){ |
| | | guard let userId = UserViewModel.getUserInfo()?.user?.id.string else {alert(msg: "请先登录");return} |
| | | guard let product = products.first else {alert(msg: "获取内购失败");return} |
| | | private func toPay(){ |
| | | guard let userId = UserViewModel.getUserInfo()?.user?.id.string else {alert(msg: "请先登录");return} |
| | | guard let product = products.first else {alert(msg: "获取内购失败");return} |
| | | |
| | | Services.orderStudent(count: 12, price: product.price.doubleValue).subscribe(onNext: {[unowned self] data in |
| | | if let m = data.data{ |
| | | showHUD("正在购买") |
| | | InPurchaseManager.purchaseProduct(ID: ProductMemberID, applicationUsername: userId) {[unowned self] model in |
| | | let transactionIdentifier = model.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | Services.orderStudent(count: 12, price: product.price.doubleValue).subscribe(onNext: {[unowned self] data in |
| | | if let m = data.data{ |
| | | showHUD("正在购买") |
| | | InPurchaseManager.purchaseProduct(ID: ProductMemberID, applicationUsername: userId) {[unowned self] model in |
| | | let transactionIdentifier = model.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | |
| | | hiddenHUD() |
| | | Services.pay(orderId: m.orderId, transactionIdentifier: transactionIdentifier).subscribe(onNext: {[unowned self] data in |
| | | var count = 0 |
| | | showHUD("正在查询支付结果") |
| | | let t = Timer(timeInterval: 2.0, repeats: true) {[unowned self] timer in |
| | | Services.queryOrderState(orderId: m.orderId).subscribe(onNext: {[unowned self]status in |
| | | if status.data == true{ |
| | | alertSuccess(msg: "购买成功") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) {[unowned self] in |
| | | navigationController?.popViewController() |
| | | NotificationCenter.default.post(name: MeUserInfoUpdate_Noti, object: nil) |
| | | } |
| | | timer.invalidate() |
| | | return |
| | | } |
| | | count += 1 |
| | | if count >= 15{ |
| | | hiddenHUD() |
| | | print("循环结束") |
| | | showHUD("查询结果失败,请联系客服") |
| | | timer.invalidate() |
| | | } |
| | | },onError: {error in |
| | | timer.invalidate() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | t.fire() |
| | | RunLoop.current.add(t, forMode: .common) |
| | | }).disposed(by: disposeBag) |
| | | hiddenHUD() |
| | | Services.pay(orderId: m.orderId, transactionIdentifier: transactionIdentifier).subscribe(onNext: {[unowned self] data in |
| | | var count = 0 |
| | | showHUD("正在查询支付结果") |
| | | let t = Timer(timeInterval: 2.0, repeats: true) {[unowned self] timer in |
| | | Services.queryOrderState(orderId: m.orderId).subscribe(onNext: {[unowned self]status in |
| | | if status.data == true{ |
| | | alertSuccess(msg: "购买成功") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) {[unowned self] in |
| | | navigationController?.popViewController() |
| | | NotificationCenter.default.post(name: MeUserInfoUpdate_Noti, object: nil) |
| | | } |
| | | timer.invalidate() |
| | | return |
| | | } |
| | | count += 1 |
| | | if count >= 15{ |
| | | hiddenHUD() |
| | | print("循环结束") |
| | | showHUD("查询结果失败,请联系客服") |
| | | timer.invalidate() |
| | | } |
| | | },onError: {error in |
| | | timer.invalidate() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | t.fire() |
| | | RunLoop.current.add(t, forMode: .common) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | } errorClouse: { error in |
| | | hiddenHUD() |
| | | alert(msg: error.localizedDescription) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } errorClouse: { error in |
| | | hiddenHUD() |
| | | alert(msg: error.localizedDescription) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |