杨锴
2024-12-04 d178e85e06d287ce8ca8b79811ec636fbc9d50e1
XQMuse/Root/Home/VC/PaymentOrderVC.swift
@@ -28,6 +28,7 @@
        case course = 2
        case vip = 3
        case recharge = 4
        case none = 0
    }
    @IBOutlet weak var image_cover: UIImageView!
@@ -101,12 +102,13 @@
    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
@@ -117,8 +119,14 @@
        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) {
@@ -139,62 +147,82 @@
        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
@@ -217,6 +245,18 @@
                    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)
@@ -360,15 +400,6 @@
    }
    @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
@@ -464,6 +495,7 @@
    @IBAction func completeAction(_ sender: UIButton) {
        var id:Int = 0
        var orderId:Int?
        if let m = courseModel{
            id = m.id
        }
@@ -474,6 +506,11 @@
            guard id != UserViewModel.getAvatarInfo().id else {
                alertError(msg: "不能赠送给自己");return
            }
        }
        if let m = pendingModel{
            id = m.id
            orderId = m.orderId
        }
        guard btn_isRead.isSelected else {
@@ -493,12 +530,17 @@
        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{
@@ -520,7 +562,7 @@
                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
@@ -563,7 +605,7 @@
        }
        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