左晓为主开发手持机充值管理机
zuoxiao
4 天以前 4ceacd9e21e09989287e8dc4e526d182091af282
generallibrary/src/main/java/com/dayu/general/activity/NewCard2Activity.kt
@@ -24,6 +24,7 @@
import com.dayu.general.databinding.ActivityNewCardGeBinding
import com.dayu.general.net.ApiManager
import com.dayu.general.net.BaseResponse
import com.dayu.general.tool.BaseCommon.Companion.protocol
import com.dayu.general.tool.CardCommon.Companion.USER_CARD_TYPE_1
import com.dayu.general.tool.CardOperationType
import com.dayu.general.tool.NfcReadHelper
@@ -46,7 +47,7 @@
    private var paymentMethod: String = "现金"
    // 支付方式ID
    private var paymentId: Long = 0
    private var paymentId: String = ""
    // 支付方式列表
    private var paymentMethodList: List<PaymentMethod> = listOf()
@@ -170,18 +171,49 @@
    private fun getPaymentMethods() {
        ApiManager.getInstance().requestGetLoading(
            this,
            "sell/paymentmethod/get",
            PaymentMethodResponse::class.java,
            "terminal/paymentmethod/get",
            Any::class.java,
            null,
            object : SubscriberListener<BaseResponse<PaymentMethodResponse>>() {
                override fun onNext(response: BaseResponse<PaymentMethodResponse>) {
            object : SubscriberListener<BaseResponse<Any>>() {
                override fun onNext(response: BaseResponse<Any>) {
                    if (response.success) {
                        // 获取支付方式列表
                        val paymentMethods = response.content?.obj ?: 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()
                            } else {
                                Toast.makeText(
                                    this@NewCard2Activity,
                                    "获取支付方式失败:返回数据为空",
                                    Toast.LENGTH_SHORT
                                ).show()
                            }
                        } catch (e: Exception) {
                            android.util.Log.e("NewCard2Activity", "解析支付方式数据失败", e)
                            android.util.Log.e("NewCard2Activity", "原始数据类型: ${response.content?.javaClass?.name}")
                            android.util.Log.e("NewCard2Activity", "原始数据内容: ${response.content}")
                            Toast.makeText(
                                this@NewCard2Activity,
                                "解析支付方式数据失败: ${e.message}",
                                Toast.LENGTH_SHORT
                            ).show()
                        }
                    } else {
                        Toast.makeText(
@@ -194,6 +226,7 @@
                override fun onError(e: Throwable?) {
                    super.onError(e)
                    android.util.Log.e("NewCard2Activity", "网络请求失败", e)
                    Toast.makeText(
                        this@NewCard2Activity,
                        "获取支付方式失败: ${e?.message ?: "网络异常"}",
@@ -323,7 +356,7 @@
        params["amount"] = rechargeAmount  // 充值金额(元)
        params["paymentId"] = paymentId // 支付方式ID
        params["remarks"] = remark // 备注
        params["protocol"] = "p206V1_0_1" // 协议
        params["protocol"] = protocol // 协议
        params["operator"] = BaseApplication.userId // 操作人ID
        // 执行卡片激活API请求
@@ -344,7 +377,7 @@
                            clientId = clientId,
                            cardFee = cardFee,
                            remark = binding.newCardRemark.text.toString(),
                            paymentMethod = paymentId.toInt(),
                            paymentMethod = paymentId.toLongOrNull()?.toInt() ?: 0,
                            isReported = true,
                            isCardWritten = false, // 初始设置为false,写卡成功后再更新为true
                            operatorId = orderId,