From eace580860a4181bc92ed9e3fb8d94d432a39eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Wed, 4 Dec 2024 13:37:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E5=A5=97=E9=A4=90?= =?UTF-8?q?=E5=95=86=E5=93=81=E7=82=B9=E9=A4=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/TableConstant.java | 17 +++++ .../cashierservice/entity/TbCashierCart.java | 3 + .../cashierservice/entity/TbProduct.java | 1 - .../cashierservice/service/CartService.java | 66 +++++++++++++++++-- 4 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java index 2b98400..1b765b7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java @@ -19,6 +19,23 @@ public interface TableConstant { } } + class Product { + @Getter + public enum Type { + NORMAL("normal"), PACKAGE("package"); + private final String value; + + Type(String value) { + this.value = value; + } + + public boolean equalsVals(String value) { + return this.value.equals(value); + } + + } + } + class CashierCart { public static final String ID = "-999"; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java index 746951b..3de2a59 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java @@ -80,6 +80,8 @@ public class TbCashierCart implements Serializable { private Integer isMember; private static final long serialVersionUID = 1L; + private String useCouponInfo; + private String proGroupInfo; public String getSkuName() { if(StringUtils.isNotBlank(skuName)){ @@ -112,4 +114,5 @@ public class TbCashierCart implements Serializable { return BigDecimal.valueOf(num).multiply(salePrice); } } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index 54010b0..ff9adbb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -192,7 +192,6 @@ public class TbProduct implements Serializable { @Transient private TbProductSkuResult productSkuResult; - private List proGroupVo; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index ae96e7c..b1d2924 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.entity.Enum.PlatformTypeEnum; import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.dto.*; +import com.chaozhanggui.system.cashierservice.entity.vo.ProductGroupVo; import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper; @@ -281,6 +282,57 @@ public class CartService { } } + /** + * 重置购物车套餐商品信息 + */ + private void resetGroupProductCart(List productIds,TbCashierCart cashierCart) { + if (StrUtil.isBlank(cashierCart.getProductId())) { + return; + } + + TbProduct product = productMapper.selectById(Integer.valueOf(cashierCart.getProductId())); + + boolean isChoseGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 1; + boolean isFixGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 0; + if (isChoseGroup && productIds != null && !productIds.isEmpty()) { + String groupSnap = product.getGroupSnap(); + if (StrUtil.isNotBlank(groupSnap)) { + ArrayList foods = new ArrayList<>(); + HashMap groupVoHashMap = new HashMap<>(); + JSONObject.parseArray(groupSnap).forEach(item -> { + ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class); + productGroupVo.getGoods().forEach(goods -> { + groupVoHashMap.put(goods.getProId().toString(), goods); + }); + }); + + productIds.forEach(item -> { + ProductGroupVo.Food food = groupVoHashMap.get(item.toString()); + if (food == null) { + throw new MsgException("存在无效套餐商品"); + } + foods.add(food); + }); + + cashierCart.setProGroupInfo(JSONObject.toJSONString(foods)); + } + }else if (isFixGroup) { + String groupSnap = product.getGroupSnap(); + if (StrUtil.isNotBlank(groupSnap)) { + ArrayList foods = new ArrayList<>(); + HashMap groupVoHashMap = new HashMap<>(); + JSONObject.parseArray(groupSnap).forEach(item -> { + ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class); + productGroupVo.getGoods().forEach(goods -> { + groupVoHashMap.put(goods.getProId().toString(), goods); + }); + }); + + cashierCart.setProGroupInfo(JSONObject.toJSONString(groupVoHashMap.values())); + } + } + } + /** * 加入购物车 * @@ -295,6 +347,7 @@ public class CartService { Integer type = jsonObject.getInteger("type"); Integer buyNum = jsonObject.getInteger("num"); Integer userId = jsonObject.getInteger("userId"); + List groupProductIdList = jsonObject.getJSONArray("groupProductIdList").toJavaList(Integer.class); // 商品备注 String note = jsonObject.getString("note"); if (StringUtils.isBlank(shopId) || StringUtils.isBlank(productId) @@ -355,7 +408,7 @@ public class CartService { if (Objects.isNull(array) || array.isEmpty()) { if (type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO); + jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList); jsonArray.add(cashierCart); cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum()); cashierCartArrayList.add(cashierCart); @@ -375,6 +428,9 @@ public class CartService { cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum()); if (cashierCart.getSkuId().equals(skuId)) { + + resetGroupProductCart(groupProductIdList, cashierCart); + cashierCart.setTotalNumber(buyNum); cashierCart.setNumber(buyNum); cashierCart.setNote(note); @@ -429,7 +485,7 @@ public class CartService { if (flag && type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO); + jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); BigDecimal mPrice = cashierCart.getIsMember() != null && cashierCart.getIsMember() == 1 && @@ -442,7 +498,7 @@ public class CartService { } else { if (type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO); + jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList); if (!TableConstant.CART_SEAT_ID.equals(productId)) { jsonArray.add(cashierCart); } @@ -577,7 +633,7 @@ public class CartService { } private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, - String tableId, String shopId, String note, ShopEatTypeInfoDTO shopEatTypeInfoDTO) throws Exception { + String tableId, String shopId, String note, ShopEatTypeInfoDTO shopEatTypeInfoDTO, List groupProductIds) throws Exception { try { // 查询用户信息 TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(String.valueOf(userId), shopId); @@ -1607,7 +1663,7 @@ public class CartService { public List choseEatModel(ChoseEatModelDTO choseEatModelDTO) { List cashierCartList; ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(choseEatModelDTO.getTableId(), choseEatModelDTO.getShopId()); - // 外带模式 + // 切换外带模式 if (choseEatModelDTO.getType() == 1) { cashierCartList = cashierCartService.selectByShopEatTypeInfo(shopEatTypeInfoDTO, choseEatModelDTO.getUserId()); cashierCartList = cashierCartList.stream().filter(item -> !TableConstant.CART_SEAT_ID.equals(item.getProductId())).collect(Collectors.toList());