| | |
| | | import androidx.lifecycle.lifecycleScope |
| | | import com.dayu.baselibrary.net.subscribers.SubscriberListener |
| | | import com.dayu.baselibrary.tools.nfc.NFCCallBack |
| | | import com.dayu.baselibrary.utils.MornyUtil |
| | | import com.dayu.baselibrary.utils.ToastUtil |
| | | import com.dayu.general.bean.card.ClearCard |
| | | import com.dayu.general.bean.card.UserCard |
| | |
| | | var cardType = "" |
| | | var cardAddr = "" |
| | | var cardFee = 0 |
| | | |
| | | |
| | | // 充值相关金额 |
| | | private var rechargeAmount = 0.0 |
| | | private var bonusAmount = 0.0 |
| | |
| | | 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 |
| | | } |
| | |
| | | textData.append("工本费:" + cardFee + "元\n") |
| | | } |
| | | if (userCard.balance != 0) { |
| | | textData.append("充值金额:" + userCard.balance + "元") |
| | | textData.append("充值金额:" + MornyUtil.changeF2Y(userCard.balance) + "元") |
| | | } |
| | | |
| | | binding?.cardData?.text = textData.toString() |
| | |
| | | CardOperationType.Recharge -> { |
| | | var textData = StringBuilder() |
| | | textData.append("用户充值\n") |
| | | |
| | | |
| | | // 显示充值金额 |
| | | if (rechargeAmount > 0) { |
| | | textData.append("充值金额:" + String.format("%.2f", rechargeAmount) + "元\n") |
| | | 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) + "元") |
| | | textData.append( |
| | | "卡内总余额:" + String.format( |
| | | "%.2f", |
| | | totalBalanceInYuan |
| | | ) + "元" |
| | | ) |
| | | } |
| | | |
| | | |
| | | binding?.cardData?.text = textData.toString() |
| | | } |
| | | |
| | |
| | | val nfcReadHelper = NfcReadHelper.getInstance(intent, this) |
| | | // 使用正常的getCardNumber()方法,它会自动关闭连接 |
| | | val cardNumber = nfcReadHelper.getCardNumber() |
| | | |
| | | |
| | | if (cardNumber.isNotEmpty() && cardNumber == cardAddr) { |
| | | val nfcWreatHelper = NfcWreatHelper.getInstance(intent, this) |
| | | when (operationType) { |
| | |
| | | val updatedCardRegistration = cardRegistration.copy(isCardWritten = true) |
| | | // 更新数据库记录 |
| | | cardRegistrationDao.update(updatedCardRegistration) |
| | | |
| | | |
| | | // 在主线程中关闭Activity |
| | | runOnUiThread { |
| | | setResult(RESULT_OK) |