| | |
| | | if(!Constants.equalsInteger(goods.getStatus(),Constants.ZERO)||!Constants.equalsInteger(goods.getIsdeleted(),Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在商品已删除或已下架,无法下单"); |
| | | } |
| | | if(goodsSku.getStock().compareTo(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))<Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在商品库存不足,无法下单!"); |
| | | if(Objects.nonNull(goodsSku.getStock())){ |
| | | if(goodsSku.getStock().compareTo(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))<Constants.ZERO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在商品库存不足,无法下单!"); |
| | | } |
| | | //商品库存扣除 |
| | | goodsSku.setStock(goodsSku.getStock().subtract(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))); |
| | | goodsSkuMapper.updateById(goodsSku); |
| | | } |
| | | //商品库存扣除 |
| | | goodsSku.setStock(goodsSku.getStock().subtract(new BigDecimal(Constants.formatIntegerNum(payDetailRequest.getGoodsNum())))); |
| | | goodsSkuMapper.updateById(goodsSku); |
| | | GoodsorderDetail goodsOrderDetail = new GoodsorderDetail(); |
| | | goodsOrderDetail.setCreator(member.getId()); |
| | | goodsOrderDetail.setCreateDate(new Date()); |
| | |
| | | if(Objects.isNull(orderGoodsCalculateResponse.getCouponDeductCash())){ |
| | | orderGoodsCalculateResponse.setCouponDeductCash(BigDecimal.ZERO); |
| | | } |
| | | // orderGoodsCalculateResponse.setIntegralDeductCash(BigDecimal.ZERO); |
| | | } |
| | | //订单总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | |
| | | orderPayConfirmResponse.setCouponAmount(couponAmount); |
| | | //获取可以使用的优惠券 |
| | | List<MemberCoupon> memberCouponList = memberCouponService.getApplyCoupon(request.getPayDetailRequestList(),request.getMemberId()); |
| | | |
| | | if(CollectionUtils.isNotEmpty(memberCouponList)){ |
| | | orderPayConfirmResponse.setMemberCouponList(memberCouponList); |
| | | if(Objects.nonNull(request.getCouponId())&&Constants.equalsInteger(request.getCouponId(),-Constants.ONE)&&Objects.nonNull(memberCouponList)){ |
| | | request.setCouponId(memberCouponList.get(Constants.ZERO).getId()); |
| | | } |
| | | //如果选择了优惠券,则判断选择的优惠券是否有效 |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | List<MemberCoupon> memberCoupons = memberCouponList.stream().filter(i->Constants.equalsInteger(i.getId(),request.getCouponId())).collect(Collectors.toList()); |
| | |
| | | } |
| | | memberCoupon = memberCoupons.get(Constants.ZERO); |
| | | couponAmount = memberCoupon.getValidAmount(); |
| | | memberCouponService.calculateCouponRata(memberCoupon,goodsCalculateList,amount); |
| | | // memberCouponService.calculateCouponRata(memberCoupon,goodsCalculateList,amount); |
| | | orderPayConfirmResponse.setMemberCoupon(memberCoupon); |
| | | } |
| | | }else { |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | if(Objects.nonNull(request.getCouponId())&&!Constants.equalsInteger(request.getCouponId(),-Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无可用优惠券,请刷新查看"); |
| | | } |
| | | } |
| | | //查询用户总积分 |
| | | Member member = memberMapper.selectById(request.getMemberId()); |
| | | //最低可用启用积分 |
| | | BigDecimal minimumIntegral = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.MINIMUM_AVAILABLE_INTEGRAL).getCode()); |
| | | BigDecimal minimumIntegral = new BigDecimal(systemDictDataBiz.queryByCode(Constants.INTEGRAL_SET,Constants.INTERALSET_MININTEGRALPRICELIMIT).getCode()); |
| | | //积分可使用状态 大于0 大于最小可用配置积分值 |
| | | orderPayConfirmResponse.setIntegralStatus( |
| | | (member.getIntegral().compareTo(BigDecimal.ZERO)<=Constants.ZERO|| |
| | |
| | | orderPayConfirmResponse.setIntegralAmount(integralAmount); |
| | | if(Constants.equalsInteger(orderPayConfirmResponse.getIntegralStatus(),Constants.ZERO)){ |
| | | integralAmount = this.calculateIntegralRata(orderPayConfirmResponse,goodsCalculateList,member.getIntegral()); |
| | | }else{ |
| | | orderPayConfirmResponse.setSurplusIntegral(member.getIntegral()); |
| | | } |
| | | |
| | | //邮费金额 |
| | |
| | | } |
| | | Areas areas = areasMapper.selectOne(new QueryWrapper<Areas>().lambda() |
| | | .eq(Areas::getIsdeleted,Constants.ZERO) |
| | | .eq(Areas::getId,StringUtils.leftPad(addr.getAreaId().toString().substring(0,2),6,"0")) |
| | | .eq(Areas::getId,StringUtils.rightPad(addr.getAreaId().toString().substring(0,2),6,"0")) |
| | | .isNotNull(Areas::getYunFeeId) |
| | | .last(" limit 1 ") |
| | | ); |
| | |
| | | BigDecimal totalWeight = goodsCalculateList.stream().map(i-> |
| | | i.getWeight().multiply(new BigDecimal(i.getGoodsNum().toString())) |
| | | ).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | if(totalWeight.compareTo(mailConfigResponse.getWeight0())>=Constants.ZERO){ |
| | | if(totalWeight.compareTo(mailConfigResponse.getWeight0())<=Constants.ZERO){ |
| | | mailAmount = mailConfigResponse.getFee0(); |
| | | }else{ |
| | | //超重重量 |
| | |
| | | orderPayConfirmResponse.setIntegralAmount(integralAmount); |
| | | } |
| | | //使用优惠券 减去优惠券抵扣金额 |
| | | if(Objects.nonNull(request.getCouponId())){ |
| | | if(Objects.nonNull(orderPayConfirmResponse.getMemberCoupon())){ |
| | | orderPayConfirmResponse.setCouponAmount(couponAmount); |
| | | } |
| | | //实际支付金额 减去优惠券、积分抵扣金额 |
| | |
| | | public BigDecimal calculateIntegralRata(OrderPayConfirmResponse orderPayConfirmResponse,List<OrderGoodsCalculateResponse> goodsCalculateList,BigDecimal totalIntegral){ |
| | | //当前选择商品最大可用积分抵扣的金额 |
| | | BigDecimal maxDeductionCash = goodsCalculateList.stream().map(i->i.getSkuAmount().subtract(Objects.isNull(i.getCouponDeductCash())?BigDecimal.ZERO:i.getCouponDeductCash()) |
| | | .multiply(i.getDeductRata()).multiply(new BigDecimal("0.01"))).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | .multiply(i.getDeductRata()).divide(new BigDecimal("100"),2,RoundingMode.DOWN)).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | //积分-现金兑换比例(XXX积分抵扣1元) |
| | | BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.SHOP_CONFIG,Constants.INTEGRAL_EXCHANGE_CASH_RATA).getCode()); |
| | | BigDecimal cashToIntegralRata = new BigDecimal(systemDictDataBiz.queryByCode(Constants.INTEGRAL_SET,Constants.INTERALSET_DEDUCTINTEGRALLIMIT).getCode()); |
| | | //当前选择商品抵扣需要使用的积分 |
| | | BigDecimal maxDeductionIntegral = maxDeductionCash.multiply(cashToIntegralRata); |
| | | //获取当前需要支付的现金总额 |
| | |
| | | //循环下单商品列表 计算应该使用的积分值 |
| | | BigDecimal realDeductionCash = BigDecimal.ZERO; |
| | | for (int j = 0; j < goodsCalculateList.size(); j++) { |
| | | BigDecimal deductionCash = goodsCalculateList.get(j).getSkuAmount().subtract(goodsCalculateList.get(j).getCouponDeductCash()); |
| | | //获取最大可抵扣金额 |
| | | BigDecimal deductionCash = goodsCalculateList.get(j).getSkuAmount().subtract(goodsCalculateList.get(j).getCouponDeductCash()) |
| | | .multiply(goodsCalculateList.get(j).getDeductRata()).divide(new BigDecimal("100"),2,RoundingMode.DOWN); |
| | | goodsCalculateList.get(j).setIntegralMaxDeductCash(deductionCash); |
| | | //如果剩余积分大于可以使用积分 则直接满额计算 反之 剩余积分不能满足全部抵扣 单独计算每个商品占比 |
| | | if(totalIntegral.compareTo(maxDeductionIntegral)<Constants.ZERO){ |
| | |
| | | List<Goodsorder> goodsorderList = goodsorderMapper.selectList(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getIsdeleted,Constants.ZERO) |
| | | .eq(Goodsorder::getReceiveType,Constants.ONE) |
| | | .isNotNull(Goodsorder::getExchangeCode) |
| | | .in(Goodsorder::getStatus,Constants.OrderStatus.WAIT_RECEIVE.getKey(), |
| | | Constants.OrderStatus.WAIT_PAY.getKey(), |
| | | Constants.OrderStatus.PAY_DONE.getKey()) |
| | |
| | | List<Goodsorder> goodsorderList = goodsorderMapper.selectList(new QueryWrapper<Goodsorder>().lambda() |
| | | .eq(Goodsorder::getIsdeleted, Constants.ZERO) |
| | | .eq(Goodsorder::getStatus, Constants.OrderStatus.WAIT_PAY.getKey()) |
| | | .ge(Goodsorder::getCreateDate, "DATE_SUB(NOW(), INTERVAL 15 MINUTE)") |
| | | .apply(" CREATE_DATE > DATE_SUB(NOW(), INTERVAL 15 MINUTE) ") |
| | | ); |
| | | if(CollectionUtils.isNotEmpty(goodsorderList)){ |
| | | for (Goodsorder goodsorder:goodsorderList) { |