fix: 支持套餐商品点餐

This commit is contained in:
张松
2024-12-04 13:37:12 +08:00
parent 8a66e491cd
commit eace580860
4 changed files with 81 additions and 6 deletions

View File

@@ -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";

View File

@@ -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);
}
}
}

View File

@@ -192,7 +192,6 @@ public class TbProduct implements Serializable {
@Transient
private TbProductSkuResult productSkuResult;
private List<ProductGroupVo> proGroupVo;
}

View File

@@ -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<Integer> 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<ProductGroupVo.Food> foods = new ArrayList<>();
HashMap<String, ProductGroupVo.Food> 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<ProductGroupVo.Food> foods = new ArrayList<>();
HashMap<String, ProductGroupVo.Food> 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<Integer> 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<Integer> groupProductIds) throws Exception {
try {
// 查询用户信息
TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(String.valueOf(userId), shopId);
@@ -1607,7 +1663,7 @@ public class CartService {
public List<TbCashierCart> choseEatModel(ChoseEatModelDTO choseEatModelDTO) {
List<TbCashierCart> 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());