杨锴
2024-12-27 fe02f75ab7a593f33d60c15308ddf7a974962db4
XQMuse/Root/Home/VC/PaymentOrderVC.swift
@@ -63,7 +63,7 @@
    @IBOutlet weak var img_action_2: UIImageView!
    @IBOutlet weak var img_action_3: UIImageView!
    private var price:Double = 0
    private var price:Double?
    private var tapType:TapType = .none{
        didSet{
@@ -126,6 +126,7 @@
    init(pendingModel:PendingItemModel,type:PaymentOrderType){
        super.init(nibName: nil, bundle: nil)
        self.pendingModel = pendingModel
        self.businessId = pendingModel.orderId
        self.type = type
    }
@@ -149,6 +150,11 @@
        if let m = pendingModel{
            if self.businessId != nil{
                self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: btn)
            }
            price = m.amount
            image_cover.sd_setImage(with: URL(string: m.coverUrl.components(separatedBy: ",").first?.jq_urlEncoded()))
            label_courseName.text = m.title
@@ -358,7 +364,7 @@
                    weakSelf.img_action_1.image = balanceData > 0 ? UIImage(named: "icon_choose_small_s") : UIImage(named: "icon_choose_small_1")
                    weakSelf.label_walletBalance.text = "当前可用 ¥\(formattedBalance)"
                    
                    if balanceData > weakSelf.price {
                    if balanceData > weakSelf.price ?? 0 {
                        weakSelf.tapType = .t1
                    }
                } else {
@@ -370,15 +376,24 @@
                weakSelf.label_walletBalance.text = "当前可用 0疗愈币"
                weakSelf.tapType = .t1
            }
            if weakSelf.price == 0{
                weakSelf.tapType = .t1
                weakSelf.btn_tap0.isUserInteractionEnabled = false
                weakSelf.btn_tap1.isUserInteractionEnabled = false
                weakSelf.btn_tap2.isUserInteractionEnabled = false
            }
        }).disposed(by: disposeBag)
    }
    @IBAction func discountByCoinAction(_ sender: TapBtn) {
        guard balance > 0 else {return}
        guard balance >= 0 else {return}
        guard let p = price else{return}
        //是否能全部抵扣
        let allDiscount = balance > price
        let allDiscount = balance > p
        if allDiscount{
            tapType = .t1
@@ -400,9 +415,10 @@
    }
    @IBAction func chooseAction(_ sender: TapBtn) {
        guard let p = price else{return}
        //是否能全部抵扣
        let allDiscount = balance > price
        let allDiscount = balance > p
        switch sender.tag {
            case 2001:
@@ -493,6 +509,7 @@
    }
    @IBAction func completeAction(_ sender: UIButton) {
        guard let p = price else{return}
        var id:Int = 0
        var orderId:Int?
@@ -543,8 +560,8 @@
                }
            }
            if balance < price && tapType == .t1{
                alertError(msg: "抵扣余额不足");return
            if tapType == .t1{
                paymentByCoin(id: id);return
            }
            //进行抵扣
@@ -553,14 +570,7 @@
                discountByCoin = 1
            }
            var payType = 1
            if tapType == .t1t2 || tapType == .t2{
                payType = 2
            }
            if tapType == .t1{
                paymentByCoin(id: id);return
            }
            let payType = (tapType == .t1t2 || tapType == .t2) ?2:1
            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 }
@@ -592,16 +602,24 @@
    }
    private func paymentByCoin(id:Int){
        guard let p = price else{return}
        guard balance > price else{
            CommonAlertView.show(title: "提示", content: "当前余额不足,请先充值", cancelStr: "暂不充值", completeStr: "去充值", isSingle: false) {[weak self] state in
                if state{
                    let vc = WalletRechargeVC()
                    self?.push(vc: vc)
                }
        //需要支付
        if p > 0 {
            if balance < p{
                alertError(msg: "抵扣余额不足");return
            }
            return
            guard balance > p  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{
@@ -611,7 +629,7 @@
                self?.courseItemModel?.isBuy = .yes
                self?.museModel?.isBuy = .yes
                self?.courseModel?.isBuy = .yes
                let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: weakSelf.price)
                let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: p)
                self?.push(vc: vc)
            }).disposed(by: disposeBag)
            return
@@ -623,7 +641,7 @@
            self?.courseItemModel?.isBuy = .yes
            self?.museModel?.isBuy = .yes
            self?.courseModel?.isBuy = .yes
            let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: weakSelf.price)
            let vc = PaymentOrderResultVC(type: weakSelf.type, id: id, price: p)
            self?.push(vc: vc)
        }).disposed(by: disposeBag)
    }