Commit 6ad191ac by 张跃

Merge remote-tracking branch 'origin/develop' into develop

parents cb408565 e3ad50e7
......@@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>assortment-ordercenter-sdk</artifactId>
<version>2.1.69-RELEASE</version>
<version>1.9.3-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -38,7 +38,7 @@
<dependency>
<groupId>cn.freemud</groupId>
<artifactId>ordercenter-sdk</artifactId>
<version>1.3.59.RELEASE</version>
<version>1.4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
......
......@@ -62,6 +62,7 @@
| 1.8.9-SNAPSHOT | 用户订单和es综合查询接口新增订单业务类型集合 | wuping | 2020-06-01 |
| 1.5.10.RELEASE | 买券订单修改升级RELEASE | wuping | 2020-06-10 |
| 1.9.2-SNAPSHOT| 预约单任务删除 | wuping | 2020-06-05 |
| 1.9.3-SNAPSHOT| 重新升级SDK | 周晓航 | 2021-06-15 |
| 1.5.11.RELEASE | 预约单任务删除RELEASE | wuping | 2020-06-15 |
| 1.5.12.RELEASE | 围餐 | dingkai | 2020-06-16 |
| 1.5.13.RELEASE | 小助手营业额统计 | 梁崇福 | 2020-06-22 |
......
......@@ -3165,6 +3165,9 @@ public class OrderSdkAdapter {
if (null != product.getProductGroupId()) {
extInfo.setProductGroupId(product.getProductGroupId());
}
if (null != product.getIsSendGoods() && product.getIsSendGoods()){
extInfo.setIsSendGoods(true);
}
extInfo.setStapleFood(product.getStapleFood());
extInfo.setOriginalGoodsUid(product.getOriginalGoodsUid());
......
......@@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>assortment-shoppingcart-sdk</artifactId>
<version>1.3.2.RELEASE</version>
<version>2.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -21,3 +21,4 @@
| 1.3.0.RELEASE| 华莱士促销算价| 张志恒 | 2021-05-11 |
| 1.3.1.RELEASE| 核销新增商城渠道| 张志恒 | 2021-05-21 |
| 1.3.2.RELEASE| 麦咖啡一键下单| 徐康 | 2021-06-10 |
| 2.0.0-SNAPSHOT| 重新升级SDK | 周晓航 | 2021-06-15 |
\ No newline at end of file
......@@ -21,6 +21,10 @@ public class RedisKeyConstant {
/**
* 用户购物车在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:";
/**
* 用户购物车在redis的key前缀
......
......@@ -82,6 +82,10 @@ public interface ShoppingCartBaseService {
*/
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 {
return null;
}
default BaseResponse<List<CartGoods>> setCartSendGoodsList(CartParamDto cartParamDto, String trackingNo, long expire, TimeUnit timeUnit) {
return null;
}
/**
* 设置购物车代金券信息
*
......@@ -140,6 +148,14 @@ public interface ShoppingCartBaseService {
default BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) {
return null;
}
/**
* 清除麦咖啡购物车赠送商品行信息
*
* @param cartParamDto
*/
default BaseResponse clearMCCafeSendGoods(CartParamDto cartParamDto, String trackingNo) {
return null;
}
/**
......
......@@ -111,6 +111,21 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
}
@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) {
try {
String redisKey = getShoppingCartCouponCodeKey(cartParamDto);
......@@ -161,6 +176,24 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
}
@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) {
try {
String redisKey = getShoppingCartCouponCodeKey(cartParamDto);
......@@ -227,6 +260,7 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
public BaseResponse clearMCCafe(CartParamDto cartParamDto, String trackingNo) {
try {
redisTemplate.delete(this.getShoppingCartGoodsKey(cartParamDto));
redisTemplate.delete(this.getShoppingCartSendGoodsKey(cartParamDto));
redisTemplate.delete(this.getShoppingCartGoodsAmountKey(cartParamDto));
cartParamDto.setCouponType(SaveCouponType.COUPON.getCode());
redisTemplate.delete(this.getShoppingCartCouponCodeKey(cartParamDto));
......@@ -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
public BaseResponse clearMCCafeCouponByType(CartParamDto cartParamDto,Integer couponType,String trackingNo) {
......@@ -367,6 +412,10 @@ public class ShoppingCartBaseServiceImpl implements ShoppingCartBaseService {
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
......
......@@ -54,7 +54,7 @@
<dependency>
<groupId>cn.freemud</groupId>
<artifactId>assortment-ordercenter-sdk</artifactId>
<version>2.1.69-RELEASE</version>
<version>1.9.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
......
......@@ -2334,6 +2334,9 @@ public class OrderAdapter {
if(StringUtils.isNotBlank(orderProductAddInfoDto.getSplitIndex())) {
productVo.setSplitIndex(orderProductAddInfoDto.getSplitIndex());
}
if(null != orderProductAddInfoDto.getIsSendGoods() && orderProductAddInfoDto.getIsSendGoods()) {
productVo.setIsSendGoods(1);
}
}
productVo.setOriginalPrice(productBean.getPrice());
productVo.setFinalPrice(productBean.getSalePrice());
......@@ -2770,6 +2773,7 @@ public class OrderAdapter {
createOrderProductDemoDto.setClassificationName(cartGoodsDetailDto.getClassificationName());
createOrderProductDemoDto.setSplitIndex(cartGoodsDetailDto.getSplitIndex());
createOrderProductDemoDto.setProductGroupId(cartGoodsDetailDto.getProductGroupId());
createOrderProductDemoDto.setIsSendGoods(cartGoodsDetailDto.getIsSendGoods());
if(CollectionUtils.isNotEmpty(cartGoodsDetailDto.getSpecialExtra())) {
createOrderProductDemoDto.setSpecialAttrs(new ArrayList<>());
cartGoodsDetailDto.getSpecialExtra().stream().forEach(o -> {
......
......@@ -178,6 +178,11 @@ public class ProductVo {
private Boolean isTableware = false;
/**
* 是否餐具商品
*/
private Integer isSendGoods = 0;
/**
* 商品单位
*/
private String unit;
......
......@@ -8,7 +8,7 @@
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>1.3.59.RELEASE</version>
<version>1.4.0-SNAPSHOT</version>
<artifactId>ordercenter-sdk</artifactId>
<dependencies>
......
......@@ -44,6 +44,7 @@
| 1.3.9.RELEASE | 增加支付渠道编号 | 李小二 | 2020-07-08 |
| 1.3.10.RELEASE | OrderExtInfoDto新增parkingAreaName | wuping | 2020-07-13 |
| 1.3.14-SNAPSHOT | es综合查询新增appId查询条件 | wuping | 2020-06-30 |
| 1.4.0-SNAPSHOT | sdk重新升级版本 | 周晓航 | 2021-06-15 |
| 1.3.11.RELEASE | 新增常量类转化 | 张志恒 | 2020-08-04 |
| 1.3.12.RELEASE | 加料商品 | 梁崇福 | 2020-08-24 |
| 1.3.13.RELEASE | 麦咖啡 | 徐康 | 2020-09-07 |
......
......@@ -45,13 +45,13 @@
<dependency>
<groupId>cn.freemud</groupId>
<artifactId>assortment-shoppingcart-sdk</artifactId>
<version>1.3.2.RELEASE</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<!-- 再来一单查询订单信息 -->
<dependency>
<groupId>cn.freemud</groupId>
<artifactId>ordercenter-sdk</artifactId>
<version>1.9.6-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.freemud.application.service.sdk</groupId>-->
......
......@@ -123,18 +123,16 @@ public class ShoppingCartMccafeAdapter {
* @param cartGoods
* @return
*/
public List<ShoppingCartGoodsDto.CartGoodsDetailDto> convertCartGoods2DetailGoodsList(CartGoods cartGoods, List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, Map<String, String> duplicateGoodsMap) {
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = new ArrayList<>();
public ShoppingCartGoodsDto.CartGoodsDetailDto convertCartGoods2DetailGoodsList(CartGoods cartGoods, List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> apportionGoodsList, Map<String, String> duplicateGoodsMap) {
if (StringUtils.isEmpty(cartGoods.getCouponCode()) && GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) {
return cartGoodsDetailDtos;
return null;
} else {
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = convertCartGoods2DetailGoods(cartGoods, apportionGoodsList, duplicateGoodsMap);
if(GoodsTypeEnum.SET_MEAL_GOODS.getGoodsType().equals(cartGoods.getGoodsType())) {
cartGoodsDetailDto.setComboProducts(this.convertComboxGoods2DetailGoods(cartGoods,cartGoodsDetailDto.getTotalDiscountAmount()));
}
cartGoodsDetailDtos.add(cartGoodsDetailDto);
return cartGoodsDetailDto;
}
return cartGoodsDetailDtos;
}
/**
......@@ -202,77 +200,18 @@ public class ShoppingCartMccafeAdapter {
List<ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra> cartGoodsExtras = BeanUtil.convertBeans(cartGoods.getExtra(), ShoppingCartGoodsDto.CartGoodsDetailDto.CartGoodsExtra::new);
cartGoodsDetailDto.setExtraList(cartGoodsExtras);
//61: 单品买M赠N \ 62:买赠 \ 6:买M赠N
if (ObjectUtils.equals(ActivityTypeEnum.TYPE_61.getCode(), cartGoods.getActivityType()) || ObjectUtils.equals(ActivityTypeEnum.TYPE_6.getCode(), cartGoods.getActivityType())
|| ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) {
cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
} else {
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getCartGoodsUid(), a.getCartGoodsUid())).collect(Collectors.toList());
//List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap);
// 设置商品行,优惠活动均摊
setActivityDiscounts(collect, cartGoodsDetailDto, duplicateGoodsMap);
}
}
return cartGoodsDetailDto;
}
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 (ObjectUtils.equals(ActivityTypeEnum.TYPE_61.getCode(), cartGoods.getActivityType()) || ObjectUtils.equals(ActivityTypeEnum.TYPE_6.getCode(), cartGoods.getActivityType())
// || ObjectUtils.equals(ActivityTypeEnum.TYPE_62.getCode(), cartGoods.getActivityType())) {
// cartGoodsDetailDto.setTotalDiscountAmount(cartGoods.getOriginalAmount().intValue() - cartGoods.getAmount().intValue());
// } else {
// List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getCartGoodsUid(), a.getCartGoodsUid())).collect(Collectors.toList());
// //List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.ApportionGoods> collect = apportionGoodsList.stream().filter(a -> ObjectUtils.equals(cartGoods.getSkuId(), a.getGoodsId()) || ObjectUtils.equals(cartGoods.getSpuId(), a.getGoodsId())).collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(collect)) {
// setTotalDiscountAndSalePrice(collect, cartGoodsDetailDto, duplicateGoodsMap);
// // 设置商品行,优惠活动均摊
// setActivityDiscounts(collect, cartGoodsDetailDto, duplicateGoodsMap);
// }
// }
//小料
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;
}
......
......@@ -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")
......
......@@ -169,6 +169,7 @@ public class ActivityCalculationDiscountResponseDto {
* 已经优惠金额
*/
private Long alreadyDiscountAmount;
private Integer alreadyDiscountThresholdAmount;
private Integer activitySubType;
private List<SendGoods> sendGoods;
}
......@@ -256,6 +257,10 @@ public class ActivityCalculationDiscountResponseDto {
*/
private String goodsId;
/**
* 0 原购物车商品 1 赠送商品 2 换购商品
*/
private Integer cartGoodType;
/**
* 商品数量
*/
private Integer goodsQuantity;
......@@ -573,6 +578,8 @@ public class ActivityCalculationDiscountResponseDto {
private String goodsId;
private String goodsName;
private Integer sendNumber;
private String picture;
private Integer originalPrice;
}
}
......
......@@ -43,7 +43,7 @@ public class ActivityList {
private String deduct;
//最高扣减金额
private String maxDeduct;
//最高扣减金额
//已减
private String alreadyDecut;
//还差
private String missing;
......@@ -53,10 +53,19 @@ public class ActivityList {
private String agianDeduct;
private List<SendGoods> sends;
private List<McCafeSendGoods> mcCafeSendGoodsList;
@Data
public static class SendGoods {
private Integer qty;
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 {
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获取缓存中购物车信息
*
......@@ -169,6 +174,12 @@ public class AssortmentSdkService {
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设置缓存中购物车信息
*
......@@ -200,6 +211,24 @@ public class AssortmentSdkService {
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设置缓存中购物车代金券
*
......@@ -208,7 +237,7 @@ public class AssortmentSdkService {
* @param useId
* @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);
cartParamDto.setCouponCode(couponCode);
cartParamDto.setCouponType(type);
......@@ -217,7 +246,7 @@ public class AssortmentSdkService {
return null;
}
return JSONArray.parseArray(JSONObject.toJSONString(baseResponse.getResult()), CartGoods.class);
return baseResponse.getResult();
}
/**
......@@ -337,6 +366,22 @@ public class AssortmentSdkService {
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更新商品行数量信息
*
......
......@@ -30,6 +30,8 @@ import cn.freemud.service.impl.mcoffee.entity.*;
import cn.freemud.service.thirdparty.CustomerApplicationClient;
import cn.freemud.utils.BeanUtil;
import cn.freemud.service.thirdparty.ProductClient;
import cn.freemud.utils.ExceptionUtils;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -86,6 +88,7 @@ import static com.freemud.sdk.api.assortment.shoppingcart.constant.ShoppingCartC
*/
@Service
@Slf4j
public class ShoppingCartMCoffeeServiceImpl {
@Autowired
......@@ -152,7 +155,6 @@ public class ShoppingCartMCoffeeServiceImpl {
String couponCode = addShoppingCartGoodsRequestVo.getCouponCode();
String spuId2 = spuId;
MCoffeeProductIdsVo vo =new MCoffeeProductIdsVo();
List<Long> productIds = new ArrayList<>();
productIds.add(Long.parseLong(goodsId));
......@@ -189,7 +191,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);
setClassificationAndPrice(addCartGoods, productBeanListSpuClass);
......@@ -228,7 +230,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动等价格计算
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);
}else{
......@@ -236,7 +238,7 @@ public class ShoppingCartMCoffeeServiceImpl {
oldCartGoodsList.add(addCartGoods);
// 促销活动的优惠金额计算
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);
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, oldCartGoodsList, null, tableNumber, this.shoppingCartBaseService);
newCartGoods = oldCartGoodsList;
}
......@@ -246,6 +248,52 @@ public class ShoppingCartMCoffeeServiceImpl {
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){
// 参数校验
if (CollectionUtils.isEmpty(requestVo.getGoodsInfos())) {
......@@ -313,22 +361,6 @@ public class ShoppingCartMCoffeeServiceImpl {
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) {
if (operationType != null && operationType == 1 && StringUtils.isBlank(couponCode)) {
......@@ -463,6 +495,7 @@ public class ShoppingCartMCoffeeServiceImpl {
updateGoodsQtyRequestVo.setVersion(requestVo.getVersion());
updateGoodsQtyRequestVo.setShopId(requestVo.getShopId());
updateGoodsQtyRequestVo.setPartnerId(requestVo.getPartnerId());
updateGoodsQtyRequestVo.setOrderType(requestVo.getOrderType());
updateGoodsQtyRequestVo.setQtyInfoList(requestVo.getQtyInfoList());
baseResponse = this.batchUpdateGoodsQty(updateGoodsQtyRequestVo);
//批量更新失败,直接返回错误
......@@ -482,6 +515,7 @@ public class ShoppingCartMCoffeeServiceImpl {
addGoodsRequestVo.setShopId(requestVo.getShopId());
addGoodsRequestVo.setOrderType(requestVo.getOrderType());
addGoodsRequestVo.setPartnerId(requestVo.getPartnerId());
addGoodsRequestVo.setOrderType(requestVo.getOrderType());
addGoodsRequestVo.setGoodsInfos(requestVo.getGoodsInfos());
baseResponse = this.addBatchGoods(addGoodsRequestVo);
//批量新增失败,直接返回错误
......@@ -584,6 +618,10 @@ public class ShoppingCartMCoffeeServiceImpl {
// 先验证商品是否存在
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;
String skuId = "";
Integer finalQty = qty;
......@@ -603,7 +641,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null);
// 促销活动的优惠金额计算
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);
}
if (cartGoodsUid.equals(cartGoods_.getCartGoodsUid())) {
......@@ -657,7 +695,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = getCoupon(couponCode, null, cartGoodsList,freightCouponCode,null);
// 促销活动的优惠金额计算
calculationService.updateShoppingCartGoodsDiscount(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), menuType, receiveId, couponCode,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null);
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,null, cartSendGoodsList);
//把月卡放到最后
if (CollectionUtils.isNotEmpty(cartGoodsList)) {
......@@ -708,6 +746,9 @@ public class ShoppingCartMCoffeeServiceImpl {
// 获取购物车商品
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, sessionId, "", shoppingCartBaseService);
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;
// 如果购物车商品不为空, 则check购物车中所有商品
if (CollectionUtils.isNotEmpty(cartGoodsList)) {
......@@ -721,14 +762,13 @@ public class ShoppingCartMCoffeeServiceImpl {
monthCardProduct = goods;
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) {
temList.add(monthCardProduct);
cartGoodsList.add(monthCardProduct);
}
cartGoodsList = temList;
if (CollectionUtils.isNotEmpty(cartGoodsList)) {
int size = cartGoodsList.size();
for(int i=0;i<size;i++) {
......@@ -800,7 +840,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算
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的虚拟商品,重新保存一次购物车
if(CollectionUtils.isNotEmpty(cartGoodsList) && cartGoodsList.stream().anyMatch(cartGoods -> cartGoods.getSkuId().equals("9999"))){
......@@ -857,7 +897,7 @@ public class ShoppingCartMCoffeeServiceImpl {
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,
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,payCardPrice);
cartGoodsList, coupons, new ArrayList<>(), shoppingCartGoodsResponseVo,payCardPrice, null);
String moneyCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(),
requestVo.getStoreId(), requestVo.getUserId(), shoppingCartBaseService,SaveCouponType.COUPON.getCode());
String deliveryFeeCoupon = assortmentSdkService.getShoppingCartCoupon(requestVo.getPartnerId(),requestVo.getStoreId(),requestVo.getUserId(),shoppingCartBaseService,SaveCouponType.FREIGHT_COUPON.getCode());
......@@ -973,6 +1013,8 @@ public class ShoppingCartMCoffeeServiceImpl {
// 获取购物车商品
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, tableNumber, shoppingCartBaseService);
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)) {
throw new ServiceException(ResponseResult.SHOPPING_CART_GETINFO_INVAILD);
}
......@@ -995,6 +1037,24 @@ public class ShoppingCartMCoffeeServiceImpl {
}
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());
//添加商品为加价购商品
......@@ -1024,7 +1084,7 @@ public class ShoppingCartMCoffeeServiceImpl {
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList = shoppingCartInfoRequestVo.getSendGoods();
// 促销活动的优惠金额计算
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虚拟商品
cartGoodsList = cartGoodsList.stream().filter(goods-> !StringUtils.equals("9999",goods.getSkuId())).collect(Collectors.toList());
......@@ -1033,7 +1093,7 @@ public class ShoppingCartMCoffeeServiceImpl {
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())) {
......@@ -1144,7 +1204,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算
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)) {
assortmentSdkService.setShoppingCart(partnerId, toStoreId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
......@@ -1230,7 +1290,7 @@ public class ShoppingCartMCoffeeServiceImpl {
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, sessionId, "", shoppingCartBaseService);
// 促销活动的优惠金额计算
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);
//再来一单清除配送费
......@@ -1542,69 +1602,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) {
if (StringUtils.isEmpty(shoppingCartGoodsResponseVo.getToastMsg())) {
......@@ -1743,7 +1740,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 skuId = addShoppingCartGoodsRequestVo.getSkuId();
// String goodsId = StringUtils.isEmpty(skuId) ? spuId : skuId;
......@@ -2168,7 +2165,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// }
return CartResponseUtil.success(checkCartRequest);
} 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().setToastMsg(ShoppingCartConstant.SHOPPING_CART_INVALIAD_GOODS);
return CartResponseUtil.error(e.getMessage(),checkCartRequest);
......@@ -2267,7 +2264,7 @@ public class ShoppingCartMCoffeeServiceImpl {
// 促销活动的优惠金额计算
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();
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;
import cn.freemud.service.CommonService;
import cn.freemud.service.impl.ItemServiceImpl;
import cn.freemud.service.thirdparty.ActivityClient;
import cn.freemud.utils.ExceptionUtils;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.PropertyConvertUtil;
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.membercenter.request.QueryReceiveAddressRequest;
import com.freemud.application.sdk.api.membercenter.response.QueryReceiveAddressResponse;
......@@ -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.service.StoreCenterService;
import com.freemud.sdk.api.assortment.shoppingcart.enums.BusinessTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -55,6 +59,7 @@ import java.util.stream.Collectors;
*/
@Service
@Slf4j
public class CalculationServiceImpl {
......@@ -67,11 +72,8 @@ public class CalculationServiceImpl {
@Autowired
private ActivityClient activityClient;
@Autowired
private ActivityAdapter activityAdapter;
@Autowired
private ItemServiceImpl itemService;
@Autowired
private TimeSaleCalculation timeSaleCalculation;
@Autowired
......@@ -85,6 +87,10 @@ public class CalculationServiceImpl {
private MaterialCalculation materialCalculation;
@Autowired
private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter;
@Autowired
private BuySendCalculation buySendCalculation;
@Autowired
private FreightCalculation freightCalculation;
/**
* 更新购物车行优惠信息
......@@ -93,7 +99,7 @@ public class CalculationServiceImpl {
boolean isMember, String menuType, String receiveId,String couponCode,
List<CartGoods> cartGoodsList, List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons,
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo,
Long payCardFee) {
Long payCardFee, List<CartGoods> cartSendGoodsList) {
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, menuType);
......@@ -115,7 +121,14 @@ public class CalculationServiceImpl {
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;
}
......@@ -153,11 +166,12 @@ public class CalculationServiceImpl {
discountRequest.setDistributionFee(deliveryAmount);
discountRequest.setIsMember(isMember);
discountRequest.setPayCardFee(payCardFee);
discountRequest.setProductChannel(orderType == 1 ? "saasdelivery" : "saas");
ActivityCalculationDiscountResponseDto activityCalculationDiscountResponseDto;
try {
activityCalculationDiscountResponseDto = activityClient.calculationDiscountSharing(discountRequest);
} 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);
}
//优惠券互斥
......@@ -168,11 +182,46 @@ public class CalculationServiceImpl {
if (activityCalculationDiscountResponseDto == null || !StringUtils.equals(activityCalculationDiscountResponseDto.getStatusCode(), ResponseCodeConstant.RESPONSE_SUCCESS_STR)) {
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<ShareDiscountActivityDto> shareDiscountActivityDtoList = CollectionUtils.isEmpty(shoppingCartGoodsDto.getShareDiscountActivityDtos()) ? new ArrayList<>() : shoppingCartGoodsDto.getShareDiscountActivityDtos();
......@@ -198,13 +247,16 @@ public class CalculationServiceImpl {
calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getApportionGoods();
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) -> {
duplicateGoodsMap.put(goodsId,String.format("%s,0", count));
cartGoodsList.stream().filter(cartGoods -> !StringUtils.equals(cartGoods.getSkuId(),"9999"))
.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++) {
CartGoods cartGoods = cartGoodsList.get(i);
List<ShoppingCartGoodsDto.CartGoodsDetailDto> cartGoodsDetailDtos = shoppingCartMccafeAdapter.convertCartGoods2DetailGoodsList(cartGoods, apportionGoodsList,duplicateGoodsMap);
cartGoodsDetailDtoList.addAll(cartGoodsDetailDtos);
ShoppingCartGoodsDto.CartGoodsDetailDto cartGoodsDetailDto = shoppingCartMccafeAdapter.convertCartGoods2DetailGoodsList(cartGoods, apportionGoodsList,duplicateGoodsMap);
if(null != cartGoodsDetailDto) {
cartGoodsDetailDtoList.add(cartGoodsDetailDto);
}
}
List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.Discount> discounts = calculationDiscountResult == null ? new ArrayList<>() : calculationDiscountResult.getDiscounts();
List<ActivityDiscountsDto> activityDiscountsDtos = shoppingCartGoodsDto.getActivityDiscountsDtos() == null ? new ArrayList<>() : shoppingCartGoodsDto.getActivityDiscountsDtos();
......@@ -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());
......@@ -268,18 +307,12 @@ public class CalculationServiceImpl {
//限时特价
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);
setMealCalculation.updateShoppingCartGoodsApportion(shoppingCartGoodsResponseVo, calculationDiscountResult, shoppingCartGoodsDto);
buySendCalculation.updateBuySendGoods(calculationDiscountResult, shoppingCartGoodsDto, cartSendGoodsList);
}
......
......@@ -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.parseFen2Yuan(activityPrompt.getAlreadyDiscountThresholdAmount()));
activityList.setAlreadyDecut(MoneyUtils.parseFen2Yuan(activityPrompt.getAlreadyDiscountAmount()));
activityList.setDeduct(MoneyUtils.parseFen2Yuan(activityPrompt.getAlreadyDiscountAmount()));
activityList.setAgianDeduct(MoneyUtils.parseFen2Yuan(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 {
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 {
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();
}
}
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