From dd2562d8dc2b01bcdfca3152f82f09efbbd09259 Mon Sep 17 00:00:00 2001
From: zuoxiao <lf_zuo@163.com>
Date: 星期三, 25 六月 2025 19:49:48 +0800
Subject: [PATCH] fix(generallibrary): 优化卡片处理和支付方式获取逻辑- 修复地区卡处理逻辑,增加对"00"类型卡的特殊处理 - 优化用户卡数据解析和显示逻辑,提高容错性 - 改进支付方式获取方法,增加错误处理和日志记录 -调整充值接口调用参数,确保正确传递当前余额等信息- 修复 AreaCard 中 areaNumber 类型,改为字符串处理

---
 generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt |  143 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 126 insertions(+), 17 deletions(-)

diff --git a/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt b/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
index 3ec2878..7658e5b 100644
--- a/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
+++ b/generallibrary/src/main/java/com/dayu/general/activity/RechargeDetailActivity.kt
@@ -23,6 +23,7 @@
 import com.dayu.general.bean.net.RechargeRequest
 import com.dayu.general.bean.net.RechargeResult
 import com.dayu.general.bean.card.UserCard
+import com.dayu.general.bean.net.PaymentMethodListResponse
 import com.dayu.general.databinding.ActivityRechargeDetailBinding
 import com.dayu.general.net.ApiManager
 import com.dayu.general.net.BaseResponse
