|
@@ -2341,7 +2341,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
if (isCalculateScorePrice.get()) {
|
|
|
// 3-1. 计算总价的50%
|
|
|
BigDecimal halfPrice = preferentialPrice.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- Integer scoreLimit = haiKongProperties.getScoreLimit();
|
|
|
+ Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
|
|
|
if (score < scoreLimit) {
|
|
|
LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", userInfo.get("customName"), score);
|
|
|
return preferentialPrice;
|
|
@@ -4303,29 +4303,36 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// 计算完活动优惠后,计算积分抵扣。(活动与积分抵扣不互斥)
|
|
|
if (!org.springframework.util.StringUtils.isEmpty(memberCode)) {
|
|
|
String memberInfoByCodeResponseJson;
|
|
|
- Response<MemberInfoDTO> response;
|
|
|
+ Response<Object> response;
|
|
|
try {
|
|
|
// 查询会员信息
|
|
|
- memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByCode("{\"code\":" + memberCode + "}");
|
|
|
- response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<MemberInfoDTO>>() {
|
|
|
+ memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByPhone("{\"phone\":" + memberCode + "}");
|
|
|
+ response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<Object>>() {
|
|
|
});
|
|
|
+ if (Objects.isNull(response) || Objects.nonNull(response.getErrorCode())) {
|
|
|
+ LOGGER.error("请求会员系统出现异常!error:{}", memberInfoByCodeResponseJson);
|
|
|
+ throw new ServiceException(String.format("请求会员系统出现异常!会员码:%s,error:%s", memberCode, memberInfoByCodeResponseJson));
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("请求会员系统失败或处理响应失败!", e);
|
|
|
throw new ServiceException(e);
|
|
|
}
|
|
|
BigDecimal afterDiscountPrice;
|
|
|
- if (Objects.nonNull(response) && response.getSuccess()) {
|
|
|
- MemberInfoDTO memberInfoDTO = response.getData();
|
|
|
+ if (response.getSuccess()) {
|
|
|
+ MemberInfoDTO memberInfoDTO = JacksonUtil.fromStringJson(JacksonUtil.toJson(response.getData()), MemberInfoDTO.class);
|
|
|
+ assert memberInfoDTO != null : String.format("会员码:【%s】会员信息错误!%s", memberCode, JacksonUtil.toJson(response));
|
|
|
Integer score = memberInfoDTO.getScore();
|
|
|
if (Objects.nonNull(score) && score > 0) {
|
|
|
// 有积分
|
|
|
afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, storeId, memberCode);
|
|
|
calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
// 订单完成后再添加积分消费记录,以及同步积分信息
|
|
|
+ return calculateOrderDiscountPriceResponseVO;
|
|
|
}
|
|
|
- } else if (Objects.nonNull(response)) {
|
|
|
+ } else {
|
|
|
LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
|
|
|
- throw new ServiceException(String.format("错误码:%s,错误信息:%s", response.getErrorCode(), response.getErrorMessage()));
|
|
|
+ throw new ServiceException(String.format("会员码:%s,错误码:%s,错误信息:%s", memberCode, response.getErrorCode(), response.getErrorMessage()));
|
|
|
}
|
|
|
}
|
|
|
calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
@@ -4353,9 +4360,9 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
// 2. 计算积分抵扣后的总价格
|
|
|
if (isCalculateScorePrice.get()) {
|
|
|
- // 3-1. 计算总价的50%,百分比可以进行设置
|
|
|
- BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- Integer scoreLimit = haiKongProperties.getScoreLimit();
|
|
|
+ // 3-1. 计算总价的50%,百分比可以进行设置,算出整数(向下取整)
|
|
|
+ BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(0, BigDecimal.ROUND_FLOOR);
|
|
|
+ Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
|
|
|
if (score < scoreLimit) {
|
|
|
LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
|
|
|
return orderTotalPrice;
|
|
@@ -4364,12 +4371,12 @@ public class OrderServiceImpl implements OrderService {
|
|
|
int scoreMayDeductionPrice = (int) (score / scoreLimit);
|
|
|
BigDecimal scoreMayDeductionPriceDecimal = new BigDecimal(scoreMayDeductionPrice);
|
|
|
// 3-3. 计算积分抵扣后的价格
|
|
|
- if (halfPrice.compareTo(scoreMayDeductionPriceDecimal) > 0) {
|
|
|
+ if (halfPrice.compareTo(scoreMayDeductionPriceDecimal) <= 0) {
|
|
|
// 积分能抵扣的金额大于订单总额的50%,按50%抵扣
|
|
|
scoreMayDeductionPriceDecimal = halfPrice;
|
|
|
}
|
|
|
orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
|
|
|
- LOGGER.info("会员【{}】,积分抵扣前剩余:{},积分抵扣订单金额后剩余:{},积分抵扣后的订单总额为:{}", memberCode, score, scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)), orderTotalPrice);
|
|
|
+ LOGGER.info("会员【{}】,积分抵扣前剩余:{},积分抵扣订单金额后剩余:{},积分抵扣后的订单总额为:{}", memberCode, score, (score - scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)).intValue()), orderTotalPrice);
|
|
|
}
|
|
|
} else {
|
|
|
LOGGER.info("会员【{}】的积分为0,不参加积分抵扣!", memberCode);
|