初始化购物车接口校验是否需要餐位费,不需要删除旧数据

This commit is contained in:
2024-10-08 11:30:35 +08:00
parent 35309e4975
commit b3c24748b3

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.*;
@@ -178,21 +179,31 @@ public class CartService {
tableId = null;
}
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
// 免除座位费,删除当前台桌座位费信息
TbShopInfo shopInfo = shopEatTypeInfoDTO.getShopInfo();
boolean ignoreTableFee = shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1;
TbCashierCart seatCartInfo = null;
if (redisUtil.exists(tableCartKey)) {
array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
for (int i = 0; i < array.size(); i++) {
JSONArray jsonArray = JSON.parseArray(redisUtil.getMessage(tableCartKey));
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
if (cashierCart.getNumber() > 0) {
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
if ((!TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId()) || !ignoreTableFee) && cashierCart.getNumber() > 0) {
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
if ("-999".equals(cashierCart.getProductId())) {
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
seatCartInfo = cashierCart;
if (!ignoreTableFee) {
array.add(cashierCart);
}
}else {
array.add(cashierCart);
}
}
} else {
// 查询购物车所有信息
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
@@ -209,18 +220,28 @@ public class CartService {
List<TbCashierCart> tbCashierCarts = mpCashierCartMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(tbCashierCarts)) {
for (TbCashierCart cashierCart : tbCashierCarts) {
if ("-999".equals(cashierCart.getProductId())) {
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
seatCartInfo = cashierCart;
if (!ignoreTableFee) {
array.add(cashierCart);
}
}else {
array.add(cashierCart);
}
array.add(cashierCart);
if (cashierCart.getIsVip().equals((byte) 1)) continue;
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
if ((!TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId()) || !ignoreTableFee) && cashierCart.getNumber() > 0) {
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
}
redisUtil.saveMessage(tableCartKey, array.toString(), 60 * 60 * 12L);
}
}
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(seatCartInfo), 60 * 60 * 12L);
if (ignoreTableFee && seatCartInfo != null) {
mpCashierCartMapper.deleteById(seatCartInfo.getId());
}else {
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(seatCartInfo), 60 * 60 * 12L);
}
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "success");