| | |
| | | |
| | | let Refreh_PaymentWallet_Noti = Notification.Name.init("Refreh_PaymentWallet_Noti") |
| | | |
| | | |
| | | enum TapType{ |
| | | case t1 |
| | | case t2 //z__f__b |
| | | case t3 //w__x |
| | | } |
| | | |
| | | class PaymentOrderVC: BaseVC { |
| | | |
| | | enum PaymentOrderType { |
| | | case course |
| | | case muse |
| | | enum PaymentOrderType:Int{ |
| | | case muse = 1 |
| | | case course = 2 |
| | | case vip = 3 |
| | | case recharge = 4 |
| | | } |
| | | |
| | | @IBOutlet weak var image_cover: UIImageView! |
| | |
| | | @IBOutlet weak var tf_phone: QMUITextField! |
| | | @IBOutlet weak var label_walletBalance: UILabel! |
| | | @IBOutlet weak var btn_isreadAgreement: UIButton! |
| | | |
| | | @IBOutlet weak var label_p_1: UILabel! |
| | | @IBOutlet weak var label_p_2: UILabel! |
| | | @IBOutlet weak var btn_tap0: TapBtn! |
| | | @IBOutlet weak var btn_tap1: TapBtn! |
| | | @IBOutlet weak var btn_tap2: TapBtn! |
| | | |
| | | @IBOutlet weak var img_action_1: UIImageView! |
| | | @IBOutlet weak var img_action_2: UIImageView! |
| | | @IBOutlet weak var img_action_3: UIImageView! |
| | | |
| | | private var tapType:TapType? |
| | | |
| | | private var isShowMore:Bool = false |
| | | private var discountByCoin:Bool = false |
| | | |
| | | private var museItemModel:MeditationModel? |
| | | private var courseItemModel:CourseModel? |
| | | private var giftUserId:Int? |
| | |
| | | private var type:PaymentOrderType! |
| | | private var showType:DisplayType! |
| | | private var businessId:Int? |
| | | |
| | | private var orderId:String? //下单后的ID |
| | | |
| | | init(museItemModel:MeditationModel? = nil,courseItemModel:CourseModel? = nil,type:PaymentOrderType,giftToOther:Bool = false,showType:DisplayType!,businessId:Int? = nil) { |
| | | super.init(nibName: nil, bundle: nil) |
| | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "确认订单" |
| | | btn_tap0.isUserInteractionEnabled = false |
| | | view_searchUserResult.isHidden = true |
| | | view_searchUserInput.isHidden = !giftToOther |
| | | img_action_1.image = UIImage(named: "icon_choose_small_s") |
| | | |
| | | getBalance() |
| | | |
| | |
| | | self.courseModel = m |
| | | self.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | self.label_courseName.text = m.courseTitle |
| | | self.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | |
| | | self.label_teacher.text = "导师 \(m.tutor)" |
| | | self.label_paymentCount.text = "x1" |
| | | |
| | | if self.isShowMore{ |
| | | self.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | self.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | }else{ |
| | | self.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | |
| | | self.museModel = m |
| | | self.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | self.label_courseName.text = m.meditationTitle |
| | | self.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_teacher.text = "" |
| | | self.label_paymentCount.text = "x1" |
| | | |
| | | if self.isShowMore{ |
| | | self.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | self.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | }else{ |
| | | self.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | Services.getTurn().subscribe(onNext: {[weak self]data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data,m == true{ |
| | | weakSelf.btn_tap0.isUserInteractionEnabled = true |
| | | weakSelf.isShowMore = m |
| | | weakSelf.img_action_1.image = UIImage(named: "icon_choose_small_1") |
| | | weakSelf.btn_tap1.isHidden = !m |
| | | weakSelf.btn_tap2.isHidden = !m |
| | | weakSelf.getBalance() |
| | | |
| | | if let m = weakSelf.courseModel{ |
| | | weakSelf.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | |
| | | if let m = weakSelf.museModel{ |
| | | weakSelf.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func setUI() { |
| | | super.setUI() |
| | | |
| | | label_p_1.text = ("支"+"付").appending("宝").appending("支").appending("付") |
| | | label_p_2.text = ("微"+"信").appending("支").appending("付") |
| | | } |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(Refreh_PaymentWallet_Noti).take(until: self.rx.deallocated).subscribe(onNext: {_ in |
| | | self.getBalance() |
| | | }).disposed(by: disposeBag) |
| | | |
| | | |
| | | 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: "购买成功") |
| | | var id = 0 |
| | | var money:Double = 0 |
| | | switch weakSelf.type { |
| | | case .muse: |
| | | id = weakSelf.museModel!.id |
| | | money = weakSelf.museModel!.iosPrice |
| | | case .course: |
| | | id = weakSelf.courseModel!.id |
| | | money = weakSelf.courseModel!.iosPrice |
| | | default:break |
| | | } |
| | | |
| | | let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: money) |
| | | weakSelf.push(vc: vc) |
| | | 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) |
| | | |
| | | } |
| | | |
| | | @objc private func cancelAction(){ |
| | |
| | | private func getBalance(){ |
| | | Services.getUserBalance().subscribe(onNext: {data in |
| | | self.balance = data.data ?? 0 |
| | | if self.isShowMore{ |
| | | self.label_walletBalance.text = String(format: "当前可用 ¥%@", data.data?.jq_formatFloat ?? "0") |
| | | }else{ |
| | | self.label_walletBalance.text = String(format: "当前可用 %@疗愈币", data.data?.jq_formatFloat ?? "0") |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | |
| | | @IBAction func discountByCoinAction(_ sender: TapBtn) { |
| | | discountByCoin.toggle() |
| | | if discountByCoin{ |
| | | img_action_1.image = UIImage(named: "icon_choose_small_s") |
| | | }else{ |
| | | img_action_1.image = UIImage(named: "icon_choose_small_1") |
| | | } |
| | | |
| | | |
| | | var price:Double = 0 |
| | | |
| | | switch type { |
| | | case .course: |
| | | if discountByCoin{ |
| | | price = max((courseModel?.iosPrice ?? 0) - balance,0) |
| | | }else{ |
| | | price = courseModel?.iosPrice ?? 0 |
| | | } |
| | | case .muse: |
| | | if discountByCoin{ |
| | | price = max((museModel?.iosPrice ?? 0) - balance,0) |
| | | }else{ |
| | | price = museModel?.iosPrice ?? 0 |
| | | } |
| | | default:break |
| | | } |
| | | |
| | | |
| | | label_totalPrice.text = "¥" + price.jq_formatFloat |
| | | } |
| | | |
| | | @IBAction func chooseAction(_ sender: TapBtn) { |
| | | switch sender.tag { |
| | | case 2001: |
| | | tapType = .t2 |
| | | img_action_2.image = UIImage(named: "icon_choose_small_s") |
| | | img_action_3.image = UIImage(named: "icon_choose_small_1") |
| | | case 2002: |
| | | tapType = .t3 |
| | | img_action_2.image = UIImage(named: "icon_choose_small_1") |
| | | img_action_3.image = UIImage(named: "icon_choose_small_s") |
| | | default: break |
| | | } |
| | | } |
| | | |
| | | @IBAction func invateRegisterAction(_ sender: UIButton) { |
| | |
| | | } |
| | | } |
| | | |
| | | if isShowMore{ |
| | | guard tapType != nil else {alertError(msg: "请选择支付方式");return} |
| | | |
| | | var price:Double = 0 |
| | | var targetId:Int = 0 |
| | | switch type { |
| | | case .course: |
| | | price = courseModel!.iosPrice |
| | | targetId = courseModel!.id |
| | | case .muse: |
| | | price = museModel!.iosPrice |
| | | targetId = museModel!.id |
| | | default:break |
| | | } |
| | | |
| | | if discountByCoin && balance < price{ |
| | | alertError(msg: "抵扣余额不足");return |
| | | } |
| | | |
| | | Services.placeOrder(orderForm: type, payType: tapType == .t2 ? 2:1, amount: nil, balanceFlag: discountByCoin ? 1:2, orderId: nil, receiverId: giftUserId, targetId: targetId, vipType: nil).subscribe(onNext: { [self] data in |
| | | if let m = data.data{ |
| | | self.orderId = m.orderId |
| | | |
| | | if self.tapType == .t2{ |
| | | UIApplication.shared.open(URL(string: m.qrcodeUrl!)!) |
| | | } |
| | | |
| | | if self.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{ |
| | | guard balance > money else{ |
| | | CommonAlertView.show(title: "提示", content: "当前余额不足,请先充值", cancelStr: "暂不充值", completeStr: "去充值", isSingle: false) {[weak self] state in |
| | | if state{ |
| | |
| | | return |
| | | } |
| | | |
| | | |
| | | Services.gvieCourse(orderForm: type, targetId: id,receiverId: giftUserId).subscribe(onNext: {[weak self]data in |
| | | guard let weakSelf = self else { return } |
| | | self?.museItemModel?.isBuy = .yes |
| | |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | } |