限制台桌选择人数

This commit is contained in:
2024-09-27 17:12:34 +08:00
parent 8a467a22ec
commit 77a6a525cd
2 changed files with 65 additions and 58 deletions

View File

@@ -32,6 +32,8 @@ public class RedisCst {
public static final String SONG_PAY_LOCK = "song_pay_lock:";
public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:";
public static final String ORDER_PRINT = "ORDER_PRINT:";
// 选择人数锁
public static final String CHOSE_TABLE_COUNT = "CHOSE_TABLE_COUNT";
static final String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";

View File

@@ -32,6 +32,7 @@ import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -102,6 +103,8 @@ public class ProductService {
private MpOrderInfoMapper mpOrderInfoMapper;
@Autowired
private RedisUtil redisUtil;
@Autowired
private StringRedisTemplate stringRedisTemplate;
public ProductService(ShopUtils shopUtils) {
this.shopUtils = shopUtils;
@@ -878,73 +881,75 @@ public class ProductService {
}
public TbCashierCart choseCount(ChoseCountDTO choseCountDTO) {
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(choseCountDTO.getTableId(), choseCountDTO.getShopId());
return Utils.runFunAndCheckKey(() -> {
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(choseCountDTO.getTableId(), choseCountDTO.getShopId());
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
if (shopInfo == null) throw new MsgException("店铺信息不存在");
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(choseCountDTO.getShopId());
if (shopInfo == null) throw new MsgException("店铺信息不存在");
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
throw new MsgException("当前店铺无需选择餐位费");
}
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
throw new MsgException("当前店铺无需选择餐位费");
}
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
if (shopTable == null) {
throw new MsgException("台桌不存在");
}
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseCountDTO.getTableId()));
if (shopTable == null) {
throw new MsgException("台桌不存在");
}
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
throw new MsgException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
}
if (shopTable.getMaxCapacity() < choseCountDTO.getNum()) {
throw new MsgException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
}
Integer userId = TokenUtil.getUserId();
Integer userId = TokenUtil.getUserId();
TbCashierCart tbCashierCart = getSeatCartInfo(choseCountDTO.getShopId(), choseCountDTO.getTableId(), userId, shopEatTypeInfoDTO);
TbCashierCart tbCashierCart = getSeatCartInfo(choseCountDTO.getShopId(), choseCountDTO.getTableId(), userId, shopEatTypeInfoDTO);
if (tbCashierCart == null) {
tbCashierCart = new TbCashierCart();
tbCashierCart.setStatus("create");
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setTableId(choseCountDTO.getTableId());
tbCashierCart.setName("客座费");
tbCashierCart.setSalePrice(shopInfo.getTableFee());
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setPlaceNum(1);
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
tbCashierCart.setUserId(userId);
mpCashierCartMapper.insert(tbCashierCart);
} else {
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
tbCashierCart.setUserId(userId);
mpCashierCartMapper.updateById(tbCashierCart);
}
if (tbCashierCart == null) {
tbCashierCart = new TbCashierCart();
tbCashierCart.setStatus("create");
tbCashierCart.setCreatedAt(System.currentTimeMillis());
tbCashierCart.setTableId(choseCountDTO.getTableId());
tbCashierCart.setName("客座费");
tbCashierCart.setSalePrice(shopInfo.getTableFee());
tbCashierCart.setShopId(String.valueOf(choseCountDTO.getShopId()));
tbCashierCart.setTradeDay(DateUtils.getDay());
tbCashierCart.setStatus("create");
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setPlaceNum(1);
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
tbCashierCart.setUserId(userId);
mpCashierCartMapper.insert(tbCashierCart);
} else {
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
tbCashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
tbCashierCart.setUserId(userId);
mpCashierCartMapper.updateById(tbCashierCart);
}
// 将数据加入缓存
String tableCartKey = RedisCst.getTableCartKey(String.valueOf(choseCountDTO.getShopId()), choseCountDTO.getTableId(), userId);
String message = redisUtil.getMessage(tableCartKey);
JSONArray jsonArray;
if (StrUtil.isNotBlank(message)) {
jsonArray = JSONObject.parseArray(message);
}else {
jsonArray = new JSONArray();
}
jsonArray.add(tbCashierCart);
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
// 将数据加入缓存
String tableCartKey = RedisCst.getTableCartKey(String.valueOf(choseCountDTO.getShopId()), choseCountDTO.getTableId(), userId);
String message = redisUtil.getMessage(tableCartKey);
JSONArray jsonArray;
if (StrUtil.isNotBlank(message)) {
jsonArray = JSONObject.parseArray(message);
}else {
jsonArray = new JSONArray();
}
jsonArray.add(tbCashierCart);
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
return tbCashierCart;
return tbCashierCart;
}, stringRedisTemplate, RedisCst.getLockKey(RedisCst.CHOSE_TABLE_COUNT, choseCountDTO.getShopId(), choseCountDTO.getTableId()));
}
private TbCashierCart getSeatCartInfo(Object shopId, String tableId, Integer userId, ShopEatTypeInfoDTO shopEatTypeInfoDTO) {