|
|
@@ -265,8 +265,7 @@ public class CheckBusiness {
|
|
|
}
|
|
|
}
|
|
|
// 4.根据消费机的消费模式验证余额,如果余额不足则返回
|
|
|
- List<PtBagVo> bagVos = new ArrayList<>();
|
|
|
- result = checkDeductionBag(bo, userAccountVo, useTermVo, bagVos);
|
|
|
+ result = checkOrigDeductionBag(bo, userAccountVo, useTermVo);
|
|
|
if (R.isError(result)) {
|
|
|
return result;
|
|
|
}
|
|
|
@@ -542,6 +541,10 @@ public class CheckBusiness {
|
|
|
}
|
|
|
|
|
|
public R<ErrorInfo> checkDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, List<PtBagVo> bagVos) {
|
|
|
+ R<ErrorInfo> result = this.checkOrigDeductionBag(bo, userAccountVo, termVo);
|
|
|
+ if (R.isError(result)) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
// 设备的扣费钱包字符串
|
|
|
String consumeType = termVo.getConsumeType();
|
|
|
@@ -562,12 +565,6 @@ public class CheckBusiness {
|
|
|
totalBalance = totalBalance.add(bagVo.getBalance());
|
|
|
}
|
|
|
}
|
|
|
- // 如果扣费钱包总余额<消费金额,则不允许消费
|
|
|
- if (consumeMoney.compareTo(totalBalance) > 0) {
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.CONSUME_CHECK_FAIL, "钱包余额不足",
|
|
|
- MessageFormat.format("余额不足,总余额[{0}],消费金额[{1}]", totalBalance, consumeMoney)));
|
|
|
- }
|
|
|
-
|
|
|
for (String bagCode : bagCodes) {
|
|
|
// 1.查询对应的钱包
|
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
|
@@ -577,13 +574,13 @@ public class CheckBusiness {
|
|
|
}
|
|
|
// 2.比较扣费金额
|
|
|
BigDecimal balance = bagVo.getBalance();
|
|
|
- log.info("钱包代码:{},钱包余额:{},消费金额:{},扣款金额:{},姓名:{}", bagCode, balance, consumeMoney,doMoney,userAccountVo.getRealName());
|
|
|
if (consumeMoney.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
// 如果是消费0元,设置为第一个钱包扣费
|
|
|
bagVo.setReceiptMoney(BigDecimal.ZERO);
|
|
|
bagVo.setBalance(balance);
|
|
|
sb.append(BagNameEnum.getMessage(Integer.parseInt(bagCode)));
|
|
|
doBagVos.add(bagVo);
|
|
|
+ log.warn("[上传交易]-[扣费钱包]-[钱包代码:{},钱包余额:{},消费金额:{},扣款金额:{},姓名:{}]", bagCode, balance, consumeMoney,doMoney,userAccountVo.getRealName());
|
|
|
break;
|
|
|
} else {
|
|
|
// 如果消费金额>0,则可能会需要多钱包扣费
|
|
|
@@ -595,6 +592,7 @@ public class CheckBusiness {
|
|
|
bagVo.setBalance(balance.subtract(doMoney));
|
|
|
sb.append(BagNameEnum.getMessage(Integer.parseInt(bagCode)));
|
|
|
doBagVos.add(bagVo);
|
|
|
+ log.warn("[上传交易]-[扣费钱包]-[钱包代码:{},钱包余额:{},消费金额:{},扣款金额:{},姓名:{}]", bagCode, balance, consumeMoney,doMoney,userAccountVo.getRealName());
|
|
|
break;
|
|
|
} else {
|
|
|
// 将钱包扣费为0,剩余待扣金额=消费金额-原钱包余额
|
|
|
@@ -603,6 +601,7 @@ public class CheckBusiness {
|
|
|
doMoney = doMoney.subtract(balance);
|
|
|
sb.append(BagNameEnum.getMessage(Integer.parseInt(bagCode)));
|
|
|
doBagVos.add(bagVo);
|
|
|
+ log.warn("[上传交易]-[扣费钱包]-[钱包代码:{},钱包余额:{},消费金额:{},扣款金额:{},姓名:{}]", bagCode, balance, consumeMoney,doMoney,userAccountVo.getRealName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -614,7 +613,29 @@ public class CheckBusiness {
|
|
|
|
|
|
return R.ok();
|
|
|
}
|
|
|
-
|
|
|
+ public R<ErrorInfo> checkOrigDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo) {
|
|
|
+ // 设备的扣费钱包字符串
|
|
|
+ String consumeType = termVo.getConsumeType();
|
|
|
+ // 分解扣费钱包
|
|
|
+ List<String> bagCodes = StrUtil.split(consumeType, ",");
|
|
|
+ Long userId = userAccountVo.getUserId();
|
|
|
+ BigDecimal consumeMoney = bo.getConsumeMoney();
|
|
|
+ BigDecimal totalBalance = BigDecimal.ZERO;
|
|
|
+ // 计算扣费钱包的总金额
|
|
|
+ for (String bagCode : bagCodes) {
|
|
|
+ PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
|
+ if (ObjectUtil.isNotEmpty(bagVo)) {
|
|
|
+ totalBalance = totalBalance.add(bagVo.getBalance());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果扣费钱包总余额<消费金额,则不允许消费
|
|
|
+ if (consumeMoney.compareTo(totalBalance) > 0) {
|
|
|
+ return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.CONSUME_CHECK_FAIL, "钱包余额不足",
|
|
|
+ MessageFormat.format("余额不足,总余额[{0}],消费金额[{1}]", totalBalance, consumeMoney)));
|
|
|
+ }
|
|
|
+ bo.setBalance(totalBalance.subtract(consumeMoney));
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
/**
|
|
|
* 设备限额、限次与折扣验证
|
|
|
*
|