fix: 转台仅剩一个商品同时转出客座费

This commit is contained in:
张松
2024-12-18 11:30:23 +08:00
parent 3135953294
commit 032f37f403
3 changed files with 66 additions and 7 deletions

View File

@@ -79,6 +79,7 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
*/
List<TbCashierCart> 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<TbCashierCart> getByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses);
/**
* 根据订单id和状态获取购物车数据

View File

@@ -182,6 +182,46 @@ public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, T
return list(queryWrapper);
}
@Override
public List<TbCashierCart> getByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) {
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.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<TbCashierCartMapper, T
return count(queryWrapper);
}
@Override
public List<TbCashierCart> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status... status) {
LambdaQueryChainWrapper<TbCashierCart> queryChainWrapper = lambdaQuery().eq(TbCashierCart::getOrderId, orderId);

View File

@@ -3384,8 +3384,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("当前台桌清理中,不能转台");
}
List<TbCashierCart> cashierCarts;
long totalSize = 99999;
List<TbCashierCart> cashierCarts = new ArrayList<>();
List<TbCashierCart> 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());