客座费支持删除清空
This commit is contained in:
@@ -47,6 +47,8 @@ public class RedisCst {
|
||||
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 CURRENT_TABLE_SEAR_COUNT = "CURRENT_TABLE_SEAR_COUNT:";
|
||||
|
||||
|
||||
public static String getCurrentOrderKey(String tableId, String shopId) {
|
||||
@@ -79,4 +81,8 @@ public class RedisCst {
|
||||
}
|
||||
return getDineInTableCartKey(shopId, tableId);
|
||||
}
|
||||
|
||||
public static String getCurrentTableSeatCount(Object shopId, String tableId) {
|
||||
return CURRENT_TABLE_SEAR_COUNT + (shopId + ":" + tableId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,6 @@ public class CartService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前台桌当前下单次数
|
||||
*
|
||||
@@ -174,6 +173,7 @@ public class CartService {
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
TbCashierCart seatCartInfo = null;
|
||||
if (redisUtil.exists(tableCartKey)) {
|
||||
array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
@@ -182,6 +182,10 @@ public class CartService {
|
||||
if (cashierCart.getNumber() > 0) {
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
|
||||
if ("-999".equals(cashierCart.getProductId())) {
|
||||
seatCartInfo = cashierCart;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 查询购物车所有信息
|
||||
@@ -197,9 +201,12 @@ public class CartService {
|
||||
queryWrapper.eq(TbCashierCart::getUserId, userId);
|
||||
}
|
||||
|
||||
List<TbCashierCart> tbCashierCarts = mpCashierCartMapper.selectList(queryWrapper);;
|
||||
List<TbCashierCart> tbCashierCarts = mpCashierCartMapper.selectList(queryWrapper);
|
||||
if (!CollectionUtils.isEmpty(tbCashierCarts)) {
|
||||
for (TbCashierCart cashierCart : tbCashierCarts) {
|
||||
if ("-999".equals(cashierCart.getProductId())) {
|
||||
seatCartInfo = cashierCart;
|
||||
}
|
||||
array.add(cashierCart);
|
||||
if (cashierCart.getIsVip().equals((byte) 1)) continue;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
|
||||
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(seatCartInfo), 60 * 60 * 12L);
|
||||
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
@@ -216,8 +227,74 @@ public class CartService {
|
||||
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 商品信息
|
||||
*/
|
||||
public Result createCart(JSONObject jsonObject) {
|
||||
@@ -284,6 +361,7 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>();
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
@@ -298,9 +376,12 @@ public class CartService {
|
||||
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
|
||||
cashierCartArrayList.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
|
||||
}
|
||||
} else {
|
||||
boolean flag = true;
|
||||
|
||||
boolean hasSeat = false;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
@@ -351,13 +432,19 @@ public class CartService {
|
||||
jsonArray.add(cashierCart);
|
||||
cashierCartArrayList.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
|
||||
if ("-999".equals(cashierCart.getProductId())) {
|
||||
hasSeat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag && type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, isVip, note, shopEatTypeInfoDTO.isTakeout());
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (type == 1) {
|
||||
@@ -1160,7 +1247,7 @@ public class CartService {
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.eq(TbCashierCart::getUserId, userId)
|
||||
.ne(TbCashierCart::getProductId, "-999")
|
||||
// .ne(TbCashierCart::getProductId, "-999")
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.set(TbCashierCart::getStatus, "closed"));
|
||||
}
|
||||
|
||||
@@ -948,6 +948,9 @@ public class ProductService {
|
||||
jsonArray.add(tbCashierCart);
|
||||
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
|
||||
|
||||
// 保存就餐人数信息
|
||||
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(choseCountDTO.getShopId(), choseCountDTO.getTableId()),
|
||||
JSONObject.toJSONString(tbCashierCart), 60L * 60 * 12);
|
||||
return tbCashierCart;
|
||||
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user