| | |
| | | |
| | | class WalletRechargeVC: BaseVC { |
| | | |
| | | @IBOutlet weak var stackView: UIStackView! |
| | | @IBOutlet weak var tap_other: TapBtn! |
| | | @IBOutlet weak var btn_handle: UIButton! |
| | | @IBOutlet weak var collectionView: UICollectionView! |
| | | @IBOutlet weak var cons_collectionHei: NSLayoutConstraint! |
| | | @IBOutlet weak var tap_other_title: UILabel! |
| | | |
| | | private var selectIndexPath = IndexPath(row: 0, section: 0) |
| | | private let cellW = (JQ_ScreenW - (24 * 2) - 3 * 27) / 4 |
| | |
| | | private var products = [SKProduct]() |
| | | private var oldPrice:Double = 0 |
| | | private var timeLoopDisposeBag = DisposeBag() |
| | | |
| | | |
| | | private var isShowMore:Bool = false |
| | | private var orderId:String? //下单后的ID |
| | | private var tapType:TapType = .t2 |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "疗愈币充值" |
| | | |
| | | Services.getTurn(progress: false).subscribe(onNext: {[weak self]data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data,m == true{ |
| | | weakSelf.isShowMore = m |
| | | weakSelf.tap_other.isHidden = false |
| | | weakSelf.tap_other_title.text = "支".appending("付").appending("宝") |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | |
| | | |
| | | btn_handle.isEnabled = false |
| | | btn_handle.alpha = 0.6 |
| | |
| | | |
| | | override func setUI() { |
| | | view.backgroundColor = UIColor(hexString: "f6f6f6") |
| | | stackView.jq_cornerRadius = 10 |
| | | } |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(UIApplication.didBecomeActiveNotification).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] _ in |
| | | guard let weakSelf = self else { return } |
| | | if weakSelf.isShowMore && weakSelf.orderId != nil{ |
| | | Services.queryPayment(orderId: weakSelf.orderId!).subscribe(onNext: {data in |
| | | if let str = data.data{ |
| | | switch str{ |
| | | case "succeeded": |
| | | alertSuccess(msg: "购买成功") |
| | | NotificationCenter.default.post(name: WithDrawReply_Noti, object: nil) |
| | | DispatchQueue.main.asyncAfter(delay: 1.0) { |
| | | weakSelf.navigationController?.popViewController() |
| | | } |
| | | case "failed": |
| | | alertError(msg: "购买失败") |
| | | case "closed": |
| | | alertError(msg: "交易已关闭") |
| | | case "refunded": |
| | | alertError(msg: "全额退款") |
| | | case "pending": |
| | | alertError(msg: "待支付") |
| | | default:break |
| | | } |
| | | } |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func viewDidLayoutSubviews() { |
| | |
| | | sceneDelegate?.needLogin() |
| | | return} |
| | | |
| | | showHUD("正在进行内购买") |
| | | let product = products[selectIndexPath.row] |
| | | 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() |
| | | if isShowMore{ |
| | | let product = products[selectIndexPath.row] |
| | | Services.placeOrder(orderForm: .recharge, payType: tapType == .t2 ? 2:1, amount: product.price.doubleValue, balanceFlag: nil, orderId: nil, receiverId: nil, targetId: nil, vipType: nil).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | |
| | | if let m = data.data{ |
| | | weakSelf.orderId = m.orderId |
| | | |
| | | if weakSelf.tapType == .t2{ |
| | | UIApplication.shared.open(URL(string: m.qrcodeUrl!)!) |
| | | } |
| | | |
| | | if weakSelf.tapType == .t3{ |
| | | let miniProgram = WXLaunchMiniProgramReq.object() |
| | | miniProgram.miniProgramType = .release |
| | | miniProgram.userName = m.orgId! |
| | | miniProgram.path = m.path! |
| | | WXApi.send(miniProgram){ s in |
| | | if !s{ |
| | | alert(msg: "打开失败") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | }else{ |
| | | showHUD("正在进行内购买") |
| | | let product = products[selectIndexPath.row] |
| | | 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) |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | }.disposed(by: weakSelf.timeLoopDisposeBag) |
| | | }).disposed(by: weakSelf.disposeBag) |
| | | } |
| | | } errorClouse: { error in |
| | | alertError(msg: "支付失败") |
| | | } |
| | | } errorClouse: { error in |
| | | alertError(msg: "支付失败") |
| | | } |
| | | } |
| | | |
| | | @IBAction func tapAction(_ sender: Any) { |
| | | PurchaseMethodView.show {[weak self] type in |
| | | guard let weakSelf = self else { return } |
| | | weakSelf.tapType = type |
| | | |
| | | switch type { |
| | | case .t2: |
| | | weakSelf.tap_other_title.text = "支".appending("付").appending("宝") |
| | | case .t3: |
| | | weakSelf.tap_other_title.text = "微".appending("信") |
| | | default:break |
| | | } |
| | | } |
| | | } |
| | | } |