|  | @@ -4643,73 +4643,75 @@ public class OrderServiceImpl implements OrderService {
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          // 根据收银端开关选择是否适用积分抵扣。
 |  |          // 根据收银端开关选择是否适用积分抵扣。
 | 
											
												
													
														|  |          boolean useScore = Objects.isNull(calculateOrderDiscountPriceVo.getUseScore()) || calculateOrderDiscountPriceVo.getUseScore();
 |  |          boolean useScore = Objects.isNull(calculateOrderDiscountPriceVo.getUseScore()) || calculateOrderDiscountPriceVo.getUseScore();
 | 
											
												
													
														|  | -        if (useScore) {
 |  | 
 | 
											
												
													
														|  | -            // 计算完活动优惠后,计算积分抵扣。(活动与积分抵扣不互斥)
 |  | 
 | 
											
												
													
														|  | -            if (!org.springframework.util.StringUtils.isEmpty(memberCode)) {
 |  | 
 | 
											
												
													
														|  | -                String memberInfoByCodeResponseJson;
 |  | 
 | 
											
												
													
														|  | -                Response<Object> response;
 |  | 
 | 
											
												
													
														|  | -                try {
 |  | 
 | 
											
												
													
														|  | -                    // 查询会员信息
 |  | 
 | 
											
												
													
														|  | -                    if (memberCode.trim().length() == 11) {
 |  | 
 | 
											
												
													
														|  | -                        memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByPhone("{\"phone\":\"" + memberCode + "\"}");
 |  | 
 | 
											
												
													
														|  | -                    } else {
 |  | 
 | 
											
												
													
														|  | -                        memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByCode("{\"code\":\"" + memberCode + "\"}");
 |  | 
 | 
											
												
													
														|  | -                    }
 |  | 
 | 
											
												
													
														|  | -                    response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<Object>>() {
 |  | 
 | 
											
												
													
														|  | -                    });
 |  | 
 | 
											
												
													
														|  | -                    if (Objects.isNull(response)) {
 |  | 
 | 
											
												
													
														|  | -                        LOGGER.error("请求会员系统出现异常!error:{}", memberInfoByCodeResponseJson);
 |  | 
 | 
											
												
													
														|  | -                        if (ErrorCodeConstants.MemberSysErrorCodeEnum.CODE_401.getCode().equals(response.getCode())) {
 |  | 
 | 
											
												
													
														|  | -                            JedisUtil.del(Constants.MEMBER_SYS_ACCESS_TOKEN_REDIS_KEY);
 |  | 
 | 
											
												
													
														|  | -                            throw new ServiceException(String.format("请求会员系统出现异常!会员码:%s,error:%s", memberCode, ErrorCodeConstants.MemberSysErrorCodeEnum.CODE_401.getDesc()));
 |  | 
 | 
											
												
													
														|  | -                        }
 |  | 
 | 
											
												
													
														|  | -                        throw new ServiceException(String.format("请求会员系统出现异常!会员码:%s,error:%s", memberCode, memberInfoByCodeResponseJson));
 |  | 
 | 
											
												
													
														|  | -                    }
 |  | 
 | 
											
												
													
														|  | -                } catch (Exception e) {
 |  | 
 | 
											
												
													
														|  | -                    LOGGER.error("请求会员系统失败或处理响应失败!", e);
 |  | 
 | 
											
												
													
														|  | -                    throw new ServiceException(e);
 |  | 
 | 
											
												
													
														|  | 
 |  | +        // 计算完活动优惠后,计算积分抵扣。(活动与积分抵扣不互斥)
 | 
											
												
													
														|  | 
 |  | +        if (!org.springframework.util.StringUtils.isEmpty(memberCode)) {
 | 
											
												
													
														|  | 
 |  | +            String memberInfoByCodeResponseJson;
 | 
											
												
													
														|  | 
 |  | +            Response<Object> response;
 | 
											
												
													
														|  | 
 |  | +            try {
 | 
											
												
													
														|  | 
 |  | +                // 查询会员信息
 | 
											
												
													
														|  | 
 |  | +                if (memberCode.trim().length() == 11) {
 | 
											
												
													
														|  | 
 |  | +                    memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByPhone("{\"phone\":\"" + memberCode + "\"}");
 | 
											
												
													
														|  | 
 |  | +                } else {
 | 
											
												
													
														|  | 
 |  | +                    memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByCode("{\"code\":\"" + memberCode + "\"}");
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | -                BigDecimal afterDiscountPrice;
 |  | 
 | 
											
												
													
														|  | -                if (response.getSuccess()) {
 |  | 
 | 
											
												
													
														|  | -                    MemberInfoDTO memberInfoDTO = JacksonUtil.fromStringJson(JacksonUtil.toJson(response.getData()), MemberInfoDTO.class);
 |  | 
 | 
											
												
													
														|  | -                    assert memberInfoDTO != null : String.format("会员码:【%s】会员信息错误!%s", memberCode, JacksonUtil.toJson(response));
 |  | 
 | 
											
												
													
														|  | -                    // 查询会员表
 |  | 
 | 
											
												
													
														|  | -                    calculateOrderDiscountPriceResponseVO.setOpenId(memberInfoDTO.getOpenId());
 |  | 
 | 
											
												
													
														|  | -                    calculateOrderDiscountPriceResponseVO.setMemberPhone(memberInfoDTO.getPhone());
 |  | 
 | 
											
												
													
														|  | -                    calculateOrderDiscountPriceResponseVO.setMemberCurrentAvailableScore(memberInfoDTO.getScore());
 |  | 
 | 
											
												
													
														|  | -                    calculateOrderDiscountPriceResponseVO.setLevelName(memberInfoDTO.getLevelName());
 |  | 
 | 
											
												
													
														|  | -                    UserEntity userEntity = userService.queryByOpenId(memberInfoDTO.getOpenId());
 |  | 
 | 
											
												
													
														|  | -                    String openId = memberInfoDTO.getOpenId();
 |  | 
 | 
											
												
													
														|  | -                    if (Objects.isNull(userEntity)) {
 |  | 
 | 
											
												
													
														|  | -                        userEntity = new UserEntity();
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setOpenId(openId);
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setMemberCode(memberCode);
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setMobile(openId);
 |  | 
 | 
											
												
													
														|  | -                        userService.save(userEntity);
 |  | 
 | 
											
												
													
														|  | -                    } else {
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setOpenId(openId);
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setMobile(openId);
 |  | 
 | 
											
												
													
														|  | -                        userEntity.setMemberCode(memberCode);
 |  | 
 | 
											
												
													
														|  | -                        userService.update(userEntity);
 |  | 
 | 
											
												
													
														|  | -                    }
 |  | 
 | 
											
												
													
														|  | -                    Integer score = memberInfoDTO.getScore();
 |  | 
 | 
											
												
													
														|  | -                    if (Objects.nonNull(score) && score > 0) {
 |  | 
 | 
											
												
													
														|  | -                        // 有积分
 |  | 
 | 
											
												
													
														|  | -                        afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, memberCode, openId, calculateOrderDiscountPriceResponseVO, goodsDetailsDtos, promotionSkuList, mkActivitiesEntityList);
 |  | 
 | 
											
												
													
														|  | -                        LOGGER.info("会员【{}】,当前积分:{},积分抵扣后的订单金额:{},积分抵扣前的订单金额:{}", openId, score, afterDiscountPrice, orderTotalPrice);
 |  | 
 | 
											
												
													
														|  | -                        calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
 |  | 
 | 
											
												
													
														|  | -                        calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
 |  | 
 | 
											
												
													
														|  | -                        calculateOrderDiscountPriceResponseVO.setBeforeScore(score);
 |  | 
 | 
											
												
													
														|  | -                        // 订单完成后再添加积分消费记录,以及同步积分信息
 |  | 
 | 
											
												
													
														|  | -                        return calculateOrderDiscountPriceResponseVO;
 |  | 
 | 
											
												
													
														|  | -                    } else {
 |  | 
 | 
											
												
													
														|  | -                        LOGGER.error("会员【{}】积分为0,积分抵扣失败!", openId);
 |  | 
 | 
											
												
													
														|  | -                        return calculateOrderDiscountPriceResponseVO;
 |  | 
 | 
											
												
													
														|  | 
 |  | +                response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<Object>>() {
 | 
											
												
													
														|  | 
 |  | +                });
 | 
											
												
													
														|  | 
 |  | +                if (Objects.isNull(response)) {
 | 
											
												
													
														|  | 
 |  | +                    LOGGER.error("请求会员系统出现异常!error:{}", memberInfoByCodeResponseJson);
 | 
											
												
													
														|  | 
 |  | +                    if (ErrorCodeConstants.MemberSysErrorCodeEnum.CODE_401.getCode().equals(response.getCode())) {
 | 
											
												
													
														|  | 
 |  | +                        JedisUtil.del(Constants.MEMBER_SYS_ACCESS_TOKEN_REDIS_KEY);
 | 
											
												
													
														|  | 
 |  | +                        throw new ServiceException(String.format("请求会员系统出现异常!会员码:%s,error:%s", memberCode, ErrorCodeConstants.MemberSysErrorCodeEnum.CODE_401.getDesc()));
 | 
											
												
													
														|  |                      }
 |  |                      }
 | 
											
												
													
														|  | 
 |  | +                    throw new ServiceException(String.format("请求会员系统出现异常!会员码:%s,error:%s", memberCode, memberInfoByCodeResponseJson));
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +                LOGGER.error("请求会员系统失败或处理响应失败!", e);
 | 
											
												
													
														|  | 
 |  | +                throw new ServiceException(e);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            BigDecimal afterDiscountPrice;
 | 
											
												
													
														|  | 
 |  | +            if (response.getSuccess()) {
 | 
											
												
													
														|  | 
 |  | +                MemberInfoDTO memberInfoDTO = JacksonUtil.fromStringJson(JacksonUtil.toJson(response.getData()), MemberInfoDTO.class);
 | 
											
												
													
														|  | 
 |  | +                assert memberInfoDTO != null : String.format("会员码:【%s】会员信息错误!%s", memberCode, JacksonUtil.toJson(response));
 | 
											
												
													
														|  | 
 |  | +                // 查询会员表
 | 
											
												
													
														|  | 
 |  | +                calculateOrderDiscountPriceResponseVO.setOpenId(memberInfoDTO.getOpenId());
 | 
											
												
													
														|  | 
 |  | +                calculateOrderDiscountPriceResponseVO.setMemberPhone(memberInfoDTO.getPhone());
 | 
											
												
													
														|  | 
 |  | +                calculateOrderDiscountPriceResponseVO.setMemberCurrentAvailableScore(memberInfoDTO.getScore());
 | 
											
												
													
														|  | 
 |  | +                calculateOrderDiscountPriceResponseVO.setLevelName(memberInfoDTO.getLevelName());
 | 
											
												
													
														|  | 
 |  | +                UserEntity userEntity = userService.queryByOpenId(memberInfoDTO.getOpenId());
 | 
											
												
													
														|  | 
 |  | +                String openId = memberInfoDTO.getOpenId();
 | 
											
												
													
														|  | 
 |  | +                if (Objects.isNull(userEntity)) {
 | 
											
												
													
														|  | 
 |  | +                    userEntity = new UserEntity();
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setOpenId(openId);
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setMemberCode(memberCode);
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setMobile(openId);
 | 
											
												
													
														|  | 
 |  | +                    userService.save(userEntity);
 | 
											
												
													
														|  |                  } else {
 |  |                  } else {
 | 
											
												
													
														|  | -                    LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
 |  | 
 | 
											
												
													
														|  | -                    throw new ServiceException(String.format("会员码:%s,错误码:%s,错误信息:%s", memberCode, response.getErrorCode(), response.getErrorMessage()));
 |  | 
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setOpenId(openId);
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setMobile(openId);
 | 
											
												
													
														|  | 
 |  | +                    userEntity.setMemberCode(memberCode);
 | 
											
												
													
														|  | 
 |  | +                    userService.update(userEntity);
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                Integer score = memberInfoDTO.getScore();
 | 
											
												
													
														|  | 
 |  | +                // 是否适用积分抵扣
 | 
											
												
													
														|  | 
 |  | +                if (useScore) {
 | 
											
												
													
														|  | 
 |  | +                    return calculateOrderDiscountPriceResponseVO;
 | 
											
												
													
														|  |                  }
 |  |                  }
 | 
											
												
													
														|  | 
 |  | +                if (Objects.nonNull(score) && score > 0) {
 | 
											
												
													
														|  | 
 |  | +                    // 有积分
 | 
											
												
													
														|  | 
 |  | +                    afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, memberCode, openId, calculateOrderDiscountPriceResponseVO, goodsDetailsDtos, promotionSkuList, mkActivitiesEntityList);
 | 
											
												
													
														|  | 
 |  | +                    LOGGER.info("会员【{}】,当前积分:{},积分抵扣后的订单金额:{},积分抵扣前的订单金额:{}", openId, score, afterDiscountPrice, orderTotalPrice);
 | 
											
												
													
														|  | 
 |  | +                    calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
 | 
											
												
													
														|  | 
 |  | +                    calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
 | 
											
												
													
														|  | 
 |  | +                    calculateOrderDiscountPriceResponseVO.setBeforeScore(score);
 | 
											
												
													
														|  | 
 |  | +                    // 订单完成后再添加积分消费记录,以及同步积分信息
 | 
											
												
													
														|  | 
 |  | +                    return calculateOrderDiscountPriceResponseVO;
 | 
											
												
													
														|  | 
 |  | +                } else {
 | 
											
												
													
														|  | 
 |  | +                    LOGGER.error("会员【{}】积分为0,积分抵扣失败!", openId);
 | 
											
												
													
														|  | 
 |  | +                    return calculateOrderDiscountPriceResponseVO;
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +            } else {
 | 
											
												
													
														|  | 
 |  | +                LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
 | 
											
												
													
														|  | 
 |  | +                throw new ServiceException(String.format("会员码:%s,错误码:%s,错误信息:%s", memberCode, response.getErrorCode(), response.getErrorMessage()));
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |          calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
 |  |          calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
 |