|
@@ -13,6 +13,8 @@ import org.dromara.backstage.api.domain.vo.*;
|
|
|
import org.dromara.common.core.constant.ApiErrorTypeConstants;
|
|
import org.dromara.common.core.constant.ApiErrorTypeConstants;
|
|
|
import org.dromara.common.core.domain.R;
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.domain.model.ErrorInfo;
|
|
import org.dromara.common.core.domain.model.ErrorInfo;
|
|
|
|
|
+import org.dromara.common.core.enums.BagNameEnum;
|
|
|
|
|
+import org.dromara.common.core.enums.CardStatusEnum;
|
|
|
import org.dromara.common.core.enums.TradeStatusEnum;
|
|
import org.dromara.common.core.enums.TradeStatusEnum;
|
|
|
import org.dromara.common.core.enums.UserAccountStatusEnum;
|
|
import org.dromara.common.core.enums.UserAccountStatusEnum;
|
|
|
import org.dromara.common.core.utils.RecordIdUtils;
|
|
import org.dromara.common.core.utils.RecordIdUtils;
|
|
@@ -26,6 +28,7 @@ import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.MessageFormat;
|
|
import java.text.MessageFormat;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
import java.time.ZoneOffset;
|
|
@@ -181,19 +184,28 @@ public class CheckBusiness {
|
|
|
* @return 验证结果
|
|
* @return 验证结果
|
|
|
*/
|
|
*/
|
|
|
public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo, XfTermVo useTermVo) {
|
|
public R<ErrorInfo> checkConsume(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo, XfTermVo useTermVo) {
|
|
|
|
|
+ ErrorInfo errorInfo;
|
|
|
R<ErrorInfo> result;
|
|
R<ErrorInfo> result;
|
|
|
// 1.消费账户状态验证,验证账户是否已开户、是否冻结、状态是否正常、是否过有效期
|
|
// 1.消费账户状态验证,验证账户是否已开户、是否冻结、状态是否正常、是否过有效期
|
|
|
if ("Y".equals(userAccountVo.getFreezeStatus())) {
|
|
if ("Y".equals(userAccountVo.getFreezeStatus())) {
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已被冻结", "账户已被冻结"));
|
|
|
|
|
|
|
+ errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已被冻结",
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的账户已被冻结,不允许交易", userAccountVo.getUserNo()));
|
|
|
|
|
+ return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if ("N".equals(userAccountVo.getStatus())) {
|
|
if ("N".equals(userAccountVo.getStatus())) {
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户状态不正常", "账户状态不正常"));
|
|
|
|
|
|
|
+ errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户状态不正常",
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的账户状态不正常,不允许交易", userAccountVo.getUserNo()));
|
|
|
|
|
+ return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (!ObjectUtil.equal(userAccountVo.getAccountStatus(), UserAccountStatusEnum.IS_OPEN.code().toString())) {
|
|
if (!ObjectUtil.equal(userAccountVo.getAccountStatus(), UserAccountStatusEnum.IS_OPEN.code().toString())) {
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户尚未开户", "账户尚未开户"));
|
|
|
|
|
|
|
+ errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户尚未开户",
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的账户尚未开户,不允许交易", userAccountVo.getUserNo()));
|
|
|
|
|
+ return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
if (userAccountVo.getLifespan() != null && bo.getConsumeDate().getTime() > userAccountVo.getLifespan().getTime()) {
|
|
if (userAccountVo.getLifespan() != null && bo.getConsumeDate().getTime() > userAccountVo.getLifespan().getTime()) {
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已过有效期", "账户已过有效期"));
|
|
|
|
|
|
|
+ errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "账户已过有效期",
|
|
|
|
|
+ MessageFormat.format("流水号为[{0}]的账户已过有效期,不允许交易", userAccountVo.getUserNo()));
|
|
|
|
|
+ return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
// 2.餐类验证
|
|
// 2.餐类验证
|
|
|
RemoteMealTypeVo mealType = remoteMealTypeService.queryMealTypeVoByTime(bo.getConsumeDate());
|
|
RemoteMealTypeVo mealType = remoteMealTypeService.queryMealTypeVoByTime(bo.getConsumeDate());
|
|
@@ -201,7 +213,7 @@ public class CheckBusiness {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "不在交易时段", "不在交易时段"));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "不在交易时段", "不在交易时段"));
|
|
|
}
|
|
}
|
|
|
// 3.设备限制验证
|
|
// 3.设备限制验证
|
|
|
- result = checkTermLimitDeal(bo, userAccountVo, useTermVo, userCardVo, mealType);
|
|
|
|
|
|
|
+ result = checkTermLimitDeal(bo, useTermVo, userCardVo, mealType);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", JSONUtil.toJsonStr(result.getData())));
|
|
return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.NOT_FOUND, "消费限制判断存在问题", JSONUtil.toJsonStr(result.getData())));
|
|
|
}
|
|
}
|
|
@@ -248,12 +260,26 @@ public class CheckBusiness {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置返回的消费用户信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param accountVo 消费账户
|
|
|
|
|
+ */
|
|
|
private void setUserInfo(ConsumptionBo bo, RemoteUserAccountVo accountVo) {
|
|
private void setUserInfo(ConsumptionBo bo, RemoteUserAccountVo accountVo) {
|
|
|
bo.setRealName(StrUtil.isEmpty(accountVo.getRealName()) ? "----" : accountVo.getRealName());
|
|
bo.setRealName(StrUtil.isEmpty(accountVo.getRealName()) ? "----" : accountVo.getRealName());
|
|
|
bo.setUserNo(accountVo.getUserNo());
|
|
bo.setUserNo(accountVo.getUserNo());
|
|
|
bo.setUserNumb(accountVo.getUserNumb());
|
|
bo.setUserNumb(accountVo.getUserNumb());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查卡流水号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param userAccountVo 消费账户
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
@NotNull
|
|
@NotNull
|
|
|
private R<ErrorInfo> checkCardNo(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
private R<ErrorInfo> checkCardNo(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
|
Long cardNo = bo.getCardNo();
|
|
Long cardNo = bo.getCardNo();
|
|
@@ -265,7 +291,7 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
- if (!"1".equals(cardVo.getStatus())) {
|
|
|
|
|
|
|
+ if (!String.valueOf(CardStatusEnum.NORMAL.code()).equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
MessageFormat.format("流水号为[{0}]的卡片状态不正确,不允许交易", cardNo));
|
|
MessageFormat.format("流水号为[{0}]的卡片状态不正确,不允许交易", cardNo));
|
|
|
|
|
|
|
@@ -286,6 +312,14 @@ public class CheckBusiness {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查物理卡号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param userAccountVo 消费账户
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
@NotNull
|
|
@NotNull
|
|
|
private R<ErrorInfo> checkFactoryId(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
private R<ErrorInfo> checkFactoryId(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
|
ErrorInfo errorInfo;
|
|
ErrorInfo errorInfo;
|
|
@@ -294,14 +328,11 @@ public class CheckBusiness {
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
MessageFormat.format("物理卡号为[{0}]的卡片不存在,不允许交易", factoryId));
|
|
MessageFormat.format("物理卡号为[{0}]的卡片不存在,不允许交易", factoryId));
|
|
|
-
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
- if (!"1".equals(cardVo.getStatus())) {
|
|
|
|
|
|
|
+ if (!String.valueOf(CardStatusEnum.NORMAL.code()).equals(cardVo.getStatus())) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
- MessageFormat.format("物理卡号为[{0}]的卡片卡片状态不正确,不允许交易",
|
|
|
|
|
- factoryId));
|
|
|
|
|
-
|
|
|
|
|
|
|
+ MessageFormat.format("物理卡号为[{0}]的卡片卡片状态不正确,不允许交易", factoryId));
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(cardVo.getUserId());
|
|
RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(cardVo.getUserId());
|
|
@@ -312,6 +343,14 @@ public class CheckBusiness {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查用户流水号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param userAccountVo 消费账户
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
@NotNull
|
|
@NotNull
|
|
|
private R<ErrorInfo> checkUserNo(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
private R<ErrorInfo> checkUserNo(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
|
ErrorInfo errorInfo;
|
|
ErrorInfo errorInfo;
|
|
@@ -326,11 +365,12 @@ public class CheckBusiness {
|
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("流水号为[{0}]的人员卡片不存在,不允许交易", userNo));
|
|
|
|
|
|
|
+ MessageFormat.format("没有流水号为[{0}]人员的卡片信息,不允许交易", userNo));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
- if (!"1".equals(cardVo.getStatus())) {
|
|
|
|
|
|
|
+ // 实体卡时需要验证卡状态
|
|
|
|
|
+ if (!String.valueOf(CardStatusEnum.NORMAL.code()).equals(cardVo.getStatus()) && cardVo.getFactoryId() > 0) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
MessageFormat.format("流水号为[{0}]的人员卡片状态不正确,不允许交易", userNo));
|
|
MessageFormat.format("流水号为[{0}]的人员卡片状态不正确,不允许交易", userNo));
|
|
|
|
|
|
|
@@ -344,6 +384,14 @@ public class CheckBusiness {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 检查人员编号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param userAccountVo 消费账户
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
@NotNull
|
|
@NotNull
|
|
|
private R<ErrorInfo> checkUserNumb(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
private R<ErrorInfo> checkUserNumb(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, RemoteCardVo userCardVo) {
|
|
|
ErrorInfo errorInfo;
|
|
ErrorInfo errorInfo;
|
|
@@ -359,11 +407,12 @@ public class CheckBusiness {
|
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(accountVo.getUserId());
|
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
if (ObjectUtil.isEmpty(cardVo)) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片不存在",
|
|
|
- MessageFormat.format("编号为[{0}]的人员卡片不存在,不允许交易", userNumb));
|
|
|
|
|
|
|
+ MessageFormat.format("没有编号为[{0}]的人员的卡片信息,不允许交易", userNumb));
|
|
|
|
|
|
|
|
return R.fail(errorInfo);
|
|
return R.fail(errorInfo);
|
|
|
}
|
|
}
|
|
|
- if (!"1".equals(cardVo.getStatus())) {
|
|
|
|
|
|
|
+ // 实体卡时需要验证卡状态
|
|
|
|
|
+ if (!String.valueOf(CardStatusEnum.NORMAL.code()).equals(cardVo.getStatus()) && cardVo.getFactoryId() > 0) {
|
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
errorInfo = new ErrorInfo(400, ApiErrorTypeConstants.PARAM_ERROR, "卡片状态不正确",
|
|
|
MessageFormat.format("编号为[{0}]的人员卡片状态不正确,不允许交易", userNumb));
|
|
MessageFormat.format("编号为[{0}]的人员卡片状态不正确,不允许交易", userNumb));
|
|
|
|
|
|
|
@@ -399,6 +448,7 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public R<ErrorInfo> checkDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, List<PtBagVo> bagVos) {
|
|
public R<ErrorInfo> checkDeductionBag(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, List<PtBagVo> bagVos) {
|
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
// 设备的扣费钱包字符串
|
|
// 设备的扣费钱包字符串
|
|
|
String consumeType = termVo.getConsumeType();
|
|
String consumeType = termVo.getConsumeType();
|
|
|
// 分解扣费钱包
|
|
// 分解扣费钱包
|
|
@@ -410,6 +460,18 @@ public class CheckBusiness {
|
|
|
// 计算后实际需要扣费的钱包,会小于或等于指定的扣费钱包数
|
|
// 计算后实际需要扣费的钱包,会小于或等于指定的扣费钱包数
|
|
|
List<PtBagVo> doBagVos = new ArrayList<>();
|
|
List<PtBagVo> doBagVos = new ArrayList<>();
|
|
|
BigDecimal totalBalance = BigDecimal.ZERO;
|
|
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)));
|
|
|
|
|
+ }
|
|
|
for (String bagCode : bagCodes) {
|
|
for (String bagCode : bagCodes) {
|
|
|
// 1.查询对应的钱包
|
|
// 1.查询对应的钱包
|
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
PtBagVo bagVo = bagService.queryByUserBagCode(userId, bagCode);
|
|
@@ -420,12 +482,11 @@ public class CheckBusiness {
|
|
|
// 2.比较扣费金额
|
|
// 2.比较扣费金额
|
|
|
BigDecimal balance = bagVo.getBalance();
|
|
BigDecimal balance = bagVo.getBalance();
|
|
|
if (balance.compareTo(BigDecimal.ZERO) > 0) {
|
|
if (balance.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- totalBalance = totalBalance.add(balance);
|
|
|
|
|
if (balance.compareTo(doMoney) >= 0) {
|
|
if (balance.compareTo(doMoney) >= 0) {
|
|
|
// 如果钱包金额>扣费金额,设置扣费结果并中断循环
|
|
// 如果钱包金额>扣费金额,设置扣费结果并中断循环
|
|
|
bagVo.setReceiptMoney(doMoney);
|
|
bagVo.setReceiptMoney(doMoney);
|
|
|
bagVo.setBalance(balance.subtract(doMoney));
|
|
bagVo.setBalance(balance.subtract(doMoney));
|
|
|
- doMoney = BigDecimal.ZERO;
|
|
|
|
|
|
|
+ sb.append(BagNameEnum.getMessage(Integer.parseInt(bagCode)));
|
|
|
doBagVos.add(bagVo);
|
|
doBagVos.add(bagVo);
|
|
|
break;
|
|
break;
|
|
|
} else {
|
|
} else {
|
|
@@ -433,28 +494,35 @@ public class CheckBusiness {
|
|
|
bagVo.setReceiptMoney(balance);
|
|
bagVo.setReceiptMoney(balance);
|
|
|
bagVo.setBalance(BigDecimal.ZERO);
|
|
bagVo.setBalance(BigDecimal.ZERO);
|
|
|
doMoney = doMoney.subtract(balance);
|
|
doMoney = doMoney.subtract(balance);
|
|
|
|
|
+ sb.append(BagNameEnum.getMessage(Integer.parseInt(bagCode)));
|
|
|
doBagVos.add(bagVo);
|
|
doBagVos.add(bagVo);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (doMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
- // 循环扣费后,如果还有未扣的金额,表示钱包余额不足,不允许交易
|
|
|
|
|
- return R.fail(new ErrorInfo(400, ApiErrorTypeConstants.CONSUME_CHECK_FAIL, "钱包余额不足",
|
|
|
|
|
- MessageFormat.format("余额不足,余额[{0}],消费金额[{1}]", totalBalance,
|
|
|
|
|
- consumeMoney)));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
bo.setBalance(totalBalance.subtract(consumeMoney));
|
|
bo.setBalance(totalBalance.subtract(consumeMoney));
|
|
|
|
|
+ bo.setDigitalSign(sb.toString());
|
|
|
bagVos.addAll(doBagVos);
|
|
bagVos.addAll(doBagVos);
|
|
|
|
|
+
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public R<ErrorInfo> checkTermLimitDeal(ConsumptionBo bo, RemoteUserAccountVo userAccountVo, XfTermVo termVo, RemoteCardVo userCardVo,
|
|
|
|
|
- RemoteMealTypeVo mealTypeVo) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备限额、限次与折扣验证
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param termVo 消费设备
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @param mealTypeVo 消费类型
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
|
|
+ public R<ErrorInfo> checkTermLimitDeal(ConsumptionBo bo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
|
Long termNo = termVo.getTermNo();
|
|
Long termNo = termVo.getTermNo();
|
|
|
BigDecimal consumeValue = bo.getConsumeMoney();
|
|
BigDecimal consumeValue = bo.getConsumeMoney();
|
|
|
Long factoryFixId = userCardVo.getFactoryId();
|
|
Long factoryFixId = userCardVo.getFactoryId();
|
|
|
String mealTypeId = mealTypeVo.getTypeId();
|
|
String mealTypeId = mealTypeVo.getTypeId();
|
|
|
if (termNo == 0 && ObjectUtil.equal("0", mealTypeId)) {
|
|
if (termNo == 0 && ObjectUtil.equal("0", mealTypeId)) {
|
|
|
|
|
+ // 机号为0并且餐类不在正常餐类
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
// 当前卡片类型
|
|
// 当前卡片类型
|
|
@@ -473,14 +541,12 @@ public class CheckBusiness {
|
|
|
int termSwipeInterval = termVo.getSwipeInterval() == null ? 0 : termVo.getSwipeInterval();
|
|
int termSwipeInterval = termVo.getSwipeInterval() == null ? 0 : termVo.getSwipeInterval();
|
|
|
// 设备是否启用了卡有效
|
|
// 设备是否启用了卡有效
|
|
|
boolean termUseValidity = Objects.equals(termVo.getTermValidity(), "0") ? Boolean.FALSE : Boolean.TRUE;
|
|
boolean termUseValidity = Objects.equals(termVo.getTermValidity(), "0") ? Boolean.FALSE : Boolean.TRUE;
|
|
|
-
|
|
|
|
|
|
|
+ // 当前时间
|
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
|
- LocalDateTime expiryLocalDt;
|
|
|
|
|
-
|
|
|
|
|
// 最后消费时间
|
|
// 最后消费时间
|
|
|
LocalDateTime lastPayLocalDt = LocalDateTime.ofInstant(userCardVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
LocalDateTime lastPayLocalDt = LocalDateTime.ofInstant(userCardVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
|
// 有效期时间
|
|
// 有效期时间
|
|
|
- expiryLocalDt = LocalDateTime.ofInstant(userCardVo.getLifespan().toInstant(), ZoneOffset.of("+8"));
|
|
|
|
|
|
|
+ LocalDateTime expiryLocalDt = LocalDateTime.ofInstant(userCardVo.getLifespan().toInstant(), ZoneOffset.of("+8"));
|
|
|
|
|
|
|
|
// 设备消费间隔验证
|
|
// 设备消费间隔验证
|
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
if ((currentLocalDt.toEpochSecond(ZoneOffset.of("+8"))
|
|
@@ -505,8 +571,7 @@ public class CheckBusiness {
|
|
|
// 餐限次验证
|
|
// 餐限次验证
|
|
|
String lastMeal = userCardVo.getLastMeal().toString();
|
|
String lastMeal = userCardVo.getLastMeal().toString();
|
|
|
int mealCount = userCardVo.getMealCount().intValue();
|
|
int mealCount = userCardVo.getMealCount().intValue();
|
|
|
- if (!ObjectUtil.equals(lastMeal, mealTypeId)
|
|
|
|
|
- || !currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
|
|
|
|
|
+ if (!ObjectUtil.equals(lastMeal, mealTypeId) || !currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
|
// 如果当前餐类!=消费餐类,初始化卡片的餐类消费数据
|
|
// 如果当前餐类!=消费餐类,初始化卡片的餐类消费数据
|
|
|
remoteCardService.initCardMealData(userCardVo.getCardNo(), mealTypeId);
|
|
remoteCardService.initCardMealData(userCardVo.getCardNo(), mealTypeId);
|
|
|
} else {
|
|
} else {
|
|
@@ -514,7 +579,7 @@ public class CheckBusiness {
|
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "设备餐限次", TradeStatusEnum.MealLimitTimes.getName()));
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitTimes.toString(), "设备餐限次", TradeStatusEnum.MealLimitTimes.getName()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 日限次 日限额效验(每日第一次消费)
|
|
|
|
|
|
|
+ // 设备日限次 日限额效验(每日第一次消费)
|
|
|
int dayCount = userCardVo.getDayCount().intValue();
|
|
int dayCount = userCardVo.getDayCount().intValue();
|
|
|
BigDecimal dayValue = userCardVo.getDayTotal();
|
|
BigDecimal dayValue = userCardVo.getDayTotal();
|
|
|
if (!currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
if (!currentLocalDt.toLocalDate().isEqual(lastPayLocalDt.toLocalDate())) {
|
|
@@ -528,6 +593,7 @@ public class CheckBusiness {
|
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.DayLimitMoney.toString(), "设备日限额", TradeStatusEnum.DayLimitMoney.getName()));
|
|
return R.fail(new ErrorInfo(400, TradeStatusEnum.DayLimitMoney.toString(), "设备日限额", TradeStatusEnum.DayLimitMoney.getName()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 当前卡片校验处理
|
|
|
R<ErrorInfo> result = checkCardLimitDeal(bo, termVo, userCardVo, mealTypeVo);
|
|
R<ErrorInfo> result = checkCardLimitDeal(bo, termVo, userCardVo, mealTypeVo);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getData());
|
|
return R.fail(result.getData());
|
|
@@ -535,6 +601,15 @@ public class CheckBusiness {
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 卡类限额、限次与折扣验证
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bo 消费业务
|
|
|
|
|
+ * @param termVo 消费设备
|
|
|
|
|
+ * @param userCardVo 消费卡片
|
|
|
|
|
+ * @param mealTypeVo 消费类型
|
|
|
|
|
+ * @return 检查结果
|
|
|
|
|
+ */
|
|
|
public R<ErrorInfo> checkCardLimitDeal(ConsumptionBo bo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
public R<ErrorInfo> checkCardLimitDeal(ConsumptionBo bo, XfTermVo termVo, RemoteCardVo userCardVo, RemoteMealTypeVo mealTypeVo) {
|
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
LocalDateTime currentLocalDt = LocalDateTime.now();
|
|
|
Long cardNo = userCardVo.getCardNo();
|
|
Long cardNo = userCardVo.getCardNo();
|
|
@@ -546,8 +621,7 @@ public class CheckBusiness {
|
|
|
cardLimitedVo = initXfCardLimited(cardNo, mealTypeVo.getMealId(), lastPayDate);
|
|
cardLimitedVo = initXfCardLimited(cardNo, mealTypeVo.getMealId(), lastPayDate);
|
|
|
}
|
|
}
|
|
|
// 最后交易时间
|
|
// 最后交易时间
|
|
|
- LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(),
|
|
|
|
|
- ZoneOffset.of("+8"));
|
|
|
|
|
|
|
+ LocalDateTime lastPayLimitLocalDt = LocalDateTime.ofInstant(cardLimitedVo.getLastPay().toInstant(), ZoneOffset.of("+8"));
|
|
|
// 最后交易餐类
|
|
// 最后交易餐类
|
|
|
Long lastPayLimitMealType = cardLimitedVo.getLastMeal();
|
|
Long lastPayLimitMealType = cardLimitedVo.getLastMeal();
|
|
|
// 判断交易是否为新的一天,如果是则需要重置日消费数据
|
|
// 判断交易是否为新的一天,如果是则需要重置日消费数据
|
|
@@ -558,8 +632,18 @@ public class CheckBusiness {
|
|
|
if (!Objects.equals(lastPayLimitMealType, mealTypeId)) {
|
|
if (!Objects.equals(lastPayLimitMealType, mealTypeId)) {
|
|
|
cardLimitedVo = cardLimitedService.resetMealCardLimitedData(cardNo, mealTypeId.toString());
|
|
cardLimitedVo = cardLimitedService.resetMealCardLimitedData(cardNo, mealTypeId.toString());
|
|
|
}
|
|
}
|
|
|
- // 卡类限次检查
|
|
|
|
|
- R<ErrorInfo> result = checkCardLimited(termVo, userCardVo, cardLimitedVo, mealTypeVo);
|
|
|
|
|
|
|
+ // 卡类折扣检查
|
|
|
|
|
+ R<ErrorInfo> result = checkCardDisCount(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo);
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return R.fail(result.getData());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 卡类限额检查
|
|
|
|
|
+ result = checkCardQuota(termVo, userCardVo, cardLimitedVo, mealTypeVo, bo.getConsumeMoney());
|
|
|
|
|
+ if (R.isError(result)) {
|
|
|
|
|
+ return R.fail(result.getData());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 卡类限次检
|
|
|
|
|
+ result = checkCardLimited(termVo, userCardVo, cardLimitedVo, mealTypeVo);
|
|
|
if (R.isError(result)) {
|
|
if (R.isError(result)) {
|
|
|
return R.fail(result.getData());
|
|
return R.fail(result.getData());
|
|
|
}
|
|
}
|
|
@@ -567,7 +651,7 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 卡片的限次验证处理
|
|
|
|
|
|
|
+ * 卡类的限次验证处理
|
|
|
*
|
|
*
|
|
|
* @param termVo 设备信息
|
|
* @param termVo 设备信息
|
|
|
* @param userCardVo 卡片信息
|
|
* @param userCardVo 卡片信息
|
|
@@ -651,8 +735,133 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 更新其它消费信息
|
|
|
|
|
|
|
+ * 卡类的限额验证处理
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param termVo 设备信息
|
|
|
|
|
+ * @param userCardVo 卡片信息
|
|
|
|
|
+ * @param cardLimitedVo 卡片限制信息
|
|
|
|
|
+ * @param mealTypeVo 餐类信息
|
|
|
|
|
+ * @param disCountMoney 折扣金额
|
|
|
|
|
+ * @return 验证结果
|
|
|
|
|
+ */
|
|
|
|
|
+ private R<ErrorInfo> checkCardQuota(XfTermVo termVo, RemoteCardVo userCardVo, XfCardLimitedVo cardLimitedVo, RemoteMealTypeVo mealTypeVo,
|
|
|
|
|
+ BigDecimal disCountMoney) {
|
|
|
|
|
+ String useQuota = remotePtParameterService.getPtParameterByKey("XE_CONSUME");
|
|
|
|
|
+ String mealType = mealTypeVo.getTypeId();
|
|
|
|
|
+ if (StrUtil.isEmpty(useQuota) || ObjectUtil.notEqual(useQuota, "1")) {
|
|
|
|
|
+ // 如果没有启用限额,直接返回
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ Long quotaTermId = remoteQuotaService.queryQuotaTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ if (ObjectUtil.equals(quotaTermId, 0L)) {
|
|
|
|
|
+ // 当前设备没有设置限额
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ RemoteQuotaVo remoteQuotaVo = remoteQuotaService.queryQuotaByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
+ if (ObjectUtil.isEmpty(remoteQuotaVo)) {
|
|
|
|
|
+ // 当前卡类没有限额信息
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ String quotaStatus = remoteQuotaVo.getStatus();
|
|
|
|
|
+ if (ObjectUtil.isEmpty(quotaStatus) || ObjectUtil.equals(quotaStatus, "0")) {
|
|
|
|
|
+ // 卡类限额未启用
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 每日金额
|
|
|
|
|
+ BigDecimal dayMoney = remoteQuotaVo.getDailyMoney();
|
|
|
|
|
+ // 早餐金额
|
|
|
|
|
+ BigDecimal oneMoney = remoteQuotaVo.getOneMoney();
|
|
|
|
|
+ // 午餐金额
|
|
|
|
|
+ BigDecimal twoMoney = remoteQuotaVo.getTwoMoney();
|
|
|
|
|
+ // 晚餐金额
|
|
|
|
|
+ BigDecimal threeMoney = remoteQuotaVo.getThreeMoney();
|
|
|
|
|
+ // 宵夜金额
|
|
|
|
|
+ BigDecimal fourMoney = remoteQuotaVo.getFourMoney();
|
|
|
|
|
+
|
|
|
|
|
+ if (dayMoney.compareTo(BigDecimal.ZERO) > 0 || oneMoney.compareTo(BigDecimal.ZERO) > 0 || twoMoney.compareTo(BigDecimal.ZERO) > 0
|
|
|
|
|
+ || threeMoney.compareTo(BigDecimal.ZERO) > 0 || fourMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ if (dayMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ BigDecimal mealQuotaMoney = cardLimitedVo.getMealMoney();
|
|
|
|
|
+ // 日限额
|
|
|
|
|
+ if (dayMoney.compareTo(cardLimitedVo.getDayMoney().add(disCountMoney)) < 0) {
|
|
|
|
|
+ return R.fail(
|
|
|
|
|
+ new ErrorInfo(400, TradeStatusEnum.DayLimitMoney.toString(), "卡类日限制额度", TradeStatusEnum.DayLimitMoney.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 早餐限额
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "1") && oneMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ if (oneMoney.compareTo(mealQuotaMoney.add(disCountMoney)) < 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitMoney.toString(), "卡类早餐限制额度",
|
|
|
|
|
+ TradeStatusEnum.MealLimitMoney.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 午餐限额
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "2") && twoMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ if (twoMoney.compareTo(mealQuotaMoney.add(disCountMoney)) < 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitMoney.toString(), "卡类午餐限制额度",
|
|
|
|
|
+ TradeStatusEnum.MealLimitMoney.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 晚餐限额
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "3") && threeMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ if (threeMoney.compareTo(mealQuotaMoney.add(disCountMoney)) < 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitMoney.toString(), "卡类晚餐限制额度",
|
|
|
|
|
+ TradeStatusEnum.MealLimitMoney.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 宵夜限额
|
|
|
|
|
+ if (ObjectUtil.equals(mealType, "4")&& threeMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ if (fourMoney.compareTo(mealQuotaMoney.add(disCountMoney)) < 0) {
|
|
|
|
|
+ return R.fail(new ErrorInfo(400, TradeStatusEnum.MealLimitMoney.toString(), "卡类夜宵限制额度",
|
|
|
|
|
+ TradeStatusEnum.MealLimitMoney.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 卡类的折扣处理
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param termVo 设备信息
|
|
|
|
|
+ * @param userCardVo 卡片信息
|
|
|
|
|
+ * @param cardLimitedVo 卡片限制信息
|
|
|
|
|
+ * @param mealTypeVo 餐类信息
|
|
|
|
|
+ * @return 验证结果
|
|
|
|
|
+ */
|
|
|
|
|
+ private R<ErrorInfo> checkCardDisCount(XfTermVo termVo, RemoteCardVo userCardVo, XfCardLimitedVo cardLimitedVo, RemoteMealTypeVo mealTypeVo,
|
|
|
|
|
+ ConsumptionBo bo) {
|
|
|
|
|
+ String useDisCount = remotePtParameterService.getPtParameterByKey("RATE_CONSUME");
|
|
|
|
|
+ if (StrUtil.isEmpty(useDisCount) || ObjectUtil.notEqual(useDisCount, "1")) {
|
|
|
|
|
+ // 如果没有启用折扣,直接返回
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ Long disCountTermId = remoteDisCountService.queryDisCountTermIdByTermId(termVo.getTermId());
|
|
|
|
|
+ if (ObjectUtil.equals(disCountTermId, 0L)) {
|
|
|
|
|
+ // 当前设备没有设置折扣
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ RemoteDiscountVo remoteDiscountVo = remoteDisCountService.queryDisCountByCardType(userCardVo.getCardType().intValue(), mealTypeVo.getTypeId());
|
|
|
|
|
+ if (ObjectUtil.isEmpty(remoteDiscountVo)) {
|
|
|
|
|
+ // 当前卡类没有折扣信息
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ String disCountStatus = remoteDiscountVo.getStatus();
|
|
|
|
|
+ if (ObjectUtil.isEmpty(disCountStatus) || ObjectUtil.equals(disCountStatus, "0")) {
|
|
|
|
|
+ // 卡类折扣未启用
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 计算折扣金额
|
|
|
|
|
+ BigDecimal disCountMoney = getDisCountMoney(cardLimitedVo, bo, remoteDiscountVo);
|
|
|
|
|
+ // 最后的消费金额为折扣后的金额
|
|
|
|
|
+ bo.setConsumeMoney(disCountMoney);
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 消费记录入库成功后更新其它消费信息
|
|
|
* 1.更新卡片交易信息
|
|
* 1.更新卡片交易信息
|
|
|
|
|
+ * 2.更新卡片的折扣、限次与限额信息
|
|
|
*
|
|
*
|
|
|
* @param bo 交易业务对象
|
|
* @param bo 交易业务对象
|
|
|
* @param userCardVo 卡片视图对象
|
|
* @param userCardVo 卡片视图对象
|
|
@@ -708,7 +917,7 @@ public class CheckBusiness {
|
|
|
// 当前设备也有折扣
|
|
// 当前设备也有折扣
|
|
|
if (ObjectUtil.isNotEmpty(disCountTermId) && disCountTermId > 0) {
|
|
if (ObjectUtil.isNotEmpty(disCountTermId) && disCountTermId > 0) {
|
|
|
// 查询卡类的折扣信息
|
|
// 查询卡类的折扣信息
|
|
|
- RemoteDiscountVo remoteDisCountVo = remoteDisCountService.queryDisCountByCardType(userCardVo.getCardType().intValue());
|
|
|
|
|
|
|
+ RemoteDiscountVo remoteDisCountVo = remoteDisCountService.queryDisCountByCardType(userCardVo.getCardType().intValue(), mealTypeVo.getTypeId());
|
|
|
// 有卡类的折扣信息并已启用
|
|
// 有卡类的折扣信息并已启用
|
|
|
if (ObjectUtil.isNotEmpty(remoteDisCountVo) && ObjectUtil.equals(remoteDisCountVo.getStatus(), "1")) {
|
|
if (ObjectUtil.isNotEmpty(remoteDisCountVo) && ObjectUtil.equals(remoteDisCountVo.getStatus(), "1")) {
|
|
|
// 更新卡类的折扣信息
|
|
// 更新卡类的折扣信息
|
|
@@ -716,10 +925,7 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -748,6 +954,7 @@ public class CheckBusiness {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取营业员信息
|
|
* 获取营业员信息
|
|
|
|
|
+ *
|
|
|
* @param bo 消费业务对象
|
|
* @param bo 消费业务对象
|
|
|
* @return 营业员信息
|
|
* @return 营业员信息
|
|
|
*/
|
|
*/
|
|
@@ -760,4 +967,41 @@ public class CheckBusiness {
|
|
|
}
|
|
}
|
|
|
return operatorVo;
|
|
return operatorVo;
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算折扣金额
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param cardLimitedVo 卡片限制信息
|
|
|
|
|
+ * @param bo 消费记录
|
|
|
|
|
+ * @param remoteDiscountVo 折扣信息
|
|
|
|
|
+ * @return 折扣金额
|
|
|
|
|
+ */
|
|
|
|
|
+ @NotNull
|
|
|
|
|
+ private static BigDecimal getDisCountMoney(XfCardLimitedVo cardLimitedVo, ConsumptionBo bo, RemoteDiscountVo remoteDiscountVo) {
|
|
|
|
|
+ int rateCount = remoteDiscountVo.getRateType().equals(
|
|
|
|
|
+ "0") ? cardLimitedVo.getDayDiscountCount().intValue() : cardLimitedVo.getMealDiscountCount().intValue();
|
|
|
|
|
+ BigDecimal disCountMoney;
|
|
|
|
|
+ BigDecimal consumeMoney = bo.getConsumeMoney();
|
|
|
|
|
+ // 折扣率1
|
|
|
|
|
+ BigDecimal oneRate = remoteDiscountVo.getOneRate();
|
|
|
|
|
+ // 折扣率2
|
|
|
|
|
+ BigDecimal twoRate = remoteDiscountVo.getTwoRate();
|
|
|
|
|
+ // 折扣率3
|
|
|
|
|
+ BigDecimal threeRate = remoteDiscountVo.getThreeRate();
|
|
|
|
|
+ // 折扣率4
|
|
|
|
|
+ BigDecimal fourRate = remoteDiscountVo.getFourRate();
|
|
|
|
|
+ if (rateCount == 0) {
|
|
|
|
|
+ disCountMoney = consumeMoney.multiply(oneRate.divide(new BigDecimal("100.0"), 2, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ } else if (rateCount == 1) {// 第二次
|
|
|
|
|
+ disCountMoney = consumeMoney.multiply(twoRate.divide(new BigDecimal("100.0"), 2, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ } else if (rateCount == 2) {// 第三次
|
|
|
|
|
+ disCountMoney = consumeMoney.multiply(threeRate.divide(new BigDecimal("100.0"), 2, RoundingMode.HALF_UP)).setScale(2,
|
|
|
|
|
+ RoundingMode.HALF_UP);
|
|
|
|
|
+ } else { // 第四次及以上
|
|
|
|
|
+ disCountMoney = consumeMoney.multiply(fourRate.divide(new BigDecimal("100.0"), 2, RoundingMode.HALF_UP)).setScale(2,
|
|
|
|
|
+ RoundingMode.HALF_UP);
|
|
|
|
|
+ }
|
|
|
|
|
+ return disCountMoney;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|