| | |
| | | class NfcWreatActivity : BaseNfcActivity() { |
| | | var binding: ActivityNfcWriteGeBinding? = null |
| | | var cardType = "" |
| | | var orderId = "" |
| | | var cardAddr = "" |
| | | var cardFee = 0 |
| | | |
| | | // 充值相关金额 |
| | | private var rechargeAmount = 0.0 |
| | | private var bonusAmount = 0.0 |
| | | |
| | | //订单编号 |
| | | var orderNumber = "" |
| | |
| | | */ |
| | | private fun getInitData() { |
| | | cardType = intent?.getStringExtra("cardType") ?: "" |
| | | orderId = intent?.getStringExtra("orderId") ?: "" |
| | | cardAddr = intent?.getStringExtra("cardAddr") ?: "" |
| | | operationTypeCode = intent?.getIntExtra("operationTypeCode", -1) ?: -1 |
| | | orderNumber = intent?.getStringExtra("orderNumber") ?: "" |
| | | operationType = CardOperationType.fromCode(operationTypeCode) |
| | | |
| | | // 获取充值相关金额 |
| | | rechargeAmount = intent?.getDoubleExtra("rechargeAmount", 0.0) ?: 0.0 |
| | | bonusAmount = intent?.getDoubleExtra("bonusAmount", 0.0) ?: 0.0 |
| | | |
| | | if (intent?.hasExtra("cardFee") == true) { |
| | | cardFee = intent?.getIntExtra("cardFee", 0) ?: 0 |
| | | } |
| | |
| | | binding?.cardData?.text = textData.toString() |
| | | } |
| | | |
| | | CardOperationType.Recharge -> { |
| | | var textData = StringBuilder() |
| | | textData.append("用户充值\n") |
| | | |
| | | // 显示充值金额 |
| | | if (rechargeAmount > 0) { |
| | | textData.append("充值金额:" + String.format("%.2f", rechargeAmount) + "元\n") |
| | | } |
| | | |
| | | // 显示赠送金额 |
| | | if (bonusAmount > 0) { |
| | | textData.append("赠送金额:" + String.format("%.2f", bonusAmount) + "元\n") |
| | | } |
| | | |
| | | // 显示总金额(写入卡内的总余额) |
| | | if (userCard.balance != 0) { |
| | | val totalBalanceInYuan = userCard.balance / 100.0 // 转换为元 |
| | | textData.append("卡内总余额:" + String.format("%.2f", totalBalanceInYuan) + "元") |
| | | } |
| | | |
| | | binding?.cardData?.text = textData.toString() |
| | | } |
| | | |
| | | CardOperationType.CancelCard -> TODO() |
| | | CardOperationType.CheckCard -> TODO() |
| | | CardOperationType.DeductCard -> TODO() |
| | | CardOperationType.Recharge -> TODO() |
| | | CardOperationType.ReplaceCard -> TODO() |
| | | null -> TODO() |
| | | } |
| | |
| | | runOnUiThread { |
| | | if (success) { |
| | | postCardData(cardType, cardAddr) |
| | | // 写卡成功后更新数据库中的isCardWritten状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | ToastUtil.show("写卡成功!") |
| | | // 处理写卡成功的情况 |
| | | } else { |
| | | // 处理写卡失败的情况 |
| | | ToastUtil.show(message) |
| | |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | // 写卡成功后更新数据库中的isCardWritten状态 |
| | | updateCardWrittenStatus(cardAddr) |
| | | ToastUtil.show("写卡成功!") |
| | | postCardData(cardType, cardAddr) |
| | | |
| | | } else { |
| | | ToastUtil.show("写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | CardOperationType.Recharge -> { |
| | | nfcWreatHelper.writeUserDataAsync(userCard, object : NFCCallBack { |
| | | override fun isSusses(flag: Boolean, msg: String?) { |
| | | // 确保Toast在主线程中调用 |
| | | runOnUiThread { |
| | | if (flag) { |
| | | postCardData(cardType, cardAddr) |
| | | ToastUtil.show("充值写卡成功!") |
| | | } else { |
| | | ToastUtil.show("充值写卡失败: ${msg ?: "未知错误"}") |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | CardOperationType.CancelCard -> TODO() |
| | | CardOperationType.CheckCard -> TODO() |
| | | CardOperationType.DeductCard -> TODO() |
| | | CardOperationType.Recharge -> TODO() |
| | | CardOperationType.ReplaceCard -> TODO() |
| | | null -> TODO() |
| | | } |
| | |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | |
| | | // 在主线程中关闭Activity |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | Intent(this@NfcWreatActivity, CardWriteSuccessActivity::class.java).apply { |
| | | putExtra("cardNumber", cardNumber) |
| | | startActivity(this) |
| | | } |
| | | } |
| | | } |
| | | } catch (e: Exception) { |
| | | CrashReport.postCatchedException(e) |
| | | e.printStackTrace() |
| | | ToastUtil.show("更新写卡状态失败: ${e.message}") |
| | | runOnUiThread { |
| | | ToastUtil.show("更新写卡状态失败: ${e.message}") |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | object : SubscriberListener<BaseResponse<String>>() { |
| | | override fun onNext(t: BaseResponse<String>) { |
| | | if (t.success) { |
| | | ToastUtil.show("写卡成功") |
| | | this@NfcWreatActivity.finish() |
| | | |
| | | updateCardWrittenStatus(cardAddr) |
| | | |
| | | |
| | | } else { |
| | | // 处理搜索失败的情况 |