Commit 01287fbb by yu.sun

Merge branch 'feature/20201112_套餐价格计算_yu.sun'

parents a69c395e 50068762
# Created by .ignore support plugin (hsz.mobi) # Created by .ignore support plugin (hsz.mobi)
.gitignore .gitignore
.idea/ .idea/
.DS_Store
assortment-ordercenter-sdk/assortment-ordercenter-sdk.iml assortment-ordercenter-sdk/assortment-ordercenter-sdk.iml
assortment-ordercenter-sdk/target/ assortment-ordercenter-sdk/target/
assortment-shoppingcart-sdk/assortment-shoppingcart-sdk.iml assortment-shoppingcart-sdk/assortment-shoppingcart-sdk.iml
......
...@@ -61,5 +61,9 @@ public class ShoppingCartConstant { ...@@ -61,5 +61,9 @@ public class ShoppingCartConstant {
public static final int PRODUCT_GROUP_EMPTY= 109; public static final int PRODUCT_GROUP_EMPTY= 109;
public static final String CART_PRODUCT_GROUP_EMPTY_STATE = "您选择的【$spuName】商品有未选商品"; public static final String CART_PRODUCT_GROUP_EMPTY_STATE = "您选择的【$spuName】商品有未选商品";
/**
* 可选商品价格校验失败
*/
public static final int PRODUCT_GROUP_PRICE_CHANGE = 113;
} }
...@@ -15,10 +15,7 @@ package cn.freemud.adapter; ...@@ -15,10 +15,7 @@ package cn.freemud.adapter;
import cn.freemud.entities.dto.*; import cn.freemud.entities.dto.*;
import cn.freemud.entities.dto.activity.ActivityDiscountsDto; import cn.freemud.entities.dto.activity.ActivityDiscountsDto;
import cn.freemud.entities.dto.openplatform.WeixinProductRequestDto; import cn.freemud.entities.dto.openplatform.WeixinProductRequestDto;
import cn.freemud.entities.dto.product.ProductAttributeValueType; import cn.freemud.entities.dto.product.*;
import cn.freemud.entities.dto.product.ValidateShopProductRequest;
import cn.freemud.entities.dto.product.ValidateShopProductType;
import cn.freemud.entities.dto.product.ValidateSkuProductType;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto; import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.vo.*; import cn.freemud.entities.vo.*;
import cn.freemud.enums.ActivityTypeEnum; import cn.freemud.enums.ActivityTypeEnum;
...@@ -296,7 +293,7 @@ public class ShoppingCartConvertAdapter { ...@@ -296,7 +293,7 @@ public class ShoppingCartConvertAdapter {
ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods goods = new ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods(); ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods goods = new ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods();
goods.setSpuId(materialGoods.getSpuId()); goods.setSpuId(materialGoods.getSpuId());
goods.setSpuName(materialGoods.getSpuName()); goods.setSpuName(materialGoods.getSpuName());
goods.setOriginalPrice(materialGoods.getOriginalPrice()); goods.setOriginalPrice(null != materialGoods.getOriginalPrice() ? materialGoods.getOriginalPrice() : 0);
goods.setSalePrice(materialGoods.getFinalPrice()); goods.setSalePrice(materialGoods.getFinalPrice());
goods.setQty(cartGoods.getQty()); goods.setQty(cartGoods.getQty());
goods.setTotalDiscountAmount(0); goods.setTotalDiscountAmount(0);
...@@ -512,7 +509,11 @@ public class ShoppingCartConvertAdapter { ...@@ -512,7 +509,11 @@ public class ShoppingCartConvertAdapter {
? cartGoods.getSkuId() : cartGoods.getSpuId()); ? cartGoods.getSkuId() : cartGoods.getSpuId());
// 应产品要求 // 应产品要求
// 普通商品,取商品的finalePrice(普通商品售价);套餐商品,取originalPrice(套餐价格) // 普通商品,取商品的finalePrice(普通商品售价);套餐商品,取originalPrice(套餐价格)
if (ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType(), cartGoods.getGoodsType())){
productType.setPrice(null == cartGoods.getOriginalPrice() ? 0 : cartGoods.getOriginalPrice().intValue());
}else{
productType.setPrice(cartGoods.getFinalPrice() == null ? 0 : cartGoods.getFinalPrice().intValue()); productType.setPrice(cartGoods.getFinalPrice() == null ? 0 : cartGoods.getFinalPrice().intValue());
}
productType.setValidatePrice(productType.getPrice() == 0 ? 0 : 1); productType.setValidatePrice(productType.getPrice() == 0 ? 0 : 1);
productType.setValidateAttribute(1); productType.setValidateAttribute(1);
productType.setValidateStatuses(Arrays.asList(2)); productType.setValidateStatuses(Arrays.asList(2));
...@@ -569,18 +570,18 @@ public class ShoppingCartConvertAdapter { ...@@ -569,18 +570,18 @@ public class ShoppingCartConvertAdapter {
* @param cartGoods 当前购物车商品行 * @param cartGoods 当前购物车商品行
* @param productBeans 购物车中所有的productId对应的商品详情 * @param productBeans 购物车中所有的productId对应的商品详情
*/ */
public void updateCartGoodsInfoForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, List<ProductBeanDTO> productBeans) { public void updateCartGoodsInfoForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, List<ProductTypeBeanDTO> productBeans) {
try { try {
Optional<ProductBeanDTO> firstProduct = productBeans.stream().filter(p -> ObjectUtils.equals(p.getPid(), cartGoods.getSpuId())).findFirst(); Optional<ProductTypeBeanDTO> firstProduct = productBeans.stream().filter(p -> ObjectUtils.equals(p.getPid(), cartGoods.getSpuId())).findFirst();
if (!firstProduct.isPresent()) { if (!firstProduct.isPresent()) {
return; return;
} }
ProductBeanDTO spuProduct = firstProduct.get(); ProductTypeBeanDTO spuProduct = firstProduct.get();
//是否是sku商品 //是否是sku商品
boolean isSkuProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.SKU_GOODS.getGoodsType(), cartGoods.getGoodsType()); boolean isSkuProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.SKU_GOODS.getGoodsType(), cartGoods.getGoodsType());
// 如果是套餐商品,更新套餐内固定商品&可选商品的详细信息 // 如果是套餐商品,更新套餐内固定商品&可选商品的详细信息
boolean isSetMealProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.SetMeal.getCode(), spuProduct.getType()) || ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.IncreasedPackage.getCode(), spuProduct.getType()); boolean isSetMealProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.SetMeal.getCode(), spuProduct.getType()) || ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.IncreasedPackage.getCode(), spuProduct.getType());
ProductBeanDTO.SkuProductBean skuProduct = isSkuProduct ? spuProduct.getSkuList().stream().filter(p -> ObjectUtils.equals(cartGoods.getSkuId(), p.getSkuId())).findFirst().get() : null; ProductTypeBeanDTO.SkuProductBean skuProduct = isSkuProduct ? spuProduct.getSkuList().stream().filter(p -> ObjectUtils.equals(cartGoods.getSkuId(), p.getSkuId())).findFirst().get() : null;
Map<String, String> attributes = getAttributesNew(cartGoods.getExtra()); Map<String, String> attributes = getAttributesNew(cartGoods.getExtra());
if(!"早餐啡常搭".equals(cartGoods.getName()) && !"早餐啡常搭".equals(cartGoods.getSkuName()) && !"早餐啡常搭".equals(cartGoods.getSpuName()) if(!"早餐啡常搭".equals(cartGoods.getName()) && !"早餐啡常搭".equals(cartGoods.getSkuName()) && !"早餐啡常搭".equals(cartGoods.getSpuName())
...@@ -641,8 +642,13 @@ public class ShoppingCartConvertAdapter { ...@@ -641,8 +642,13 @@ public class ShoppingCartConvertAdapter {
//更新当前商品行价格 //更新当前商品行价格
Long newOrigOriginalPrice = 0L; Long newOrigOriginalPrice = 0L;
if (isSetMealProduct) { if (isSetMealProduct) {
if (null != cartGoods.getOriginalPrice() && cartGoods.getOriginalPrice()>0){
newOrigOriginalPrice += cartGoods.getOriginalPrice();
}else {
newOrigOriginalPrice += cartGoods.getProductComboList().stream().mapToLong(t -> t.getOriginalAmount()).sum(); newOrigOriginalPrice += cartGoods.getProductComboList().stream().mapToLong(t -> t.getOriginalAmount()).sum();
}
newOrigOriginalPrice += cartGoods.getProductGroupList().stream().mapToLong(t -> t.getOriginalAmount()).sum(); newOrigOriginalPrice += cartGoods.getProductGroupList().stream().mapToLong(t -> t.getOriginalAmount()).sum();
} else { } else {
newOrigOriginalPrice = isSkuProduct ? skuProduct.getFinalPrice() : spuProduct.getFinalPrice(); newOrigOriginalPrice = isSkuProduct ? skuProduct.getFinalPrice() : spuProduct.getFinalPrice();
} }
...@@ -673,22 +679,23 @@ public class ShoppingCartConvertAdapter { ...@@ -673,22 +679,23 @@ public class ShoppingCartConvertAdapter {
* @param isComboxGoods 是否是固定商品 * @param isComboxGoods 是否是固定商品
* @return * @return
*/ */
private void updateComboxGoodsInfoForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods comboxGoods, ProductBeanDTO parentProductBean, boolean isComboxGoods) { private void updateComboxGoodsInfoForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods comboxGoods, ProductTypeBeanDTO parentProductBean, boolean isComboxGoods) {
if("0".equals(comboxGoods.getGoodsId())){ if("0".equals(comboxGoods.getGoodsId())){
return; return;
} }
ProductBeanDTO.ProductComboType productComboType = new ProductBeanDTO.ProductComboType(); ProductTypeBeanDTO.ProductComboType productComboType = new ProductTypeBeanDTO.ProductComboType();
ProductBeanDTO.ProductGroupType.GroupDetailType groupDetailType = new ProductBeanDTO.ProductGroupType.GroupDetailType(); ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType = new ProductTypeBeanDTO.ProductGroupType.GroupDetailType();
if (isComboxGoods) { if (isComboxGoods) {
productComboType = parentProductBean.getProductComboList().stream().filter(p -> ObjectUtils.equals(comboxGoods.getGoodsId(), p.getProductId())).findFirst().orElse(new ProductBeanDTO.ProductComboType()); productComboType = parentProductBean.getProductComboList().stream().filter(p -> ObjectUtils.equals(comboxGoods.getGoodsId(), p.getProductId())).findFirst().orElse(new ProductTypeBeanDTO.ProductComboType());
} else { } else {
Map<String, ProductBeanDTO.ProductGroupType.GroupDetailType> map = new HashMap<>(); Map<String, ProductTypeBeanDTO.ProductGroupType.GroupDetailType> map = new HashMap<>();
parentProductBean.getProductGroupList().stream().map(t -> t.getGroupDetail()).forEach(group -> group.forEach(detailType -> map.put(detailType.getProductId(), detailType))); parentProductBean.getProductGroupList().stream().map(t -> t.getGroupDetail()).forEach(group -> group.forEach(detailType -> map.put(detailType.getProductId(), detailType)));
groupDetailType = map.get(comboxGoods.getGoodsId()); groupDetailType = map.get(comboxGoods.getGoodsId());
} }
// 若是固定商品则取商品详情的FinalPrice,若是可选商品则取MarkUpPrice // 若是固定商品则取商品详情的FinalPrice,若是可选商品则取MarkUpPrice
Long finalPrice = isComboxGoods ? productComboType.getFinalPrice().longValue() : groupDetailType.getMarkUpPrice().longValue(); Long finalPrice = isComboxGoods ? (null != productComboType.getFinalPrice() ? productComboType.getFinalPrice().longValue() : 0L)
: (null != groupDetailType.getMarkUpPrice() ? groupDetailType.getMarkUpPrice().longValue() : 0L);
// 设置商品详情 // 设置商品详情
Map<String, String> attributes = getAttributesNew(comboxGoods.getExtra()); Map<String, String> attributes = getAttributesNew(comboxGoods.getExtra());
comboxGoods.setSpuId(comboxGoods.getSpuId()); comboxGoods.setSpuId(comboxGoods.getSpuId());
...@@ -697,16 +704,22 @@ public class ShoppingCartConvertAdapter { ...@@ -697,16 +704,22 @@ public class ShoppingCartConvertAdapter {
comboxGoods.setSpecProductId(attributes.get(ATTRIBUTEID)); comboxGoods.setSpecProductId(attributes.get(ATTRIBUTEID));
comboxGoods.setSubName(attributes.get(ATTRIBUTENAME)); comboxGoods.setSubName(attributes.get(ATTRIBUTENAME));
comboxGoods.setPic(isComboxGoods ? productComboType.getPicture() : groupDetailType.getPicture()); comboxGoods.setPic(isComboxGoods ? productComboType.getPicture() : groupDetailType.getPicture());
comboxGoods.setOriginalPrice(isComboxGoods ? productComboType.getFinalPrice().longValue() : groupDetailType.getProductFinalPrice().longValue()); comboxGoods.setOriginalPrice(isComboxGoods ? (null != productComboType.getFinalPrice() ? productComboType.getFinalPrice().longValue() : 0L)
: (null != groupDetailType.getProductFinalPrice() ? groupDetailType.getProductFinalPrice().longValue() : 0L));
comboxGoods.setOriginalAmount(comboxGoods.getOriginalPrice() * comboxGoods.getQty()); comboxGoods.setOriginalAmount(comboxGoods.getOriginalPrice() * comboxGoods.getQty());
comboxGoods.setAmount(finalPrice * comboxGoods.getQty()); comboxGoods.setAmount(finalPrice * comboxGoods.getQty());
comboxGoods.setCustomerCode(isComboxGoods ? productComboType.getCustomerCode() : groupDetailType.getCustomerCode()); comboxGoods.setCustomerCode(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getCustomerCode()) ? productComboType.getCustomerCode() : "")
: (StringUtils.isNotEmpty(groupDetailType.getCustomerCode()) ? groupDetailType.getCustomerCode() : ""));
comboxGoods.setFinalPrice(finalPrice); comboxGoods.setFinalPrice(finalPrice);
comboxGoods.setWeightType(isComboxGoods ? CommonsConstant.WEIGHT_PRODUCT.equals(productComboType.getWeightType()) : CommonsConstant.WEIGHT_PRODUCT.equals(groupDetailType.getWeightType())); comboxGoods.setWeightType(isComboxGoods ? CommonsConstant.WEIGHT_PRODUCT.equals(productComboType.getWeightType()) : CommonsConstant.WEIGHT_PRODUCT.equals(groupDetailType.getWeightType()));
comboxGoods.setUnit(isComboxGoods ? productComboType.getUnit() : groupDetailType.getUnit()); comboxGoods.setUnit(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getUnit()) ? productComboType.getUnit() :"") :
comboxGoods.setWeight(isComboxGoods ? productComboType.getWeight() : groupDetailType.getWeight()); (StringUtils.isNotEmpty(groupDetailType.getUnit()) ? groupDetailType.getUnit() : ""));
comboxGoods.setTax(isComboxGoods ? productComboType.getTax() : groupDetailType.getTax()); comboxGoods.setWeight(isComboxGoods ? (null == productComboType.getWeight() ? 0 : productComboType.getWeight()) :
comboxGoods.setTaxId(isComboxGoods ? productComboType.getTaxId() : groupDetailType.getTaxId()); (null == groupDetailType.getWeight() ? 0:groupDetailType.getWeight()));
comboxGoods.setTax(isComboxGoods ? (null == productComboType.getTax() ? 0 : productComboType.getTax())
: (null == groupDetailType.getTax() ? 0 : groupDetailType.getTax()));
comboxGoods.setTaxId(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getTaxId()) ? productComboType.getTaxId() : "") :
(StringUtils.isNotEmpty(groupDetailType.getTaxId()) ? groupDetailType.getTaxId() : ""));
// TODO: 2020/10/22 套餐内可选商品加料,暂无 // TODO: 2020/10/22 套餐内可选商品加料,暂无
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){ if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
...@@ -729,23 +742,22 @@ public class ShoppingCartConvertAdapter { ...@@ -729,23 +742,22 @@ public class ShoppingCartConvertAdapter {
return result; return result;
} }
private void checkMaterialProductForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, ProductBeanDTO spuProduct) { private void checkMaterialProductForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, ProductTypeBeanDTO spuProduct) {
if (CollectionUtils.isEmpty(cartGoods.getProductMaterialList())) return; if (CollectionUtils.isEmpty(cartGoods.getProductMaterialList())) return;
//加料信息为空 //加料信息为空
if (CollectionUtils.isEmpty(spuProduct.getAdditionalGroupList())) { if (CollectionUtils.isEmpty(spuProduct.getAdditionalGroupList())) {
cartGoods.setGoodsType(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.EXCEPTION_GOODS.getGoodsType()); checkSkuMaterialProductForMccafe(cartGoods,spuProduct);
cartGoods.setProductMaterialList(new ArrayList<>());
return; return;
} }
//提取加料信息 //提取加料信息
List<String> materialSpu = new ArrayList<>(); List<String> materialSpu = new ArrayList<>();
List<ProductBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>(); List<ProductTypeBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>();
for (ProductBeanDTO.ProductGroupType productGroupType : spuProduct.getAdditionalGroupList()){ for (ProductTypeBeanDTO.ProductGroupType productGroupType : spuProduct.getAdditionalGroupList()){
groupDetail.addAll(productGroupType.getGroupDetail()); groupDetail.addAll(productGroupType.getGroupDetail());
} }
HashMap<String, ProductBeanDTO.ProductGroupType.GroupDetailType> materialHash = new HashMap<>(); HashMap<String, ProductTypeBeanDTO.ProductGroupType.GroupDetailType> materialHash = new HashMap<>();
for (ProductBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail) { for (ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail) {
materialHash.put(groupDetailType.getProductId(), groupDetailType); materialHash.put(groupDetailType.getProductId(), groupDetailType);
materialSpu.add(groupDetailType.getProductId()); materialSpu.add(groupDetailType.getProductId());
} }
...@@ -760,7 +772,7 @@ public class ShoppingCartConvertAdapter { ...@@ -760,7 +772,7 @@ public class ShoppingCartConvertAdapter {
Long originalMaterAmount = 0L; Long originalMaterAmount = 0L;
String materialSubName = cartGoods.getSubName(); String materialSubName = cartGoods.getSubName();
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) { for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) {
ProductBeanDTO.ProductGroupType.GroupDetailType detail = materialHash.get(materialGoods.getSpuId()); ProductTypeBeanDTO.ProductGroupType.GroupDetailType detail = materialHash.get(materialGoods.getSpuId());
if (detail == null) continue; if (detail == null) continue;
com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods material = new com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods(); com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods material = new com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods();
material.setSpuName(detail.getProductName()); material.setSpuName(detail.getProductName());
...@@ -787,14 +799,14 @@ public class ShoppingCartConvertAdapter { ...@@ -787,14 +799,14 @@ public class ShoppingCartConvertAdapter {
} }
public void updateCartGoodsInfo(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, ProductBeanDTO spuProduct,Map<String,ProductBeanDTO> subProductTypeMap) { public void updateCartGoodsInfo(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, ProductTypeBeanDTO spuProduct,Map<String,ProductTypeBeanDTO> subProductTypeMap) {
try { try {
//是否是sku商品 //是否是sku商品
boolean isSkuProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.SKU_GOODS.getGoodsType(), cartGoods.getGoodsType()) boolean isSkuProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.SKU_GOODS.getGoodsType(), cartGoods.getGoodsType())
|| !ObjectUtils.equals(cartGoods.getSpuId(),cartGoods.getSkuId()); || !ObjectUtils.equals(cartGoods.getSpuId(),cartGoods.getSkuId());
// 如果是套餐商品,更新套餐内固定商品&可选商品的详细信息 // 如果是套餐商品,更新套餐内固定商品&可选商品的详细信息
boolean isSetMealProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.SetMeal.getCode(), spuProduct.getType()) || ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.IncreasedPackage.getCode(), spuProduct.getType()); boolean isSetMealProduct = ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.SetMeal.getCode(), spuProduct.getType()) || ObjectUtils.equals(com.freemud.sdk.api.assortment.shoppingcart.constant.ProductType.IncreasedPackage.getCode(), spuProduct.getType());
ProductBeanDTO.SkuProductBean skuProduct = isSkuProduct ? spuProduct.getSkuList().stream().filter(p -> ObjectUtils.equals(cartGoods.getSkuId(), p.getSkuId())).findFirst().get() : null; ProductTypeBeanDTO.SkuProductBean skuProduct = isSkuProduct ? spuProduct.getSkuList().stream().filter(p -> ObjectUtils.equals(cartGoods.getSkuId(), p.getSkuId())).findFirst().get() : null;
Map<String, String> attributes = getAttributesNew(cartGoods.getExtra()); Map<String, String> attributes = getAttributesNew(cartGoods.getExtra());
if(!"早餐啡常搭".equals(cartGoods.getName()) && !"早餐啡常搭".equals(cartGoods.getSkuName()) && !"早餐啡常搭".equals(cartGoods.getSpuName()) if(!"早餐啡常搭".equals(cartGoods.getName()) && !"早餐啡常搭".equals(cartGoods.getSkuName()) && !"早餐啡常搭".equals(cartGoods.getSpuName())
...@@ -829,7 +841,7 @@ public class ShoppingCartConvertAdapter { ...@@ -829,7 +841,7 @@ public class ShoppingCartConvertAdapter {
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods productCombo : cartGoods.getProductComboList()){ for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods productCombo : cartGoods.getProductComboList()){
//套餐子商品多规格商品 //套餐子商品多规格商品
if(productCombo.getSpuId() != null && !productCombo.getSkuId().equals(productCombo.getSpuId()) ){ if(productCombo.getSpuId() != null && !productCombo.getSkuId().equals(productCombo.getSpuId()) ){
ProductBeanDTO productBeanDTO = subProductTypeMap.get(productCombo.getSpuId()); ProductTypeBeanDTO productBeanDTO = subProductTypeMap.get(productCombo.getSpuId());
updateComboxGoodsInfoFor(productCombo, productBeanDTO, true); updateComboxGoodsInfoFor(productCombo, productBeanDTO, true);
}else { }else {
//套餐子商品为单品 //套餐子商品为单品
...@@ -856,22 +868,24 @@ public class ShoppingCartConvertAdapter { ...@@ -856,22 +868,24 @@ public class ShoppingCartConvertAdapter {
//更新当前商品行价格 //更新当前商品行价格
Long newOrigOriginalPrice = 0L; Long newOrigOriginalPrice = 0L;
if (isSetMealProduct) { if (isSetMealProduct) {
Long comboxGoodsFinalPrice = cartGoods.getProductComboList().stream().mapToLong(t -> t.getFinalPrice()).sum();
Long comboxGoodsOriginalPrice = cartGoods.getProductComboList().stream().mapToLong(t -> t.getOriginalAmount()).sum(); Long comboxGoodsOriginalPrice = cartGoods.getProductComboList().stream().mapToLong(t -> t.getOriginalAmount()).sum();
Long groupGoodsOriginalPrice = cartGoods.getProductGroupList().stream().mapToLong(t -> t.getOriginalAmount()).sum(); Long groupGoodsOriginalPrice = cartGoods.getProductGroupList().stream().mapToLong(t -> t.getOriginalAmount()).sum();
Long comboxGoodsFinalPrice = cartGoods.getProductComboList().stream().mapToLong(t -> t.getFinalPrice()).sum();
Long groupGoodsFinalPrice = cartGoods.getProductGroupList().stream().mapToLong(t -> t.getFinalPrice()).sum(); Long groupGoodsFinalPrice = cartGoods.getProductGroupList().stream().mapToLong(t -> t.getFinalPrice()).sum();
cartGoods.setOriginalPrice(comboxGoodsOriginalPrice); cartGoods.setOriginalPrice(null != cartGoods.getOriginalPrice()? cartGoods.getOriginalPrice() :
cartGoods.setOriginalAmount((comboxGoodsOriginalPrice+groupGoodsOriginalPrice)* cartGoods.getQty()); comboxGoodsOriginalPrice);
cartGoods.setAmount((comboxGoodsFinalPrice+groupGoodsFinalPrice) * cartGoods.getQty()); cartGoods.setOriginalAmount((cartGoods.getOriginalPrice()+groupGoodsOriginalPrice)* cartGoods.getQty());
//咨询商品服务,套餐售价取originalPrice //咨询商品服务,套餐售价取originalPrice
cartGoods.setFinalPrice(comboxGoodsFinalPrice); cartGoods.setFinalPrice(null != cartGoods.getOriginalPrice() ? cartGoods.getOriginalPrice() :
comboxGoodsFinalPrice);
cartGoods.setAmount((cartGoods.getFinalPrice()+groupGoodsFinalPrice) * cartGoods.getQty());
} else { } else {
newOrigOriginalPrice = isSkuProduct ? skuProduct.getFinalPrice() : spuProduct.getFinalPrice(); newOrigOriginalPrice = isSkuProduct ? skuProduct.getFinalPrice() : spuProduct.getFinalPrice();
cartGoods.setOriginalPrice(newOrigOriginalPrice); cartGoods.setOriginalPrice(newOrigOriginalPrice);
cartGoods.setOriginalAmount(newOrigOriginalPrice * cartGoods.getQty()); cartGoods.setOriginalAmount(newOrigOriginalPrice * cartGoods.getQty());
cartGoods.setAmount(newOrigOriginalPrice * cartGoods.getQty()); cartGoods.setAmount(newOrigOriginalPrice * cartGoods.getQty());
//咨询商品服务,套餐售价取originalPrice //咨询商品服务,套餐售价取originalPrice
cartGoods.setFinalPrice(isSkuProduct ? skuProduct.getFinalPrice() : spuProduct.getFinalPrice()); cartGoods.setFinalPrice(isSkuProduct ? skuProduct.getOriginalPrice() : spuProduct.getFinalPrice());
} }
cartGoods.setWeight(isSkuProduct ? skuProduct.getWeight() : spuProduct.getWeight()); cartGoods.setWeight(isSkuProduct ? skuProduct.getWeight() : spuProduct.getWeight());
cartGoods.setUnit(isSkuProduct ? skuProduct.getUnit() : spuProduct.getUnit()); cartGoods.setUnit(isSkuProduct ? skuProduct.getUnit() : spuProduct.getUnit());
...@@ -888,12 +902,12 @@ public class ShoppingCartConvertAdapter { ...@@ -888,12 +902,12 @@ public class ShoppingCartConvertAdapter {
} }
private void updateComboxGoodsInfoFor(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods comboxGoods, ProductBeanDTO productBeanDTO, boolean isComboxGoods) { private void updateComboxGoodsInfoFor(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods comboxGoods, ProductTypeBeanDTO productBeanDTO, boolean isComboxGoods) {
if(CollectionUtils.isEmpty(productBeanDTO.getSkuList())){ if(CollectionUtils.isEmpty(productBeanDTO.getSkuList())){
return; return;
} }
ProductBeanDTO.SkuProductBean comboxGoodsSkuProductBean = null; ProductTypeBeanDTO.SkuProductBean comboxGoodsSkuProductBean = null;
for (ProductBeanDTO.SkuProductBean skuProductBean : productBeanDTO.getSkuList()){ for (ProductTypeBeanDTO.SkuProductBean skuProductBean : productBeanDTO.getSkuList()){
if(comboxGoods.getSkuId().equals(skuProductBean.getSkuId())){ if(comboxGoods.getSkuId().equals(skuProductBean.getSkuId())){
comboxGoodsSkuProductBean = skuProductBean; comboxGoodsSkuProductBean = skuProductBean;
break; break;
...@@ -925,12 +939,30 @@ public class ShoppingCartConvertAdapter { ...@@ -925,12 +939,30 @@ public class ShoppingCartConvertAdapter {
//套餐内商品加料 //套餐内商品加料
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){ if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
if (CollectionUtils.isNotEmpty(productBeanDTO.getAdditionalGroupList())) { if (CollectionUtils.isNotEmpty(productBeanDTO.getAdditionalGroupList())) {
List<ProductBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>(); List<ProductTypeBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>();
for (ProductBeanDTO.ProductGroupType productGroupType : productBeanDTO.getAdditionalGroupList()){ for (ProductTypeBeanDTO.ProductGroupType productGroupType : productBeanDTO.getAdditionalGroupList()){
groupDetail.addAll(productGroupType.getGroupDetail());
}
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods productMaterial :comboxGoods.getProductMaterialList()){
for (ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail){
if(groupDetailType.getProductId().equals(productMaterial.getSpuId())){
productMaterial.setSpuId(groupDetailType.getProductId());
productMaterial.setAmount(groupDetailType.getProductFinalPrice().longValue());
productMaterial.setFinalPrice(groupDetailType.getProductFinalPrice().longValue());
productMaterial.setOriginalAmount(groupDetailType.getProductFinalPrice().longValue());
productMaterial.setOriginalPrice(groupDetailType.getProductFinalPrice().longValue());
productMaterial.setSpuName(groupDetailType.getProductName());
}
}
}
}else {
if(CollectionUtils.isNotEmpty(comboxGoodsSkuProductBean.getAdditionalGroupList())){
List<ProductTypeBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>();
for (ProductTypeBeanDTO.ProductGroupType productGroupType : comboxGoodsSkuProductBean.getAdditionalGroupList()){
groupDetail.addAll(productGroupType.getGroupDetail()); groupDetail.addAll(productGroupType.getGroupDetail());
} }
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods productMaterial :comboxGoods.getProductMaterialList()){ for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods productMaterial :comboxGoods.getProductMaterialList()){
for (ProductBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail){ for (ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail){
if(groupDetailType.getProductId().equals(productMaterial.getSpuId())){ if(groupDetailType.getProductId().equals(productMaterial.getSpuId())){
productMaterial.setSpuId(groupDetailType.getProductId()); productMaterial.setSpuId(groupDetailType.getProductId());
productMaterial.setAmount(groupDetailType.getProductFinalPrice().longValue()); productMaterial.setAmount(groupDetailType.getProductFinalPrice().longValue());
...@@ -941,7 +973,80 @@ public class ShoppingCartConvertAdapter { ...@@ -941,7 +973,80 @@ public class ShoppingCartConvertAdapter {
} }
} }
} }
}else {
//都不存在移除商品
comboxGoods.setProductMaterialList(new ArrayList<>());
}
}
}
}
/**
* 多规格商品下添加单规格作为子商品,校验子商品的加料信息
* @param cartGoods
* @param spuProduct
*/
private void checkSkuMaterialProductForMccafe(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods,ProductTypeBeanDTO spuProduct) {
if (CollectionUtils.isNotEmpty(spuProduct.getSkuList())) {
spuProduct.getSkuList().stream().filter(sku-> sku.getSkuId().equals(cartGoods.getGoodsId())).collect(Collectors.toList()).forEach(
skuProductBean -> {
if (CollectionUtils.isNotEmpty(skuProductBean.getAdditionalGroupList())){
List<String> materialSpu = new ArrayList<>();
HashMap<String, ProductTypeBeanDTO.ProductGroupType.GroupDetailType> materialHash = new HashMap<>();
for (ProductTypeBeanDTO.ProductGroupType productGroupType : skuProductBean.getAdditionalGroupList()) {
//提取加料信息
List<ProductTypeBeanDTO.ProductGroupType.GroupDetailType> groupDetail = new ArrayList<>();
groupDetail.addAll(productGroupType.getGroupDetail());
for (ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType : groupDetail) {
materialHash.put(groupDetailType.getProductId(), groupDetailType);
materialSpu.add(groupDetailType.getProductId());
}
}
//加车小料和商品小料没有交集则提示商品信息有异常
if (CollectionUtils.isEmpty(cartGoods.getProductMaterialList().stream().filter(e -> materialSpu.contains(e.getSpuId())).collect(Collectors.toList()))) {
cartGoods.setGoodsType(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.EXCEPTION_GOODS.getGoodsType());
cartGoods.setProductMaterialList(new ArrayList<>());
return;
}
ArrayList<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods> materialGoodsList = new ArrayList<>();
Long materialAmount = 0L;
Long originalMaterAmount = 0L;
String materialSubName = cartGoods.getSubName();
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) {
ProductTypeBeanDTO.ProductGroupType.GroupDetailType detail = materialHash.get(materialGoods.getSpuId());
if (detail == null) continue;
com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods material = new com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods();
material.setSpuName(detail.getProductName());
material.setSpuId(detail.getProductId());
//行单价 \ 行总价
material.setFinalPrice(detail.getProductFinalPrice().longValue());
material.setAmount(detail.getProductFinalPrice().longValue() * cartGoods.getQty());
//原行单价*数量
material.setOriginalAmount(detail.getProductFinalPrice().longValue() * cartGoods.getQty());
material.setOriginalPrice(detail.getProductFinalPrice().longValue());
material.setCustomerCode(materialGoods.getCustomerCode());
materialGoodsList.add(material);
materialAmount += detail.getProductFinalPrice().longValue() * cartGoods.getQty();
originalMaterAmount += detail.getProductFinalPrice().longValue() * cartGoods.getQty();
;
materialSubName = materialSubName + "/" + detail.getProductName();
}
//设置购物车行记录
cartGoods.setProductMaterialList(materialGoodsList);
//加料行记录现价总价
cartGoods.setMaterialAmount(materialAmount);
//加料行记录原价总价
cartGoods.setOriginalMaterialAmount(originalMaterAmount);
}else{
cartGoods.setGoodsType(com.freemud.sdk.api.assortment.shoppingcart.constant.GoodsTypeEnum.EXCEPTION_GOODS.getGoodsType());
cartGoods.setProductMaterialList(new ArrayList<>());
return;
}
} }
);
} }
} }
......
package cn.freemud.adapter;
import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto;
import cn.freemud.entities.dto.activity.ActivityDiscountsDto;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.vo.CartGoods;
import cn.freemud.enums.ActivityTypeEnum;
import cn.freemud.enums.GoodsTypeEnum;
import cn.freemud.enums.ProductType;
import cn.freemud.utils.BeanUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @version V1.0
* @Title: ShoppingCartMccafeAdapter
* @Package cn.freemud.adapter
* @Description: 简单描述下这个类是做什么用的
* @author: yu.sun
* @date: 2020/12/4 11:45
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Component
public class ShoppingCartMccafeAdapter {
/**
* @param cartGoods
* @return
*/
public List<ShoppingCartGoodsDto.CartGoodsDetailDto> convertComboxGoods2DetailGoods(CartGoods cartGoods, Integer totalDiscountAmount) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = new ArrayList<>();
cartGoodsDetailDtos.addAll(getComboxGoods2DetailGoods(cartGoods, cartGoods.getProductComboList(), true,totalDiscountAmount));
cartGoodsDetailDtos.addAll(getComboxGoods2DetailGoods(cartGoods, cartGoods.getProductGroupList(), false,totalDiscountAmount));
return cartGoodsDetailDtos;
}
/**
* @param cartGoods
* @return
*/
public List<ShoppingCartGoodsDto.CartGoodsDetailDto> getComboxGoods2DetailGoods(CartGoods cartGoods, List<CartGoods.ComboxGoods> comboxGoodsList, boolean isFixed,Integer totalDiscountAmount) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = new ArrayList<>();
if (CollectionUtils.isEmpty(comboxGoodsList)) {
return cartGoodsDetailDtos;
}
int size = comboxGoodsList.size();
//当前套餐(固定搭配)总优惠=原总价-现总价-可选商品优惠价
Long discountAmount = totalDiscountAmount -
cartGoods.getProductGroupList().stream().mapToLong(product -> (product.getOriginalPrice() - product.getFinalPrice()) * product.getQty()).sum() * cartGoods.getQty();
// 当前套餐(固定搭配)总原价
// Long totalOriginalPrice = cartGoods.getProductComboList().stream().mapToLong(cart -> cart.getQty() * cart.getOriginalPrice()).sum() * cartGoods.getQty();
Long totalOriginalPrice = cartGoods.getProductComboList().stream().mapToLong(cart -> cart.getQty() * cart.getFinalPrice()).sum() * cartGoods.getQty();
Integer tempDiscount = 0;
for (CartGoods.ComboxGoods comboxGoods : comboxGoodsList) {
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = new ShoppingCartGoodsDto.CartGoodsDetailDto();
cartGoodsDetailDto.setTaxId(cartGoods.getTaxId());
cartGoodsDetailDto.setTax(cartGoods.getTax());
cartGoodsDetailDto.setSpuId(comboxGoods.getSpuId());
cartGoodsDetailDto.setSpuName(comboxGoods.getSpuName());
cartGoodsDetailDto.setSkuId(comboxGoods.getGoodsId());
cartGoodsDetailDto.setSkuName(StringUtils.isEmpty(comboxGoods.getSkuName()) ? comboxGoods.getSpuName() : comboxGoods.getSkuName());
cartGoodsDetailDto.setOriginalPrice(comboxGoods.getOriginalPrice());
cartGoodsDetailDto.setPicture(comboxGoods.getPic());
int qty = comboxGoods.getQty() * cartGoods.getQty();
cartGoodsDetailDto.setQty(qty);
cartGoodsDetailDto.setProductType(comboxGoods.isWeightType() ? ProductType.WEIGHT_PRODUCT.getCode() : ProductType.SETMEAL.getCode());
cartGoodsDetailDto.setParentProductId(cartGoods.getGoodsId());
cartGoodsDetailDto.setIsFixedProduct(isFixed);
cartGoodsDetailDto.setStockLimit(cartGoods.isStockLimit());
cartGoodsDetailDto.setCustomerCode(comboxGoods.getCustomerCode());
cartGoodsDetailDto.setWeight(comboxGoods.getWeight());
cartGoodsDetailDto.setUnit(comboxGoods.getUnit());
List<ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra> cartGoodsExtras = BeanUtil.convertBeans(comboxGoods.getExtra(), ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra::new);
cartGoodsDetailDto.setExtraList(cartGoodsExtras);
cartGoodsDetailDto.setSpecialExtra(comboxGoods.getSpecialExtra());
//小料
if (CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods> materialList = new ArrayList<>(0);
for (CartGoods.MaterialGoods materialGoods : comboxGoods.getProductMaterialList()) {
ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods goods = new ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods();
goods.setSpuId(materialGoods.getSpuId());
goods.setSpuName(materialGoods.getSpuName());
goods.setOriginalPrice(materialGoods.getOriginalPrice());
goods.setSalePrice(materialGoods.getFinalPrice());
goods.setQty(cartGoods.getQty());
goods.setTotalDiscountAmount(0);
goods.setProductCode(materialGoods.getCustomerCode());
goods.setCustomerCode(materialGoods.getCustomerCode());
materialList.add(goods);
}
cartGoodsDetailDto.setMaterialList(materialList);
}
//获取当前套餐固定商品的均摊价格
if (isFixed) {
if (size-- == 1) {
cartGoodsDetailDto.setTotalDiscountAmount(discountAmount.intValue() - tempDiscount);
} else {
Long currentDiscountAmount = (qty * comboxGoods.getOriginalPrice() * discountAmount) / totalOriginalPrice;
cartGoodsDetailDto.setTotalDiscountAmount(currentDiscountAmount.intValue());
tempDiscount += currentDiscountAmount.intValue();
}
} else {
cartGoodsDetailDto.setTotalDiscountAmount((comboxGoods.getOriginalPrice().intValue() - comboxGoods.getFinalPrice().intValue()) * comboxGoods.getQty() * cartGoods.getQty());
}
cartGoodsDetailDtos.add(cartGoodsDetailDto);
}
return cartGoodsDetailDtos;
}
/**
* @param cartGoods
* @return
*/
public ShoppingCartGoodsDto.CartGoodsDetailDto convertCartGoods2DetailGoods(CartGoods cartGoods, List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, Map<String, String> duplicateGoodsMap) {
// 设置基础信息
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = new ShoppingCartGoodsDto.CartGoodsDetailDto();
cartGoodsDetailDto.setCartGoodsUid(cartGoods.getCartGoodsUid());
cartGoodsDetailDto.setTaxId(cartGoods.getTaxId());
cartGoodsDetailDto.setTax(cartGoods.getTax());
cartGoodsDetailDto.setSpuId(cartGoods.getSpuId());
cartGoodsDetailDto.setSpuName(cartGoods.getSpuName());
cartGoodsDetailDto.setSkuId(StringUtils.isEmpty(cartGoods.getSkuId()) ? cartGoods.getSpuId() : cartGoods.getSkuId());
cartGoodsDetailDto.setSkuName(StringUtils.isEmpty(cartGoods.getSkuName()) ? cartGoods.getSpuName() : cartGoods.getSkuName());
cartGoodsDetailDto.setOriginalPrice(cartGoods.getOriginalPrice());
// cartGoodsDetailDto.setTotalDiscountAmount(0);
cartGoodsDetailDto.setSalePrice(cartGoods.getOriginalPrice());
cartGoodsDetailDto.setPicture(cartGoods.getPic());
cartGoodsDetailDto.setQty(cartGoods.getQty());
cartGoodsDetailDto.setActivityType(cartGoods.getActivityType());
cartGoodsDetailDto.setNodeId(cartGoods.getNodeId());
cartGoodsDetailDto.setCategoryName(cartGoods.getCategoryName());
cartGoodsDetailDto.setCouponCode(cartGoods.getCouponCode());
cartGoodsDetailDto.setStockLimit(cartGoods.isStockLimit());
cartGoodsDetailDto.setProductCode(cartGoods.getCustomerCode());
cartGoodsDetailDto.setCustomerCode(cartGoods.getCustomerCode());
cartGoodsDetailDto.setWeight(cartGoods.getWeight());
cartGoodsDetailDto.setUnit(cartGoods.getUnit());
cartGoodsDetailDto.setActivityDiscountsDtos(new ArrayList<>());
cartGoodsDetailDto.setTotalDiscountAmount(0);
cartGoodsDetailDto.setSpecialExtra(cartGoods.getSpecialExtra());
cartGoodsDetailDto.setClassificationId(cartGoods.getClassificationId());
cartGoodsDetailDto.setClassificationName(cartGoods.getClassificationName());
if (GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) {
cartGoodsDetailDto.setProductType(ProductType.SETMEAL.getCode());
} else if (cartGoods.isWeightType()) {
cartGoodsDetailDto.setProductType(ProductType.WEIGHT_PRODUCT.getCode());
}
//小料
if (CollectionUtils.isNotEmpty(cartGoods.getProductMaterialList())) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods> materialList = new ArrayList<>(0);
for (CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) {
ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods goods = new ShoppingCartGoodsDto.CartGoodsDetailDto.MaterialGoods();
goods.setSpuId(materialGoods.getSpuId());
goods.setSpuName(materialGoods.getSpuName());
goods.setOriginalPrice(materialGoods.getOriginalPrice());
goods.setSalePrice(materialGoods.getFinalPrice());
goods.setCustomerCode(materialGoods.getCustomerCode());
goods.setProductCode(materialGoods.getCustomerCode());
goods.setQty(cartGoods.getQty());
goods.setTotalDiscountAmount(0);
materialList.add(goods);
}
cartGoodsDetailDto.setMaterialList(materialList);
}
// 设置总优惠&售价
List<ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra> cartGoodsExtras = BeanUtil.convertBeans(cartGoods.getExtra(), ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra::new);
cartGoodsDetailDto.setExtraList(cartGoodsExtras);
//61: 单品买M赠N \ 62:买赠 \ 6:买M赠N
if (ObjectUtils.equals(ActivityTypeEnum.TYPE_61.getCode(), cartGoods.getActivityType()) || ObjectUtils.equals(ActivityTypeEnum.TYPE_6.getCode(), cartGoods.getActivityType())
|| ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) {
cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
} else {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getCartGoodsUid(), a.getCartGoodsUid())).collect(Collectors.toList());
//List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap);
// 设置商品行,优惠活动均摊
setActivityDiscounts(collect, cartGoodsDetailDto, duplicateGoodsMap);
}
}
return cartGoodsDetailDto;
}
/**
* 活动级别的促销均摊
* 获取当前商品的售后价格
*
* @param apportionGoodsList 促销均摊列表
* @param cartGoodsDetailDto 当前商品行
* @param duplicateGoodsMap 当前商品行 此map是为了促销除不尽时,拆商品行所用,例如,3份折扣10元
* key为:goodsId;value以逗号分割:0为goodsId分组对应的数量,value为已计算的折扣金额
*
*/
private void setTotalDiscountAndSalePrice(List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto, Map<String, String> duplicateGoodsMap) {
Long originalPrice = cartGoodsDetailDto.getOriginalPrice();
Long discountPrice = 0L;
int goodsTotalQty = apportionGoodsList.stream().mapToInt(apportionGoods -> apportionGoods.getGoodsQuantity()).sum();
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods apportionGoods : apportionGoodsList) {
//折扣=所有折扣和*百分比(当前行商品数量/购物车总商品数量)
discountPrice += apportionGoods.getApportionDetails().stream().filter(d -> ObjectUtils.notEqual(ActivityTypeEnum.TYPE_32.getCode(), d.getActivityType())
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_104.getCode(), d.getActivityType()) //X件Y折
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_2.getCode(), d.getActivityType()) //单品特价
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_21.getCode(), d.getActivityType())//单品折扣
).mapToLong(t -> t.getActivityApportionAmount() * apportionGoods.getGoodsQuantity()).sum() * cartGoodsDetailDto.getQty() / goodsTotalQty;
}
String currentGoodsIdMap = duplicateGoodsMap.get(cartGoodsDetailDto.getCartGoodsUid());
if (currentGoodsIdMap != null) {
String[] value = currentGoodsIdMap.split(",");
//不是最后一行商品,折扣为discountPrice
if (Integer.parseInt(value[0]) > 1) {
int totalDiscountPrice = Integer.parseInt(value[1]) + discountPrice.intValue();
int index = Integer.parseInt(value[0]) - 1;
duplicateGoodsMap.put(cartGoodsDetailDto.getCartGoodsUid(), String.format("%s,%s", index, totalDiscountPrice));
} else {
//最后一行
Long totalDiscountAmount = 0L;
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods apportionGoods : apportionGoodsList) {
totalDiscountAmount += apportionGoods.getApportionDetails().stream().filter(d -> ObjectUtils.notEqual(ActivityTypeEnum.TYPE_32.getCode(), d.getActivityType())
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_104.getCode(), d.getActivityType())
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_2.getCode(), d.getActivityType())
&& ObjectUtils.notEqual(ActivityTypeEnum.TYPE_21.getCode(), d.getActivityType())
).mapToLong(t -> t.getActivityApportionAmount() * apportionGoods.getGoodsQuantity()).sum();
}
//折扣为:总折扣金额-已折扣金额
discountPrice = totalDiscountAmount - Integer.parseInt(value[1]);
}
}
cartGoodsDetailDto.setTotalDiscountAmount(discountPrice.intValue());
cartGoodsDetailDto.setSalePrice(originalPrice - discountPrice / cartGoodsDetailDto.getQty());
}
private void setActivityDiscounts(List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto, Map<String, String> duplicateGoodsMap) {
List<ActivityDiscountsDto> activityDiscountsDtoList = new ArrayList<>();
int goodsTotalQty = apportionGoodsList.stream().mapToInt(apportionGoods -> apportionGoods.getGoodsQuantity()).sum();
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods apportionGoods : apportionGoodsList) {
/**
* 1. 商品券:cartGoodsDetailDto.couponCode非空,保留ApportionGoods#ApportionDetails#apportionType中32的
* 2. 普通商品:cartGoodsDetailDto.couponCode空,去掉32的
*/
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods.ApportionDetails> apportionDetails = apportionGoods.getApportionDetails().stream().filter(detail -> !detail.getActivityType().equals(ActivityTypeEnum.TYPE_32.getCode())
&& !detail.getActivityType().equals(ActivityTypeEnum.TYPE_104.getCode()) && !detail.getActivityType().equals(ActivityTypeEnum.TYPE_2.getCode()) && !detail.getActivityType().equals(ActivityTypeEnum.TYPE_21.getCode())).collect(Collectors.toList());
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods.ApportionDetails detail : apportionDetails) {
List<ActivityDiscountsDto> currentDiscount = activityDiscountsDtoList.stream().filter(discount -> ObjectUtils.equals(discount.getActivityCode(), detail.getActivityCode())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(currentDiscount)) {
currentDiscount.get(0).setDiscountAmount(currentDiscount.get(0).getDiscountAmount() + detail.getActivityApportionAmount().intValue() * apportionGoods.getGoodsQuantity() * cartGoodsDetailDto.getQty() / goodsTotalQty);
} else {
ActivityDiscountsDto activityDiscountsDto = new ActivityDiscountsDto();
activityDiscountsDto.setActivityCode(detail.getActivityCode());
activityDiscountsDto.setActivityName(detail.getActivityName());
activityDiscountsDto.setActivityType(detail.getActivityType());
activityDiscountsDto.setDiscountAmount(detail.getActivityApportionAmount().intValue() * apportionGoods.getGoodsQuantity() * cartGoodsDetailDto.getQty() / goodsTotalQty);
activityDiscountsDtoList.add(activityDiscountsDto);
}
}
}
cartGoodsDetailDto.setActivityDiscountsDtos(activityDiscountsDtoList);
}
}
\ No newline at end of file
package cn.freemud.entities.dto.product;
import lombok.Data;
import java.util.List;
/**
* All rights Reserved, Designed By sunary.site
*
* @version v1.0
* @Title: IntelliJ IDEA
* @Package cn.freemud.entities.dto.product
* @Description: 请简单描述下这个类是做什么用的
* @author: yu.sun
* @date: 2020-11-25 11:51:44
* @Copyright: 2019 www.freemud.cn Inc. All rights reserved.
*/
@Data
public class ProductTypeBeanDTO {
private String businessNo;
private String barcode;
private String brandId;
private String brandName;
private String category;
private String categoryName;
private String companyId;
private String customerCode;
private String productCode;
private Long finalPrice;
private Integer isSkuProduct;
private String name;
private Long originalPrice;
private Long packPrice;
private String picture;
private String pid;
private String specification;
private Integer status;
private Integer stock;
private Integer stockLimit;
private int type;
private String unit;
private Integer riseSell;
private String rawMaterial;
private Double tax;
private String taxId;
private Integer openMemberDiscount;
private Integer memberDiscount;
private List<ProductAttributeGroupListBean> productAttributeGroupList;
private List<ProductPictureListBean> productPictureList;
private List<SkuProductBean> skuList;
private List<ProductComboType> productComboList;
private List<ProductGroupType> productGroupList;
private List<SkuProductBean.SkuSpecValue> skuSpecValues;
private List<PackageProductTypeDto> packageProductTypes;
private List<ProductGroupType> additionalGroupList;
private List<ProductComboDetailTypeDto> productComboInfos;
private Integer isDishware;
private Integer weightType;
private Double weight;
public Integer getMemberDiscountResult() {
return this.openMemberDiscount != null && this.openMemberDiscount == 1 ? this.memberDiscount : 100;
}
public ProductTypeBeanDTO() {
}
@Data
public static class ProductComboDetailTypeDto {
private String productId;
private Integer quantity;
private Integer sequence;
public ProductComboDetailTypeDto() {
}
}
@Data
public static class ProductAttributeGroupListBean {
private String attributeName;
private Integer attributeType;
private List<AttributeValueBean> attributeValues;
public ProductAttributeGroupListBean() {
}
}
@Data
public static class AttributeValueBean {
private String attributeId;
private String attributeValue;
private Long id;
private Long price;
private Integer sequence;
private Integer status;
public AttributeValueBean() {
}
}
@Data
public static class PackageProductTypeDto {
private Long groupId;
private Integer sequence;
public PackageProductTypeDto() {
}
}
@Data
public static class ProductGroupType {
private String pgid;
private String linkId;
private String groupCode;
private String options;
private String name;
private Integer must;
private Integer allowRepeat;
private Integer minNumber;
private Integer maxNumber;
private String remark;
private Integer total;
private List<ProductGroupType.GroupDetailType> groupDetail;
public ProductGroupType() {
}
@Data
public static class GroupDetailType {
private String productId;
private String productName;
private String customerCode;
private Integer productPrice;
protected Integer productFinalPrice;
protected Integer markUpPrice;
private String picture;
private Integer stockLimit;
protected String unit;
protected String productCode;
private Integer weightType;
private Double weight;
private Double tax;
private String taxId;
}
}
@Data
public static class ProductComboType {
private String productId;
private String productName;
private String customerCode;
private Integer originalPrice;
protected Integer finalPrice;
protected Integer packPrice;
private String picture;
protected String unit;
protected String productCode;
private Integer quantity;
private Integer weightType;
private Double weight;
private Double tax;
private String taxId;
}
@Data
public static class ProductPictureListBean {
private String pictureId;
private String productId;
private String sequence;
private String type;
private String url;
@Data
public static class AttributeValueBean {
private String attributeId;
private String attributeValue;
private Long id;
private Long price;
private Integer sequence;
private Integer status;
public AttributeValueBean() {
}
}
}
@Data
public static class ProductLabelNameListBean {
private String id;
private String name;
private String partnerId;
List<?> productList;
private String storeId;
private String type;
public ProductLabelNameListBean() {
}
}
@Data
public static class SpecificationGroupBean {
private String partnerId;
private Integer sequence;
private String specId;
private String specName;
private List<SpecificationGroupBean.SpecValueVo> specValueVos;
public SpecificationGroupBean() {
}
@Data
public static class SpecValueVo {
private Integer sequence;
private String specId;
private String specValue;
private String specValueId;
public SpecValueVo() {
}
}
}
@Data
public static class SkuProductBean {
private String customerCode;
private String productCode;
private Long finalPrice;
private Long originalPrice;
private String productName;
private Integer productType;
private Integer sequence;
private String skuCode;
private String skuId;
private Integer status;
private Integer stockLimit;
private Integer stockQty;
private Long packPrice;
private Integer riseSell;
private String rawMaterial;
private Double tax;
private String taxId;
private List<SkuProductBean.SkuSpecValue> skuSpecValues;
private List<ProductGroupType> additionalGroupList;
private Double weight;
protected String unit;
private Integer openMemberDiscount;
private Integer memberDiscount;
public Integer getMemberDiscountResult() {
return this.openMemberDiscount != null && this.openMemberDiscount == 1 ? this.memberDiscount : 100;
}
public SkuProductBean() {
}
@Data
public static class SkuSpecValue {
private String productId;
private Integer sequence;
private String specId;
private String specName;
private String specValue;
private String specValueId;
public SkuSpecValue() {
}
}
@Data
public static class PackageProductTypeDto {
private Long groupId;
private Integer sequence;
public PackageProductTypeDto() {
}
}
}
}
package cn.freemud.entities.dto.product; package cn.freemud.entities.dto.product;
import com.freemud.application.sdk.api.productcenter.domain.ProductBeanDTO;
import lombok.Data; import lombok.Data;
import java.util.Map; import java.util.Map;
...@@ -24,9 +24,9 @@ public class ValiadShopProductResult { ...@@ -24,9 +24,9 @@ public class ValiadShopProductResult {
private String message; private String message;
private String skuId; private String skuId;
private String spuId; private String spuId;
private ProductBeanDTO productType; private ProductTypeBeanDTO productType;
private String uuid; private String uuid;
private Map<String,ProductBeanDTO> subProductTypeMap; private Map<String,ProductTypeBeanDTO> subProductTypeMap;
} }
...@@ -9,9 +9,7 @@ import cn.freemud.constant.ShoppingCartConstant; ...@@ -9,9 +9,7 @@ import cn.freemud.constant.ShoppingCartConstant;
import cn.freemud.entities.dto.*; import cn.freemud.entities.dto.*;
import cn.freemud.entities.dto.activity.ActivityQueryDto; import cn.freemud.entities.dto.activity.ActivityQueryDto;
import cn.freemud.entities.dto.activity.ActivityQueryResponseDto; import cn.freemud.entities.dto.activity.ActivityQueryResponseDto;
import cn.freemud.entities.dto.product.ValiadShopProductResponse; import cn.freemud.entities.dto.product.*;
import cn.freemud.entities.dto.product.ValiadShopProductResult;
import cn.freemud.entities.dto.product.ValidateShopProductRequest;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto; import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.dto.user.GetSessionUserInfoDto; import cn.freemud.entities.dto.user.GetSessionUserInfoDto;
import cn.freemud.entities.vo.*; import cn.freemud.entities.vo.*;
...@@ -33,6 +31,7 @@ import cn.freemud.service.thirdparty.CustomerApplicationClient; ...@@ -33,6 +31,7 @@ import cn.freemud.service.thirdparty.CustomerApplicationClient;
import cn.freemud.utils.BeanUtil; import cn.freemud.utils.BeanUtil;
import cn.freemud.service.thirdparty.ProductClient; import cn.freemud.service.thirdparty.ProductClient;
import cn.freemud.utils.ResponseUtil; import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.base.SDKCommonBaseContextWare; import com.freemud.application.sdk.api.base.SDKCommonBaseContextWare;
...@@ -169,7 +168,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -169,7 +168,6 @@ public class ShoppingCartMCoffeeServiceImpl {
if (CollectionUtils.isEmpty(oldCartGoodsList)) { if (CollectionUtils.isEmpty(oldCartGoodsList)) {
oldCartGoodsList = new ArrayList<>(); oldCartGoodsList = new ArrayList<>();
} }
//商品券已添加情况校验 //商品券已添加情况校验
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = checkGoodsCoupon(oldCartGoodsList, operationType, couponCode,goodsId, addShoppingCartGoodsRequestVo); List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = checkGoodsCoupon(oldCartGoodsList, operationType, couponCode,goodsId, addShoppingCartGoodsRequestVo);
CartGoods addCartGoods = convent2CartGoods(addShoppingCartGoodsRequestVo, goodsId ,vo); CartGoods addCartGoods = convent2CartGoods(addShoppingCartGoodsRequestVo, goodsId ,vo);
...@@ -322,7 +320,12 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -322,7 +320,12 @@ public class ShoppingCartMCoffeeServiceImpl {
// checkUpdateStock(partnerId, storeId, menuType, qty, cartGoods); // checkUpdateStock(partnerId, storeId, menuType, qty, cartGoods);
// check购物车中所有商品 // check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); // cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList);
List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
// 重新存储最新购物车 // 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
...@@ -374,7 +377,11 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -374,7 +377,11 @@ public class ShoppingCartMCoffeeServiceImpl {
// 如果购物车商品不为空, 则check购物车中所有商品 // 如果购物车商品不为空, 则check购物车中所有商品
if (CollectionUtils.isNotEmpty(cartGoodsList)) { if (CollectionUtils.isNotEmpty(cartGoodsList)) {
// check购物车中所有商品 // check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
// 重新存储最新购物车 // 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
} }
...@@ -688,12 +695,17 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -688,12 +695,17 @@ public class ShoppingCartMCoffeeServiceImpl {
List<CartGoods> onlyCheckGoodsList = new ArrayList<>(); List<CartGoods> onlyCheckGoodsList = new ArrayList<>();
if (requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()){ if (requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()){
onlyCheckGoodsList.addAll(cartGoodsList);
// 新门店check购物车中所有商品 // 新门店check购物车中所有商品
onlyCheckGoodsList = checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, onlyCheckGoodsList); for (CartGoods cartGoods : cartGoodsList) {
onlyCheckGoodsList.addAll(checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(cartGoods)));
}
}else{ }else{
// 新门店check购物车中所有商品 // 新门店check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
} }
if (requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()) { if (requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()) {
...@@ -705,7 +717,13 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -705,7 +717,13 @@ public class ShoppingCartMCoffeeServiceImpl {
return ResponseUtil.success(shoppingCartGoodsResponseVo); return ResponseUtil.success(shoppingCartGoodsResponseVo);
}else { }else {
// 新门店check购物车中所有商品 // 新门店check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, toStoreId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
// 重新存储新门店购物车 // 重新存储新门店购物车
assortmentSdkService.setShoppingCart(partnerId, toStoreId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, toStoreId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
//清空商品券商品 //清空商品券商品
...@@ -792,7 +810,13 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -792,7 +810,13 @@ public class ShoppingCartMCoffeeServiceImpl {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_GETINFO_INVAILD); return ResponseUtil.error(ResponseResult.SHOPPING_CART_GETINFO_INVAILD);
} }
// check购物车中所有商品 // check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); // cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList);
List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
// 如果购物车商品不为空, 则check购物车中所有商品 // 如果购物车商品不为空, 则check购物车中所有商品
if (shoppingCartGoodsResponseVo.getChanged() && requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()) { if (shoppingCartGoodsResponseVo.getChanged() && requestVo.getOperationType() == ShoppingCartOperationType.CHECK.getCode()) {
return ResponseUtil.success(shoppingCartGoodsResponseVo); return ResponseUtil.success(shoppingCartGoodsResponseVo);
...@@ -1034,24 +1058,26 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1034,24 +1058,26 @@ public class ShoppingCartMCoffeeServiceImpl {
*/ */
public List<CartGoods> updateCartGoodsLegal(String partnerId, String storeId, Integer orderType, String tableNumber, String menuType, String userId, public List<CartGoods> updateCartGoodsLegal(String partnerId, String storeId, Integer orderType, String tableNumber, String menuType, String userId,
CartGoods addCartGoods, ShoppingCartGoodsBaseResponseVo shoppingCartGoodsResponseVo, List<CartGoods> oldCartGoodsList) { CartGoods addCartGoods, ShoppingCartGoodsBaseResponseVo shoppingCartGoodsResponseVo, List<CartGoods> oldCartGoodsList) {
oldCartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType,shoppingCartGoodsResponseVo, oldCartGoodsList);
List<CartGoods> newCartGoods = new ArrayList<>(); List<CartGoods> newCartGoods = new ArrayList<>();
newCartGoods.addAll(oldCartGoodsList);
newCartGoods.add(addCartGoods); newCartGoods.add(addCartGoods);
//加购商品校验 //加购商品校验
List<CartGoods> allCartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, newCartGoods); List<CartGoods> newCartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType,shoppingCartGoodsResponseVo, newCartGoods);
List<CartGoods> nowCartGoodsList = new ArrayList<>(); List<CartGoods> nowCartGoodsList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(oldCartGoodsList)){
nowCartGoodsList.addAll(oldCartGoodsList);
}
if(CollectionUtils.isNotEmpty(newCartGoodsList)){
//判断当前商品在购物车是否已存在,存在则数量+1,不存在商品行 + 1 //判断当前商品在购物车是否已存在,存在则数量+1,不存在商品行 + 1
allCartGoodsList.forEach(oldCartGoods -> { newCartGoodsList.forEach(newCartGood -> {
int index; int index;
if ((index = nowCartGoodsList.indexOf(oldCartGoods)) >= 0) { if ((index = nowCartGoodsList.indexOf(newCartGood)) >= 0) {
nowCartGoodsList.get(index).setQty(nowCartGoodsList.get(index).getQty() + addCartGoods.getQty()); nowCartGoodsList.get(index).setQty(nowCartGoodsList.get(index).getQty() + addCartGoods.getQty());
} else { } else {
nowCartGoodsList.add(oldCartGoods); nowCartGoodsList.add(newCartGood);
} }
}); });
}
// 重新set购物车信息到缓存中 // 重新set购物车信息到缓存中
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, nowCartGoodsList, null, tableNumber, this.shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, nowCartGoodsList, null, tableNumber, this.shoppingCartBaseService);
return nowCartGoodsList; return nowCartGoodsList;
...@@ -1244,6 +1270,36 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1244,6 +1270,36 @@ public class ShoppingCartMCoffeeServiceImpl {
cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId()); cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId());
} }
//套餐商品赋值
if (ObjectUtils.equals(GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType(), cartGoods.getGoodsType())){
cartGoods.setOriginalPrice(productBeanListSpuClass.get(0).getOriginalPrice());
cartGoods.setFinalPrice(productBeanListSpuClass.get(0).getFinalPrice());
cartGoods.setPackPrice(productBeanListSpuClass.get(0).getPackPrice());
cartGoods.setCustomerCode(productBeanListSpuClass.get(0).getCustomerCode());
cartGoods.setName(productBeanListSpuClass.get(0).getName());
cartGoods.setSpuName(productBeanListSpuClass.get(0).getName());
cartGoods.setSkuName(productBeanListSpuClass.get(0).getName());
cartGoods.setPic(productBeanListSpuClass.get(0).getPicture());
cartGoods.setStockLimit(productBeanListSpuClass.get(0).getStockLimit() == 1);
cartGoods.setTax(productBeanListSpuClass.get(0).getTax());
cartGoods.setTaxId(productBeanListSpuClass.get(0).getTaxId());
//套餐可选商品赋值
if (CollectionUtils.isNotEmpty(productBeanListSpuClass.get(0).getProductGroupList())){
for (ProductBeanDTO.ProductGroupType groupType : productBeanListSpuClass.get(0).getProductGroupList()) {
if (CollectionUtils.isNotEmpty(groupType.getGroupDetail())){
for (ProductBeanDTO.ProductGroupType.GroupDetailType detailType : groupType.getGroupDetail()) {
for (CartGoods.ComboxGoods groupGoods : cartGoods.getProductGroupList()) {
if (detailType.getProductId().equals(groupGoods.getGoodsId())) {
groupGoods.setFinalPrice(detailType.getMarkUpPrice().longValue());
groupGoods.setOriginalPrice(detailType.getProductPrice().longValue());
}
}
}
}
}
}
}
} }
...@@ -1482,7 +1538,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1482,7 +1538,6 @@ public class ShoppingCartMCoffeeServiceImpl {
try { try {
ValidateShopProductRequest validateShopProductRequest = shoppingCartConvertAdapter.getValidateShopProductRequest(checkCartRequest); ValidateShopProductRequest validateShopProductRequest = shoppingCartConvertAdapter.getValidateShopProductRequest(checkCartRequest);
ProductBaseResponse<ValiadShopProductResponse> valiadResponse = productClient.validateShopProductAboutReason(validateShopProductRequest); ProductBaseResponse<ValiadShopProductResponse> valiadResponse = productClient.validateShopProductAboutReason(validateShopProductRequest);
if (valiadResponse == null || !CartResponseConstant.SUCCESS.getCode().equals(valiadResponse.getErrcode().toString()) || valiadResponse.getData()==null) { if (valiadResponse == null || !CartResponseConstant.SUCCESS.getCode().equals(valiadResponse.getErrcode().toString()) || valiadResponse.getData()==null) {
checkCartRequest.getCartGoodsList().clear(); checkCartRequest.getCartGoodsList().clear();
checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true); checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true);
...@@ -1526,7 +1581,13 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1526,7 +1581,13 @@ public class ShoppingCartMCoffeeServiceImpl {
} }
if (PRODUCT_PRICE_CHANGE == validaProduct.getCode()) { if (PRODUCT_PRICE_CHANGE == validaProduct.getCode()) {
changePriceSpu.add(spuName); changePriceSpu.add(spuName);
List<ProductBeanDTO> productList = validateResult.getFailureList().stream().map(ValiadShopProductResult::getProductType).collect(Collectors.toList()); List<ProductTypeBeanDTO> productList =
validateResult.getFailureList().stream().map(ValiadShopProductResult::getProductType).collect(Collectors.toList());
shoppingCartConvertAdapter.updateCartGoodsInfoForMCoffee(cartGoods, productList);
}
if (PRODUCT_GROUP_PRICE_CHANGE == validaProduct.getCode()) {
changePriceSpu.add(spuName);
List<ProductTypeBeanDTO> productList = validateResult.getFailureList().stream().map(ValiadShopProductResult::getProductType).collect(Collectors.toList());
shoppingCartConvertAdapter.updateCartGoodsInfoForMCoffee(cartGoods, productList); shoppingCartConvertAdapter.updateCartGoodsInfoForMCoffee(cartGoods, productList);
} }
if (PRODUCT_GROUP_EMPTY == validaProduct.getCode()) { if (PRODUCT_GROUP_EMPTY == validaProduct.getCode()) {
...@@ -1565,9 +1626,12 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1565,9 +1626,12 @@ public class ShoppingCartMCoffeeServiceImpl {
continue; continue;
} }
for (ValiadShopProductResult valiadShopProductResult : validateResult.getSuccessList()){ for (ValiadShopProductResult valiadShopProductResult : validateResult.getSuccessList()){
ProductBeanDTO productType = valiadShopProductResult.getProductType(); ProductTypeBeanDTO productType = valiadShopProductResult.getProductType();
if(ObjectUtils.equals(productType.getPid(), cartGoods.getSpuId())){ if(ObjectUtils.equals(productType.getPid(), cartGoods.getSpuId())){
Map<String,ProductBeanDTO> subProductTypeMap = valiadShopProductResult.getSubProductTypeMap(); //多规格商品更新套餐价格为商品返回
cartGoods.setFinalPrice(valiadShopProductResult.getProductType().getFinalPrice());
cartGoods.setOriginalPrice(valiadShopProductResult.getProductType().getFinalPrice());
Map<String,ProductTypeBeanDTO> subProductTypeMap = valiadShopProductResult.getSubProductTypeMap();
shoppingCartConvertAdapter.updateCartGoodsInfo(cartGoods, productType,subProductTypeMap); shoppingCartConvertAdapter.updateCartGoodsInfo(cartGoods, productType,subProductTypeMap);
break; break;
} }
...@@ -1636,7 +1700,12 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1636,7 +1700,12 @@ public class ShoppingCartMCoffeeServiceImpl {
// 如果购物车商品不为空, 则check购物车中所有商品 // 如果购物车商品不为空, 则check购物车中所有商品
if (CollectionUtils.isNotEmpty(cartGoodsList)) { if (CollectionUtils.isNotEmpty(cartGoodsList)) {
// check购物车中所有商品 // check购物车中所有商品
cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList); // cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartGoodsList);
List<CartGoods> temList = new ArrayList<>();
for (CartGoods goods : cartGoodsList) {
temList.addAll(checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods)));
}
cartGoodsList = temList;
// 重新存储最新购物车 // 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
......
...@@ -412,7 +412,8 @@ public class CalculationServiceImpl { ...@@ -412,7 +412,8 @@ public class CalculationServiceImpl {
material.setType(2); material.setType(2);
material.setGoodsId(materialGoods.getGoodsId()); material.setGoodsId(materialGoods.getGoodsId());
material.setGoodsQuantity(materialGoods.getQty()); material.setGoodsQuantity(materialGoods.getQty());
material.setOriginalPrice(materialGoods.getFinalPrice()); material.setOriginalPrice(null != materialGoods.getFinalPrice() ?
materialGoods.getFinalPrice() : 0);
materials.add(material); materials.add(material);
} }
} }
...@@ -430,7 +431,8 @@ public class CalculationServiceImpl { ...@@ -430,7 +431,8 @@ public class CalculationServiceImpl {
material.setType(1); material.setType(1);
material.setGoodsId(materialGoods2.getSpuId()); material.setGoodsId(materialGoods2.getSpuId());
material.setGoodsQuantity(1); material.setGoodsQuantity(1);
material.setOriginalPrice(materialGoods2.getFinalPrice()); material.setOriginalPrice(null != materialGoods2.getFinalPrice() ?
materialGoods2.getFinalPrice() : 0);
materials.add(material); materials.add(material);
} }
} }
...@@ -438,14 +440,15 @@ public class CalculationServiceImpl { ...@@ -438,14 +440,15 @@ public class CalculationServiceImpl {
} }
//加料 //加料
if (cartGoods != null && CollectionUtils.isNotEmpty(cartGoods.getProductMaterialList())) { if (null != cartGoods && CollectionUtils.isNotEmpty(cartGoods.getProductMaterialList())) {
for (CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) { for (CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) {
ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material material = new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material(); ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material material = new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material();
material.setType(1); material.setType(1);
material.setGoodsId(materialGoods.getSpuId()); material.setGoodsId(materialGoods.getSpuId());
material.setGoodsQuantity(1); material.setGoodsQuantity(1);
material.setOriginalPrice(materialGoods.getOriginalPrice()); material.setOriginalPrice(null != materialGoods.getOriginalPrice() ?
material.setNowPrice(materialGoods.getFinalPrice().intValue()); materialGoods.getOriginalPrice() : 0);
material.setNowPrice(null != materialGoods.getFinalPrice() ? materialGoods.getFinalPrice().intValue():0);
materials.add(material); materials.add(material);
} }
} }
......
package cn.freemud.service.impl.mcoffee.calculation; package cn.freemud.service.impl.mcoffee.calculation;
import cn.freemud.adapter.ShoppingCartConvertAdapter; import cn.freemud.adapter.ShoppingCartConvertAdapter;
import cn.freemud.adapter.ShoppingCartMccafeAdapter;
import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto; import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto;
import cn.freemud.entities.dto.UserLoginInfoDto; import cn.freemud.entities.dto.UserLoginInfoDto;
import cn.freemud.entities.dto.activity.ActivityDiscountsDto; import cn.freemud.entities.dto.activity.ActivityDiscountsDto;
...@@ -38,6 +39,8 @@ public class SetMealCalculation { ...@@ -38,6 +39,8 @@ public class SetMealCalculation {
@Autowired @Autowired
private ShoppingCartConvertAdapter shoppingCartConvertAdapter; private ShoppingCartConvertAdapter shoppingCartConvertAdapter;
@Autowired
private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter;
public void updateShoppingCartGoodsDiscount(ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) { public void updateShoppingCartGoodsDiscount(ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
...@@ -62,11 +65,15 @@ public class SetMealCalculation { ...@@ -62,11 +65,15 @@ public class SetMealCalculation {
cartGoods.setPackPrice(cartGoods.getPackPrice() * cartGoods.getQty()); cartGoods.setPackPrice(cartGoods.getPackPrice() * cartGoods.getQty());
// 可选商品现总价 // 可选商品现总价
productGroupTotalAmount = 0l; productGroupTotalAmount = 0l;
long productGroupAmount = cartGoods.getProductGroupList().stream().mapToLong(t -> t.getFinalPrice() * t.getQty()).sum(); long productGroupAmount =
null == cartGoods.getProductGroupList() ? 0 :
cartGoods.getProductGroupList().stream().mapToLong(t -> (null != t.getFinalPrice() ?
t.getFinalPrice():0) * (null != t.getQty() ? t.getQty():0)).sum();
productGroupTotalAmount += productGroupAmount * cartGoods.getQty(); productGroupTotalAmount += productGroupAmount * cartGoods.getQty();
// 固定商品现总价 // 固定商品现总价
long productComboAmount = cartGoods.getProductComboList().stream().mapToLong(t -> t.getFinalPrice() * t.getQty()).sum(); long productComboAmount = cartGoods.getProductComboList().stream().mapToLong(t -> (null != t.getFinalPrice() ?
t.getFinalPrice():0) * (null != t.getQty() ? t.getQty():0)).sum();
long productComboTotalAmount = productComboAmount * cartGoods.getQty(); long productComboTotalAmount = productComboAmount * cartGoods.getQty();
long materialPrice = 0l; long materialPrice = 0l;
...@@ -76,18 +83,26 @@ public class SetMealCalculation { ...@@ -76,18 +83,26 @@ public class SetMealCalculation {
Long comboxmaterialPrice = 0L; Long comboxmaterialPrice = 0L;
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){ if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
for (CartGoods.MaterialGoods materialGoods : comboxGoods.getProductMaterialList()){ for (CartGoods.MaterialGoods materialGoods : comboxGoods.getProductMaterialList()){
comboxmaterialPrice+= materialGoods.getFinalPrice() * cartGoods.getQty(); comboxmaterialPrice+= null != materialGoods.getFinalPrice() ? materialGoods.getFinalPrice() * cartGoods.getQty() : 0;
} }
} }
comboxGoods.setAmount(comboxGoods.getAmount()+comboxmaterialPrice); comboxGoods.setAmount((null == comboxGoods.getAmount() ? 0 :
comboxGoods.getAmount())+comboxmaterialPrice);
materialPrice = materialPrice + comboxmaterialPrice; materialPrice = materialPrice + comboxmaterialPrice;
} }
} }
cartGoods.setOriginalAmount(productGroupTotalAmount + productComboTotalAmount + materialPrice);
cartGoods.setOriginalPrice(productComboTotalAmount); Long amount = null != cartGoods.getFinalPrice() ? cartGoods.getFinalPrice()*cartGoods.getQty() + productGroupTotalAmount + materialPrice :
cartGoods.setAmount(productGroupTotalAmount + productComboTotalAmount + materialPrice); productGroupTotalAmount + productComboTotalAmount + materialPrice;
cartGoods.setFinalPrice(productComboTotalAmount); Long comboOriginalPriceAmount = null != cartGoods.getOriginalAmount() ? cartGoods.getOriginalAmount() :
productComboTotalAmount;
cartGoods.setOriginalAmount(productGroupTotalAmount + comboOriginalPriceAmount + materialPrice);
cartGoods.setOriginalPrice(null != cartGoods.getOriginalPrice() ? cartGoods.getOriginalPrice() :
productComboTotalAmount);
cartGoods.setAmount(amount);
cartGoods.setFinalPrice(null != cartGoods.getFinalPrice() ? cartGoods.getFinalPrice() :
productComboTotalAmount);
// 套餐(固定商品)现价 // 套餐(固定商品)现价
// String toastMsg = getTotalAmount(cartGoods, productGroupAmount, numberMap, goodsMap); // String toastMsg = getTotalAmount(cartGoods, productGroupAmount, numberMap, goodsMap);
...@@ -131,11 +146,11 @@ public class SetMealCalculation { ...@@ -131,11 +146,11 @@ public class SetMealCalculation {
int productGroupDiscountAmount = cartGoods.getProductGroupList().stream().mapToInt(t -> t.getFinalPrice().intValue() * t.getQty()).sum(); int productGroupDiscountAmount = cartGoods.getProductGroupList().stream().mapToInt(t -> t.getFinalPrice().intValue() * t.getQty()).sum();
// totalDiscountAmount += discountAmount - productGroupDiscountAmount * cartGoods.getQty(); // totalDiscountAmount += discountAmount - productGroupDiscountAmount * cartGoods.getQty();
// 添加套餐父商品 // 添加套餐父商品
ShoppingCartGoodsDto.CartGoodsDetailDto parentCartGoods = shoppingCartConvertAdapter.convertCartGoods2DetailGoods(cartGoods, apportionGoods,duplicateGoodsMap); ShoppingCartGoodsDto.CartGoodsDetailDto parentCartGoods = shoppingCartMccafeAdapter.convertCartGoods2DetailGoods(cartGoods, apportionGoods,duplicateGoodsMap);
// parentCartGoods.setTotalDiscountAmount(parentCartGoods.getTotalDiscountAmount()+ cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue()); // parentCartGoods.setTotalDiscountAmount(parentCartGoods.getTotalDiscountAmount()+ cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
// parentCartGoods.getActivityDiscountsDtos().add(getActivityDiscountsDto(discountAmount - productGroupDiscountAmount * cartGoods.getQty())); // parentCartGoods.getActivityDiscountsDtos().add(getActivityDiscountsDto(discountAmount - productGroupDiscountAmount * cartGoods.getQty()));
// 添加套餐固定商品&可选商品: 做均摊 // 添加套餐固定商品&可选商品: 做均摊
parentCartGoods.setComboProducts(shoppingCartConvertAdapter.convertComboxGoods2DetailGoods(cartGoods,parentCartGoods.getTotalDiscountAmount())); parentCartGoods.setComboProducts(shoppingCartMccafeAdapter.convertComboxGoods2DetailGoods(cartGoods,parentCartGoods.getTotalDiscountAmount()));
cartGoodsDetailDtos.add(parentCartGoods); cartGoodsDetailDtos.add(parentCartGoods);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment