清空购物车保留餐位费信息

This commit is contained in:
2024-09-27 17:10:14 +08:00
parent a10500241e
commit 8a467a22ec

View File

@@ -235,15 +235,18 @@ public class CartService {
return Result.fail("参数缺失"); return Result.fail("参数缺失");
} }
boolean isSeatCart = "-999".equals(productId);
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId); ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId); String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = null;
if (!isSeatCart) {
TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId)); TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
if (tbProduct == null) { if (tbProduct == null) {
log.error("该商品不存在 productId:{}", productId); log.error("该商品不存在 productId:{}", productId);
return Result.fail("该商品不存在"); return Result.fail("该商品不存在");
} }
// 判断商品是否已下架 // 判断商品是否已下架
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
if (tbProductSkuWithBLOBs == null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) { if (tbProductSkuWithBLOBs == null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) {
rmCart(jsonObject, skuId, tableCartKey); rmCart(jsonObject, skuId, tableCartKey);
return Result.fail("商品已下架"); return Result.fail("商品已下架");
@@ -277,6 +280,7 @@ public class CartService {
} }
} }
} }
}
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>(); ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>();
@@ -304,7 +308,7 @@ public class CartService {
cashierCart.setTotalNumber(buyNum); cashierCart.setTotalNumber(buyNum);
cashierCart.setNumber(buyNum); cashierCart.setNumber(buyNum);
cashierCart.setNote(note); cashierCart.setNote(note);
if (type == 0 && isVip == 0 && tbProductSkuWithBLOBs.getSuit() != null if (tbProductSkuWithBLOBs != null && type == 0 && isVip == 0 && tbProductSkuWithBLOBs.getSuit() != null
&& tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) { && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue; continue;
@@ -314,7 +318,7 @@ public class CartService {
// 设置备注 // 设置备注
cashierCart.setNote(note); cashierCart.setNote(note);
// 设置打包费 // 设置打包费
if (shopEatTypeInfoDTO.isTakeout()) { if (shopEatTypeInfoDTO.isTakeout() && !isSeatCart) {
// 打包费 // 打包费
TbProduct product = productMapper.selectById(Integer.valueOf(productId)); TbProduct product = productMapper.selectById(Integer.valueOf(productId));
cashierCart.setPackFee(product.getPackFee() != null ? cashierCart.setPackFee(product.getPackFee() != null ?
@@ -324,7 +328,8 @@ public class CartService {
if (isVip == 1) { if (isVip == 1) {
cashierCart.setTotalAmount(BigDecimal.ZERO); cashierCart.setTotalAmount(BigDecimal.ZERO);
} else { } else {
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber())
.multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
} }
cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
mpCashierCartMapper.updateById(cashierCart); mpCashierCartMapper.updateById(cashierCart);
@@ -1124,7 +1129,12 @@ public class CartService {
.set(TbCashierCart::getStatus, "closed")); .set(TbCashierCart::getStatus, "closed"));
} }
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId); String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
redisUtil.deleteByKey(tableCartKey); String message = redisUtil.getMessage(tableCartKey);
if (StrUtil.isNotBlank(message)) {
JSONArray jsonArray = JSONObject.parseArray(message);
List<Object> collect = jsonArray.stream().filter(info -> "-999".equals(((TbCashierCart) info).getProductId())).collect(Collectors.toList());
redisUtil.saveMessage(tableCartKey, JSONObject.toJSONString(collect));
}
// redisUtil.saveMessage(tableCartKey, new JSONArray().toJSONString()); // redisUtil.saveMessage(tableCartKey, new JSONArray().toJSONString());
JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success"); jsonObject1.put("status", "success");