1.代客下单 已下单商品不支持操作

This commit is contained in:
SongZhang 2024-09-11 14:08:41 +08:00
parent dc0f6eae1e
commit f2bfc718c3
1 changed files with 52 additions and 6 deletions

View File

@ -272,6 +272,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
throw new BadRequestException("购物车商品不存在");
}
int currentPlaceNum = getCurrentPlaceNum(tbCashierCart.getTableId().toString(), tbCashierCart.getShopId());
if (!tbCashierCart.getPlaceNum().equals(currentPlaceNum)) {
throw new BadRequestException("已下单商品仅支持退单操作");
}
if (updateCartDTO.getNum() == 0) {
cashierCartRepository.deleteById(updateCartDTO.getCartId());
return null;
@ -332,12 +338,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private int getCurrentPlaceNum(String tableId, String shopId) {
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId,
shopId);
if (StrUtil.isBlank(currentOrderKey)) {
String orderId = redisTemplate.opsForValue().get(currentOrderKey);
if (StrUtil.isBlank(orderId)) {
return 1;
}
TbOrderInfo orderInfo = orderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getUseType, "postPay")
.eq(TbOrderInfo::getId, currentOrderKey).select(TbOrderInfo::getPlaceNum));
.eq(TbOrderInfo::getId, orderId).select(TbOrderInfo::getPlaceNum));
return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1;
}
@ -345,7 +352,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
checkTableIsOpen(addCartDTO.getTableId());
int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getShopId().toString(), addCartDTO.getTableId());
int currentPlaceNum = getCurrentPlaceNum(addCartDTO.getTableId(), addCartDTO.getShopId().toString());
TbProductSku productSku = productMapper.selectSkuByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getSkuId());
TbProduct product = productMapper.selectByIdAndShopId(addCartDTO.getShopId(), addCartDTO.getProductId());
@ -488,12 +495,15 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 会员点单
TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, removeCartDTO.getShopId())
.eq(TbCashierCart::getPlaceNum, currentPlaceNum)
.eq(TbCashierCart::getId, removeCartDTO.getCartId()));
if (cashierCart == null) {
throw new BadRequestException("购物车商品不存在");
}
if (!cashierCart.getPlaceNum().equals(currentPlaceNum)) {
throw new BadRequestException("已下单商品仅支持退单操作");
}
if (cashierCart.getOrderId() != null) {
orderDetailMapper.delete(new LambdaQueryWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getShopId, cashierCart.getShopId())
@ -633,6 +643,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
skuIds.add(Integer.valueOf(item.getSkuId()));
});
if (!skuIds.isEmpty()) {
List<TbProductSku> skuList = productSkuRepository.findAllById(skuIds);
HashMap<String, TbProductSku> skuMap = new HashMap<>();
@ -647,9 +659,22 @@ public class TbShopTableServiceImpl implements TbShopTableService {
});
com.baomidou.mybatisplus.extension.plugins.pagination.Page copyPage = BeanUtil.copyProperties(cartPage, com.baomidou.mybatisplus.extension.plugins.pagination.Page.class);
copyPage.setRecords(infos);
// 根据placeNum进行分组
Map<Object, List<Map<String, Object>>> groupedByPlaceNum = infos.stream()
.collect(Collectors.groupingBy(info -> info.get("placeNum")));
ArrayList<HashMap<String, Object>> list = new ArrayList<>();
groupedByPlaceNum.forEach((k, v) -> {
HashMap<String, Object> item = new HashMap<>();
item.put("placeNum", k);
item.put("info", v);
list.add(item);
});
copyPage.setRecords(list);
return copyPage;
}
return cartPage;
}
@ -991,7 +1016,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
BigDecimal feeAmount = BigDecimal.ZERO;
BigDecimal saleAmount = BigDecimal.ZERO;
// 当前下单次数
int placeNum = orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1;
int placeNum = getCurrentPlaceNum(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString());
List<TbOrderDetail> orderDetails = new ArrayList<>();
boolean mealCost = false;
@ -1052,6 +1077,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderInfo.setUseType(createOrderDTO.isPostPay() ? "postPay" : "afterPay");
orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId()));
orderInfo.setCreatedAt(DateUtil.current());
orderInfo.setPlaceNum(placeNum);
orderInfoMapper.updateById(orderInfo);
} else {
String orderNo = generateOrderNumber();
@ -1078,6 +1104,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
orderInfo.setUserId(createOrderDTO.getVipUserId() == null ? null : String.valueOf(createOrderDTO.getVipUserId()));
orderInfo.setCreatedAt(DateUtil.current());
orderInfo.setTableName(tbShopTable.getName());
orderInfo.setPlaceNum(placeNum);
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>()
.eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId())
.eq(TbMerchantAccount::getStatus, 1));
@ -1102,6 +1129,9 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 是否是第一次添加的商品
boolean isFirst = true;
for (TbCashierCart cashierCart : cashierCarts) {
if ("-999".equals(cashierCart.getProductId())) {
continue;
}
TbProduct product = productMapper.selectById(cashierCart.getProductId());
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
@ -1450,6 +1480,18 @@ public class TbShopTableServiceImpl implements TbShopTableService {
return redisTemplate.opsForValue().get(currentOrderKey);
}
private void setCurrentOrderId(String tableId, String shopId, String orderId) {
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId);
redisTemplate.opsForValue().set(currentOrderKey, orderId);
}
private String removeCurrentOrderId(String tableId, String shopId) {
String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId);
String orderId = redisTemplate.opsForValue().get(currentOrderKey);
redisTemplate.delete(currentOrderKey);
return orderId;
}
@Override
public Object choseTable(ChoseTableDTO choseTableDTO) {
String masterId = getMasterId(choseTableDTO.getShopId(), Long.valueOf(choseTableDTO.getNewTableId()), null).getString("masterId");
@ -1493,6 +1535,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
.eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId())
.set(TbShopTable::getStatus, "idle"));
// 将台桌redis数据迁移
String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString());
setCurrentOrderId(choseTableDTO.getNewTableId(), choseTableDTO.getShopId().toString(), orderId);
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, currentOrderId)
.set(TbOrderInfo::getMasterId, masterId)