| | |
| | | case course = 2 |
| | | case vip = 3 |
| | | case recharge = 4 |
| | | case none = 0 |
| | | } |
| | | |
| | | @IBOutlet weak var image_cover: UIImageView! |
| | |
| | | private var museItemModel:MeditationModel? |
| | | private var courseItemModel:CourseModel? |
| | | private var giftUserId:Int? |
| | | private var giftToOther:Bool! |
| | | private var giftToOther:Bool = false |
| | | private var courseModel:CourseModel? |
| | | private var museModel:MeditationModel? |
| | | private var pendingModel:PendingItemModel? |
| | | private var balance:Double = 0 |
| | | private var type:PaymentOrderType! |
| | | private var showType:DisplayType! |
| | | private var type:PaymentOrderType = .none |
| | | // private var showType:DisplayType! |
| | | private var businessId:Int? |
| | | |
| | | private var orderId:String? //下单后的ID |
| | |
| | | self.courseItemModel = courseItemModel |
| | | self.giftToOther = giftToOther |
| | | self.type = type |
| | | self.showType = showType |
| | | // self.showType = showType |
| | | self.businessId = businessId |
| | | } |
| | | |
| | | init(pendingModel:PendingItemModel,type:PaymentOrderType){ |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.pendingModel = pendingModel |
| | | self.type = type |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | |
| | | btn.titleLabel?.font = .systemFont(ofSize: 15) |
| | | btn.addTarget(self, action: #selector(cancelAction), for: .touchUpInside) |
| | | |
| | | if type == .course{ |
| | | if self.businessId != nil{ |
| | | self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn) |
| | | |
| | | if let m = pendingModel{ |
| | | price = m.amount |
| | | image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | label_courseName.text = m.title |
| | | label_teacher.text = "" |
| | | label_paymentCount.text = "x1" |
| | | |
| | | if isShowMore{ |
| | | label_price.text = "¥\(m.amount.jq_formatFloat)" |
| | | label_orderPrice.text = "¥\(m.amount.jq_formatFloat)" |
| | | label_totalPrice.text = "¥\(m.amount.jq_formatFloat)" |
| | | }else{ |
| | | label_price.text = "愈疗币\(m.amount.jq_formatFloat)" |
| | | label_orderPrice.text = "愈疗币\(m.amount.jq_formatFloat)" |
| | | label_totalPrice.text = "愈疗币\(m.amount.jq_formatFloat)" |
| | | } |
| | | getBalance() |
| | | }else{ |
| | | if type == .course{ |
| | | if self.businessId != nil{ |
| | | self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn) |
| | | } |
| | | |
| | | Services.getCourseDetail(courseId: courseItemModel!.id).subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | self.courseModel = m |
| | | self.price = m.iosPrice |
| | | self.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | self.label_courseName.text = m.courseTitle |
| | | |
| | | 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)" |
| | | } |
| | | self.getBalance() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | Services.getCourseDetail(courseId: courseItemModel!.id).subscribe(onNext: {data in |
| | | if let m = data.data{ |
| | | self.courseModel = m |
| | | self.price = m.iosPrice |
| | | self.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | self.label_courseName.text = m.courseTitle |
| | | |
| | | 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)" |
| | | } |
| | | self.getBalance() |
| | | if type == .muse{ |
| | | if self.businessId != nil{ |
| | | self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | if type == .muse{ |
| | | if self.businessId != nil{ |
| | | self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn) |
| | | Services.getMeditationDetail(id: museItemModel!.id).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data{ |
| | | weakSelf.museModel = m |
| | | weakSelf.price = m.iosPrice |
| | | weakSelf.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | weakSelf.label_courseName.text = m.meditationTitle |
| | | weakSelf.label_teacher.text = "" |
| | | weakSelf.label_paymentCount.text = "x1" |
| | | |
| | | if weakSelf.isShowMore{ |
| | | weakSelf.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | }else{ |
| | | weakSelf.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | weakSelf.getBalance() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | Services.getMeditationDetail(id: museItemModel!.id).subscribe(onNext: {[weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data{ |
| | | weakSelf.museModel = m |
| | | weakSelf.price = m.iosPrice |
| | | weakSelf.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | weakSelf.label_courseName.text = m.meditationTitle |
| | | weakSelf.label_teacher.text = "" |
| | | weakSelf.label_paymentCount.text = "x1" |
| | | |
| | | if weakSelf.isShowMore{ |
| | | weakSelf.label_price.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "¥\(m.iosPrice.jq_formatFloat)" |
| | | }else{ |
| | | weakSelf.label_price.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)" |
| | | } |
| | | weakSelf.getBalance() |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | Services.getTurn().subscribe(onNext: {[weak self]data in |
| | |
| | | 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.pendingModel{ |
| | | weakSelf.price = m.amount |
| | | weakSelf.image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded())) |
| | | weakSelf.label_courseName.text = m.title |
| | | weakSelf.label_teacher.text = "" |
| | | weakSelf.label_paymentCount.text = "x1" |
| | | weakSelf.label_price.text = "¥\(m.amount.jq_formatFloat)" |
| | | weakSelf.label_orderPrice.text = "¥\(m.amount.jq_formatFloat)" |
| | | weakSelf.label_totalPrice.text = "¥\(m.amount.jq_formatFloat)" |
| | | weakSelf.getBalance() |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | |
| | | } |
| | | |
| | | @IBAction func chooseAction(_ sender: TapBtn) { |
| | | var price:Double = 0 |
| | | switch type { |
| | | case .course: |
| | | price = courseModel?.iosPrice ?? 0 |
| | | case .muse: |
| | | price = courseModel?.iosPrice ?? 0 |
| | | default:break |
| | | } |
| | | |
| | | |
| | | //是否能全部抵扣 |
| | | let allDiscount = balance > price |
| | |
| | | @IBAction func completeAction(_ sender: UIButton) { |
| | | |
| | | var id:Int = 0 |
| | | var orderId:Int? |
| | | if let m = courseModel{ |
| | | id = m.id |
| | | } |
| | |
| | | guard id != UserViewModel.getAvatarInfo().id else { |
| | | alertError(msg: "不能赠送给自己");return |
| | | } |
| | | } |
| | | |
| | | if let m = pendingModel{ |
| | | id = m.id |
| | | orderId = m.orderId |
| | | } |
| | | |
| | | guard btn_isRead.isSelected else { |
| | |
| | | if isShowMore{ |
| | | guard tapType != .none else {alertError(msg: "请选择支付方式");return} |
| | | var targetId:Int = 0 |
| | | switch type { |
| | | case .course: |
| | | targetId = courseModel!.id |
| | | case .muse: |
| | | targetId = museModel!.id |
| | | default:break |
| | | |
| | | if let m = pendingModel{ |
| | | targetId = m.id |
| | | }else{ |
| | | switch type { |
| | | case .course: |
| | | targetId = courseModel!.id |
| | | case .muse: |
| | | targetId = museModel!.id |
| | | default:break |
| | | } |
| | | } |
| | | |
| | | if balance < price && tapType == .t1{ |
| | |
| | | paymentByCoin(id: id);return |
| | | } |
| | | |
| | | Services.placeOrder(orderForm: type, payType: payType, amount: nil, balanceFlag: discountByCoin, orderId: nil, receiverId: giftUserId, targetId: targetId, vipType: nil).subscribe(onNext: { [weak self] data in |
| | | Services.placeOrder(orderForm: type, payType: payType, amount: nil, balanceFlag: discountByCoin, orderId: orderId, receiverId: giftUserId, targetId: targetId, vipType: nil).subscribe(onNext: { [weak self] data in |
| | | guard let weakSelf = self else { return } |
| | | if let m = data.data{ |
| | | weakSelf.orderId = m.orderId |
| | |
| | | } |
| | | |
| | | if businessId != nil{ |
| | | Services.gvieCourseAgain(orderForm: type, id: businessId!).subscribe(onNext: {[weak self]data in |
| | | Services.gvieCourseAgain(id: businessId!).subscribe(onNext: {[weak self]data in |
| | | guard let weakSelf = self else { return } |
| | | self?.museItemModel?.isBuy = .yes |
| | | self?.courseItemModel?.isBuy = .yes |