lmw
2025-01-10 601f14db94013373df700e007095f7f2f5ecbe24
app/src/main/java/com/sinata/xqmuse/ui/home/BuyVoiceActivity.kt
@@ -16,6 +16,7 @@
import com.sinata.xqmuse.utils.interfaces.StringCallback
import com.sinata.xqmuse.utils.pay.PayListener
import kotlinx.android.synthetic.main.activity_buy_course.*
import org.jetbrains.anko.browse
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
@@ -25,6 +26,7 @@
    private val fromDetail by lazy { intent.getBooleanExtra("fromDetail",true) }
    private val id by lazy { intent.getStringExtra("id") }
    private var data:ConfirmOrder? = null
    private var orderId = ""
    override fun initClick() {
        tv_buy_rule.clickDelay {
@@ -42,18 +44,15 @@
        tv_action.setOnClickListener {
            if (cb_rule.isChecked){
                if (cb_rule.isChecked){
                    if (rb_balance.isChecked&&((data?.balance?:"0.0").toDouble()>=(data?.generalPrice?:"0.0").toDouble())){//余额勾选,并且可用余额大于课程价格,直接扣余额
                        payBalance()
                    }else if (rb_ali.isChecked){
                        pay(2)
                    }else if (rb_wx.isChecked){
                        pay(1)
                    }else{
                        toast("请选择支付方式")
                    }
                }else
                    toast("请阅读并同意《购买协议》")
                if ((data?.generalPrice?:"0.0").toDouble() == 0.0||rb_balance.isChecked&&((data?.balance?:"0.0").toDouble()>=(data?.generalPrice?:"0.0").toDouble())){//余额勾选,并且可用余额大于课程价格,直接扣余额
                    payBalance()
                }else if (rb_ali.isChecked){
                    pay(2)
                }else if (rb_wx.isChecked){
                    pay(1)
                }else{
                    toast("请选择支付方式")
                }
            }else
                toast("请阅读并同意《购买协议》")
        }
@@ -62,8 +61,13 @@
    private fun pay(way:Int) {
        tv_action.isEnabled = false
        showDialog()
        HttpManager.placeOrder(1,way,if (rb_balance.isChecked) 1 else 2,null,null,data?.id?:"",null).request(this,success = {_,data->
            onPaySuccess()
        HttpManager.placeOrder(1,way,if (rb_balance.isChecked) 1 else 2,null,null,data?.id?:"",null,data?.orderId).request(this,success = {_,data->
            tv_action.isEnabled = true
            orderId = data?.orderId?:""
            if (way == 1)
                data?.jumpToWx(this)
            else
                browse(data?.qrcodeUrl?:"")
        }){_,_->
            tv_action.isEnabled = true
        }
@@ -110,6 +114,13 @@
                tv_total.text = generalPrice
                val s = "余额抵扣 当前可用 ¥$balance"
                rb_balance.text = SpanBuilder(s).size(4,s.length,11).color(this@BuyVoiceActivity,4,s.length,R.color.textColor99).build()
                rb_balance.isChecked = !(balance.isNullOrEmpty()||balance.toDouble() == 0.0)
                if ((data?.generalPrice?:"0.0").toDouble() == 0.0){
                    rb_ali.isEnabled = false
                    rb_wx.isEnabled = false
                    rb_ali.alpha = 0.6f
                    rb_wx.alpha = 0.6f
                }
            }
        }
    }
@@ -126,10 +137,36 @@
                tv_total.text = generalPrice
                val s = "余额抵扣 当前可用 ¥$balance"
                rb_balance.text = SpanBuilder(s).size(4,s.length,11).color(this@BuyVoiceActivity,4,s.length,R.color.textColor99).build()
                rb_balance.isChecked = !(balance.isNullOrEmpty()||balance.toDouble() == 0.0)
            }
        }
    }
    private fun checkPayStatus(){
        if (!orderId.isNullOrEmpty()){
            HttpManager.queryPayment(orderId).request(this){_,data->
                when(data){
                    "pending"->{
                        toast("未查询到支付结果,如已付款请忽略")
                    }
                    "succeeded"->{
                        toast("支付成功")
                        onPaySuccess()
                    }
                    "failed"->{
                        toast("支付失败")
                    }
                }
            }
            orderId = ""
        }
    }
    override fun onResume() {
        super.onResume()
        checkPayStatus()
    }
    override fun onPaySuccess() {
        setResult(RESULT_OK)
        startActivity<PaySuccessActivity>("data" to data,"fromDetail" to fromDetail,"isAudio" to true)