客座费支持删除清空

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 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);
}
}

View File

@@ -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 {
// 查询购物车所有信息
@@ -193,20 +197,27 @@ public class CartService {
if (StrUtil.isNotBlank(tableId)) {
queryWrapper.eq(TbCashierCart::getTableId, tableId);
}else {
} else {
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;
if (cashierCart.getIsVip().equals((byte) 1)) continue;
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
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,23 +361,27 @@ public class CartService {
}
}
JSONArray jsonArray = new JSONArray();
ArrayList<TbCashierCart> cashierCartArrayList = new ArrayList<>();
BigDecimal amount = BigDecimal.ZERO;
try{
try {
if (redisUtil.exists(tableCartKey)) {
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
if (Objects.isNull(array) || array.isEmpty()) {
if (type == 1) {
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);
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,18 +432,24 @@ 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());
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) {
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);
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
cashierCartArrayList.add(cashierCart);
@@ -371,8 +458,8 @@ public class CartService {
}
}
}
}catch (MsgException e){
if(e.getMessage().equals("商品起售库存不足")){
} catch (MsgException e) {
if (e.getMessage().equals("商品起售库存不足")) {
return Result.fail("商品起售库存不足");
}
}
@@ -412,7 +499,7 @@ public class CartService {
return list;
}
private void rmCart(JSONObject jsonObject,String skuId, String redisKey) {
private void rmCart(JSONObject jsonObject, String skuId, String redisKey) {
JSONArray jsonArray = new JSONArray();
BigDecimal amount = BigDecimal.ZERO;
if (redisUtil.exists(redisKey)) {
@@ -425,7 +512,7 @@ public class CartService {
if (cashierCart.getSkuId().equals(skuId)) {
if (StrUtil.isNotBlank(cashierCart.getMasterId())) {
throw new MsgException("代客下单商品不支持操作");
}else {
} else {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
flag = true;
continue;
@@ -442,7 +529,7 @@ public class CartService {
jsonObject1.put("data", jsonArray);
jsonObject1.put("amount", amount);
jsonObject1.put("reqData", jsonObject);
if(flag){
if (flag) {
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), redisKey, "", false);
}
}
@@ -518,7 +605,7 @@ public class CartService {
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId());
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
}else {
} else {
log.info("{}已在30分钟内推送过消息跳过发送", item.getOpenId());
}
@@ -527,7 +614,7 @@ public class CartService {
}
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num,
String tableId, String shopId,Integer isVip, String note, boolean isTakeout) throws Exception{
String tableId, String shopId, Integer isVip, String note, boolean isTakeout) throws Exception {
try {
TbProduct product = productMapper.selectById(Integer.valueOf(productId));
String key = tableId + "-" + shopId;
@@ -540,13 +627,13 @@ public class CartService {
if (Integer.valueOf(product.getIsDistribute()).equals(1)) {
if (num > productSku.getSuit()) {
if (num > product.getStockNumber()) isSale = true;
}else {
} else {
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
}
} else {
if (num > productSku.getSuit()) {
if (num > productSku.getStockNumber()) isSale = true;
}else {
} else {
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
}
}
@@ -554,10 +641,10 @@ public class CartService {
throw new MsgException("商品起售库存不足");
}
}
if(num > productSku.getSuit()){
if (num > productSku.getSuit()) {
cashierCart.setNumber(num);
cashierCart.setTotalNumber(num);
}else {
} else {
cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit());
}
@@ -589,11 +676,11 @@ public class CartService {
if (isTakeout && product.getPackFee() != null) {
cashierCart.setPackFee(product.getPackFee().multiply(BigDecimal.valueOf(num)));
}
if(isVip==1){
if (isVip == 1) {
cashierCart.setIsVip(Byte.parseByte("1"));
cashierCart.setTotalAmount(BigDecimal.ZERO);
cashierCart.setSalePrice(BigDecimal.ZERO);
}else {
} else {
cashierCart.setIsVip((byte) 0);
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee())));
}
@@ -623,7 +710,7 @@ public class CartService {
String tableId = jsonObject.getString("tableId");
String userId = jsonObject.getString("userId");
String sendType = jsonObject.getString("sendType");
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
String remark = StringUtils.isBlank(jsonObject.getString("remark")) ? "" : jsonObject.getString("remark");
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, Integer.valueOf(userId));
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
BigDecimal totalAmount = BigDecimal.ZERO;
@@ -721,7 +808,7 @@ public class CartService {
}
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId);
boolean isVip= tbShopUser != null && tbShopUser.getIsVip().equals((byte) 1);
boolean isVip = tbShopUser != null && tbShopUser.getIsVip().equals((byte) 1);
// 查询历史orderDetail
Integer finalOrderId = orderId;
@@ -754,7 +841,7 @@ public class CartService {
TbProduct product = productMapper.selectById(Integer.valueOf(cart.getProductId()));
cart.setPackFee(product.getPackFee() != null ?
product.getPackFee().multiply(BigDecimal.valueOf(cart.getNumber())) : BigDecimal.ZERO);
}else {
} else {
cart.setTableId(tableId);
cart.setPackFee(BigDecimal.ZERO);
}
@@ -819,7 +906,7 @@ public class CartService {
continue;
}
saleAmount = saleAmount.add(tbProduct.getSalePrice());
}else {
} else {
tbProduct = null;
saleAmount = saleAmount.add(shopEatTypeInfoDTO.getShopInfo().getTableFee());
@@ -1012,7 +1099,7 @@ public class CartService {
orderDetail.setOrderId(orderInfo.getId());
if (orderDetail.getId() != null) {
mpOrderDetailMapper.updateById(orderDetail);
}else {
} else {
mpOrderDetailMapper.insert(orderDetail);
}
}
@@ -1049,7 +1136,7 @@ public class CartService {
mpCashierCartMapper.updateById(cashierCart);
}
if(!CollectionUtils.isEmpty(outRecords)) outRecordMapper.insertBatch(outRecords);
if (!CollectionUtils.isEmpty(outRecords)) outRecordMapper.insertBatch(outRecords);
// 打印票据
if (!addOrderDetail.isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) {
@@ -1155,12 +1242,12 @@ public class CartService {
Integer userId = TokenUtil.getUserId();
if (StrUtil.isNotBlank(tableId)) {
cashierCartMapper.updateStatusByOrderIdForMini(jsonObject.getString("tableId"), "closed");
}else {
} else {
mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.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"));
}

View File

@@ -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()));
}