| | |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.mapper.ShoppingCartMapper; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.order.model.OrderBalancePayment; |
| | | import com.ruoyi.order.model.OrderGood; |
| | | import com.ruoyi.order.model.ShoppingCart; |
| | | import com.ruoyi.order.service.CommissionService; |
| | | import com.ruoyi.order.service.OrderGoodService; |
| | | import com.ruoyi.order.service.OrderService; |
| | | import com.ruoyi.order.service.ShoppingCartService; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.vo.*; |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.feignClient.*; |
| | |
| | | |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private PointSettingClient pointSettingClient; |
| | | |
| | | @Resource |
| | | private OrderBalancePaymentService orderBalancePaymentService; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取购物车列表 |
| | | * @param type |
| | |
| | | price.setEarnSpendingPoints(goodsSeckill.getEarnSpendingPoints()); |
| | | price.setSuperiorSubcommission(goodsSeckill.getSuperiorSubcommission()); |
| | | price.setSuperiorRebatePoints(goodsSeckill.getSuperiorRebatePoints()); |
| | | price.setSuperiorType(goodsSeckill.getSuperiorType()); |
| | | price.setSuperiorType(String.valueOf(goodsSeckill.getSuperiorType())); |
| | | price.setServuceShopCharges(goodsSeckill.getServuceShopCharges()); |
| | | price.setServuceShopPoints(goodsSeckill.getServuceShopPoints()); |
| | | price.setTechnicianPoints(goodsSeckill.getTechnicianPoints()); |
| | |
| | | //使用商品的基础价格 |
| | | price.setCash(1 == goods.getCashPayment() ? goods.getSellingPrice() : null); |
| | | price.setPoint(1 == goods.getPointPayment() ? goods.getIntegral() : null); |
| | | price.setCashPayment(goods.getCashPayment() == 1 ? true : false); |
| | | price.setPointPayment(goods.getPointPayment() == 1 ? true : false); |
| | | price.setCashPayment(goods.getCashPayment() == 1); |
| | | price.setPointPayment(goods.getPointPayment() == 1); |
| | | } |
| | | vo.setCash(price.getCash()); |
| | | vo.setPoint(price.getPoint()); |
| | |
| | | goodsShop.setGoodsId(shoppingCart.getGoodsId()); |
| | | goodsShop.setShopId(shopId); |
| | | GoodsShop goodsShop1 = goodsShopClient.getGoodsShop(goodsShop).getData(); |
| | | vo.setVerifiable(goods.getAppointStore() == 1 && null == goodsShop1 ? false : true); |
| | | vo.setVerifiable(goods.getAppointStore() != 1 || null != goodsShop1); |
| | | //判断当前数量是否已经超出限购数量(需要计算已经购买的数量) |
| | | if(null == goods.getPurchaseLimit() || -1 == goods.getPurchaseLimit()){ |
| | | vo.setPurchaseLimit(false); |
| | |
| | | List<Order> orders = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getAppUserId, appUser.getId()).eq(Order::getDelFlag, 0).in(Order::getOrderStatus, Arrays.asList(4, 8))); |
| | | List<Long> orderIds = orders.stream().map(Order::getId).collect(Collectors.toList()); |
| | | int sum = 0; |
| | | if(orderIds.size() > 0){ |
| | | if(!orderIds.isEmpty()){ |
| | | 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(); |
| | | } |
| | | vo.setPurchaseLimit((num + sum) > goods.getPurchaseLimit() ? true : false); |
| | | vo.setPurchaseLimit((num + sum) > goods.getPurchaseLimit()); |
| | | } |
| | | vo.setDistributionMode(goods.getDistributionMode()); |
| | | vo.setEarnSpendingPoints(price.getEarnSpendingPoints()); |
| | |
| | | OrderActivityInfo orderActivityInfo = orderActivityInfoClient.getNowOrderActivityInfo(appUser.getVipId()).getData(); |
| | | BaseSetting baseSetting = baseSettingClient.getBaseSetting(4).getData(); |
| | | //系统活动设置(优惠券和活动能否同时使用) |
| | | boolean useSimultaneously = baseSetting.getContent().equals("1") ? true : false; |
| | | boolean useSimultaneously = baseSetting.getContent().equals("1"); |
| | | //满XX才打折,只有现金才能优惠 |
| | | //如果使用优惠券,则需要判断是否可以和同时使用,且活动满足使用条件。 |
| | | //没有使用优惠券,只需要判断是都满足使用条件 |
| | | if(((useSimultaneously && null != shoppingCartPayment.getUserCouponId()) || null == shoppingCartPayment.getUserCouponId()) && |
| | | if((useSimultaneously || null == shoppingCartPayment.getUserCouponId()) && |
| | | null != orderActivityInfo && shoppingCartPayment.getPaymentType() != 3 && orderActivityInfo.getConditionAmount().compareTo(paymentMoney) <= 0){ |
| | | BigDecimal paymentMoney1 = orderActivityInfo.getDiscount().divide(new BigDecimal(10)).multiply(paymentMoney); |
| | | BigDecimal bigDecimal = paymentMoney.subtract(paymentMoney1).setScale(2, RoundingMode.HALF_EVEN); |
| | |
| | | |
| | | } |
| | | //账户余额 |
| | | BigDecimal redPacketAmount = BigDecimal.ZERO; |
| | | BigDecimal distributionAmount = BigDecimal.ZERO; |
| | | if(2 == shoppingCartPayment.getPaymentType()){ |
| | | BigDecimal totalRedPacketAmount = appUser.getTotalRedPacketAmount(); |
| | | BigDecimal totalDistributionAmount = appUser.getTotalDistributionAmount(); |
| | | BigDecimal balance = appUser.getBalance(); |
| | | //红包金额满足支付 |
| | | if(paymentMoney.compareTo(totalRedPacketAmount) <= 0){ |
| | | totalRedPacketAmount = totalRedPacketAmount.subtract(paymentMoney); |
| | | balance = balance.subtract(paymentMoney); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setBalance(balance); |
| | | redPacketAmount = paymentMoney; |
| | | }else{ |
| | | paymentMoney = paymentMoney.subtract(totalRedPacketAmount); |
| | | redPacketAmount = totalRedPacketAmount; |
| | | totalRedPacketAmount = BigDecimal.ZERO; |
| | | if(paymentMoney.compareTo(totalDistributionAmount) <= 0){ |
| | | totalDistributionAmount = totalDistributionAmount.subtract(paymentMoney); |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = paymentMoney; |
| | | }else{ |
| | | paymentMoney = paymentMoney.subtract(totalDistributionAmount); |
| | | totalDistributionAmount = BigDecimal.ZERO; |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = totalDistributionAmount; |
| | | } |
| | | } |
| | | //构建积分流水记录 |
| | | if(earnPoint > 0){ |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | int earnPoint1 = earnPoint; |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = earnPoint1 * (100 - pointSetting.getBuyPoint()); |
| | | } |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint1); |
| | | userPoint.setVariablePoint(earnPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){ |
| | | order.setOrderStatus(2); |
| | | } |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | |
| | | //积分支付 |
| | | if(3 == shoppingCartPayment.getPaymentType()){ |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setLavePoint(lavePoint - orderPoint); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | int earnPoint1 = earnPoint; |
| | | //计算可用积分比例 |
| | | if(null != pointSetting && 1 == pointSetting.getBuyPointOpen()){ |
| | | earnPoint1 = earnPoint1 * (100 - pointSetting.getBuyPoint()); |
| | | } |
| | | appUser.setLavePoint(appUser.getLavePoint() - orderPoint); |
| | | appUser.setShopPoint(appUser.getShopPoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + earnPoint1); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + earnPoint); |
| | | appUser.setShopAmount(appUser.getShopAmount().add(paymentMoney).setScale(2, RoundingMode.HALF_EVEN)); |
| | | appUser.setLastShopTime(LocalDateTime.now()); |
| | | appUserClient.editAppUserById(appUser); |
| | | //检查消费积分满足后升级会员 |
| | |
| | | |
| | | //构建积分流水记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(4); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(orderPoint); |
| | | Integer point = appUser.getLavePoint() - lavePoint; |
| | | userPoint.setVariablePoint(point >= 0 ? point : point * -1); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | if(earnPoint > 0){ |
| | | userPoint = new UserPoint(); |
| | | userPoint.setType(1); |
| | | userPoint.setHistoricalPoint(appUser.getLavePoint() - earnPoint); |
| | | userPoint.setVariablePoint(earnPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPoint.setObjectId(order.getId()); |
| | | userPointClient.saveUserPoint(userPoint); |
| | | } |
| | | //如果有运费,需要先扣除账户积分,再进行支付。支付成功后修改订单状态,未支付成功则回退积分,删除的订单 |
| | | if(expressFee.compareTo(BigDecimal.ZERO) > 0){ |
| | | if(shoppingCartPayment.getFreightPaymentType() == 1){ |
| | |
| | | balance = balance.subtract(expressFee); |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setBalance(balance); |
| | | redPacketAmount = expressFee; |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalRedPacketAmount); |
| | | redPacketAmount = totalRedPacketAmount; |
| | | totalRedPacketAmount = BigDecimal.ZERO; |
| | | if(expressFee.compareTo(totalDistributionAmount) <= 0){ |
| | | totalDistributionAmount = totalDistributionAmount.subtract(expressFee); |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = expressFee; |
| | | }else{ |
| | | expressFee = expressFee.subtract(totalDistributionAmount); |
| | | totalDistributionAmount = BigDecimal.ZERO; |
| | |
| | | appUser.setTotalRedPacketAmount(totalRedPacketAmount); |
| | | appUser.setTotalDistributionAmount(totalDistributionAmount); |
| | | appUser.setBalance(balance); |
| | | distributionAmount = totalDistributionAmount; |
| | | } |
| | | } |
| | | |
| | |
| | | balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord); |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){ |
| | | order.setOrderStatus(2); |
| | | } |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | |
| | | }else{ |
| | | //修改订支付状态 |
| | | order.setPayStatus(2); |
| | | if(goods.getType() == 2 && null == shoppingCartPayment.getUserAddressId()){ |
| | | order.setOrderStatus(2); |
| | | } |
| | | orderService.updateById(order); |
| | | //删除购物车数据 |
| | | this.removeBatchByIds(ids); |
| | | } |
| | | } |
| | | //添加账户余额支付明细 |
| | | if(redPacketAmount.compareTo(BigDecimal.ZERO) > 0 || distributionAmount.compareTo(BigDecimal.ZERO) > 0){ |
| | | OrderBalancePayment orderBalancePayment = new OrderBalancePayment(); |
| | | orderBalancePayment.setOrderId(order.getId()); |
| | | orderBalancePayment.setRedPacketAmount(redPacketAmount); |
| | | orderBalancePayment.setDistributionAmount(distributionAmount); |
| | | orderBalancePaymentService.save(orderBalancePayment); |
| | | } |
| | | return R.ok(order.getId().toString()); |
| | | } |
| | |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | | Integer vipLevelUpShopRole = vipSetting3.getVipLevelUpShopRole(); |
| | | Integer vipLevelUpShop = vipSetting3.getVipLevelUpShop(); |
| | | if(1 == vipLevelUpShopRole && appUser.getVipId() < 3 && shopPoint >= vipLevelUpShop){ |
| | | if(null != vipLevelUpShopRole && 1 == vipLevelUpShopRole && appUser.getVipId() < 3 && shopPoint >= vipLevelUpShop){ |
| | | appUser.setVipId(3); |
| | | appUserClient.editAppUserById(appUser); |
| | | //添加等级变化记录 |
| | |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | vipLevelUpShopRole = vipSetting2.getVipLevelUpShopRole(); |
| | | vipLevelUpShop = vipSetting2.getVipLevelUpShop(); |
| | | if(1 == vipLevelUpShopRole && appUser.getVipId() < 2 && shopPoint >= vipLevelUpShop){ |
| | | if(null != vipLevelUpShopRole && 1 == vipLevelUpShopRole && appUser.getVipId() < 2 && shopPoint >= vipLevelUpShop){ |
| | | appUser.setVipId(2); |
| | | appUserClient.editAppUserById(appUser); |
| | | //添加等级变化记录 |