| | |
| | | |
| | | 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 label_price: UILabel! |
| | | @IBOutlet weak var label_teacher: UILabel! |
| | | @IBOutlet weak var label_paymentCount: UILabel! |
| | | @IBOutlet weak var label_courseName: UILabel! |
| | | @IBOutlet weak var label_orderPrice: UILabel! |
| | | @IBOutlet weak var label_currentAccount: UILabel! |
| | | @IBOutlet weak var label_totalPrice: UILabel! |
| | | @IBOutlet weak var view_searchUserInput: UIView! |
| | | @IBOutlet weak var view_searchUserResult: UIView! |
| | | @IBOutlet weak var image_cover: UIImageView! |
| | | @IBOutlet weak var label_price: UILabel! |
| | | @IBOutlet weak var label_teacher: UILabel! |
| | | @IBOutlet weak var label_paymentCount: UILabel! |
| | | @IBOutlet weak var label_courseName: UILabel! |
| | | @IBOutlet weak var label_orderPrice: UILabel! |
| | | @IBOutlet weak var label_currentAccount: UILabel! |
| | | @IBOutlet weak var label_totalPrice: UILabel! |
| | | @IBOutlet weak var view_searchUserInput: UIView! |
| | | @IBOutlet weak var view_searchUserResult: UIView! |
| | | |
| | | @IBOutlet weak var image_avatar: UIImageView! |
| | | @IBOutlet weak var label_userName: UILabel! |
| | | @IBOutlet weak var label_userPhone: UILabel! |
| | | @IBOutlet weak var label_searchInfo: UILabel! |
| | | @IBOutlet weak var btn_invate: UIButton! |
| | | @IBOutlet weak var btn_isRead: UIButton! |
| | | @IBOutlet weak var image_avatar: UIImageView! |
| | | @IBOutlet weak var label_userName: UILabel! |
| | | @IBOutlet weak var label_userPhone: UILabel! |
| | | @IBOutlet weak var label_searchInfo: UILabel! |
| | | @IBOutlet weak var btn_invate: UIButton! |
| | | @IBOutlet weak var btn_isRead: UIButton! |
| | | |
| | | @IBOutlet weak var tf_phone: QMUITextField! |
| | | @IBOutlet weak var label_walletBalance: UILabel! |
| | | @IBOutlet weak var btn_isreadAgreement: UIButton! |
| | | private var museItemModel:MeditationModel? |
| | | @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 giftToOther:Bool! |
| | | private var courseModel:CourseModel? |
| | | private var giftUserId:Int? |
| | | private var giftToOther:Bool! |
| | | private var courseModel:CourseModel? |
| | | private var museModel:MeditationModel? |
| | | private var balance:Double = 0 |
| | | private var balance:Double = 0 |
| | | 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) |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.museItemModel = museItemModel |
| | | self.courseItemModel = courseItemModel |
| | | self.giftToOther = giftToOther |
| | | self.giftToOther = giftToOther |
| | | self.type = type |
| | | self.showType = showType |
| | | self.businessId = businessId |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "确认订单" |
| | | view_searchUserResult.isHidden = true |
| | | view_searchUserInput.isHidden = !giftToOther |
| | | } |
| | | |
| | | getBalance() |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | 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() |
| | | |
| | | let btn = UIButton(type: .custom) |
| | | btn.setTitle("取消订单", for: .normal) |
| | |
| | | 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" |
| | | self.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | |
| | | 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) |
| | | } |
| | |
| | | if self.businessId != nil{ |
| | | self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn) |
| | | } |
| | | |
| | | |
| | | Services.getMeditationDetail(id: museItemModel!.id).subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | 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" |
| | | self.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | self.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | |
| | | 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() |
| | | } |
| | | override func setUI() { |
| | | super.setUI() |
| | | |
| | | override func setRx() { |
| | | NotificationCenter.default.rx.notification(Refreh_PaymentWallet_Noti).take(until: self.rx.deallocated).subscribe(onNext: {_ in |
| | | self.getBalance() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | 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(){ |
| | | if businessId != nil{ |
| | |
| | | } |
| | | } |
| | | |
| | | private func getBalance(){ |
| | | Services.getUserBalance().subscribe(onNext: {data in |
| | | self.balance = data.data ?? 0 |
| | | self.label_walletBalance.text = String(format: "当前可用 %@疗愈币", data.data?.jq_formatFloat ?? "0") |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | 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 invateRegisterAction(_ sender: UIButton) { |
| | | |
| | | @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) { |
| | | |
| | | let string = String(format: "%@%@?userId=%ld",ShareUrl,"/register/register",UserViewModel.getAvatarInfo().id) |
| | | ShareView.show(URL(string: string)!, title: "分享疗愈时光,让宁静触手可及", desc: "这份疗愈之旅,带来了意想不到的平静和安宁。愿与你一同分享,让我们在繁忙的生活中找到片刻的温柔,静享属于我们的宁静时光。",hasSave: false) { |
| | | // alertSuccess(msg: "已保存至相册") |
| | | // alertSuccess(msg: "已保存至相册") |
| | | } |
| | | } |
| | | } |
| | | |
| | | @IBAction func searchUserAction(_ sender: UIButton) { |
| | | @IBAction func searchUserAction(_ sender: UIButton) { |
| | | tf_phone.resignFirstResponder() |
| | | guard !tf_phone.text!.isEmpty else { |
| | | alertError(msg: tf_phone.placeholder ?? "请输入好友手机号");return |
| | | } |
| | | guard !tf_phone.text!.isEmpty else { |
| | | alertError(msg: tf_phone.placeholder ?? "请输入好友手机号");return |
| | | } |
| | | |
| | | guard tf_phone.text!.jq_isPhone else { |
| | | alertError(msg: "请输入正确的手机号");return |
| | | } |
| | | guard tf_phone.text!.jq_isPhone else { |
| | | alertError(msg: "请输入正确的手机号");return |
| | | } |
| | | |
| | | Services.searchUserByPhone(tf_phone.text!,ignoreAlert: false).subscribe(onNext: { data in |
| | | self.view_searchUserResult.isHidden = false |
| | | if let m = data.data,m.id != 0{ |
| | | self.giftUserId = m.id |
| | | self.image_avatar.sd_setImage(with: URL(string: m.avatar)) |
| | | self.label_userName.text = m.nickname |
| | | self.label_userPhone.text = m.cellPhone |
| | | self.label_searchInfo.isHidden = true |
| | | self.btn_invate.isHidden = true |
| | | self.view_searchUserResult.isHidden = false |
| | | if let m = data.data,m.id != 0{ |
| | | self.giftUserId = m.id |
| | | self.image_avatar.sd_setImage(with: URL(string: m.avatar)) |
| | | self.label_userName.text = m.nickname |
| | | self.label_userPhone.text = m.cellPhone |
| | | self.label_searchInfo.isHidden = true |
| | | self.btn_invate.isHidden = true |
| | | self.image_avatar.isHidden = false |
| | | self.label_userName.isHidden = false |
| | | self.label_userPhone.isHidden = false |
| | | self.btn_invate.isHidden = true |
| | | } |
| | | } |
| | | },onError: { _ in |
| | | self.view_searchUserResult.isHidden = false |
| | | self.image_avatar.isHidden = true |
| | |
| | | self.btn_invate.isHidden = false |
| | | }).disposed(by: disposeBag) |
| | | |
| | | } |
| | | } |
| | | |
| | | @IBAction func readAgreementAction(_ sender: UIButton) { |
| | | sender.isSelected = !sender.isSelected |
| | | } |
| | | @IBAction func readAgreementAction(_ sender: UIButton) { |
| | | sender.isSelected = !sender.isSelected |
| | | } |
| | | |
| | | |
| | | @IBAction func webAgreementAction(_ sender: UIButton) { |
| | | @IBAction func webAgreementAction(_ sender: UIButton) { |
| | | |
| | | Services.agreementBy(.course).subscribe(onNext: {data in |
| | | if let model = data.data{ |
| | |
| | | self.present(vc, animated: true) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | |
| | | |
| | | var money:Double = 0 |
| | |
| | | } |
| | | } |
| | | |
| | | guard balance > money else{ |
| | | CommonAlertView.show(title: "提示", content: "当前余额不足,请先充值", cancelStr: "暂不充值", completeStr: "去充值", isSingle: false) {[weak self] state in |
| | | if state{ |
| | | let vc = WalletRechargeVC() |
| | | self?.push(vc: vc) |
| | | } |
| | | } |
| | | return |
| | | } |
| | | if isShowMore{ |
| | | guard tapType != nil else {alertError(msg: "请选择支付方式");return} |
| | | |
| | | if businessId != nil{ |
| | | Services.gvieCourseAgain(orderForm: type, id: businessId!).subscribe(onNext: {[weak self]data in |
| | | 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{ |
| | | let vc = WalletRechargeVC() |
| | | self?.push(vc: vc) |
| | | } |
| | | } |
| | | return |
| | | } |
| | | |
| | | if businessId != nil{ |
| | | Services.gvieCourseAgain(orderForm: type, id: businessId!).subscribe(onNext: {[weak self]data in |
| | | guard let weakSelf = self else { return } |
| | | self?.museItemModel?.isBuy = .yes |
| | | self?.courseItemModel?.isBuy = .yes |
| | | self?.museModel?.isBuy = .yes |
| | | self?.courseModel?.isBuy = .yes |
| | | let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: money) |
| | | self?.push(vc: vc) |
| | | }).disposed(by: disposeBag) |
| | | 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 |
| | | self?.courseItemModel?.isBuy = .yes |
| | |
| | | let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: money) |
| | | self?.push(vc: vc) |
| | | }).disposed(by: disposeBag) |
| | | 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 |
| | | self?.courseItemModel?.isBuy = .yes |
| | | self?.museModel?.isBuy = .yes |
| | | self?.courseModel?.isBuy = .yes |
| | | let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: money) |
| | | self?.push(vc: vc) |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |
| | | } |