From 8d72ec1b07a4fe0863b41b1140a8c0e679867b93 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期四, 03 四月 2025 17:44:29 +0800
Subject: [PATCH] save

---
 app/src/main/java/com/sinata/xqmuse/ui/course/BuyCourseActivity.kt |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/com/sinata/xqmuse/ui/course/BuyCourseActivity.kt b/app/src/main/java/com/sinata/xqmuse/ui/course/BuyCourseActivity.kt
index 970f3d5..95358d0 100644
--- a/app/src/main/java/com/sinata/xqmuse/ui/course/BuyCourseActivity.kt
+++ b/app/src/main/java/com/sinata/xqmuse/ui/course/BuyCourseActivity.kt
@@ -22,6 +22,7 @@
 import com.sinata.xqmuse.utils.pay.PayListener
 import com.umeng.socialize.bean.SHARE_MEDIA
 import kotlinx.android.synthetic.main.activity_buy_course.*
+import org.jetbrains.anko.browse
 import org.jetbrains.anko.startActivity
 import org.jetbrains.anko.toast
 
@@ -32,6 +33,7 @@
     private val fromDetail by lazy { intent.getBooleanExtra("fromDetail",true) }
     private val data by lazy { intent.getParcelableExtra<ConfirmOrder>("data") }
     private var receiveId:String? = null
+    private var orderId = ""
 
     override fun initClick() {
         tv_search.setOnClickListener {
@@ -112,8 +114,13 @@
     private fun pay(way:Int) {
         tv_action.isEnabled = false
         showDialog()
-        HttpManager.placeOrder(2,way,if (rb_balance.isChecked) 1 else 2,null,receiveId,data?.id?:"",null).request(this,success = {_,data->
-            onPaySuccess()
+        HttpManager.placeOrder(2,way,if (rb_balance.isChecked) 1 else 2,null,receiveId,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
         }
@@ -161,9 +168,42 @@
             tv_total.text = generalPrice
             val s = "余额抵扣 当前可用 ¥$balance"
             rb_balance.text = SpanBuilder(s).size(4,s.length,11).color(this@BuyCourseActivity,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
+            }
         }
     }
 
+    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)

--
Gitblit v1.7.1