| | |
| | | } |
| | | confirmOrderVo.setOrderPoint(sum); |
| | | } |
| | | //查询当前是否有订单活动 |
| | | OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | |
| | | BigDecimal orderMoney = confirmOrderVo.getOrderMoney(); |
| | | BigDecimal paymentMoney = orderMoney; |
| | | //总优惠金额 |
| | | BigDecimal activityAmount = BigDecimal.ZERO; |
| | | |
| | | //减去优惠券优惠金额 |
| | | CouponInfoVo couponInfoVo = null; |
| | | if(null != confirmOrder.getCouponId() && 2 != confirmOrder.getPaymentType()){ |
| | | couponInfoVo = userCouponClient.getCouponInfo(confirmOrder.getCouponId()).getData(); |
| | | String forGoodIds = couponInfoVo.getForGoodIds(); |
| | | String[] split = forGoodIds.split(","); |
| | | List<String> parseArray = Arrays.asList(split); |
| | | //全部商品 |
| | | if("-1".equals(forGoodIds)){ |
| | | //满减 |
| | | if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(paymentMoney) <= 0){ |
| | | paymentMoney = paymentMoney.subtract(couponInfoVo.getDiscountAmount()); |
| | | activityAmount = activityAmount.add(couponInfoVo.getDiscountAmount()); |
| | | } |
| | | //代金券 |
| | | if(2 == couponInfoVo.getCouponType()){ |
| | | paymentMoney = paymentMoney.subtract(couponInfoVo.getMoneyAmount()); |
| | | activityAmount = activityAmount.add(couponInfoVo.getMoneyAmount()); |
| | | if(paymentMoney.compareTo(BigDecimal.ZERO) < 0){ |
| | | paymentMoney = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | //折扣券 |
| | | if(3 == couponInfoVo.getCouponType()){ |
| | | BigDecimal paymentMoney1 = couponInfoVo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); |
| | | paymentMoney = paymentMoney1; |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | } |
| | | }else{ |
| | | //部分商品,需要计算参与优惠商品的支付金额,然后再对商品进行优惠券处理 |
| | | paymentMoney = BigDecimal.ZERO; |
| | | BigDecimal goodsMoney = BigDecimal.ZERO; |
| | | for (MyShoppingCartVo myShoppingCartVo : goodsList) { |
| | | String goodsId = myShoppingCartVo.getGoodsId().toString(); |
| | | BigDecimal cash = myShoppingCartVo.getCash(); |
| | | if(parseArray.contains(goodsId)){ |
| | | goodsMoney = goodsMoney.add(cash); |
| | | }else{ |
| | | paymentMoney = paymentMoney.add(cash); |
| | | } |
| | | } |
| | | |
| | | //满减 |
| | | if(1 == couponInfoVo.getCouponType() && couponInfoVo.getConditionAmount().compareTo(goodsMoney) <= 0){ |
| | | goodsMoney = goodsMoney.subtract(couponInfoVo.getDiscountAmount()); |
| | | activityAmount = activityAmount.add(couponInfoVo.getDiscountAmount()); |
| | | } |
| | | //代金券 |
| | | if(2 == couponInfoVo.getCouponType()){ |
| | | goodsMoney = goodsMoney.subtract(couponInfoVo.getMoneyAmount()); |
| | | activityAmount = activityAmount.add(couponInfoVo.getMoneyAmount()); |
| | | if(goodsMoney.compareTo(BigDecimal.ZERO) < 0){ |
| | | goodsMoney = BigDecimal.ZERO; |
| | | } |
| | | } |
| | | //折扣券 |
| | | if(3 == couponInfoVo.getCouponType()){ |
| | | BigDecimal paymentMoney1 = couponInfoVo.getDiscount().divide(new BigDecimal(10)).multiply(goodsMoney); |
| | | BigDecimal bigDecimal = goodsMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); |
| | | goodsMoney = paymentMoney1; |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | } |
| | | paymentMoney = paymentMoney.add(goodsMoney); |
| | | } |
| | | } |
| | | |
| | | //查询当前是否有订单活动 |
| | | OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | //满XX才打折,只有现金才能优惠 |
| | | if(null != orderActivityInfo && confirmOrder.getPaymentType() == 1 && orderActivityInfo.getConditionAmount().compareTo(orderMoney) <= 0){ |
| | | confirmOrderVo.setActivityName(orderActivityInfo.getActivityName()); |
| | | paymentMoney = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(orderMoney); |
| | | confirmOrderVo.setDiscountAmount(orderMoney.subtract(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | BigDecimal multiply = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); |
| | | activityAmount = activityAmount.add(bigDecimal); |
| | | } |
| | | confirmOrderVo.setDiscountAmount(activityAmount); |
| | | BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); |
| | | confirmOrderVo.setUseSimultaneously(JSON.parseObject(baseSetting.getContent()).getInteger("status") == 1); |
| | | int earnPoint = goodsList.stream().mapToInt(MyShoppingCartVo::getEarnSpendingPoints).sum(); |
| | |
| | | for (int i = 0; i < objects.size(); i++) { |
| | | Long id = objects.getJSONObject(i).getLong("id"); |
| | | Integer num1 = objects.getJSONObject(i).getInteger("num"); |
| | | Integer type = objects.getJSONObject(i).getInteger("type"); |
| | | num += num1; |
| | | ShoppingCart shoppingCart = this.getById(id); |
| | | //判断当前数量是否已经超出限购数量(需要计算已经购买的数量) |
| | | Integer goodsSaleNum = orderService.getGoodsSaleNum(shoppingCart.getGoodsId(), type); |
| | | Goods goods = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData(); |
| | | if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit()){ |
| | | List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, appUser.getId()).eq(Order::getDelFlag, 0).notIn(Order::getOrderStatus, Arrays.asList(5, 6))); |
| | | List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList()); |
| | | int sum = 0; |
| | | if(orderIds.size() > 0){ |
| | | List<OrderGood> orderGoodList = orderGoodService.list(new LambdaQueryWrapper<OrderGood>().in(OrderGood::getOrderId, orderIds) |
| | | .eq(OrderGood::getGoodsId, shoppingCart.getGoodsId()).eq(OrderGood::getDelFlag, 0)); |
| | | sum = orderGoodList.stream().mapToInt(OrderGood::getNum).sum(); |
| | | } |
| | | if((num1 + sum) > goods.getPurchaseLimit()){ |
| | | if(1 == type){ |
| | | if(null != goods.getPurchaseLimit() && -1 != goods.getPurchaseLimit() && (goodsSaleNum + num1) > goods.getPurchaseLimit()){ |
| | | return R.fail(goods.getName() + "已超出购买上限"); |
| | | } |
| | | }else{ |
| | | GetSeckillActivityInfo info = new GetSeckillActivityInfo(); |
| | | info.setGoodsId(shoppingCart.getGoodsId()); |
| | | info.setVip(appUser.getVipId()); |
| | | GoodsSeckill goodsSeckill = seckillActivityInfoClient.getSeckillActivityInfo(info).getData(); |
| | | if(null != goodsSeckill ){ |
| | | SeckillActivityInfo activityInfo = seckillActivityInfoClient.getSeckillActivityInfoById(goodsSeckill.getSeckillActivityInfoId()).getData(); |
| | | if(null != activityInfo.getMaxNum() && -1 != activityInfo.getMaxNum() && (goodsSaleNum + num1) > activityInfo.getMaxNum()){ |
| | | return R.fail(goods.getName() + "已超出秒杀活动购买上限"); |
| | | } |
| | | } |
| | | } |
| | | ids.add(id); |
| | |
| | | OrderGood orderGood = new OrderGood(); |
| | | orderGood.setGoodsId(myShoppingCartVo.getGoodsId()); |
| | | orderGood.setOrderId(order.getId()); |
| | | for (int i = 0; i < objects.size(); i++) { |
| | | Long id = objects.getJSONObject(i).getLong("id"); |
| | | if(myShoppingCartVo.getId().equals(id.toString())){ |
| | | ShoppingCart shoppingCart = this.getById(id); |
| | | Integer num1 = objects.getJSONObject(i).getInteger("num"); |
| | | Integer type = objects.getJSONObject(i).getInteger("type"); |
| | | orderGood.setNum(num1); |
| | | orderGood.setType(type); |
| | | if(2 == type){ |
| | | GetSeckillActivityInfo info = new GetSeckillActivityInfo(); |
| | | info.setGoodsId(myShoppingCartVo.getGoodsId()); |
| | | info.setVip(appUser.getVipId()); |
| | |
| | | if(null != goodsSeckill){ |
| | | orderGood.setSeckillJson(JSON.toJSONString(goodsSeckill)); |
| | | } |
| | | for (int i = 0; i < objects.size(); i++) { |
| | | Long id = objects.getJSONObject(i).getLong("id"); |
| | | if(myShoppingCartVo.getId().equals(id.toString())){ |
| | | ShoppingCart shoppingCart = this.getById(id); |
| | | Integer num1 = objects.getJSONObject(i).getInteger("num"); |
| | | orderGood.setNum(num1); |
| | | } |
| | | Goods goods1 = goodsClient.getGoodsById(shoppingCart.getGoodsId()).getData(); |
| | | orderGood.setGoodJson(JSON.toJSONString(goods1)); |
| | | break; |
| | |
| | | for (String code : orderPayment) { |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("OrderPayment", code); |
| | | continue; |
| | | } |
| | | //开始执行关闭订单操作 |
| | |
| | | redisTemplate.opsForZSet().add("OrderPayment", code, 0); |
| | | log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("OrderPayment", code); |
| | | } |
| | | |
| | | //快递支付 |
| | |
| | | code = code.substring(0, 23); |
| | | Order order = orderService.getOne(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, code)); |
| | | if(null == order || order.getPayStatus() != 1){ |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", code); |
| | | continue; |
| | | } |
| | | //开始执行关闭订单操作 |
| | |
| | | redisTemplate.opsForZSet().add("MaterialFlowPayment", code, 0); |
| | | log.error("关闭订单失败:{}---->{}", code, JSON.toJSONString(closeOrderResult)); |
| | | } |
| | | redisTemplate.opsForZSet().remove("MaterialFlowPayment", code); |
| | | } |
| | | } |
| | | } |