diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java index a50572cf..b7d41c54 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/MpCashierCartService.java @@ -79,6 +79,7 @@ public interface MpCashierCartService extends IService { */ List selectByShopEatTypeAndOrderId(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses); Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses); + List getByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses); /** * 根据订单id和状态获取购物车数据 diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java index a592adce..189fe217 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/MpCashierCartServiceImpl.java @@ -182,6 +182,46 @@ public class MpCashierCartServiceImpl extends ServiceImpl getByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) + .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) + .and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId)); + + if (statuses.length == 0) { + queryWrapper.in(TbCashierCart::getStatus, "create", "return"); + } else { + queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses) + .map(TableConstant.OrderInfo.Status::getValue) + .collect(Collectors.toList())); + } + + if (orderId != null) { + queryWrapper.and(q -> q.eq(TbCashierCart::getOrderId, orderId) + .or().isNull(TbCashierCart::getOrderId)); + } + + if (onlySearchPc) { + queryWrapper.ne(TbCashierCart::getPlatformType, "mimiapp"); + } + + // 非堂食校验台桌状态 + if (shopEatTypeInfoDTO.isTakeout()) { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) + .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); + } else { + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId()); + } else { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")); + } + + } + return list(queryWrapper); + } + @Override public Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) { @@ -223,6 +263,8 @@ public class MpCashierCartServiceImpl extends ServiceImpl selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... status) { LambdaQueryChainWrapper queryChainWrapper = lambdaQuery().eq(TbCashierCart::getOrderId, orderId); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index 4157c66e..e905d6ec 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -3384,8 +3384,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("当前台桌清理中,不能转台"); } - List cashierCarts; - long totalSize = 99999; + List cashierCarts = new ArrayList<>(); + List allCarts = new ArrayList<>(); if (switchTableDTO.isFull()) { cashierCarts = mpCashierCartService.selectByShopEatTypeAndOrderId(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(), true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); @@ -3394,10 +3394,26 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("请选择转单商品"); } - totalSize = mpCashierCartService.countByShopEatType(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(), + allCarts = mpCashierCartService.getByShopEatType(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(), true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); - cashierCarts = mpCashierCartService.selectByIds(switchTableDTO.getShopId(), null, switchTableDTO.getCartIds(), - TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); + + TbCashierCart seatCart = null; + for (TbCashierCart allCart : allCarts) { + if (switchTableDTO.getCartIds().contains(allCart.getId())) { + cashierCarts.add(allCart); + }else if (TableConstant.CART_SEAT_ID.equals(allCart.getProductId())) { + seatCart = allCart; + } + } + + // 如果购物车剩余一个商品并且存在客座费,同时转出客座费 + if (seatCart != null && allCarts.size() - cashierCarts.size() == 1) { + cashierCarts.add(seatCart); + } +// cashierCarts = mpCashierCartService.selectByIds(switchTableDTO.getShopId(), null, switchTableDTO.getCartIds(), +// TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); + + } if (cashierCarts.isEmpty()) { @@ -3461,11 +3477,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { mpOrderDetailService.removeByCartIds(cartIds); // 删除原有台桌detail和order信息 - if (orderId != null && (switchTableDTO.isFull() || switchTableDTO.getCartIds().size() == totalSize)) { + if (orderId != null && (switchTableDTO.isFull() || cashierCarts.size() == allCarts.size())) { mpOrderInfoService.removeById(orderId); } - if (!switchTableDTO.isFull() && switchTableDTO.getCartIds().size() == totalSize) { + if (!switchTableDTO.isFull() && cashierCarts.size() == allCarts.size()) { // 重新创建订单数据 CreateOrderDTO createOrderDTO = new CreateOrderDTO(); createOrderDTO.setMasterId(switchTableDTO.getMasterId());