@@ -149,23 +150,60 @@
     }
 
     /**
-     * 鑾峰彇鏀粯鏂瑰紡鍒楄〃
+     * 鑾峰彇鏀粯鏂瑰紡鍒楄〃 - 浣跨敤Object绫诲瀷瀹夊叏澶勭悊JSON鏁扮粍
      */
     private fun getPaymentMethods() {
         ApiManager.getInstance().requestGetLoading(
             this,
             "terminal/paymentmethod/get",
-            Array<PaymentMethod>::class.java,
+            Any::class.java,
             null,
-            object : SubscriberListener<BaseResponse<Array<PaymentMethod>>>() {
-                override fun onNext(response: BaseResponse<Array<PaymentMethod>>) {
+            object : SubscriberListener<BaseResponse<Any>>() {
+                override fun onNext(response: BaseResponse<Any>) {
                     if (response.success) {
-                        // 鑾峰彇鏀粯鏂瑰紡鍒楄〃锛岀幇鍦╟ontent鐩存帴鏄疨aymentMethod鏁扮粍
-                        val paymentMethods = response.content?.toList() ?: listOf()
-                        if (paymentMethods.isNotEmpty()) {
-                            paymentMethodList = paymentMethods
-                            // 鏇存柊鏀粯鏂瑰紡鏄剧ず
-                            updatePaymentMethodRadioGroup()
+                        try {
+                            // 瀹夊叏鍦板鐞嗚繑鍥炵殑content锛屾湇鍔″櫒杩斿洖鐨勬槸ArrayList<LinkedHashMap>
+                            val paymentMethods = mutableListOf<PaymentMethod>()
+                            val content = response.content
+                            
+                            if (content is List<*>) {
+                                content.forEach { item ->
+                                    if (item is Map<*, *>) {
+                                        val id = item["id"]?.toString() ?: ""
+                                        val name = item["name"]?.toString() ?: ""
+                                        if (id.isNotEmpty() && name.isNotEmpty()) {
+                                            paymentMethods.add(PaymentMethod(id, name))
+                                        }
+                                    }
+                                }
+                            }
+                            
+                            if (paymentMethods.isNotEmpty()) {
+                                paymentMethodList = paymentMethods
+                                // 鏇存柊鏀粯鏂瑰紡鏄剧ず
+                                updatePaymentMethodRadioGroup()
+                                
+                                // 璋冭瘯鏃ュ織
+                                android.util.Log.d("RechargeDetail", "鎴愬姛鑾峰彇${paymentMethods.size}涓敮浠樻柟寮�:")
+                                paymentMethods.forEach { method ->
+                                    android.util.Log.d("RechargeDetail", "- ID: ${method.id}, Name: ${method.name}")
+                                }
+                            } else {
+                                Toast.makeText(
+                                    this@RechargeDetailActivity,
+                                    "鑾峰彇鏀粯鏂瑰紡澶辫触锛氳繑鍥炴暟鎹负绌�",
+                                    Toast.LENGTH_SHORT
+                                ).show()
+                            }
+                        } catch (e: Exception) {
+                            android.util.Log.e("RechargeDetail", "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触", e)
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁绫诲瀷: ${response.content?.javaClass?.name}")
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁鍐呭: $response.content")
+                            Toast.makeText(
+                                this@RechargeDetailActivity,
+                                "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触: ${e.message}",
+                                Toast.LENGTH_SHORT
+                            ).show()
                         }
                     } else {
                         Toast.makeText(
@@ -178,6 +216,7 @@
 
                 override fun onError(e: Throwable?) {
                     super.onError(e)
+                    android.util.Log.e("RechargeDetail", "缃戠粶璇锋眰澶辫触", e)
                     Toast.makeText(
                         this@RechargeDetailActivity,
                         "鑾峰彇鏀粯鏂瑰紡澶辫触: ${e?.message ?: "缃戠粶寮傚父"}",
@@ -341,30 +380,42 @@
             return
         }
 
-        // 璋冪敤鍏呭�兼帴鍙�
-        callRechargeApi(rechargeAmount, bonusAmount)
+        // 璋冪敤鍏呭�兼帴鍙o紝浼犻�掑綋鍓嶄綑棰�
+        callRechargeApi(currentBalance, rechargeAmount, bonusAmount)
     }
 
     /**
      * 璋冪敤鍏呭�兼帴鍙�
      */
-    private fun callRechargeApi(rechargeAmount: Double, bonusAmount: Double) {
+    private fun callRechargeApi(currentBalance: Double, rechargeAmount: Double, bonusAmount: Double) {
         val cardNum = cardInfo?.cardNum ?: cardAddress ?: ""
         if (cardNum.isEmpty()) {
             ToastUtil.show("鍗″彿淇℃伅缂哄け")
             return
         }
 
+        // 楠岃瘉鏀粯鏂瑰紡鏄惁宸查�夋嫨锛屽鏋滀负绌哄垯閲嶆柊鑾峰彇鏀粯鏂瑰紡
+        if (paymentId.isEmpty()) {
+            ToastUtil.show("鏀粯鏂瑰紡鏈姞杞斤紝姝e湪閲嶆柊鑾峰彇...")
+            // 閲嶆柊鑾峰彇鏀粯鏂瑰紡锛屾垚鍔熷悗鑷姩閲嶈瘯鍏呭��
+            getPaymentMethodsAndRetryRecharge(currentBalance, rechargeAmount, bonusAmount)
+            return
+        }
+
         // 鑾峰彇姘翠环锛堝鏋滀负绌轰細鑷姩瑙﹀彂MainActivity鑾峰彇锛�
         val currentWaterPrice = BaseApplication.requestWaterPrice()
 
-        // 鏋勫缓鍏呭�艰姹傚弬鏁�
+        // 鎵撳嵃璋冭瘯淇℃伅
+        android.util.Log.d("RechargeDetail", "鍏呭�煎弬鏁� - paymentMethod: $paymentMethod, paymentId: $paymentId")
+        android.util.Log.d("RechargeDetail", "瀛楁鍚箟 - money(褰撳墠浣欓): ${String.format("%.2f", currentBalance)}鍏�, amount(鍏呭�奸噾棰�): ${String.format("%.2f", rechargeAmount)}鍏�, gift(璧犻�侀噾棰�): ${String.format("%.2f", bonusAmount)}鍏�")
+
+        // 鏋勫缓鍏呭�艰姹傚弬鏁� - 淇瀛楁鍚箟
         val rechargeRequest = RechargeRequest(
             rechargeType = 2,
             cardNum = cardNum,
-            money = String.format("%.0f", rechargeAmount),
-            amount = String.format("%.0f", bonusAmount),
-            gift = String.format("%.0f", bonusAmount),
+            money = String.format("%.2f", currentBalance), // money涓哄綋鍓嶅崱浣欓
+            amount = String.format("%.2f", rechargeAmount), // amount涓哄厖鍊奸噾棰�
+            gift = String.format("%.2f", bonusAmount), // gift涓鸿禒閫侀噾棰�
             paymentId = paymentId,
             price = String.format("%.2f", currentWaterPrice), // 浣跨敤缁熶竴鑾峰彇鐨勬按浠�
             remarks = "鍏呭��",
@@ -412,6 +463,64 @@
     }
 
     /**
+     * 閲嶆柊鑾峰彇鏀粯鏂瑰紡骞堕噸璇曞厖鍊�
+     */
+    private fun getPaymentMethodsAndRetryRecharge(currentBalance: Double, rechargeAmount: Double, bonusAmount: Double) {
+        ApiManager.getInstance().requestGetLoading(
+            this,
+            "terminal/paymentmethod/get",
+            Any::class.java,
+            null,
+            object : SubscriberListener<BaseResponse<Any>>() {
+                override fun onNext(response: BaseResponse<Any>) {
+                    if (response.success) {
+                        try {
+                            // 瀹夊叏鍦板鐞嗚繑鍥炵殑content锛屾湇鍔″櫒杩斿洖鐨勬槸ArrayList<LinkedHashMap>
+                            val paymentMethods = mutableListOf<PaymentMethod>()
+                            val content = response.content
+                            
+                            if (content is List<*>) {
+                                content.forEach { item ->
+                                    if (item is Map<*, *>) {
+                                        val id = item["id"]?.toString() ?: ""
+                                        val name = item["name"]?.toString() ?: ""
+                                        if (id.isNotEmpty() && name.isNotEmpty()) {
+                                            paymentMethods.add(PaymentMethod(id, name))
+                                        }
+                                    }
+                                }
+                            }
+                            
+                            if (paymentMethods.isNotEmpty()) {
+                                paymentMethodList = paymentMethods
+                                // 鏇存柊鏀粯鏂瑰紡鏄剧ず
+                                updatePaymentMethodRadioGroup()
+                                // 鏀粯鏂瑰紡鍔犺浇鎴愬姛鍚庯紝鑷姩閲嶈瘯鍏呭��
+                                ToastUtil.show("鏀粯鏂瑰紡鍔犺浇鎴愬姛锛屾鍦ㄩ噸璇曞厖鍊�...")
+                                callRechargeApi(currentBalance, rechargeAmount, bonusAmount)
+                            } else {
+                                ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触锛氳繑鍥炴暟鎹负绌�")
+                            }
+                        } catch (e: Exception) {
+                            android.util.Log.e("RechargeDetail", "瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触", e)
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁绫诲瀷: ${response.content?.javaClass?.name}")
+                            android.util.Log.e("RechargeDetail", "鍘熷鏁版嵁鍐呭: ${response.content}")
+                            ToastUtil.show("瑙f瀽鏀粯鏂瑰紡鏁版嵁澶辫触: ${e.message}")
+                        }
+                    } else {
+                        ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触: ${response.msg}")
+                    }
+                }
+
+                override fun onError(e: Throwable?) {
+                    super.onError(e)
+                    ToastUtil.show("鑾峰彇鏀粯鏂瑰紡澶辫触: ${e?.message ?: "缃戠粶寮傚父"}")
+                }
+            }
+        )
+    }
+
+    /**
      * 鍚姩鍐欏崱鐣岄潰
      */
     private fun startWriteCardActivity(

--
Gitblit v1.8.0