切换就餐模式计算打包费

This commit is contained in:
2024-10-08 14:59:24 +08:00
parent 68a6326dac
commit c5015446df
2 changed files with 25 additions and 6 deletions

View File

@@ -1589,6 +1589,7 @@ public class CartService {
public List<TbCashierCart> choseEatModel(ChoseEatModelDTO choseEatModelDTO) {
Integer userId = TokenUtil.getUserId();
List<TbCashierCart> cashierCartList;
// 外带模式
if (choseEatModelDTO.getType() == 1) {
// 查询购物车所有信息
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
@@ -1597,9 +1598,26 @@ public class CartService {
.isNull(TbCashierCart::getOrderId)
.ne(TbCashierCart::getProductId, "-999")
.eq(TbCashierCart::getStatus, "create");
// 外带模式
queryWrapper.eq(TbCashierCart::getUserId, userId);
cashierCartList = mpCashierCartMapper.selectList(queryWrapper);
// 计算打包费
List<String> productIds = cashierCartList.stream().map(TbCashierCart::getProductId).collect(Collectors.toList());
Map<Integer, TbProduct> productMap = productMapper.selectByIds(productIds).stream()
.collect(Collectors.toMap(
TbProduct::getId, // keyMapper使用 Product 的 getId() 方法作为 key
product -> product // valueMapper直接使用 Product 对象作为 value
));
cashierCartList.forEach(item -> {
TbProduct tbProduct = productMap.get(Integer.parseInt(item.getProductId()));
item.setIsPack("true");
if (tbProduct != null && tbProduct.getPackFee() != null) {
BigDecimal packFee = tbProduct.getPackFee().multiply(BigDecimal.valueOf(item.getNumber()));
item.setPackFee(packFee);
item.setTotalAmount(item.getTotalAmount().add(packFee));
}
});
}else {
cashierCartList = new ArrayList<>();
String tableCartKey = RedisCst.getTableCartKey(choseEatModelDTO.getShopId().toString(), choseEatModelDTO.getTableId(), userId);

View File

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaozhanggui.system.cashierservice.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum;
@@ -925,8 +926,8 @@ public class ProductService {
tbCashierCart.setStatus("create");
tbCashierCart.setTotalAmount(new BigDecimal(choseCountDTO.getNum()).multiply(shopInfo.getTableFee()));
tbCashierCart.setPlaceNum(1);
tbCashierCart.setProductId("-999");
tbCashierCart.setSkuId("-999");
tbCashierCart.setProductId(TableConstant.CART_SEAT_ID);
tbCashierCart.setSkuId(TableConstant.CART_SEAT_ID);
tbCashierCart.setPackFee(BigDecimal.ZERO);
tbCashierCart.setNumber(choseCountDTO.getNum());
tbCashierCart.setTotalNumber(choseCountDTO.getNum());
@@ -954,7 +955,7 @@ public class ProductService {
jsonArray = new JSONArray();
}
long count = jsonArray.stream().filter(item -> "-999".equals(((JSONObject) item).getString("productId"))).count();
long count = jsonArray.stream().filter(item -> TableConstant.CART_SEAT_ID.equals(((JSONObject) item).getString("productId"))).count();
if (count < 1) {
jsonArray.add(tbCashierCart);
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
@@ -970,8 +971,8 @@ public class ProductService {
private TbCashierCart getSeatCartInfo(Object shopId, String tableId, Integer userId, ShopEatTypeInfoDTO shopEatTypeInfoDTO) {
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
.eq(TbCashierCart::getProductId, "-999")
.eq(TbCashierCart::getSkuId, "-999")
.eq(TbCashierCart::getProductId, TableConstant.CART_SEAT_ID)
.eq(TbCashierCart::getSkuId, TableConstant.CART_SEAT_ID)
.eq(TbCashierCart::getStatus, "create")
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
// .and(r -> r.eq(TbCashierCart::getUserId, userId).or().isNull(TbCashierCart::getUserId))