Commit cd020c75 by 徐康

Merge branch 'feature/xukang_20200601_麦咖啡P7V1'

# Conflicts:
#	assortment-ordercenter-sdk/src/main/java/com/freemud/sdk/api/assortment/order/adapter/OrderSdkAdapter.java
#	order-application-service/src/main/java/cn/freemud/adapter/OrderAdapter.java
#	order-application-service/src/main/java/cn/freemud/service/impl/MCCafeOrderServiceImpl.java
#	shopping-cart-application-service/src/main/java/cn/freemud/service/impl/mcoffee/ShoppingCartMCoffeeServiceImpl.java
parents 7cd0a959 904c22cf
...@@ -3187,6 +3187,9 @@ public class OrderSdkAdapter { ...@@ -3187,6 +3187,9 @@ public class OrderSdkAdapter {
if (null != product.getProductGroupId()) { if (null != product.getProductGroupId()) {
extInfo.setProductGroupId(product.getProductGroupId()); extInfo.setProductGroupId(product.getProductGroupId());
} }
if (null != product.getIsSendGoods() && product.getIsSendGoods()){
extInfo.setIsSendGoods(true);
}
extInfo.setStapleFood(product.getStapleFood()); extInfo.setStapleFood(product.getStapleFood());
extInfo.setOriginalGoodsUid(product.getOriginalGoodsUid()); extInfo.setOriginalGoodsUid(product.getOriginalGoodsUid());
......
...@@ -21,6 +21,10 @@ public class RedisKeyConstant { ...@@ -21,6 +21,10 @@ public class RedisKeyConstant {
/** /**
* 用户购物车在redis的key前缀 * 用户购物车在redis的key前缀
*/ */
public final static String SAAS_SHOPPINGCART_SENDGOODS_KEY_PREFIX = "saas:user:info:cart:sendgoods:";
/**
* 用户购物车在redis的key前缀
*/
public final static String SAAS_SHOPPINGCART_COUPON_KEY_PREFIX = "saas:user:info:cart:coupon:"; public final static String SAAS_SHOPPINGCART_COUPON_KEY_PREFIX = "saas:user:info:cart:coupon:";
/** /**
* 用户购物车在redis的key前缀 * 用户购物车在redis的key前缀
......
...@@ -82,6 +82,10 @@ public interface ShoppingCartBaseService { ...@@ -82,6 +82,10 @@ public interface ShoppingCartBaseService {
*/ */
BaseResponse<List<CartGoods>> getCartGoodsList(CartParamDto cartParamDto, String trackingNo); BaseResponse<List<CartGoods>> getCartGoodsList(CartParamDto cartParamDto, String trackingNo);
default BaseResponse<List<CartGoods>> getCartSendGoodsList(CartParamDto cartParamDto, String trackingNo) {
return null;
}
/** /**
* 设置购物车商品行集合信息 * 设置购物车商品行集合信息
* *
...@@ -100,6 +104,10 @@ public interface ShoppingCartBaseService { ...@@ -100,6 +104,10 @@ public interface ShoppingCartBaseService {
return null; return null;
} }
default BaseResponse<List<CartGoods>> setCartSendGoodsList(CartParamDto cartParamDto, String trackingNo, long expire, TimeUnit timeUnit) {
return null;
}
/** /**
* 设置购物车代金券信息 * 设置购物车代金券信息
* *
...@@ -140,6 +148,14 @@ public interface ShoppingCartBaseService { ...@@ -140,6 +148,14 @@ public interface ShoppingCartBaseService {
default BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) { default BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) {
return null; return null;
} }
/**
* 清除麦咖啡购物车赠送商品行信息
*
* @param cartParamDto
*/
default BaseResponse clearMCCafeSendGoods(CartParamDto cartParamDto, String trackingNo) {
return null;
}
/** /**
......
...@@ -111,6 +111,21 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService { ...@@ -111,6 +111,21 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
} }
@Override @Override
public BaseResponse<List<CartGoods>> getCartSendGoodsList(CartParamDto cartParamDto, String trackingNo) {
try {
String redisKey = getShoppingCartSendGoodsKey(cartParamDto);
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
List<CartGoods> cartGoodsList = operations.values();
//对创建时间进行排序
cartGoodsList.sort(Comparator.comparingLong(CartGoods::getCreateTimeMili));
return CartResponseUtil.success(cartGoodsList);
} catch (Exception e) {
ErrorLog.printErrorLog("assortment-shoppingcart-sdk", trackingNo, e.getMessage(), "getCartGoodsList", cartParamDto, e, Level.ERROR);
return null;
}
}
@Override
public BaseResponse<String> getCartCouponCode(CartParamDto cartParamDto, String trackingNo) { public BaseResponse<String> getCartCouponCode(CartParamDto cartParamDto, String trackingNo) {
try { try {
String redisKey = getShoppingCartCouponCodeKey(cartParamDto); String redisKey = getShoppingCartCouponCodeKey(cartParamDto);
...@@ -161,6 +176,24 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService { ...@@ -161,6 +176,24 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
} }
@Override @Override
public BaseResponse<List<CartGoods>> setCartSendGoodsList(CartParamDto cartParamDto, String trackingNo, long expire, TimeUnit timeUnit) {
try {
String redisKey = getShoppingCartSendGoodsKey(cartParamDto);
BoundHashOperations<String, String, CartGoods> operations = redisTemplate.boundHashOps(redisKey);
this.clearMCCafeSendGoods(cartParamDto, trackingNo);
Map<String, CartGoods> cartGoodsMap = cartParamDto.getCartGoodsList().parallelStream()
.filter(k -> StringUtils.isNotEmpty(k.getCartGoodsUid()))
.collect(Collectors.toMap(CartGoods::getCartGoodsUid, Function.identity(), (k1, k2) -> k1));
operations.putAll(cartGoodsMap);
operations.expire(expire, timeUnit);
return CartResponseUtil.success();
} catch (Exception e) {
ErrorLog.printErrorLog("assortment-shoppingcart-sdk", trackingNo, e.getMessage(), "setCartSendGoodsList", cartParamDto, e, Level.ERROR);
return null;
}
}
@Override
public BaseResponse<String> setCartCouponCode(CartParamDto cartParamDto, String trackingNo) { public BaseResponse<String> setCartCouponCode(CartParamDto cartParamDto, String trackingNo) {
try { try {
String redisKey = getShoppingCartCouponCodeKey(cartParamDto); String redisKey = getShoppingCartCouponCodeKey(cartParamDto);
...@@ -227,6 +260,7 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService { ...@@ -227,6 +260,7 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
public BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) { public BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) {
try { try {
redisTemplate.delete(this.getShoppingCartGoodsKey(cartParamDto)); redisTemplate.delete(this.getShoppingCartGoodsKey(cartParamDto));
redisTemplate.delete(this.getShoppingCartSendGoodsKey(cartParamDto));
redisTemplate.delete(this.getShoppingCartGoodsAmountKey(cartParamDto)); redisTemplate.delete(this.getShoppingCartGoodsAmountKey(cartParamDto));
cartParamDto.setCouponType(SaveCouponType.COUPON.getCode()); cartParamDto.setCouponType(SaveCouponType.COUPON.getCode());
redisTemplate.delete(this.getShoppingCartCouponCodeKey(cartParamDto)); redisTemplate.delete(this.getShoppingCartCouponCodeKey(cartParamDto));
...@@ -239,6 +273,17 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService { ...@@ -239,6 +273,17 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
} }
} }
@Override
public BaseResponse clearMCCafeSendGoods(CartParamDto cartParamDto, String trackingNo) {
try {
redisTemplate.delete(this.getShoppingCartSendGoodsKey(cartParamDto));
return new BaseResponse(VersionUtils.VER_1, CartResponseConstant.SUCCESS.getCode(), CartResponseConstant.SUCCESS.getMessage());
} catch (Exception e) {
ErrorLog.printErrorLog("assortment-shoppingcart-sdk", trackingNo, e.getMessage(), "clear", cartParamDto, e, Level.ERROR);
return null;
}
}
@Override @Override
public BaseResponse clearMCCafeCouponByType(CartParamDto cartParamDto,Integer couponType,String trackingNo) { public BaseResponse clearMCCafeCouponByType(CartParamDto cartParamDto,Integer couponType,String trackingNo) {
...@@ -367,6 +412,10 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService { ...@@ -367,6 +412,10 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
return RedisKeyConstant.SAAS_SHOPPINGCART_KEY_PREFIX + cartParamDto.getPartnerId() + "_" + cartParamDto.getStoreId() + "_" + cartParamDto.getUserId(); return RedisKeyConstant.SAAS_SHOPPINGCART_KEY_PREFIX + cartParamDto.getPartnerId() + "_" + cartParamDto.getStoreId() + "_" + cartParamDto.getUserId();
} }
private String getShoppingCartSendGoodsKey(CartParamDto cartParamDto) {
return RedisKeyConstant.SAAS_SHOPPINGCART_SENDGOODS_KEY_PREFIX + cartParamDto.getPartnerId() + "_" + cartParamDto.getStoreId() + "_" + cartParamDto.getUserId();
}
/** /**
* 获取记录购物车coupon的key * 获取记录购物车coupon的key
......
...@@ -2335,6 +2335,9 @@ public class OrderAdapter { ...@@ -2335,6 +2335,9 @@ public class OrderAdapter {
if(StringUtils.isNotBlank(orderProductAddInfoDto.getSplitIndex())) { if(StringUtils.isNotBlank(orderProductAddInfoDto.getSplitIndex())) {
productVo.setSplitIndex(orderProductAddInfoDto.getSplitIndex()); productVo.setSplitIndex(orderProductAddInfoDto.getSplitIndex());
} }
if(null != orderProductAddInfoDto.getIsSendGoods() && orderProductAddInfoDto.getIsSendGoods()) {
productVo.setIsSendGoods(1);
}
} }
productVo.setOriginalPrice(productBean.getPrice()); productVo.setOriginalPrice(productBean.getPrice());
productVo.setFinalPrice(productBean.getSalePrice()); productVo.setFinalPrice(productBean.getSalePrice());
...@@ -2771,6 +2774,7 @@ public class OrderAdapter { ...@@ -2771,6 +2774,7 @@ public class OrderAdapter {
createOrderProductDemoDto.setClassificationName(cartGoodsDetailDto.getClassificationName()); createOrderProductDemoDto.setClassificationName(cartGoodsDetailDto.getClassificationName());
createOrderProductDemoDto.setSplitIndex(cartGoodsDetailDto.getSplitIndex()); createOrderProductDemoDto.setSplitIndex(cartGoodsDetailDto.getSplitIndex());
createOrderProductDemoDto.setProductGroupId(cartGoodsDetailDto.getProductGroupId()); createOrderProductDemoDto.setProductGroupId(cartGoodsDetailDto.getProductGroupId());
createOrderProductDemoDto.setIsSendGoods(cartGoodsDetailDto.getIsSendGoods());
if(CollectionUtils.isNotEmpty(cartGoodsDetailDto.getSpecialExtra())) { if(CollectionUtils.isNotEmpty(cartGoodsDetailDto.getSpecialExtra())) {
createOrderProductDemoDto.setSpecialAttrs(new ArrayList<>()); createOrderProductDemoDto.setSpecialAttrs(new ArrayList<>());
cartGoodsDetailDto.getSpecialExtra().stream().forEach(o -> { cartGoodsDetailDto.getSpecialExtra().stream().forEach(o -> {
......
...@@ -178,6 +178,11 @@ public class ProductVo { ...@@ -178,6 +178,11 @@ public class ProductVo {
private Boolean isTableware = false; private Boolean isTableware = false;
/** /**
* 是否餐具商品
*/
private Integer isSendGoods = 0;
/**
* 商品单位 * 商品单位
*/ */
private String unit; private String unit;
......
...@@ -123,18 +123,16 @@ public class ShoppingCartMccafeAdapter { ...@@ -123,18 +123,16 @@ public class ShoppingCartMccafeAdapter {
* @param cartGoods * @param cartGoods
* @return * @return
*/ */
public List<ShoppingCartGoodsDto.CartGoodsDetailDto> convertCartGoods2DetailGoodsList(CartGoods cartGoods, List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, Map<String, String> duplicateGoodsMap) { public ShoppingCartGoodsDto.CartGoodsDetailDto convertCartGoods2DetailGoodsList(CartGoods cartGoods, List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, Map<String, String> duplicateGoodsMap) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = new ArrayList<>();
if (StringUtils.isEmpty(cartGoods.getCouponCode()) && GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) { if (StringUtils.isEmpty(cartGoods.getCouponCode()) && GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) {
return cartGoodsDetailDtos; return null;
} else { } else {
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = convertCartGoods2DetailGoods(cartGoods, apportionGoodsList, duplicateGoodsMap); ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = convertCartGoods2DetailGoods(cartGoods, apportionGoodsList, duplicateGoodsMap);
if(GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) { if(GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) {
cartGoodsDetailDto.setComboProducts(this.convertComboxGoods2DetailGoods(cartGoods,cartGoodsDetailDto.getTotalDiscountAmount())); cartGoodsDetailDto.setComboProducts(this.convertComboxGoods2DetailGoods(cartGoods,cartGoodsDetailDto.getTotalDiscountAmount()));
} }
cartGoodsDetailDtos.add(cartGoodsDetailDto); return cartGoodsDetailDto;
} }
return cartGoodsDetailDtos;
} }
/** /**
...@@ -202,77 +200,18 @@ public class ShoppingCartMccafeAdapter { ...@@ -202,77 +200,18 @@ public class ShoppingCartMccafeAdapter {
List<ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra> cartGoodsExtras = BeanUtil.convertBeans(cartGoods.getExtra(), ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra::new); List<ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra> cartGoodsExtras = BeanUtil.convertBeans(cartGoods.getExtra(), ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra::new);
cartGoodsDetailDto.setExtraList(cartGoodsExtras); cartGoodsDetailDto.setExtraList(cartGoodsExtras);
//61: 单品买M赠N \ 62:买赠 \ 6:买M赠N //61: 单品买M赠N \ 62:买赠 \ 6:买M赠N
if (ObjectUtils.equals(ActivityTypeEnum.TYPE_61.getCode(), cartGoods.getActivityType()) || ObjectUtils.equals(ActivityTypeEnum.TYPE_6.getCode(), cartGoods.getActivityType()) // 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())) { // || ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) {
cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue()); // cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
} else { // } 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.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()); // //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)) { // if (CollectionUtils.isNotEmpty(collect)) {
setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap); // setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap);
// 设置商品行,优惠活动均摊 // // 设置商品行,优惠活动均摊
setActivityDiscounts(collect, cartGoodsDetailDto, duplicateGoodsMap); // setActivityDiscounts(collect, cartGoodsDetailDto, duplicateGoodsMap);
} // }
}
return cartGoodsDetailDto;
}
public ShoppingCartGoodsDto.CartGoodsDetailDto convertComboProduct2DetailGoods(CartGoods.ComboxGoods cartGoods) {
// 设置基础信息
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.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);
return cartGoodsDetailDto; return cartGoodsDetailDto;
} }
......
...@@ -46,6 +46,15 @@ public class MCoffeeShoppingCartController { ...@@ -46,6 +46,15 @@ public class MCoffeeShoppingCartController {
} }
/** /**
* 向购物车中添加商品
*/
@ApiAnnotation(logMessage = "selectSendGoods")
@PostMapping(value = "/selectSendGoods")
public BaseResponse selectSendGoods(@Validated @LogParams @RequestBody MCoffeeAddGoodsRequestVo request) {
return shoppingCartMCoffeeService.selectSendGoods(request);
}
/**
* 批量向购物车中添加商品 * 批量向购物车中添加商品
*/ */
@ApiAnnotation(logMessage = "batchAddGoods") @ApiAnnotation(logMessage = "batchAddGoods")
......
...@@ -169,6 +169,7 @@ public class ActivityCalculationDiscountResponseDto { ...@@ -169,6 +169,7 @@ public class ActivityCalculationDiscountResponseDto {
* 已经优惠金额 * 已经优惠金额
*/ */
private Long alreadyDiscountAmount; private Long alreadyDiscountAmount;
private Integer alreadyDiscountThresholdAmount;
private Integer activitySubType; private Integer activitySubType;
private List<SendGoods> sendGoods; private List<SendGoods> sendGoods;
} }
...@@ -256,6 +257,10 @@ public class ActivityCalculationDiscountResponseDto { ...@@ -256,6 +257,10 @@ public class ActivityCalculationDiscountResponseDto {
*/ */
private String goodsId; private String goodsId;
/** /**
* 0 原购物车商品 1 赠送商品 2 换购商品
*/
private Integer cartGoodType;
/**
* 商品数量 * 商品数量
*/ */
private Integer goodsQuantity; private Integer goodsQuantity;
...@@ -573,6 +578,8 @@ public class ActivityCalculationDiscountResponseDto { ...@@ -573,6 +578,8 @@ public class ActivityCalculationDiscountResponseDto {
private String goodsId; private String goodsId;
private String goodsName; private String goodsName;
private Integer sendNumber; private Integer sendNumber;
private String picture;
private Integer originalPrice;
} }
} }
......
...@@ -43,7 +43,7 @@ public class ActivityList { ...@@ -43,7 +43,7 @@ public class ActivityList {
private String deduct; private String deduct;
//最高扣减金额 //最高扣减金额
private String maxDeduct; private String maxDeduct;
//最高扣减金额 //已减
private String alreadyDecut; private String alreadyDecut;
//还差 //还差
private String missing; private String missing;
...@@ -53,10 +53,19 @@ public class ActivityList { ...@@ -53,10 +53,19 @@ public class ActivityList {
private String agianDeduct; private String agianDeduct;
private List<SendGoods> sends; private List<SendGoods> sends;
private List<McCafeSendGoods> mcCafeSendGoodsList;
@Data @Data
public static class SendGoods { public static class SendGoods {
private Integer qty; private Integer qty;
private String goodsName; private String goodsName;
} }
@Data
public static class McCafeSendGoods extends CartGoods {
private Integer isSelected;
private String originalPriceStr;
private String finalPriceStr;
}
} }
...@@ -116,6 +116,11 @@ public class AssortmentSdkService { ...@@ -116,6 +116,11 @@ public class AssortmentSdkService {
return getNowBuyShoppingCart( buyType, partnerId, storeId, useId, sessionId, tableNumber, shoppingCartService); return getNowBuyShoppingCart( buyType, partnerId, storeId, useId, sessionId, tableNumber, shoppingCartService);
} }
public List<CartGoods> getShoppingCartSendGoods(String partnerId, String storeId, String useId, String sessionId, String tableNumber, ShoppingCartBaseService shoppingCartService) {
int buyType = 0 ;
return getNowBuyShoppingCartSendGoods( buyType, partnerId, storeId, useId, sessionId, tableNumber, shoppingCartService);
}
/** /**
* 调用聚合sdk获取缓存中购物车信息 * 调用聚合sdk获取缓存中购物车信息
* *
...@@ -169,6 +174,12 @@ public class AssortmentSdkService { ...@@ -169,6 +174,12 @@ public class AssortmentSdkService {
return setNowBuyShoppingCart(buyType,partnerId, storeId, useId , cartGoodsList, sessionId, tableNumber, shoppingCartService); return setNowBuyShoppingCart(buyType,partnerId, storeId, useId , cartGoodsList, sessionId, tableNumber, shoppingCartService);
} }
public List<CartGoods> setShoppingCartSendGoods(String partnerId, String storeId, String useId, List<CartGoods> cartGoodsList, String sessionId, String tableNumber, ShoppingCartBaseService shoppingCartService) {
int buyType = 0;
return setNowBuyShoppingCartSendGoods(buyType,partnerId, storeId, useId , cartGoodsList, sessionId, tableNumber, shoppingCartService);
}
/** /**
* 调用聚合sdk设置缓存中购物车信息 * 调用聚合sdk设置缓存中购物车信息
* *
...@@ -200,6 +211,24 @@ public class AssortmentSdkService { ...@@ -200,6 +211,24 @@ public class AssortmentSdkService {
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class); return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class);
} }
public List<CartGoods> setNowBuyShoppingCartSendGoods(int buyType,String partnerId, String storeId, String useId, List<CartGoods> cartGoodsList, String sessionId, String tableNumber, ShoppingCartBaseService shoppingCartService) {
com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = getCartParamDto(partnerId, storeId, useId);
cartParamDto.setSessionId(sessionId);
cartParamDto.setTableNumber(tableNumber);
cartParamDto.setUserId(useId);
//立即购买==1 ,设置新的缓存key
if(buyType == ShoppingCartConstant.NOW_BUY_TYPE) {
cartParamDto.setBuyType(buyType);
}
cartParamDto.setCartGoodsList(JSONArray.parseArray(JSONObject.toJSONString(cartGoodsList), com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.class));
BaseResponse<List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods>> baseResponse = shoppingCartService.setCartSendGoodsList(cartParamDto, LogThreadLocal.getTrackingNo(), 3, TimeUnit.DAYS);
if (baseResponse == null || !ResponseResult.SUCCESS.getCode().equals(baseResponse.getCode())) {
return null;
}
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class);
}
/** /**
* 调用聚合sdk设置缓存中购物车代金券 * 调用聚合sdk设置缓存中购物车代金券
* *
...@@ -208,7 +237,7 @@ public class AssortmentSdkService { ...@@ -208,7 +237,7 @@ public class AssortmentSdkService {
* @param useId * @param useId
* @return * @return
*/ */
public List<CartGoods> setShoppingCartCouponCode(String partnerId, String storeId, String useId, String couponCode, ShoppingCartBaseService shoppingCartService, Integer type) { public String setShoppingCartCouponCode(String partnerId, String storeId, String useId, String couponCode, ShoppingCartBaseService shoppingCartService, Integer type) {
com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = getCartParamDto(partnerId, storeId, useId); com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = getCartParamDto(partnerId, storeId, useId);
cartParamDto.setCouponCode(couponCode); cartParamDto.setCouponCode(couponCode);
cartParamDto.setCouponType(type); cartParamDto.setCouponType(type);
...@@ -217,7 +246,7 @@ public class AssortmentSdkService { ...@@ -217,7 +246,7 @@ public class AssortmentSdkService {
return null; return null;
} }
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class); return baseResponse.getResult();
} }
/** /**
...@@ -337,6 +366,22 @@ public class AssortmentSdkService { ...@@ -337,6 +366,22 @@ public class AssortmentSdkService {
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class); return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class);
} }
public List<CartGoods> getNowBuyShoppingCartSendGoods(int buyType,String partnerId, String storeId, String useId, String sessionId, String tableNumber, ShoppingCartBaseService shoppingCartService) {
com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = getCartParamDto(partnerId, storeId, useId);
cartParamDto.setSessionId(sessionId);
cartParamDto.setTableNumber(tableNumber);
cartParamDto.setUserId(useId);
if(buyType == ShoppingCartConstant.NOW_BUY_TYPE) {
cartParamDto.setBuyType(buyType);
}
// 根据不同点餐类型获取不同购物车实例
BaseResponse<List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods>> baseResponse = shoppingCartService.getCartSendGoodsList(cartParamDto, LogThreadLocal.getTrackingNo());
if (baseResponse == null || !ResponseResult.SUCCESS.getCode().equals(baseResponse.getCode()) || CollectionUtils.isEmpty(baseResponse.getResult())) {
return new ArrayList<>();
}
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class);
}
/** /**
* 调用聚合sdk更新商品行数量信息 * 调用聚合sdk更新商品行数量信息
* *
......
...@@ -20,6 +20,7 @@ import cn.freemud.service.CouponService; ...@@ -20,6 +20,7 @@ import cn.freemud.service.CouponService;
import cn.freemud.service.impl.AssortmentSdkService; import cn.freemud.service.impl.AssortmentSdkService;
import cn.freemud.service.impl.CouponServiceImpl; import cn.freemud.service.impl.CouponServiceImpl;
import cn.freemud.service.impl.FullSubtractionActivityServiceImpl; import cn.freemud.service.impl.FullSubtractionActivityServiceImpl;
import cn.freemud.service.impl.mcoffee.calculation.BuySendCalculation;
import cn.freemud.service.impl.mcoffee.calculation.CalculationServiceImpl; import cn.freemud.service.impl.mcoffee.calculation.CalculationServiceImpl;
import cn.freemud.service.impl.mcoffee.calculation.CouponDiscountCalculation; import cn.freemud.service.impl.mcoffee.calculation.CouponDiscountCalculation;
import cn.freemud.service.impl.mcoffee.entity.CopyShoppingCartRequestVo; import cn.freemud.service.impl.mcoffee.entity.CopyShoppingCartRequestVo;
...@@ -30,6 +31,8 @@ import cn.freemud.service.impl.mcoffee.entity.*; ...@@ -30,6 +31,8 @@ import cn.freemud.service.impl.mcoffee.entity.*;
import cn.freemud.service.thirdparty.CustomerApplicationClient; 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.ExceptionUtils;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.ResponseUtil; import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -86,6 +89,7 @@ import static com.freemud.sdk.api.assortment.shoppingcart.constant.ShoppingCartC ...@@ -86,6 +89,7 @@ import static com.freemud.sdk.api.assortment.shoppingcart.constant.ShoppingCartC
*/ */
@Service @Service
@Slf4j
public class ShoppingCartMCoffeeServiceImpl { public class ShoppingCartMCoffeeServiceImpl {
@Autowired @Autowired
...@@ -112,6 +116,8 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -112,6 +116,8 @@ public class ShoppingCartMCoffeeServiceImpl {
private ProductClient productClient; private ProductClient productClient;
@Autowired @Autowired
private ShoppingCartConvertAdapter shoppingCartConvertAdapter; private ShoppingCartConvertAdapter shoppingCartConvertAdapter;
@Autowired
private BuySendCalculation buySendCalculation;
private static final String nullSeat = "508106"; private static final String nullSeat = "508106";
...@@ -152,7 +158,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -152,7 +158,6 @@ public class ShoppingCartMCoffeeServiceImpl {
String couponCode = addShoppingCartGoodsRequestVo.getCouponCode(); String couponCode = addShoppingCartGoodsRequestVo.getCouponCode();
String spuId2 = spuId; String spuId2 = spuId;
MCoffeeProductIdsVo vo =new MCoffeeProductIdsVo();
List<Long> productIds = new ArrayList<>(); List<Long> productIds = new ArrayList<>();
productIds.add(Long.parseLong(goodsId)); productIds.add(Long.parseLong(goodsId));
...@@ -178,10 +183,10 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -178,10 +183,10 @@ public class ShoppingCartMCoffeeServiceImpl {
//餐具和月享卡数量限制 //餐具和月享卡数量限制
if (mcCafeTablewareSkuId.equals(skuId) || StringUtils.equals("9999",skuId)) { if (mcCafeTablewareSkuId.equals(skuId) || StringUtils.equals("9999",skuId)) {
for (CartGoods cartGoods : oldCartGoodsList) { for (CartGoods cartGoods : oldCartGoodsList) {
if (mcCafeTablewareSkuId.equals(cartGoods.getSkuId())) { if (mcCafeTablewareSkuId.equals(skuId) && mcCafeTablewareSkuId.equals(cartGoods.getSkuId())) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_ADD_ERROR.getCode(), "不能重复添加餐具商品"); return ResponseUtil.error(ResponseResult.SHOPPING_CART_ADD_ERROR.getCode(), "不能重复添加餐具商品");
} }
if (StringUtils.equals("9999",cartGoods.getSkuId())) { if (StringUtils.equals("9999",skuId) && StringUtils.equals("9999",cartGoods.getSkuId())) {
// 返回购物车数据 // 返回购物车数据
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, oldCartGoodsList, null, ShoppingCartConstant.ADD_AND_UPDATE, null); setAddAndUpdateResponse(shoppingCartGoodsResponseVo, oldCartGoodsList, null, ShoppingCartConstant.ADD_AND_UPDATE, null);
return ResponseUtil.success(shoppingCartGoodsResponseVo); return ResponseUtil.success(shoppingCartGoodsResponseVo);
...@@ -189,7 +194,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -189,7 +194,7 @@ public class ShoppingCartMCoffeeServiceImpl {
} }
} }
CartGoods addCartGoods = convent2CartGoods(addShoppingCartGoodsRequestVo, goodsId, vo); CartGoods addCartGoods = convent2CartGoods(addShoppingCartGoodsRequestVo, goodsId);
//商品券已添加情况校验 //商品券已添加情况校验
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = checkGoodsCoupon(oldCartGoodsList, operationType, couponCode, goodsId, addCartGoods); List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = checkGoodsCoupon(oldCartGoodsList, operationType, couponCode, goodsId, addCartGoods);
setClassificationAndPrice(addCartGoods, productBeanListSpuClass); setClassificationAndPrice(addCartGoods, productBeanListSpuClass);
...@@ -228,7 +233,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -228,7 +233,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动等价格计算 // 促销活动等价格计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null, calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null,
newCartGoods, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, null); newCartGoods, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, null, null);
// 重新保存购物车数据 // 重新保存购物车数据
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, newCartGoods, null, tableNumber, this.shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, newCartGoods, null, tableNumber, this.shoppingCartBaseService);
}else{ }else{
...@@ -236,7 +241,25 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -236,7 +241,25 @@ public class ShoppingCartMCoffeeServiceImpl {
oldCartGoodsList.add(addCartGoods); oldCartGoodsList.add(addCartGoods);
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode, calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode,
oldCartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null); oldCartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null, null);
if(null != shoppingCartGoodsResponseVo.getActivityTip() && CollectionUtils.isNotEmpty(shoppingCartGoodsResponseVo.getActivityTip().getActivityList())) {
Optional<ActivityList> activityListOptional = shoppingCartGoodsResponseVo.getActivityTip().getActivityList().stream().filter(
o -> ActivityTypeEnum.TYPE_230.getCode().equals(o.getTipType())).findFirst();
if(activityListOptional.isPresent()) {
List<CartGoods> cartSendGoodsList = assortmentSdkService.getShoppingCartSendGoods(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
if(CollectionUtils.isEmpty(cartSendGoodsList)
|| activityListOptional.get().getMcCafeSendGoodsList().stream().noneMatch(o-> o.getGoodsId().equals(cartSendGoodsList.get(0).getSkuId()))) {
MCoffeeAddGoodsRequestVo selectGoodsRequest = new MCoffeeAddGoodsRequestVo();
BeanUtils.copyProperties(addShoppingCartGoodsRequestVo, selectGoodsRequest);
selectGoodsRequest.setSkuId(activityListOptional.get().getMcCafeSendGoodsList().get(0).getGoodsId());
selectGoodsRequest.setSpuId(activityListOptional.get().getMcCafeSendGoodsList().get(0).getGoodsId());
selectGoodsRequest.setOperationType(1);
selectSendGoods(selectGoodsRequest);
}
}
}
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, oldCartGoodsList, null, tableNumber, this.shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, oldCartGoodsList, null, tableNumber, this.shoppingCartBaseService);
newCartGoods = oldCartGoodsList; newCartGoods = oldCartGoodsList;
} }
...@@ -246,6 +269,52 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -246,6 +269,52 @@ public class ShoppingCartMCoffeeServiceImpl {
return ResponseUtil.success(shoppingCartGoodsResponseVo); return ResponseUtil.success(shoppingCartGoodsResponseVo);
} }
/**
* 添加商品、超值加购、商品券
*/
public BaseResponse selectSendGoods(MCoffeeAddGoodsRequestVo addShoppingCartGoodsRequestVo) {
// 参数校验
if (StringUtils.isEmpty(addShoppingCartGoodsRequestVo.getShopId())) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_SHOP_ID_NOT_EMPTY);
}
if (addShoppingCartGoodsRequestVo.getQty() != null && addShoppingCartGoodsRequestVo.getQty() < 0) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_ADD_ERROR);
}
String sessionId = addShoppingCartGoodsRequestVo.getSessionId();
// 获取用户信息
CustomerInfoVo assortmentCustomerInfoVo = getCustomerInfoVo(sessionId);
ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo = new ShoppingCartGoodsResponseVo();
String userId = assortmentCustomerInfoVo.getMemberId();
String partnerId = addShoppingCartGoodsRequestVo.getPartnerId();
String storeId = addShoppingCartGoodsRequestVo.getShopId();
String spuId = addShoppingCartGoodsRequestVo.getSpuId();
String skuId = StringUtils.isNotBlank(addShoppingCartGoodsRequestVo.getSkuId()) ? addShoppingCartGoodsRequestVo.getSkuId() : "";
String goodsId = StringUtils.isEmpty(skuId) ? spuId : skuId;
String tableNumber = addShoppingCartGoodsRequestVo.getTableNumber();
String menuType = addShoppingCartGoodsRequestVo.getMenuType();
Integer orderType = addShoppingCartGoodsRequestVo.getOrderType();
if(addShoppingCartGoodsRequestVo.getOperationType() == 1) {
List<ProductBeanDTO> productBeanListSpuClass = assortmentSdkService.getProductsInfoSdk(partnerId, storeId, Collections.singletonList(spuId), menuType, this.shoppingCartBaseService);
CartGoods addCartGoods = convent2CartGoods(addShoppingCartGoodsRequestVo, goodsId);
addCartGoods.setSkuId(spuId);
setClassificationAndPrice(addCartGoods, productBeanListSpuClass);
List<CartGoods> newCartGoods = updateCartGoodsLegal(partnerId, storeId, orderType, tableNumber, menuType, userId, addCartGoods, shoppingCartGoodsResponseVo, new ArrayList<>());
// 保存赠送商品
assortmentSdkService.setShoppingCartSendGoods(partnerId, storeId, userId, newCartGoods, null, tableNumber, this.shoppingCartBaseService);
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, newCartGoods, null, ShoppingCartConstant.ADD_AND_UPDATE, null);
} else {
com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = assortmentSdkService.getCartParamDto(partnerId, storeId, userId);
shoppingCartBaseService.clearMCCafeSendGoods(cartParamDto, LogThreadLocal.getTrackingNo());
}
// 返回购物车数据
return ResponseUtil.success(shoppingCartGoodsResponseVo);
}
public BaseResponse addBatchGoods(MCoffeeBatchAddGoodsRequestVo requestVo){ public BaseResponse addBatchGoods(MCoffeeBatchAddGoodsRequestVo requestVo){
// 参数校验 // 参数校验
if (CollectionUtils.isEmpty(requestVo.getGoodsInfos())) { if (CollectionUtils.isEmpty(requestVo.getGoodsInfos())) {
...@@ -313,22 +382,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -313,22 +382,6 @@ public class ShoppingCartMCoffeeServiceImpl {
return baseResponse; return baseResponse;
} }
private MCoffeeProductIdsVo validCoupon(String partnerId, String storeId, String spuId, List<Long> productIds, String menuType) {
CheckSpqInfoRequestDto checkSpqInfoRequestDto = new CheckSpqInfoRequestDto(partnerId, storeId, spuId.substring(CommonsConstant.COUPON_PREFIX.length()), menuType);
CouponService couponService = SDKCommonBaseContextWare.getBean(CouponService.class);
CheckSpqInfoResponseDto checkSpqInfoResponseDto = couponService.checkSpqInfo(checkSpqInfoRequestDto);
if (checkSpqInfoResponseDto == null) {
throw new ServiceException(ResponseResult.SHOPPING_CART_COUPON_NOT_EXIST);
}
productIds.add(Long.parseLong(checkSpqInfoResponseDto.getSkuId()));
String skuId2 = checkSpqInfoResponseDto.getSkuId();
String spuId2 = checkSpqInfoResponseDto.getSpuId();
MCoffeeProductIdsVo vo =new MCoffeeProductIdsVo();
vo.setSkuId(skuId2);
vo.setSpuId(spuId2);
return vo;
}
private List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> checkGoodsCoupon(List<CartGoods> oldCartGoodsList, Integer operationType, String couponCode, String goodsId, CartGoods addShoppingCartGoodsRequestVo) { private List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> checkGoodsCoupon(List<CartGoods> oldCartGoodsList, Integer operationType, String couponCode, String goodsId, CartGoods addShoppingCartGoodsRequestVo) {
if (operationType != null && operationType == 1 && StringUtils.isBlank(couponCode)) { if (operationType != null && operationType == 1 && StringUtils.isBlank(couponCode)) {
...@@ -463,6 +516,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -463,6 +516,7 @@ public class ShoppingCartMCoffeeServiceImpl {
updateGoodsQtyRequestVo.setVersion(requestVo.getVersion()); updateGoodsQtyRequestVo.setVersion(requestVo.getVersion());
updateGoodsQtyRequestVo.setShopId(requestVo.getShopId()); updateGoodsQtyRequestVo.setShopId(requestVo.getShopId());
updateGoodsQtyRequestVo.setPartnerId(requestVo.getPartnerId()); updateGoodsQtyRequestVo.setPartnerId(requestVo.getPartnerId());
updateGoodsQtyRequestVo.setOrderType(requestVo.getOrderType());
updateGoodsQtyRequestVo.setQtyInfoList(requestVo.getQtyInfoList()); updateGoodsQtyRequestVo.setQtyInfoList(requestVo.getQtyInfoList());
baseResponse = this.batchUpdateGoodsQty(updateGoodsQtyRequestVo); baseResponse = this.batchUpdateGoodsQty(updateGoodsQtyRequestVo);
//批量更新失败,直接返回错误 //批量更新失败,直接返回错误
...@@ -482,6 +536,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -482,6 +536,7 @@ public class ShoppingCartMCoffeeServiceImpl {
addGoodsRequestVo.setShopId(requestVo.getShopId()); addGoodsRequestVo.setShopId(requestVo.getShopId());
addGoodsRequestVo.setOrderType(requestVo.getOrderType()); addGoodsRequestVo.setOrderType(requestVo.getOrderType());
addGoodsRequestVo.setPartnerId(requestVo.getPartnerId()); addGoodsRequestVo.setPartnerId(requestVo.getPartnerId());
addGoodsRequestVo.setOrderType(requestVo.getOrderType());
addGoodsRequestVo.setGoodsInfos(requestVo.getGoodsInfos()); addGoodsRequestVo.setGoodsInfos(requestVo.getGoodsInfos());
baseResponse = this.addBatchGoods(addGoodsRequestVo); baseResponse = this.addBatchGoods(addGoodsRequestVo);
//批量新增失败,直接返回错误 //批量新增失败,直接返回错误
...@@ -584,6 +639,10 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -584,6 +639,10 @@ public class ShoppingCartMCoffeeServiceImpl {
// 先验证商品是否存在 // 先验证商品是否存在
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, null, shoppingCartBaseService); List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, null, shoppingCartBaseService);
ApiLog.debug("cartGoodsList: {}",JSONObject.toJSONString(cartGoodsList));
List<CartGoods> cartSendGoodsList = assortmentSdkService.getShoppingCartSendGoods(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
ApiLog.debug("cartSendGoodsList: {}",JSONObject.toJSONString(cartSendGoodsList));
CartGoods cartGoods = null; CartGoods cartGoods = null;
String skuId = ""; String skuId = "";
Integer finalQty = qty; Integer finalQty = qty;
...@@ -603,7 +662,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -603,7 +662,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null); List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null);
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode, calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null); cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null, null);
return ResponseUtil.success(shoppingCartGoodsResponseVo); return ResponseUtil.success(shoppingCartGoodsResponseVo);
} }
if (cartGoodsUid.equals(cartGoods_.getCartGoodsUid())) { if (cartGoodsUid.equals(cartGoods_.getCartGoodsUid())) {
...@@ -656,8 +715,29 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -656,8 +715,29 @@ public class ShoppingCartMCoffeeServiceImpl {
// 当couponCode不为空时,需参与价格计算 // 当couponCode不为空时,需参与价格计算
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null); List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null);
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscount = calculationService.updateShoppingCartGoodsDiscount(
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null); partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null, cartSendGoodsList);
if(null != shoppingCartGoodsResponseVo.getActivityTip() && CollectionUtils.isNotEmpty(shoppingCartGoodsResponseVo.getActivityTip().getActivityList())) {
Optional<ActivityList> activityListOptional = shoppingCartGoodsResponseVo.getActivityTip().getActivityList().stream().filter(
o -> ActivityTypeEnum.TYPE_230.getCode().equals(o.getTipType())).findFirst();
if(activityListOptional.isPresent()) {
List<CartGoods> finalCartSendGoodsList = new ArrayList<>();
finalCartSendGoodsList.addAll(cartSendGoodsList);
if(CollectionUtils.isEmpty(cartSendGoodsList)
|| activityListOptional.get().getMcCafeSendGoodsList().stream().noneMatch(o-> o.getGoodsId().equals(finalCartSendGoodsList.get(0).getSkuId()))) {
MCoffeeAddGoodsRequestVo selectGoodsRequest = new MCoffeeAddGoodsRequestVo();
BeanUtils.copyProperties(updateShoppingCartGoodsQtyRequestVo, selectGoodsRequest);
selectGoodsRequest.setSkuId(activityListOptional.get().getMcCafeSendGoodsList().get(0).getGoodsId());
selectGoodsRequest.setSpuId(activityListOptional.get().getMcCafeSendGoodsList().get(0).getGoodsId());
selectGoodsRequest.setOperationType(1);
selectSendGoods(selectGoodsRequest);
cartSendGoodsList = assortmentSdkService.getShoppingCartSendGoods(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
buySendCalculation.updateBuySendActivityTip(calculationDiscount, shoppingCartGoodsResponseVo, cartSendGoodsList);
}
}
}
//把月卡放到最后 //把月卡放到最后
if (CollectionUtils.isNotEmpty(cartGoodsList)) { if (CollectionUtils.isNotEmpty(cartGoodsList)) {
...@@ -708,6 +788,9 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -708,6 +788,9 @@ public class ShoppingCartMCoffeeServiceImpl {
// 获取购物车商品 // 获取购物车商品
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService); List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
ApiLog.debug("cartGoodsList: {}",JSONObject.toJSONString(cartGoodsList)); ApiLog.debug("cartGoodsList: {}",JSONObject.toJSONString(cartGoodsList));
List<CartGoods> cartSendGoodsList = assortmentSdkService.getShoppingCartSendGoods(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
ApiLog.debug("cartSendGoodsList: {}",JSONObject.toJSONString(cartSendGoodsList));
CartGoods monthCardProduct = null; CartGoods monthCardProduct = null;
// 如果购物车商品不为空, 则check购物车中所有商品 // 如果购物车商品不为空, 则check购物车中所有商品
if (CollectionUtils.isNotEmpty(cartGoodsList)) { if (CollectionUtils.isNotEmpty(cartGoodsList)) {
...@@ -721,14 +804,13 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -721,14 +804,13 @@ public class ShoppingCartMCoffeeServiceImpl {
monthCardProduct = goods; monthCardProduct = goods;
continue; continue;
} }
temList.addAll(checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, Arrays.asList(goods), sessionId)); temList.add(goods);
} }
cartGoodsList = checkCartGoods(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, temList, sessionId);
if (null != monthCardProduct) { if (null != monthCardProduct) {
temList.add(monthCardProduct); cartGoodsList.add(monthCardProduct);
} }
cartGoodsList = temList;
if (CollectionUtils.isNotEmpty(cartGoodsList)) { if (CollectionUtils.isNotEmpty(cartGoodsList)) {
int size = cartGoodsList.size(); int size = cartGoodsList.size();
for(int i=0;i<size;i++) { for(int i=0;i<size;i++) {
...@@ -800,7 +882,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -800,7 +882,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult = calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult = calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, payCardPrice); cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, payCardPrice, cartSendGoodsList);
//如果促销返回的商品里有月享卡2.0的虚拟商品,重新保存一次购物车 //如果促销返回的商品里有月享卡2.0的虚拟商品,重新保存一次购物车
if(CollectionUtils.isNotEmpty(cartGoodsList) && cartGoodsList.stream().anyMatch(cartGoods -> cartGoods.getSkuId().equals("9999"))){ if(CollectionUtils.isNotEmpty(cartGoodsList) && cartGoodsList.stream().anyMatch(cartGoods -> cartGoods.getSkuId().equals("9999"))){
...@@ -857,7 +939,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -857,7 +939,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(null, null, cartGoodsList,null,buyMonthlyCard); List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(null, null, cartGoodsList,null,buyMonthlyCard);
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(requestVo.getPartnerId(), requestVo.getStoreId(), requestVo.getUserId(), requestVo.getAppId(), requestVo.getOrderType(), assortmentCustomerInfoVo.isMemberPaid(), requestVo.getMenuType(), requestVo.getReceiveId(), null, calculationService.updateShoppingCartGoodsDiscount(requestVo.getPartnerId(), requestVo.getStoreId(), requestVo.getUserId(), requestVo.getAppId(), requestVo.getOrderType(), assortmentCustomerInfoVo.isMemberPaid(), requestVo.getMenuType(), requestVo.getReceiveId(), null,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,payCardPrice); cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,payCardPrice, null);
String moneyCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(), String moneyCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(),
requestVo.getStoreId(), requestVo.getUserId(), shoppingCartBaseService,SaveCouponType.COUPON.getCode()); requestVo.getStoreId(), requestVo.getUserId(), shoppingCartBaseService,SaveCouponType.COUPON.getCode());
String deliveryFeeCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(),requestVo.getStoreId(),requestVo.getUserId(),shoppingCartBaseService,SaveCouponType.FREIGHT_COUPON.getCode()); String deliveryFeeCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(),requestVo.getStoreId(),requestVo.getUserId(),shoppingCartBaseService,SaveCouponType.FREIGHT_COUPON.getCode());
...@@ -973,6 +1055,8 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -973,6 +1055,8 @@ public class ShoppingCartMCoffeeServiceImpl {
// 获取购物车商品 // 获取购物车商品
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, tableNumber, shoppingCartBaseService); List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, tableNumber, shoppingCartBaseService);
ApiLog.debug("cartGoodsList: {}",JSONObject.toJSONString(cartGoodsList)); ApiLog.debug("cartGoodsList: {}",JSONObject.toJSONString(cartGoodsList));
List<CartGoods> cartSendGoodsList = assortmentSdkService.getShoppingCartSendGoods(partnerId, storeId, userId, null, tableNumber, shoppingCartBaseService);
ApiLog.debug("cartSendGoodsList: {}",JSONObject.toJSONString(cartSendGoodsList));
if (cartGoodsList == null || CollectionUtils.isEmpty(cartGoodsList)) { if (cartGoodsList == null || CollectionUtils.isEmpty(cartGoodsList)) {
throw new ServiceException(ResponseResult.SHOPPING_CART_GETINFO_INVAILD); throw new ServiceException(ResponseResult.SHOPPING_CART_GETINFO_INVAILD);
} }
...@@ -995,6 +1079,24 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -995,6 +1079,24 @@ public class ShoppingCartMCoffeeServiceImpl {
} }
allCartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class); allCartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class);
} }
CheckCartRequest checkCartSendGoodsRequest = checkCartGoodsForToPay(partnerId, storeId, orderType, menuType, shoppingCartGoodsResponseVo, cartSendGoodsList);
if (null != checkCartSendGoodsRequest) {
//商品不再售卖状态或价格变动,直接返回报错
if (null != checkCartSendGoodsRequest.getShoppingCartGoodsResponseVo()) {
com.freemud.sdk.api.assortment.shoppingcart.domain.ShoppingCartGoodsResponseVo cartGoodsResponseVo = checkCartSendGoodsRequest.getShoppingCartGoodsResponseVo();
if (cartGoodsResponseVo.getCartGoodsStates() != null && cartGoodsResponseVo.getCartGoodsStates().isHasInvalidGoods()) {
return ResponseUtil.error(ResponseResult.STORE_ITEM_CHECK_INVAILD);
}
if (cartGoodsResponseVo.getCartGoodsStates() != null && cartGoodsResponseVo.getCartGoodsStates().isPriceChanged()) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_ACTIVITY_CHANGE);
}
shoppingCartGoodsResponseVo.setToastMsg(cartGoodsResponseVo.getToastMsg());
}
cartSendGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartSendGoodsRequest.getCartGoodsList()), CartGoods.class);
}
//加价购商品 //加价购商品
List<CartGoods> reduceGoods = cartGoodsList.stream().filter(cartGoods -> cartGoods.getGoodsType() == GoodsTypeEnum.REDUCE_PRICE_GOODS.getGoodsType()).collect(Collectors.toList()); List<CartGoods> reduceGoods = cartGoodsList.stream().filter(cartGoods -> cartGoods.getGoodsType() == GoodsTypeEnum.REDUCE_PRICE_GOODS.getGoodsType()).collect(Collectors.toList());
//添加商品为加价购商品 //添加商品为加价购商品
...@@ -1024,7 +1126,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1024,7 +1126,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList = shoppingCartInfoRequestVo.getSendGoods(); List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList = shoppingCartInfoRequestVo.getSendGoods();
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscount = calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscount = calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null,
cartGoodsList, coupons, sendGoodsList, shoppingCartGoodsResponseVo, payCardPrice); cartGoodsList, coupons, sendGoodsList, shoppingCartGoodsResponseVo, payCardPrice, null);
//过滤月享卡2.0虚拟商品 //过滤月享卡2.0虚拟商品
cartGoodsList = cartGoodsList.stream().filter(goods-> !StringUtils.equals("9999",goods.getSkuId())).collect(Collectors.toList()); cartGoodsList = cartGoodsList.stream().filter(goods-> !StringUtils.equals("9999",goods.getSkuId())).collect(Collectors.toList());
...@@ -1033,7 +1135,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1033,7 +1135,7 @@ public class ShoppingCartMCoffeeServiceImpl {
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.QUERY_INFO, shoppingCartInfoRequestVo); setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.QUERY_INFO, shoppingCartInfoRequestVo);
//设置均摊信息 //设置均摊信息
calculationService.updateShoppingCartGoodsApportion(shoppingCartGoodsResponseVo, calculationDiscount, shoppingCartGoodsDto, premiumExchangeActivity, shoppingCartInfoRequestVo); calculationService.updateShoppingCartGoodsApportion(shoppingCartGoodsResponseVo, calculationDiscount, shoppingCartGoodsDto, premiumExchangeActivity, shoppingCartInfoRequestVo, cartSendGoodsList);
//如果是餐具商品,则放到最后 //如果是餐具商品,则放到最后
if (CollectionUtils.isNotEmpty(shoppingCartGoodsDto.getProducts())) { if (CollectionUtils.isNotEmpty(shoppingCartGoodsDto.getProducts())) {
...@@ -1144,7 +1246,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1144,7 +1246,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, toStoreId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null, calculationService.updateShoppingCartGoodsDiscount(partnerId, toStoreId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, null); cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo, null, null);
// 重新存储新门店购物车 // 重新存储新门店购物车
if(CollectionUtils.isNotEmpty(cartGoodsList)) { if(CollectionUtils.isNotEmpty(cartGoodsList)) {
assortmentSdkService.setShoppingCart(partnerId, toStoreId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, toStoreId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
...@@ -1230,7 +1332,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1230,7 +1332,7 @@ public class ShoppingCartMCoffeeServiceImpl {
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, null, null, calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, null, null,
cartGoodsList, new ArrayList<>(), new ArrayList<>(), shoppingCartGoodsResponseVo,null); cartGoodsList, new ArrayList<>(), new ArrayList<>(), shoppingCartGoodsResponseVo,null, null);
//设置更新响应信息 //设置更新响应信息
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.ADD_AND_UPDATE, null); setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.ADD_AND_UPDATE, null);
//再来一单清除配送费 //再来一单清除配送费
...@@ -1542,69 +1644,6 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1542,69 +1644,6 @@ public class ShoppingCartMCoffeeServiceImpl {
} }
} }
/**
* 检查sku数量
*
* @param oldCartGoodsList
* @param addCartGoods
* @return
*/
private Integer checkSkuQty(List<CartGoods> oldCartGoodsList, CartGoods addCartGoods) {
Integer qty = addCartGoods.getQty() == null ? 0 : addCartGoods.getQty();
if (CollectionUtils.isNotEmpty(oldCartGoodsList)) {
for (CartGoods goods : oldCartGoodsList) {
if (goods.getSkuId().equals(addCartGoods.getSkuId()) && goods.getSpuId().equals(addCartGoods.getSpuId())) {
qty += goods.getQty();
}
}
}
return qty;
}
// /**
// * 套餐空键位处理
// */
// private Map<String, String> checkNewCartGoods(List<CartGoods> newCartGoods,Integer oper,Map<String, String> result) {
//
// Map<String, String> map = new HashMap<>();
//
// //删除套餐空键位
// if(oper == 1){
// for (CartGoods goods : newCartGoods) {
// if (CollectionUtils.isNotEmpty(goods.getProductGroupList())) {
// List<CartGoods.ComboxGoods> productGroupList = new ArrayList<>();
// for (CartGoods.ComboxGoods comboxGoods : goods.getProductGroupList()) {
// if (nullSeat.equals(comboxGoods.getGoodsId())) {
// map.put(goods.getCartGoodsUid(), goods.getGoodsId());
// } else {
// productGroupList.add(comboxGoods);
// }
// }
// goods.setProductGroupList(productGroupList);
// }
// }
// return map;
// }
//
// //恢复套餐空键位
// if(oper == 2 && result.size() != 0){
// for (CartGoods cartGoods : newCartGoods) {
// if (result.get(cartGoods.getCartGoodsUid()) != null) {
// CartGoods.ComboxGoods comboxGoods = new CartGoods.ComboxGoods();
// comboxGoods.setGoodsId(nullSeat);
// comboxGoods.setSkuId(nullSeat);
// comboxGoods.setCustomerCode(nullSeat);
// comboxGoods.setQty(1);
// comboxGoods.setOriginalPrice(0L);
// comboxGoods.setFinalPrice(0L);
// cartGoods.getProductGroupList().add(comboxGoods);
// }
// }
// }
//
// return map;
// }
private void setToastMsgIfNotExist(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, String message) { private void setToastMsgIfNotExist(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, String message) {
if (StringUtils.isEmpty(shoppingCartGoodsResponseVo.getToastMsg())) { if (StringUtils.isEmpty(shoppingCartGoodsResponseVo.getToastMsg())) {
...@@ -1743,7 +1782,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1743,7 +1782,7 @@ public class ShoppingCartMCoffeeServiceImpl {
} }
public static CartGoods convent2CartGoods(MCoffeeAddGoodsRequestVo addShoppingCartGoodsRequestVo, String goodsId, MCoffeeProductIdsVo mCoffeeProductIdsVo) { public static CartGoods convent2CartGoods(MCoffeeAddGoodsRequestVo addShoppingCartGoodsRequestVo, String goodsId) {
String spuId = addShoppingCartGoodsRequestVo.getSpuId(); String spuId = addShoppingCartGoodsRequestVo.getSpuId();
String skuId = addShoppingCartGoodsRequestVo.getSkuId(); String skuId = addShoppingCartGoodsRequestVo.getSkuId();
// String goodsId = StringUtils.isEmpty(skuId) ? spuId : skuId; // String goodsId = StringUtils.isEmpty(skuId) ? spuId : skuId;
...@@ -2168,7 +2207,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -2168,7 +2207,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// } // }
return CartResponseUtil.success(checkCartRequest); return CartResponseUtil.success(checkCartRequest);
} catch (Exception e) { } catch (Exception e) {
ErrorLog.printErrorLog("assortment-shoppingcart-sdk", checkCartRequest.getTrackingNo(), e.getMessage(), "checkAllCartGoods", checkCartRequest, e, Level.ERROR); log.error("assortment-shoppingcart-sdk : " + ExceptionUtils.getExceptionInfo(e) + " checkAllCartGoods : " + JSON.toJSONString(checkCartRequest));
checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true); checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true);
checkCartRequest.getShoppingCartGoodsResponseVo().setToastMsg(ShoppingCartConstant.SHOPPING_CART_INVALIAD_GOODS); checkCartRequest.getShoppingCartGoodsResponseVo().setToastMsg(ShoppingCartConstant.SHOPPING_CART_INVALIAD_GOODS);
return CartResponseUtil.error(e.getMessage(),checkCartRequest); return CartResponseUtil.error(e.getMessage(),checkCartRequest);
...@@ -2267,7 +2306,7 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -2267,7 +2306,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算 // 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null, calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, null,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null); cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null, null);
//设置更新响应信息 //设置更新响应信息
ShoppingCartInfoRequestVo shoppingCartInfoRequestVo =new ShoppingCartInfoRequestVo(); ShoppingCartInfoRequestVo shoppingCartInfoRequestVo =new ShoppingCartInfoRequestVo();
BeanUtil.convertBean(cardAddVo,shoppingCartInfoRequestVo); BeanUtil.convertBean(cardAddVo,shoppingCartInfoRequestVo);
......
package cn.freemud.service.impl.mcoffee.calculation;
import cn.freemud.adapter.ShoppingCartMccafeAdapter;
import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.vo.ActivityList;
import cn.freemud.entities.vo.ActivityTip;
import cn.freemud.entities.vo.CartGoods;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import cn.freemud.enums.ActivityTypeEnum;
import cn.freemud.utils.MoneyUtils;
import com.google.common.base.Functions;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class BuySendCalculation {
@Autowired
private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter;
public void updateBuySendActivityTip(ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, List<CartGoods> cartSendGoodsList) {
if(CollectionUtils.isNotEmpty(calculationDiscountResult.getActivityPrompts())) {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ActivityPrompt> activityPromptList = calculationDiscountResult.getActivityPrompts().stream().filter(o -> ActivityTypeEnum.TYPE_230.getCode().equals(o.getActivityType())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(activityPromptList)) {
ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ActivityPrompt activityPrompt = activityPromptList.get(0);
if(activityPrompt.getThresholdAmount() > activityPrompt.getTotalAmount()) {
return;
}
ActivityTip activityTip = shoppingCartGoodsResponseVo.getActivityTip();
if(activityTip == null) {
activityTip = new ActivityTip();
shoppingCartGoodsResponseVo.setActivityTip(activityTip);
}
if(CollectionUtils.isEmpty(activityTip.getActivityList())) {
activityTip.setActivityList(new ArrayList<ActivityList>());
}
ActivityList activityList = new ActivityList();
activityList.setTipType(activityPrompt.getActivityType());
activityList.setSatisfy(MoneyUtils.parseFen2Yuan(activityPrompt.getThresholdAmount()));
if(activityPrompt.getThresholdAmount() > activityPrompt.getTotalAmount()) {
activityList.setMissing(MoneyUtils.parseFen2Yuan(activityPrompt.getThresholdAmount() - activityPrompt.getTotalAmount()));
activityList.setAgainBuy(MoneyUtils.parseFen2Yuan(activityPrompt.getThresholdAmount() - activityPrompt.getTotalAmount()));
} else {
activityList.setMissing("0");
activityList.setAgainBuy("0");
}
if(CollectionUtils.isNotEmpty(activityPrompt.getSendGoods())) {
if (CollectionUtils.isEmpty(cartSendGoodsList)) {
cartSendGoodsList = new ArrayList<>();
}
Map<String, CartGoods> map = cartSendGoodsList.stream().collect(Collectors.toMap(CartGoods::getSpuId, Function.identity(), (k1, k2) -> k1));
List<ActivityList.McCafeSendGoods> mcCafeSendGoodsList = activityPrompt.getSendGoods().stream().map(o -> {
ActivityList.McCafeSendGoods mcCafeSendGoods = new ActivityList.McCafeSendGoods();
mcCafeSendGoods.setGoodsId(o.getGoodsId());
mcCafeSendGoods.setSpuName(o.getGoodsName());
mcCafeSendGoods.setQty(o.getSendNumber());
mcCafeSendGoods.setPic(o.getPicture());
mcCafeSendGoods.setOriginalPriceStr(MoneyUtils.parseFen2Yuan(o.getOriginalPrice()));
mcCafeSendGoods.setFinalPriceStr("0");
if(map.get(o.getGoodsId()) != null) {
mcCafeSendGoods.setIsSelected(1);
}
return mcCafeSendGoods;
}).collect(Collectors.toList());
activityList.setMcCafeSendGoodsList(mcCafeSendGoodsList);
} else {
activityList.setMcCafeSendGoodsList(new ArrayList<ActivityList.McCafeSendGoods>());
}
activityTip.getActivityList().add(activityList);
}
}
}
public void updateBuySendGoods(ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, ShoppingCartGoodsDto shoppingCartGoodsDto, List<CartGoods> cartSendGoodsList) {
if(CollectionUtils.isNotEmpty(calculationDiscountResult.getSendGoods())) {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity> sendActivityList = calculationDiscountResult.getSendGoods().stream().filter(o -> ActivityTypeEnum.TYPE_230.getCode().equals(o.getActivityType())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(sendActivityList)) {
ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity = sendActivityList.get(0);
if(CollectionUtils.isNotEmpty(sendActivity.getSendGoods()) && CollectionUtils.isNotEmpty(cartSendGoodsList)) {
Map<String, CartGoods> map = cartSendGoodsList.stream().collect(Collectors.toMap(CartGoods::getSpuId, Functions.identity(), (k1, k2) -> k1));
sendActivity.getSendGoods().forEach( o -> {
CartGoods cartGoods = map.get(o.getGoodsId());
if(null != cartGoods) {
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = shoppingCartMccafeAdapter.convertCartGoods2DetailGoodsList(cartGoods, null, null);
if(null != cartGoodsDetailDto) {
cartGoodsDetailDto.setOriginalPrice(0l);
cartGoodsDetailDto.setSalePrice(0l);
cartGoodsDetailDto.setIsSendGoods(true);
shoppingCartGoodsDto.getProducts().add(cartGoodsDetailDto);
}
}
});
}
}
}
}
}
...@@ -19,9 +19,11 @@ import cn.freemud.interceptor.ServiceException; ...@@ -19,9 +19,11 @@ import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.CommonService; import cn.freemud.service.CommonService;
import cn.freemud.service.impl.ItemServiceImpl; import cn.freemud.service.impl.ItemServiceImpl;
import cn.freemud.service.thirdparty.ActivityClient; import cn.freemud.service.thirdparty.ActivityClient;
import cn.freemud.utils.ExceptionUtils;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.PropertyConvertUtil; import cn.freemud.utils.PropertyConvertUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.freemud.application.sdk.api.log.ErrorLog; import com.freemud.application.sdk.api.log.ApiLog;
import com.freemud.application.sdk.api.log.LogThreadLocal; import com.freemud.application.sdk.api.log.LogThreadLocal;
import com.freemud.application.sdk.api.membercenter.request.QueryReceiveAddressRequest; import com.freemud.application.sdk.api.membercenter.request.QueryReceiveAddressRequest;
import com.freemud.application.sdk.api.membercenter.response.QueryReceiveAddressResponse; import com.freemud.application.sdk.api.membercenter.response.QueryReceiveAddressResponse;
...@@ -32,11 +34,13 @@ import com.freemud.application.sdk.api.storecenter.response.QueryDeliverDetailRe ...@@ -32,11 +34,13 @@ import com.freemud.application.sdk.api.storecenter.response.QueryDeliverDetailRe
import com.freemud.application.sdk.api.storecenter.response.StoreResponse; import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService; import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import com.freemud.sdk.api.assortment.shoppingcart.enums.BusinessTypeEnum; import com.freemud.sdk.api.assortment.shoppingcart.enums.BusinessTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -55,6 +59,7 @@ import java.util.stream.Collectors; ...@@ -55,6 +59,7 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
@Slf4j
public class CalculationServiceImpl { public class CalculationServiceImpl {
...@@ -67,11 +72,8 @@ public class CalculationServiceImpl { ...@@ -67,11 +72,8 @@ public class CalculationServiceImpl {
@Autowired @Autowired
private ActivityClient activityClient; private ActivityClient activityClient;
@Autowired @Autowired
private ActivityAdapter activityAdapter;
@Autowired
private ItemServiceImpl itemService; private ItemServiceImpl itemService;
@Autowired @Autowired
private TimeSaleCalculation timeSaleCalculation; private TimeSaleCalculation timeSaleCalculation;
@Autowired @Autowired
...@@ -85,6 +87,10 @@ public class CalculationServiceImpl { ...@@ -85,6 +87,10 @@ public class CalculationServiceImpl {
private MaterialCalculation materialCalculation; private MaterialCalculation materialCalculation;
@Autowired @Autowired
private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter; private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter;
@Autowired
private BuySendCalculation buySendCalculation;
@Autowired
private FreightCalculation freightCalculation;
/** /**
* 更新购物车行优惠信息 * 更新购物车行优惠信息
...@@ -93,7 +99,7 @@ public class CalculationServiceImpl { ...@@ -93,7 +99,7 @@ public class CalculationServiceImpl {
boolean isMember, String menuType, String receiveId,String couponCode, boolean isMember, String menuType, String receiveId,String couponCode,
List<CartGoods> cartGoodsList, List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons, List<CartGoods> cartGoodsList, List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons,
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo,
Long payCardFee) { Long payCardFee, List<CartGoods> cartSendGoodsList) {
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, menuType); Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, menuType);
...@@ -115,7 +121,14 @@ public class CalculationServiceImpl { ...@@ -115,7 +121,14 @@ public class CalculationServiceImpl {
setMealCalculation.updateShoppingCartGoodsDiscount(calculationDiscount,cartGoodsList,shoppingCartGoodsResponseVo); setMealCalculation.updateShoppingCartGoodsDiscount(calculationDiscount,cartGoodsList,shoppingCartGoodsResponseVo);
//加料 //加料
materialCalculation.updateShoppingCartGoodsApportion(calculationDiscount,cartGoodsList); // materialCalculation.updateShoppingCartGoodsApportion(calculationDiscount,cartGoodsList);
if(null != calculationDiscount) {
//买赠
buySendCalculation.updateBuySendActivityTip(calculationDiscount, shoppingCartGoodsResponseVo, cartSendGoodsList);
//运费
freightCalculation.updateBuySendActivityTip(calculationDiscount, shoppingCartGoodsResponseVo);
}
return calculationDiscount; return calculationDiscount;
} }
...@@ -153,11 +166,12 @@ public class CalculationServiceImpl { ...@@ -153,11 +166,12 @@ public class CalculationServiceImpl {
discountRequest.setDistributionFee(deliveryAmount); discountRequest.setDistributionFee(deliveryAmount);
discountRequest.setIsMember(isMember); discountRequest.setIsMember(isMember);
discountRequest.setPayCardFee(payCardFee); discountRequest.setPayCardFee(payCardFee);
discountRequest.setProductChannel(orderType == 1 ? "saasdelivery" : "saas");
ActivityCalculationDiscountResponseDto activityCalculationDiscountResponseDto; ActivityCalculationDiscountResponseDto activityCalculationDiscountResponseDto;
try { try {
activityCalculationDiscountResponseDto = activityClient.calculationDiscountSharing(discountRequest); activityCalculationDiscountResponseDto = activityClient.calculationDiscountSharing(discountRequest);
} catch (Exception ex) { } catch (Exception ex) {
ErrorLog.printErrorLog("calculation_discount_error", "/calculation/discount/sharding", discountRequest, ex); log.error("calculation_discount_error " + "/calculation/discount/sharding " + JSON.toJSONString(discountRequest) + " " + ExceptionUtils.getExceptionInfo(ex));
throw new ServiceException(ResponseResult.OPERATE_TOO_OFTEN); throw new ServiceException(ResponseResult.OPERATE_TOO_OFTEN);
} }
//优惠券互斥 //优惠券互斥
...@@ -168,11 +182,46 @@ public class CalculationServiceImpl { ...@@ -168,11 +182,46 @@ public class CalculationServiceImpl {
if (activityCalculationDiscountResponseDto == null || !StringUtils.equals(activityCalculationDiscountResponseDto.getStatusCode(), ResponseCodeConstant.RESPONSE_SUCCESS_STR)) { if (activityCalculationDiscountResponseDto == null || !StringUtils.equals(activityCalculationDiscountResponseDto.getStatusCode(), ResponseCodeConstant.RESPONSE_SUCCESS_STR)) {
throw new ServiceException(ResponseResult.OPERATE_TOO_OFTEN); throw new ServiceException(ResponseResult.OPERATE_TOO_OFTEN);
} }
return activityCalculationDiscountResponseDto.getResult();
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult = activityCalculationDiscountResponseDto.getResult();
if(null != calculationDiscountResult) {
if(CollectionUtils.isNotEmpty(calculationDiscountResult.getDiscounts())) {
Integer discount = calculationDiscountResult.getDiscounts().stream().filter(o -> o.getType() == 230).mapToInt(o -> o.getDiscount()).sum();
calculationDiscountResult.setTotalDiscountAmount(calculationDiscountResult.getTotalDiscountAmount() - discount);
calculationDiscountResult.setOriginalTotalAmount(calculationDiscountResult.getOriginalTotalAmount() - discount);
calculationDiscountResult.getDiscounts().removeIf(o -> o.getType() == 230);
}
if(CollectionUtils.isNotEmpty(calculationDiscountResult.getGoods())) {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Goods> goods = new ArrayList<>();
ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity = new ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity();
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods> sendGoodsList2 = new ArrayList<>();
sendActivity.setSendGoods(sendGoodsList2);
sendActivity.setActivityType(ActivityTypeEnum.TYPE_230.getCode());
calculationDiscountResult.getGoods().stream().forEach(o -> {
if(o.getCartGoodType() == 1) {
ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods sendGoods = new ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods();
sendGoods.setGoodsId(o.getGoodsId());
sendGoods.setNowPrice(o.getNowPrice());
sendGoods.setOriginalPrice(o.getOriginalPrice());
sendGoods.setSendNumber(o.getGoodsQuantity());
sendGoods.setOriginalGoodsUid(o.getOriginalGoodsUid());
sendGoodsList2.add(sendGoods);
} else {
goods.add(o);
}
});
calculationDiscountResult.setGoods(goods);
calculationDiscountResult.setSendGoods(Arrays.asList(sendActivity));
}
}
log.info("calculationDiscountResultAfterProcess : " + JSON.toJSONString(calculationDiscountGoodsList));
return calculationDiscountResult;
} }
public void updateShoppingCartGoodsApportion(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, ShoppingCartGoodsDto shoppingCartGoodsDto, CreateOrderVo.PremiumExchangeActivity premiumExchangeActivity, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo){ public void updateShoppingCartGoodsApportion(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
, ShoppingCartGoodsDto shoppingCartGoodsDto, CreateOrderVo.PremiumExchangeActivity premiumExchangeActivity
, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo, List<CartGoods> cartSendGoodsList){
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtoList = CollectionUtils.isEmpty(shoppingCartGoodsDto.getProducts()) ? new ArrayList<>() : shoppingCartGoodsDto.getProducts(); List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtoList = CollectionUtils.isEmpty(shoppingCartGoodsDto.getProducts()) ? new ArrayList<>() : shoppingCartGoodsDto.getProducts();
List<ShareDiscountActivityDto> shareDiscountActivityDtoList = CollectionUtils.isEmpty(shoppingCartGoodsDto.getShareDiscountActivityDtos()) ? new ArrayList<>() : shoppingCartGoodsDto.getShareDiscountActivityDtos(); List<ShareDiscountActivityDto> shareDiscountActivityDtoList = CollectionUtils.isEmpty(shoppingCartGoodsDto.getShareDiscountActivityDtos()) ? new ArrayList<>() : shoppingCartGoodsDto.getShareDiscountActivityDtos();
...@@ -198,13 +247,16 @@ public class CalculationServiceImpl { ...@@ -198,13 +247,16 @@ public class CalculationServiceImpl {
calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getApportionGoods(); calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getApportionGoods();
Map<String, String> duplicateGoodsMap = new HashMap<>(); Map<String, String> duplicateGoodsMap = new HashMap<>();
cartGoodsList.stream().filter(cartGoods -> !StringUtils.equals(cartGoods.getSkuId(),"9999")).collect(Collectors.groupingBy(CartGoods::getGoodsId, Collectors.counting())).forEach((goodsId, count) -> { cartGoodsList.stream().filter(cartGoods -> !StringUtils.equals(cartGoods.getSkuId(),"9999"))
duplicateGoodsMap.put(goodsId,String.format("%s,0", count)); .collect(Collectors.groupingBy(CartGoods::getGoodsId, Collectors.counting()))
.forEach((goodsId, count) -> {duplicateGoodsMap.put(goodsId,String.format("%s,0", count));
}); });
for (int i = 0, len = cartGoodsList.size(); i < len; i++) { for (int i = 0, len = cartGoodsList.size(); i < len; i++) {
CartGoods cartGoods = cartGoodsList.get(i); CartGoods cartGoods = cartGoodsList.get(i);
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = shoppingCartMccafeAdapter.convertCartGoods2DetailGoodsList(cartGoods, apportionGoodsList,duplicateGoodsMap); ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = shoppingCartMccafeAdapter.convertCartGoods2DetailGoodsList(cartGoods, apportionGoodsList,duplicateGoodsMap);
cartGoodsDetailDtoList.addAll(cartGoodsDetailDtos); if(null != cartGoodsDetailDto) {
cartGoodsDetailDtoList.add(cartGoodsDetailDto);
}
} }
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Discount> discounts = calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getDiscounts(); List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Discount> discounts = calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getDiscounts();
List<ActivityDiscountsDto> activityDiscountsDtos = shoppingCartGoodsDto.getActivityDiscountsDtos() == null ? new ArrayList<>() : shoppingCartGoodsDto.getActivityDiscountsDtos(); List<ActivityDiscountsDto> activityDiscountsDtos = shoppingCartGoodsDto.getActivityDiscountsDtos() == null ? new ArrayList<>() : shoppingCartGoodsDto.getActivityDiscountsDtos();
...@@ -225,19 +277,6 @@ public class CalculationServiceImpl { ...@@ -225,19 +277,6 @@ public class CalculationServiceImpl {
} }
} }
//订单级别券优惠
// for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.CouponResults discount : calculationDiscountResult.getCouponDiscounts()) {
// int discountAmount = (discount.getDiscountAmount() == null) ? 0 : discount.getDiscountAmount();
// Integer discountType = discount.getActivityType();
// if (discountType != null && discountAmount > 0) {
// ActivityDiscountsDto activityDiscountsDto = new ActivityDiscountsDto();
// activityDiscountsDto.setActivityCode(discount.getCouponCode());
// activityDiscountsDto.setActivityName(discount.getActivityName());
// activityDiscountsDto.setActivityType(discountType);
// activityDiscountsDto.setDiscountAmount(0 - discountAmount);
// activityDiscountsDtos.add(activityDiscountsDto);
// }
// }
//过滤出加价购 //过滤出加价购
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Discount> addMoneyDiscounts = discounts.stream().filter(discount -> ActivityTypeEnum.TYPE_81.getCode().equals(discount.getType())).collect(Collectors.toList()); List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Discount> addMoneyDiscounts = discounts.stream().filter(discount -> ActivityTypeEnum.TYPE_81.getCode().equals(discount.getType())).collect(Collectors.toList());
...@@ -268,18 +307,12 @@ public class CalculationServiceImpl { ...@@ -268,18 +307,12 @@ public class CalculationServiceImpl {
//限时特价 //限时特价
timeSaleCalculation.updateShoppingCartGoodsApportion(calculationDiscountResult, shoppingCartGoodsDto); timeSaleCalculation.updateShoppingCartGoodsApportion(calculationDiscountResult, shoppingCartGoodsDto);
CouponPromotionVO couponPromotionVO = new CouponPromotionVO();
// couponPromotionVO.setPartnerId("1206");
// couponPromotionVO.setUserId(userId);
// couponPromotionVO.setStoreId(storeId);
// couponPromotionVO.setCouponCode(null);
// couponPromotionVO.setOrderType(orderType);
// couponPromotionVO.setFlg(CouponFlag.YES.getCode());
//优惠券 //优惠券
couponDiscountCalculation.updateShoppingCartGoodsApportion(calculationDiscountResult, shoppingCartGoodsDto, shoppingCartInfoRequestVo); couponDiscountCalculation.updateShoppingCartGoodsApportion(calculationDiscountResult, shoppingCartGoodsDto, shoppingCartInfoRequestVo);
setMealCalculation.updateShoppingCartGoodsApportion(shoppingCartGoodsResponseVo, calculationDiscountResult, shoppingCartGoodsDto); setMealCalculation.updateShoppingCartGoodsApportion(shoppingCartGoodsResponseVo, calculationDiscountResult, shoppingCartGoodsDto);
buySendCalculation.updateBuySendGoods(calculationDiscountResult, shoppingCartGoodsDto, cartSendGoodsList);
} }
......
...@@ -302,28 +302,8 @@ public class CouponDiscountCalculation { ...@@ -302,28 +302,8 @@ public class CouponDiscountCalculation {
} }
} }
} }
} }
// public void getCoupon(CouponPromotionVO couponPromotionVO, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo){
// // 用户选择了查询优惠券信息
// if (couponPromotionVO != null && ObjectUtils.equals(CouponFlag.YES.getCode(), couponPromotionVO.getFlg())) {
// // 构建可用不可用优惠券
// ActivityClassifyCouponBean activityClassifyCouponBean = availableCoupon(couponPromotionVO.getPartnerId()
// , couponPromotionVO.getUserId(), couponPromotionVO.getStoreId(), couponPromotionVO.getCouponCode(), couponPromotionVO.getOrderType(),cartGoodsList);
// if (Objects.equals(activityClassifyCouponBean, null)) {
// // 构建一个空得订单券信息
// activityClassifyCouponBean = new ActivityClassifyCouponBean();
// activityClassifyCouponBean.setCouponNum(0);
// activityClassifyCouponBean.setDisableCouponNum(0);
// activityClassifyCouponBean.setUsableCouponNum(0);
// activityClassifyCouponBean.setDisableCoupons(Lists.newArrayList());
// activityClassifyCouponBean.setUsableCoupons(Lists.newArrayList());
// }
// shoppingCartGoodsResponseVo.setAvailableCoupon(activityClassifyCouponBean);
// }
// }
......
package cn.freemud.service.impl.mcoffee.calculation;
import cn.freemud.entities.dto.ActivityCalculationDiscountResponseDto;
import cn.freemud.entities.vo.ActivityList;
import cn.freemud.entities.vo.ActivityTip;
import cn.freemud.entities.vo.CartGoods;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import cn.freemud.enums.ActivityTypeEnum;
import cn.freemud.utils.MoneyUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class FreightCalculation {
public void updateBuySendActivityTip(ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
if(CollectionUtils.isNotEmpty(calculationDiscountResult.getActivityPrompts())) {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ActivityPrompt> activityPromptList = calculationDiscountResult.getActivityPrompts().stream().filter(o -> ActivityTypeEnum.TYPE_14.getCode().equals(o.getActivityType())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(activityPromptList)) {
ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ActivityPrompt activityPrompt = activityPromptList.get(0);
ActivityTip activityTip = shoppingCartGoodsResponseVo.getActivityTip();
if (activityTip == null) {
activityTip = new ActivityTip();
shoppingCartGoodsResponseVo.setActivityTip(activityTip);
}
if (CollectionUtils.isEmpty(activityTip.getActivityList())) {
activityTip.setActivityList(new ArrayList<ActivityList>());
}
if(activityPrompt.getAlreadyDiscountAmount() == 0) {
return;
}
ActivityList activityList = new ActivityList();
activityList.setTipType(activityPrompt.getActivityType());
activityList.setSatisfy(MoneyUtils.parseFen2YuanInt(activityPrompt.getAlreadyDiscountThresholdAmount()));
activityList.setAlreadyDecut(MoneyUtils.parseFen2YuanInt(activityPrompt.getAlreadyDiscountAmount()));
activityList.setDeduct(MoneyUtils.parseFen2YuanInt(activityPrompt.getAlreadyDiscountAmount()));
activityList.setAgianDeduct(MoneyUtils.parseFen2YuanInt(activityPrompt.getDiscountAmout() - activityPrompt.getAlreadyDiscountAmount()));
if(activityPrompt.getThresholdAmount() > activityPrompt.getTotalAmount()) {
activityList.setMissing(MoneyUtils.parseFen2Yuan(activityPrompt.getThresholdAmount() - activityPrompt.getTotalAmount()));
activityList.setAgainBuy(MoneyUtils.parseFen2Yuan(activityPrompt.getThresholdAmount() - activityPrompt.getTotalAmount()));
} else {
activityList.setMissing("0");
activityList.setAgainBuy("0");
}
activityTip.getActivityList().add(activityList);
}
}
}
}
\ No newline at end of file
...@@ -102,23 +102,8 @@ public class SetMealCalculation { ...@@ -102,23 +102,8 @@ public class SetMealCalculation {
cartGoods.setOriginalAmount(cartGoods.getOriginalAmount() + materialPrice); cartGoods.setOriginalAmount(cartGoods.getOriginalAmount() + materialPrice);
} }
// 套餐(固定商品)现价
// String toastMsg = getTotalAmount(cartGoods, productGroupAmount, numberMap, goodsMap);
// if (StringUtils.isNotEmpty(toastMsg)) {
// shoppingCartGoodsResponseVo.setToastMsg(toastMsg);
// }
} }
// long totalFinalPrice = setMealProducts.stream().mapToLong(product -> product.getFinalPrice() * product.getQty()).sum();
// long totalOriginalPrice = setMealProducts.stream().mapToLong(product -> product.getOriginalPrice() * product.getQty()).sum();
//总原价=促销优惠 - 套餐finalPrice + 套餐原价
// shoppingCartGoodsResponseVo.setOriginalTotalAmount(shoppingCartGoodsResponseVo.getOriginalTotalAmount() - totalFinalPrice + totalOriginalPrice);
//总现价=促销现总价 + 可选商品现总价
// shoppingCartGoodsResponseVo.setTotalAmount(shoppingCartGoodsResponseVo.getTotalAmount() + productGroupTotalAmount);
//总优惠=促销总优惠 + (套餐总原件 - 套餐总finalPrice - 可选商品总售价)
// shoppingCartGoodsResponseVo.setTotalDiscountAmount(shoppingCartGoodsResponseVo.getTotalDiscountAmount() + totalOriginalPrice - totalFinalPrice - productGroupTotalAmount);
} }
...@@ -144,57 +129,6 @@ public class SetMealCalculation { ...@@ -144,57 +129,6 @@ public class SetMealCalculation {
cartGoodsDetailDtos.add(parentCartGoods); cartGoodsDetailDtos.add(parentCartGoods);
} }
} }
// //订单级别,套餐优惠活动
// if (totalDiscountAmount > 0) {
// shoppingCartGoodsDto.getActivityDiscountsDtos().add(getActivityDiscountsDto(-totalDiscountAmount));
// }
}
private ActivityDiscountsDto getActivityDiscountsDto(Integer totalDiscountAmount) {
ActivityDiscountsDto activityDiscountsDto = new ActivityDiscountsDto();
activityDiscountsDto.setActivityCode("setMeal");
activityDiscountsDto.setActivityName("套餐商品优惠");
activityDiscountsDto.setActivityType(211);
activityDiscountsDto.setDiscountAmount(totalDiscountAmount);
return activityDiscountsDto;
}
/**
* 促销活动有份数限制时,计算当前商品行总现价
* 当超出份数限制,提示:该商品限 N 份优惠 超出按照原价计算哦
*
* @param cartGoods
* @param productGroupAmount
* @param numberMap
* @param goodsMap
* @return
*/
private String getTotalAmount(CartGoods cartGoods, long productGroupAmount, Map<String, Integer> numberMap, Map<String, ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Goods> goodsMap) {
if (goodsMap.isEmpty()||goodsMap.get(cartGoods.getGoodsId()).getDiscountAmount() == 0) {
cartGoods.setAmount((cartGoods.getFinalPrice() + productGroupAmount) * cartGoods.getQty());
return "";
}
if (numberMap.get(cartGoods.getGoodsId()) == null) {
int actualGoodsNumber = goodsMap.get(cartGoods.getGoodsId()).getDiscounts().stream().mapToInt(ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Goods.GoodsDiscount::getActualGoodsNumber)
.min().orElse(goodsMap.get(cartGoods.getGoodsId()).getGoodsQuantity());
numberMap.put(cartGoods.getGoodsId(), actualGoodsNumber);
}
// 可优惠数量
Integer number = numberMap.get(cartGoods.getGoodsId());
if (number > 0) {
Long nowPrice = goodsMap.get(cartGoods.getGoodsId()).getNowPrice();
//套餐固定商品价格
long productComboxAmount = cartGoods.getQty() > number ? number * nowPrice + (cartGoods.getQty() - number) * cartGoods.getFinalPrice() : cartGoods.getQty() * nowPrice;
cartGoods.setAmount(productComboxAmount + productGroupAmount * cartGoods.getQty());
//设置剩余优惠数量
numberMap.put(cartGoods.getGoodsId(), number - cartGoods.getQty());
return number - cartGoods.getQty() < 0 ? "该商品限" + goodsMap.get(cartGoods.getGoodsId()).getActualGoodsNumber() + "份优惠 超出按照原价计算哦" : "";
} else {
cartGoods.setAmount((cartGoods.getFinalPrice() + productGroupAmount) * cartGoods.getQty());
return "该商品限" + goodsMap.get(cartGoods.getGoodsId()).getActualGoodsNumber() + "份优惠 超出按照原价计算哦";
}
} }
} }
package cn.freemud.utils;
import java.math.BigDecimal;
public class MoneyUtils {
public static String parseFen2Yuan(Long fen) {
if(null == fen) {
return "0";
}
return new BigDecimal(fen).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP).toPlainString();
}
public static String parseFen2Yuan(Integer fen) {
if(null == fen) {
return "0";
}
return new BigDecimal(fen).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP).toPlainString();
}
public static String parseFen2YuanInt(Long fen) {
if(null == fen) {
return "0";
}
return new BigDecimal(fen).divide(new BigDecimal(100), 0, BigDecimal.ROUND_HALF_UP).toPlainString();
}
public static String parseFen2YuanInt(Integer fen) {
if(null == fen) {
return "0";
}
return new BigDecimal(fen).divide(new BigDecimal(100), 0, BigDecimal.ROUND_HALF_UP).toPlainString();
}
}
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