客座费支持删除清空

This commit is contained in:
2024-09-28 14:38:20 +08:00
parent 4e8cbbc293
commit bf3be4e37c
3 changed files with 125 additions and 29 deletions

View File

@@ -47,6 +47,8 @@ public class RedisCst {
public static final String TAKEOUT_TABLE_CART = "TAKEOUT_TABLE_CART:"; public static final String TAKEOUT_TABLE_CART = "TAKEOUT_TABLE_CART:";
// 店内就餐购物车缓存 // 店内就餐购物车缓存
public static final String DINE_IN_TABLE_CART = "DINE_IN_TABLE_CART:"; public static final String DINE_IN_TABLE_CART = "DINE_IN_TABLE_CART:";
// 当前台桌人数
public static final String CURRENT_TABLE_SEAR_COUNT = "CURRENT_TABLE_SEAR_COUNT:";
public static String getCurrentOrderKey(String tableId, String shopId) { public static String getCurrentOrderKey(String tableId, String shopId) {
@@ -79,4 +81,8 @@ public class RedisCst {
} }
return getDineInTableCartKey(shopId, tableId); return getDineInTableCartKey(shopId, tableId);
} }
public static String getCurrentTableSeatCount(Object shopId, String tableId) {
return CURRENT_TABLE_SEAR_COUNT + (shopId + ":" + tableId);
}
} }

View File

