//
|
// PaymentOrderVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/15.
|
//
|
|
import UIKit
|
import QMUIKit
|
|
let Refreh_PaymentWallet_Noti = Notification.Name.init("Refreh_PaymentWallet_Noti")
|
|
class PaymentOrderVC: BaseVC {
|
|
enum PaymentOrderType {
|
case course
|
case muse
|
}
|
|
@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 tf_phone: QMUITextField!
|
@IBOutlet weak var label_walletBalance: UILabel!
|
@IBOutlet weak var btn_isreadAgreement: UIButton!
|
private var museItemModel:MeditationModel?
|
private var courseItemModel:CourseModel?
|
private var giftUserId:Int?
|
private var giftToOther:Bool!
|
private var courseModel:CourseModel?
|
private var museModel:MeditationModel?
|
private var balance:Double = 0
|
private var type:PaymentOrderType!
|
|
init(museItemModel:MeditationModel? = nil,courseItemModel:CourseModel? = nil,type:PaymentOrderType,giftToOther:Bool = false) {
|
super.init(nibName: nil, bundle: nil)
|
self.museItemModel = museItemModel
|
self.courseItemModel = courseItemModel
|
self.giftToOther = giftToOther
|
self.type = type
|
}
|
|
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()
|
|
if type == .course{
|
Services.getCourseDetail(courseId: courseItemModel!.id).subscribe(onNext: {data in
|
if let m = data.data{
|
self.courseModel = m
|
self.image_cover.sd_setImage(with: URL(string: m.coverUrl.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 = "x\(m.count == 0 ? 1:m.count)"
|
self.label_orderPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)"
|
self.label_totalPrice.text = "愈疗币\(m.iosPrice.jq_formatFloat)"
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
if type == .muse{
|
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.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)"
|
}
|
}).disposed(by: disposeBag)
|
}
|
}
|
|
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)
|
}
|
|
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)
|
}
|
|
@IBAction func invateRegisterAction(_ sender: UIButton) {
|
|
}
|
|
@IBAction func searchUserAction(_ sender: UIButton) {
|
guard !tf_phone.text!.isEmpty else {
|
alertError(msg: tf_phone.placeholder ?? "请输入好友手机号");return
|
}
|
|
guard tf_phone.text!.jq_isPhone else {
|
alertError(msg: "请输入正确的手机号");return
|
}
|
|
Services.searchUserByPhone(tf_phone.text!).subscribe(onNext: { data in
|
self.view_searchUserResult.isHidden = false
|
if let m = data.data,m.id != 0{
|
self.giftUserId = m.userId
|
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
|
}else{
|
self.image_avatar.isHidden = true
|
self.label_userName.isHidden = true
|
self.label_userPhone.isHidden = true
|
self.label_searchInfo.isHidden = false
|
self.btn_invate.isHidden = false
|
}
|
}).disposed(by: disposeBag)
|
|
}
|
|
@IBAction func readAgreementAction(_ sender: UIButton) {
|
sender.isSelected = !sender.isSelected
|
}
|
|
|
@IBAction func webAgreementAction(_ sender: UIButton) {
|
let vc = WebVC(type: .course)
|
push(vc: vc)
|
}
|
|
@IBAction func completeAction(_ sender: UIButton) {
|
|
|
var money:Double = 0
|
var id:Int = 0
|
|
if let m = courseModel{
|
money = m.iosPrice
|
id = m.id
|
}
|
|
if let m = museModel{
|
money = m.iosPrice
|
id = m.id
|
}
|
|
|
guard btn_isRead.isSelected else {
|
alertError(msg: "请先阅读并同意《课程/疗愈音频购买协议》");return
|
}
|
|
if giftToOther {
|
guard !tf_phone.text!.isEmpty else {
|
alertError(msg: "请输入您要赠送人的手机号");return
|
}
|
|
guard giftUserId != nil else {
|
alertError(msg: "请先查询赠送人是否存在");return
|
}
|
}
|
|
guard balance > money else{
|
CommonAlertView.show(title: "提示", content: "当前余额不足,请先充值", cancelStr: "暂不充值", completeStr: "去充值", isSingle: false) { 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
|
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)
|
}
|
}
|