@@ -137,7 +137,6 @@ public class CartService {
} }
/** /**
* 获取当前台桌当前下单次数 * 获取当前台桌当前下单次数
* *
@@ -174,6 +173,7 @@ public class CartService {
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId); String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
TbCashierCart seatCartInfo = null;
if (redisUtil.exists(tableCartKey)) { if (redisUtil.exists(tableCartKey)) {
array = JSON.parseArray(redisUtil.getMessage(tableCartKey)); array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
@@ -182,6 +182,10 @@ public class CartService {
if (cashierCart.getNumber() > 0) { if (cashierCart.getNumber() > 0) {
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
} }
if ("-999".equals(cashierCart.getProductId())) {
seatCartInfo = cashierCart;
}
} }
} else { } else {
// 查询购物车所有信息 // 查询购物车所有信息
@@ -197,9 +201,12 @@ public class CartService {
queryWrapper.eq(TbCashierCart::getUserId, userId); queryWrapper.eq(TbCashierCart::getUserId, userId);
} }
List<TbCashierCart> tbCashierCarts = mpCashierCartMapper.selectList(queryWrapper);; List<TbCashierCart> tbCashierCarts = mpCashierCartMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(tbCashierCarts)) { if (!CollectionUtils.isEmpty(tbCashierCarts)) {
for (TbCashierCart cashierCart : tbCashierCarts) { for (TbCashierCart cashierCart : tbCashierCarts) {
if ("-999".equals(cashierCart.getProductId())) {
seatCartInfo = cashierCart;
}
array.add(cashierCart); array.add(cashierCart);
if (cashierCart.getIsVip().equals((byte) 1)) continue; if (cashierCart.getIsVip().equals((byte) 1)) continue;
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
@@ -207,6 +214,10 @@ public class CartService {
redisUtil.saveMessage(tableCartKey, array.toString()); redisUtil.saveMessage(tableCartKey, array.toString());
} }
} }
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(seatCartInfo), 60 * 60 * 12L);
JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success"); jsonObject1.put("status", "success");
jsonObject1.put("msg", "成功"); jsonObject1.put("msg", "成功");
@@ -216,8 +227,74 @@ public class CartService {
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, "", false); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, "", false);
} }
public void checkSeatInfo(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String tableId, Integer userId) {
TbShopInfo shopInfo = shopEatTypeInfoDTO.getShopInfo();
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
return;
}
if (!shopEatTypeInfoDTO.isTakeout()) {
String tableCartKey = RedisCst.getTableCartKey(shopEatTypeInfoDTO.getShopInfo().getId().toString(), tableId, userId);
String message = redisUtil.getMessage(tableCartKey);
boolean hasSeatInfo = false;
JSONArray array = null;
if (StrUtil.isNotBlank(message)) {
array = JSON.parseArray(message);
long count = array.stream().filter(item -> {
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(((JSONObject) item).toJSONString(), TbCashierCart.class);
return "-999".equals(cashierCart.getProductId());
}).count();
hasSeatInfo = count > 0;
}
if (hasSeatInfo) {
return;
}
if (array == null) {
array = new JSONArray();
}
String oldSeatInfo = redisUtil.getMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId));
TbCashierCart tbCashierCart = null;
if (StrUtil.isNotBlank(oldSeatInfo)) {
tbCashierCart = JSONObject.parseObject(oldSeatInfo, TbCashierCart.class);
}
if (tbCashierCart == null) {
tbCashierCart = new TbCashierCart();
tbCashierCart.setStatus("create");
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setTableId(tableId);
tbCashierCart.setName("客座费");
tbCashierCart.setSalePrice(shopInfo.getTableFee());
tbCashierCart.setShopId(String.valueOf(shopEatTypeInfoDTO.getShopInfo().getId()));
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setTotalAmount(shopInfo.getTableFee());
tbCashierCart.setPlaceNum(1);
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setNumber(1);
tbCashierCart.setTotalNumber(1);
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
tbCashierCart.setUserId(userId);
}
tbCashierCart.setId(null);
mpCashierCartMapper.insert(tbCashierCart);
array.add(tbCashierCart);
redisUtil.saveMessage(tableCartKey, array.toString());
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(tbCashierCart), 60 * 60 * 12L);
}
}
/** /**
* 加入购物车 * 加入购物车
*
* @param jsonObject 商品信息 * @param jsonObject 商品信息
*/ */
public Result createCart(JSONObject jsonObject) { public Result createCart(JSONObject jsonObject) {
@@ -284,6 +361,7 @@ public class CartService {
} }
} }
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>(); ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>();
BigDecimal amount = BigDecimal.ZERO; BigDecimal amount = BigDecimal.ZERO;
@@ -298,9 +376,12 @@ public class CartService {
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum()); cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
cashierCartArrayList.add(cashierCart); cashierCartArrayList.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
} }
} else { } else {
boolean flag = true; boolean flag = true;
boolean hasSeat = false;
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i); JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
@@ -351,13 +432,19 @@ public class CartService {
jsonArray.add(cashierCart); jsonArray.add(cashierCart);
cashierCartArrayList.add(cashierCart); cashierCartArrayList.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
if ("-999".equals(cashierCart.getProductId())) {
hasSeat = true;
} }
}
if (flag && type == 1) { if (flag && type == 1) {
TbCashierCart cashierCart = addCart(productId, skuId, TbCashierCart cashierCart = addCart(productId, skuId,
jsonObject.getInteger("userId"), buyNum, tableId, shopId, isVip, note, shopEatTypeInfoDTO.isTakeout()); jsonObject.getInteger("userId"), buyNum, tableId, shopId, isVip, note, shopEatTypeInfoDTO.isTakeout());
jsonArray.add(cashierCart); jsonArray.add(cashierCart);
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
} }
} }
} else { } else {
if (type == 1) { if (type == 1) {
@@ -1160,7 +1247,7 @@ public class CartService {
.eq(TbCashierCart::getShopId, shopId) .eq(TbCashierCart::getShopId, shopId)
.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) .and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
.eq(TbCashierCart::getUserId, userId) .eq(TbCashierCart::getUserId, userId)
.ne(TbCashierCart::getProductId, "-999") // .ne(TbCashierCart::getProductId, "-999")
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.set(TbCashierCart::getStatus, "closed")); .set(TbCashierCart::getStatus, "closed"));
} }

View File

@@ -948,6 +948,9 @@ public class ProductService {
jsonArray.add(tbCashierCart); jsonArray.add(tbCashierCart);
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString()); redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
// 保存就餐人数信息
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(choseCountDTO.getShopId(), choseCountDTO.getTableId()),
JSONObject.toJSONString(tbCashierCart), 60L * 60 * 12);
return tbCashierCart; return tbCashierCart;
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId())); }, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
} }