Commit 2f55378a by ping.wu

新增麦咖啡购物车

parent 9acc200b
package cn.freemud.service.impl.mcoffee;
import cn.freemud.adapter.ActivityAdapter;
import cn.freemud.adapter.CouponAdapter;
import cn.freemud.adapter.ShoppingCartConvertAdapter;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.constant.ResponseCodeConstant;
......@@ -77,26 +78,25 @@ public class ShoppingCartMCoffeeServiceImpl {
// private long goodsCacheSeconds;
@Autowired
private ActivityAdapter activityAdapter;
// @Autowired
// @Autowired
// private StoreItemClient storeItemClient;
@Autowired
private ActivityClient activityClient;
@Autowired
private ItemService itemService;
// @Autowired
// @Autowired
// private ShoppingCartNewBaseService shoppingCartNewBaseService;
@Autowired
private ShoppingCartBaseServiceImpl shoppingCartBaseService;
@Autowired
private CouponService couponService;
// @Autowired
// @Autowired
// private ShoppingCartConvertAdapter shoppingCartConvertAdapter;
@Autowired
private FullSubtractionActivityServiceImpl fullSubtractionActivityService;
// @Autowired
// @Autowired
// private BuriedPointService buriedPointService;
// @Autowired
// private OpenPlatformClient openPlatformClient;
......@@ -104,17 +104,17 @@ public class ShoppingCartMCoffeeServiceImpl {
private StockClient stockClient;
@Autowired
private AssortmentSdkService assortmentSdkService;
// @Autowired
// private CouponAdapter couponAdapter;
@Autowired
private CouponAdapter couponAdapter;
@Autowired
private CustomerApplicationClient customerApplicationClient;
// @Autowired
// @Autowired
// private AssortmentCustomerInfoManager customerInfoManager;
// @Autowired
// private PaymentNewService paymentNewService;
@Autowired
private MemberCenterService memberCenterService;
// @Autowired
// @Autowired
// private AssortmentOpenPlatformPartnerStoreDeliveryConfigManager deliveryConfigManager;
// @Autowired
// private StoreServiceImpl storeService;
......@@ -135,10 +135,10 @@ public class ShoppingCartMCoffeeServiceImpl {
*/
public BaseResponse addGoods(AddShoppingCartGoodsRequestVo addShoppingCartGoodsRequestVo) {
// TODO: 2020/7/21 参数校验
if (StringUtils.isEmpty(addShoppingCartGoodsRequestVo.getShopId())){
if (StringUtils.isEmpty(addShoppingCartGoodsRequestVo.getShopId())) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_SHOP_ID_NOT_EMPTY);
}
if (addShoppingCartGoodsRequestVo.getQty() != null && addShoppingCartGoodsRequestVo.getQty() < 0){
if (addShoppingCartGoodsRequestVo.getQty() != null && addShoppingCartGoodsRequestVo.getQty() < 0) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_ADD_ERROR);
}
String sessionId = addShoppingCartGoodsRequestVo.getSessionId();
......@@ -177,12 +177,12 @@ public class ShoppingCartMCoffeeServiceImpl {
productIds.add(Long.parseLong(goodsId));
// 获取商品详细信息
List<ProductBeanDTO> productBeanListSpuClass = assortmentSdkService.getProductsInfoSdk(partnerId, storeId
, Collections.singletonList(spuId2),menuType, this.shoppingCartBaseService);
, Collections.singletonList(spuId2), menuType, this.shoppingCartBaseService);
//查询多个商品库存信息
ShoppingCartConvertAdapter.setClassification(addCartGoods, productBeanListSpuClass);
Integer checkQty = this.checkSkuQty(oldCartGoodsList, addCartGoods);
queryManyGoodsStocks(partnerId,storeId,menuType, productIds, productBeanListSpuClass, skuId, checkQty);
queryManyGoodsStocks(partnerId, storeId, menuType, productIds, productBeanListSpuClass, skuId, checkQty);
// 如果购物车中有商品券,则当前添加的商品是特价商品时,需要提示“已选商品券,与其他优惠商品不同享,商品将恢复原价”
boolean haveCouponProduct = oldCartGoodsList.parallelStream().anyMatch(k -> k.getCartGoodsUid().startsWith(CommonsConstant.COUPON_PREFIX));
......@@ -193,22 +193,24 @@ public class ShoppingCartMCoffeeServiceImpl {
// TODO: 2020/7/21 促销活动等价格计算
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo);
// 获取优惠信息
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
=getCalculationDiscountResult(menuType,partnerId,storeId,userId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(), oldCartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount);
// 获取优惠信息=
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult =
// getCalculationDiscountResult(menuType,partnerId,storeId,userId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(), oldCartGoodsList,new ArrayList<>(),new ArrayList<>(),null,deliveryAmount);
getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), oldCartGoodsList, new ArrayList<>(), new ArrayList<>(), BusinessTypeEnum.getByType(menuType).getCode(), deliveryAmount);
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, addShoppingCartGoodsRequestVo.getOrderType());
// 促销活动的优惠金额计算
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, oldCartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto,addShoppingCartGoodsRequestVo.getMenuType(),deliveryAmount);
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, oldCartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto, addShoppingCartGoodsRequestVo.getMenuType(), deliveryAmount);
// TODO: 2020/7/21 购物车数据更新
List<CartGoods> newCartGoods = new ArrayList<>();
newCartGoods.add(addCartGoods);
// 校验合法性,更新缓存中购物车信息
updateCartGoodsLegal(partnerId,storeId,orderType,tableNumber,menuType, userId, newCartGoods,shoppingCartGoodsResponseVo, oldCartGoodsList);
updateCartGoodsLegal(partnerId, storeId, orderType, tableNumber, menuType, userId, newCartGoods, shoppingCartGoodsResponseVo, oldCartGoodsList);
// TODO: 2020/7/21 返回购物车数据
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, calculationDiscountResult, oldCartGoodsList, null, partnerId, storeId, userId, ShoppingCartConstant.ADD_AND_UPDATE, null);
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, oldCartGoodsList, null, ShoppingCartConstant.ADD_AND_UPDATE, null);
// //埋点添加购物车行为
// this.buriedPointShoppingCart(addShoppingCartGoodsRequestVo, spuId, productName);
......@@ -222,10 +224,10 @@ public class ShoppingCartMCoffeeServiceImpl {
* @return
*/
public BaseResponse updateGoodsQty(UpdateShoppingCartGoodsQtyRequestVo updateShoppingCartGoodsQtyRequestVo) {
if (StringUtils.isEmpty(updateShoppingCartGoodsQtyRequestVo.getShopId())){
if (StringUtils.isEmpty(updateShoppingCartGoodsQtyRequestVo.getShopId())) {
throw new ServiceException(ResponseResult.SHOPPING_CART_SHOP_ID_NOT_EMPTY);
}
if (updateShoppingCartGoodsQtyRequestVo.getQty() != null && updateShoppingCartGoodsQtyRequestVo.getQty() < 0){
if (updateShoppingCartGoodsQtyRequestVo.getQty() != null && updateShoppingCartGoodsQtyRequestVo.getQty() < 0) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_ADD_ERROR);
}
ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo = new ShoppingCartGoodsResponseVo();
......@@ -238,17 +240,15 @@ public class ShoppingCartMCoffeeServiceImpl {
String cartGoodsUid = updateShoppingCartGoodsQtyRequestVo.getCartGoodsUid();
Integer qty = updateShoppingCartGoodsQtyRequestVo.getQty();
String menuType = updateShoppingCartGoodsQtyRequestVo.getMenuType();
Integer orderType=updateShoppingCartGoodsQtyRequestVo.getOrderType();
Integer orderType = updateShoppingCartGoodsQtyRequestVo.getOrderType();
String receiveId = updateShoppingCartGoodsQtyRequestVo.getReceiveId();
// 先验证商品是否存在
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId,userId,null,null,shoppingCartBaseService);
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, null, shoppingCartBaseService);
CartGoods cartGoods = null;
for (CartGoods cartGoods_ : cartGoodsList){
if(cartGoodsUid.equals(cartGoods_.getCartGoodsUid())){
cartGoods =cartGoods_;
// 检查购物车商品库存数量
checkUpdateStock(partnerId,storeId,menuType,qty,cartGoods);
for (CartGoods cartGoods_ : cartGoodsList) {
if (cartGoodsUid.equals(cartGoods_.getCartGoodsUid())) {
cartGoods = cartGoods_;
cartGoods_.setQty(qty);
break;
}
......@@ -258,25 +258,27 @@ public class ShoppingCartMCoffeeServiceImpl {
throw new ServiceException(ResponseResult.SHOPPING_CART_UPDATE_ERROR);
}
// 检查购物车商品库存数量
checkUpdateStock(partnerId, storeId, menuType, qty, cartGoods);
// 更新购物车中数量
// List<CartGoods> cartGoodsList = assortmentSdkService.updateGoodsQtyBySdk(partnerId, userId, storeId, cartGoodsUid, qty<0?0:qty, "", shoppingCartBaseService);
// check购物车中所有商品
CheckCartRequest checkCartRequest = assortmentSdkService.checkShoppingCartSdk(cartGoodsList, partnerId, storeId, shoppingCartGoodsResponseVo, updateShoppingCartGoodsQtyRequestVo.getOrderType(), "", updateShoppingCartGoodsQtyRequestVo.getMenuType(), shoppingCartBaseService);
if (checkCartRequest.getShoppingCartGoodsResponseVo() != null) {
shoppingCartGoodsResponseVo.setChanged(checkCartRequest.getShoppingCartGoodsResponseVo().getChanged());
shoppingCartGoodsResponseVo.setToastMsg(checkCartRequest.getShoppingCartGoodsResponseVo().getToastMsg());
}
// if (checkCartRequest.getShoppingCartGoodsResponseVo() != null) {
// shoppingCartGoodsResponseVo.setChanged(checkCartRequest.getShoppingCartGoodsResponseVo().getChanged());
// shoppingCartGoodsResponseVo.setToastMsg(checkCartRequest.getShoppingCartGoodsResponseVo().getToastMsg());
// }
cartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class);
// 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, updateShoppingCartGoodsQtyRequestVo.getSessionId(), "", shoppingCartBaseService);
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo);
// 获取优惠信息
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
=getCalculationDiscountResult(menuType,partnerId,storeId,userId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(),cartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount);
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult =
// getCalculationDiscountResult(menuType,partnerId,storeId,userId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(),cartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount);
getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), cartGoodsList, new ArrayList<>(), new ArrayList<>(), BusinessTypeEnum.getByType(menuType).getCode(), deliveryAmount);
if (calculationDiscountResult == null) {
shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
}
......@@ -284,11 +286,11 @@ public class ShoppingCartMCoffeeServiceImpl {
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, updateShoppingCartGoodsQtyRequestVo.getOrderType());
// 促销活动的优惠金额计算
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto,updateShoppingCartGoodsQtyRequestVo.getMenuType(),deliveryAmount);
updateShoppingCartGoodsDiscount(null, activityQueryDto, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo, null, userLoginInfoDto, menuType, deliveryAmount);
//设置更新响应信息
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), partnerId, storeId, userId, ShoppingCartConstant.ADD_AND_UPDATE, null);
return ResponseUtil.success();
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.ADD_AND_UPDATE, null);
return ResponseUtil.success(shoppingCartGoodsResponseVo);
}
/**
......@@ -302,7 +304,7 @@ public class ShoppingCartMCoffeeServiceImpl {
//查询商品信息
List<String> pids = new ArrayList<>();
pids.add(cartGoods.getGoodsId());
Map<String, GetProductsVo> products = itemService.getProducts(pids, partnerId, storeId,BusinessTypeEnum.getByType(menuType).getCode());
Map<String, GetProductsVo> products = itemService.getProducts(pids, partnerId, storeId, BusinessTypeEnum.getByType(menuType).getCode());
GetProductsVo getProductsVo = products.get(cartGoods.getGoodsId());
// 商品没有库存限制
......@@ -336,65 +338,65 @@ public class ShoppingCartMCoffeeServiceImpl {
* @return
*/
public BaseResponse getGoodsList(ShoppingCartInfoRequestVo shoppingCartInfoRequestVo) {
// if (StringUtils.isEmpty(shoppingCartInfoRequestVo.getShopId())){
// throw new ServiceException(ResponseResult.SHOPPING_CART_SHOP_ID_NOT_EMPTY);
// }
// ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo = new ShoppingCartGoodsResponseVo();
// // 获取用户信息
// CustomerInfoVo assortmentCustomerInfoVo = getCustomerInfoVo(shoppingCartInfoRequestVo.getSessionId());
// UserLoginInfoDto userLoginInfoDto = convert2UserLoginInfoDto(assortmentCustomerInfoVo);
// String userId = userLoginInfoDto.getMemberId();
// String partnerId = shoppingCartInfoRequestVo.getPartnerId();
// String storeId = shoppingCartInfoRequestVo.getShopId();
// String appId = shoppingCartInfoRequestVo.getAppId();
// String couponCode = shoppingCartInfoRequestVo.getCouponCode();
// String activityCode = shoppingCartInfoRequestVo.getActivityCode();
// String menuType = shoppingCartInfoRequestVo.getMenuType();
// Integer orderType = shoppingCartInfoRequestVo.getOrderType();
// String receiveId = shoppingCartInfoRequestVo.getReceiveId();
//
// // 获取购物车商品
// List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, "", shoppingCartBaseService);
// // 如果购物车商品不为空, 则check购物车中所有商品
// if (CollectionUtils.isNotEmpty(cartGoodsList)){
// CheckCartRequest checkCartRequest = assortmentSdkService.checkShoppingCartSdk(cartGoodsList, partnerId, storeId, shoppingCartGoodsResponseVo, shoppingCartInfoRequestVo.getOrderType(), "", shoppingCartInfoRequestVo.getMenuType() ,shoppingCartBaseService);
// if (checkCartRequest.getShoppingCartGoodsResponseVo() != null) {
// shoppingCartGoodsResponseVo.setChanged(checkCartRequest.getShoppingCartGoodsResponseVo().getChanged());
// shoppingCartGoodsResponseVo.setToastMsg(checkCartRequest.getShoppingCartGoodsResponseVo().getToastMsg());
// }
// cartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class);
// // 重新存储最新购物车
// assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, assortmentCustomerInfoVo.getSessionId(), "", this.shoppingCartBaseService);
// }
// List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = new ArrayList<>();
// // 当couponCode不为空时,需参与价格计算
// if (StringUtils.isNotEmpty(couponCode)) {
// ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon coupon = new ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon();
// coupon.setCode(couponCode);
// coupon.setActivityCode(activityCode);
// coupons.add(coupon);
// }
// Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo);
//
// // 获取优惠信息
// ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult = getCalculationDiscountResult(menuType,partnerId,storeId,userId,appId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(),cartGoodsList,coupons,null,shoppingCartInfoRequestVo.getReceiveId(),deliveryAmount);
//
// if (calculationDiscountResult == null) {
// shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
// }
//
// ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType());
//
// CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto);
// // 促销活动的优惠金额计算
// this.updateShoppingCartGoodsDiscount(couponPromotionVO, activityQueryDto, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo, shoppingCartInfoRequestVo, userLoginInfoDto,shoppingCartInfoRequestVo.getMenuType(),deliveryAmount);
// //设置更新响应信息
// setAddAndUpdateResponse(shoppingCartGoodsResponseVo, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), partnerId, storeId, userId, ShoppingCartConstant.QUERY_INFO, shoppingCartInfoRequestVo);
// // 在原价、现价、折扣价上增加第一次使用会员卡的费用
// this.addNeedCardAmount(shoppingCartInfoRequestVo, shoppingCartGoodsResponseVo);
//
// return ResponseUtil.success(shoppingCartGoodsResponseVo);
return ResponseUtil.success();
if (StringUtils.isEmpty(shoppingCartInfoRequestVo.getShopId())) {
throw new ServiceException(ResponseResult.SHOPPING_CART_SHOP_ID_NOT_EMPTY);
}
ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo = new ShoppingCartGoodsResponseVo();
// 获取用户信息
CustomerInfoVo assortmentCustomerInfoVo = getCustomerInfoVo(shoppingCartInfoRequestVo.getSessionId());
UserLoginInfoDto userLoginInfoDto = convert2UserLoginInfoDto(assortmentCustomerInfoVo);
String userId = userLoginInfoDto.getMemberId();
String partnerId = shoppingCartInfoRequestVo.getPartnerId();
String storeId = shoppingCartInfoRequestVo.getShopId();
String appId = shoppingCartInfoRequestVo.getAppId();
String couponCode = shoppingCartInfoRequestVo.getCouponCode();
String activityCode = shoppingCartInfoRequestVo.getActivityCode();
String menuType = shoppingCartInfoRequestVo.getMenuType();
Integer orderType = shoppingCartInfoRequestVo.getOrderType();
String receiveId = shoppingCartInfoRequestVo.getReceiveId();
// 获取购物车商品
List<CartGoods> cartGoodsList = assortmentSdkService.getShoppingCart(partnerId, storeId, userId, null, "", shoppingCartBaseService);
// 如果购物车商品不为空, 则check购物车中所有商品
if (CollectionUtils.isNotEmpty(cartGoodsList)) {
CheckCartRequest checkCartRequest = assortmentSdkService.checkShoppingCartSdk(cartGoodsList, partnerId, storeId, shoppingCartGoodsResponseVo, shoppingCartInfoRequestVo.getOrderType(), "", shoppingCartInfoRequestVo.getMenuType(), shoppingCartBaseService);
if (checkCartRequest.getShoppingCartGoodsResponseVo() != null) {
shoppingCartGoodsResponseVo.setChanged(checkCartRequest.getShoppingCartGoodsResponseVo().getChanged());
shoppingCartGoodsResponseVo.setToastMsg(checkCartRequest.getShoppingCartGoodsResponseVo().getToastMsg());
}
cartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class);
// 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, assortmentCustomerInfoVo.getSessionId(), "", this.shoppingCartBaseService);
}
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons = new ArrayList<>();
// 当couponCode不为空时,需参与价格计算
if (StringUtils.isNotEmpty(couponCode)) {
ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon coupon = new ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon();
coupon.setCode(couponCode);
coupon.setActivityCode(activityCode);
coupons.add(coupon);
}
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo);
// 获取优惠信息
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult =
// getCalculationDiscountResult(menuType,partnerId,storeId,userId,appId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(),cartGoodsList,coupons,null,shoppingCartInfoRequestVo.getReceiveId(),deliveryAmount);
getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType, assortmentCustomerInfoVo.isMemberPaid(), cartGoodsList, new ArrayList<>(), new ArrayList<>(), BusinessTypeEnum.getByType(menuType).getCode(), deliveryAmount);
if (calculationDiscountResult == null) {
shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
}
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType());
CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto);
// 促销活动的优惠金额计算
this.updateShoppingCartGoodsDiscount(couponPromotionVO, activityQueryDto, calculationDiscountResult, cartGoodsList, shoppingCartGoodsResponseVo, shoppingCartInfoRequestVo, userLoginInfoDto, shoppingCartInfoRequestVo.getMenuType(), deliveryAmount);
//设置更新响应信息
setAddAndUpdateResponse(shoppingCartGoodsResponseVo, cartGoodsList, shoppingCartGoodsResponseVo.getToastMsg(), ShoppingCartConstant.QUERY_INFO, shoppingCartInfoRequestVo);
// 在原价、现价、折扣价上增加第一次使用会员卡的费用
this.addNeedCardAmount(shoppingCartInfoRequestVo, shoppingCartGoodsResponseVo);
return ResponseUtil.success(shoppingCartGoodsResponseVo);
}
/**
......@@ -437,14 +439,14 @@ public class ShoppingCartMCoffeeServiceImpl {
return ResponseUtil.error(ResponseResult.PARAMETER_MISSING, "appId不能为空");
}
String userId = shoppingCartClearRequestVo.getUserId();
if (StringUtils.isEmpty(userId)){
CustomerInfoVo userLoginInfoDto =getCustomerInfoVo(shoppingCartClearRequestVo.getSessionId());
userId=userLoginInfoDto.getMemberId();
if (StringUtils.isEmpty(userId)) {
CustomerInfoVo userLoginInfoDto = getCustomerInfoVo(shoppingCartClearRequestVo.getSessionId());
userId = userLoginInfoDto.getMemberId();
}
String partnerId = shoppingCartClearRequestVo.getPartnerId();
String storeId = shoppingCartClearRequestVo.getShopId();
com.freemud.sdk.api.assortment.shoppingcart.domain.CartParamDto cartParamDto = assortmentSdkService.getCartParamDto(partnerId, storeId, userId);
shoppingCartBaseService.clear(cartParamDto,LogThreadLocal.getTrackingNo());
shoppingCartBaseService.clear(cartParamDto, LogThreadLocal.getTrackingNo());
if (ObjectUtils.equals(shoppingCartClearRequestVo.getOperationType(), OperationTypeEnum.PAY_SUCCESS.getOperationType())) {
return ResponseUtil.success();
}
......@@ -628,9 +630,13 @@ public class ShoppingCartMCoffeeServiceImpl {
* @return
*/
public ActivityCalculationDiscountResponseDto.CalculationDiscountResult getActivityCalculationDiscountResponse(
String partnerId, String storeId, String userId, String appId, Integer orderType,boolean isMember, List<CartGoods> cartGoodsList,
String partnerId, String storeId, String userId, String appId, Integer orderType, boolean isMember, List<CartGoods> cartGoodsList,
List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons,
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList,String menuType,Long distributionFee) {
List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList, String menuType, Long distributionFee) {
if (BusinessTypeEnum.SAAS_DELIVERY.getCode().equals(menuType)) {
distributionFee = null;
}
ActivityCalculationDiscountRequestDto activityCalculationDiscountRequestDto = getActivityCalculationDiscountRequestDto(partnerId, storeId, userId, appId, orderType);
List<ActivityCalculationDiscountRequestDto.CalculationDiscountGoods> calculationDiscountGoodsList = new ArrayList<>();
......@@ -641,13 +647,13 @@ public class ShoppingCartMCoffeeServiceImpl {
String cartGoodsUid = cartGoods.getCartGoodsUid();
// 商品不是商品券
if (!cartGoodsUid.startsWith(CommonsConstant.COUPON_PREFIX)) {
this.addCalculationDiscountGoods(calculationDiscountGoodsList, cartGoods.getGoodsId(), cartGoods.getQty(), cartGoods.getFinalPrice(),cartGoods.getMemberDiscount());
this.addCalculationDiscountGoods(calculationDiscountGoodsList, cartGoods.getGoodsId(), cartGoods.getQty(), cartGoods.getFinalPrice(), cartGoods.getMemberDiscount());
}
// 商品是商品券
else {
// 商品券ID换取商品
String spqId = cartGoods.getCartGoodsUid().substring(CommonsConstant.COUPON_PREFIX.length());
CheckSpqInfoRequestDto checkSpqInfoRequestDto = new CheckSpqInfoRequestDto(partnerId, storeId, spqId,menuType);
CheckSpqInfoRequestDto checkSpqInfoRequestDto = new CheckSpqInfoRequestDto(partnerId, storeId, spqId, menuType);
CheckSpqInfoResponseDto checkSpqInfoResponseDto = couponService.checkSpqInfo(checkSpqInfoRequestDto);
// 商品券不存在时,将商品券从购物车移除
if (checkSpqInfoResponseDto == null) {
......@@ -665,13 +671,13 @@ public class ShoppingCartMCoffeeServiceImpl {
coupons.add(coupon);
// 添加商品券代表的商品
String goodsId = StringUtils.isEmpty(checkSpqInfoResponseDto.getSkuId()) ? checkSpqInfoResponseDto.getSpuId() : checkSpqInfoResponseDto.getSkuId();
this.addCalculationDiscountGoods(calculationDiscountGoodsList, goodsId, 1, checkSpqInfoResponseDto.getPrice(),100);
this.addCalculationDiscountGoods(calculationDiscountGoodsList, goodsId, 1, checkSpqInfoResponseDto.getPrice(), 100);
}
}
// 当加价购商品不为空时
if (CollectionUtils.isNotEmpty(sendGoodsList)) {
for (ShoppingCartInfoRequestVo.SendGoods sendGoods : sendGoodsList) {
this.addCalculationDiscountGoods(calculationDiscountGoodsList, sendGoods.getGoodsId(), sendGoods.getQty(), sendGoods.getOriginalPrice(),100);
this.addCalculationDiscountGoods(calculationDiscountGoodsList, sendGoods.getGoodsId(), sendGoods.getQty(), sendGoods.getOriginalPrice(), 100);
}
}
calculationDiscountGoodsList.removeIf(calculationDiscountGoods -> (calculationDiscountGoods.getGoodsQuantity().equals(0)));
......@@ -706,7 +712,7 @@ public class ShoppingCartMCoffeeServiceImpl {
shoppingCartClearRequestVo.setShopId(storeId);
shoppingCartClearRequestVo.setOperationType(1);
clear(shoppingCartClearRequestVo);
if (activityCalculationDiscountResponseDto != null && StringUtils.equals(activityCalculationDiscountResponseDto.getStatusCode(), "103")){
if (activityCalculationDiscountResponseDto != null && StringUtils.equals(activityCalculationDiscountResponseDto.getStatusCode(), "103")) {
throw new ServiceException(ResponseResult.SHOPPING_CART_COUPON_CAN_NOT_USE_THIS_SHOP);
}
throw new ServiceException(ResponseResult.OPERATE_TOO_OFTEN);
......@@ -721,7 +727,7 @@ public class ShoppingCartMCoffeeServiceImpl {
* @param originalPrice
*/
private void addCalculationDiscountGoods(List<ActivityCalculationDiscountRequestDto.CalculationDiscountGoods> calculationDiscountGoodsList,
String goodsId, Integer goodsQuantity, Long originalPrice,Integer memberDiscount) {
String goodsId, Integer goodsQuantity, Long originalPrice, Integer memberDiscount) {
ActivityCalculationDiscountRequestDto.CalculationDiscountGoods calculationDiscountGoods = new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods();
calculationDiscountGoods.setGoodsId(goodsId);
calculationDiscountGoods.setGoodsQuantity(goodsQuantity);
......@@ -819,7 +825,7 @@ public class ShoppingCartMCoffeeServiceImpl {
* @param shoppingCartGoodsResponseVo
*/
private void updateShoppingCartGoodsDiscount(CouponPromotionVO couponPromotionVO, ActivityQueryDto activityQueryDto, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult, List<CartGoods> cartGoodsList
, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo, UserLoginInfoDto userLoginInfoDto,String menuType,Long deliveryAmount) {
, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo, UserLoginInfoDto userLoginInfoDto, String menuType, Long deliveryAmount) {
}
......@@ -963,7 +969,7 @@ public class ShoppingCartMCoffeeServiceImpl {
* @param productBeanListSpuClass
* @param skuId
*/
private void queryManyGoodsStocks(String partnerId,String storeId,String menuType, List<Long> productIds
private void queryManyGoodsStocks(String partnerId, String storeId, String menuType, List<Long> productIds
, List<ProductBeanDTO> productBeanListSpuClass, String skuId, Integer qty) {
GetProductStockRequestDto requestDto = new GetProductStockRequestDto();
requestDto.setChannel(BusinessTypeEnum.getByType(menuType).getCode());
......@@ -1002,81 +1008,76 @@ public class ShoppingCartMCoffeeServiceImpl {
* 查询购物车计算包装费
*
* @param shoppingCartGoodsResponseVo
* @param calculationDiscountResult
* @param cartGoodsList
* @param toastMsg
* @param userId
* @param opt
* @param shoppingCartInfoRequestVo
*/
private void setAddAndUpdateResponse(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
, List<CartGoods> cartGoodsList, String toastMsg, String partnerId, String storeId, String userId, String opt, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo) {
private void setAddAndUpdateResponse(ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo, List<CartGoods> cartGoodsList,
String toastMsg, String opt, ShoppingCartInfoRequestVo shoppingCartInfoRequestVo) {
shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
shoppingCartGoodsResponseVo.setProductsCount(cartGoodsList.size());
if (StringUtils.isNotEmpty(toastMsg)) {
toastMsg=shoppingCartInfoRequestVo!=null && ObjectUtils.equals(1, shoppingCartInfoRequestVo.getFlag())?SHOPPING_CART_EMPTY_GOODS_LIST:SHOPPING_CART_INVALIAD_GOODS;
toastMsg = shoppingCartInfoRequestVo != null && ObjectUtils.equals(1, shoppingCartInfoRequestVo.getFlag()) ? SHOPPING_CART_EMPTY_GOODS_LIST : SHOPPING_CART_INVALIAD_GOODS;
setToastMsgIfNotExist(shoppingCartGoodsResponseVo, toastMsg);
//结算页,只有商品全部非法(即products为空)时,才提示changed为true toastMsg 不为空
if (shoppingCartInfoRequestVo!=null && ObjectUtils.equals(1, shoppingCartInfoRequestVo.getFlag())){
if (shoppingCartInfoRequestVo != null && ObjectUtils.equals(1, shoppingCartInfoRequestVo.getFlag())) {
shoppingCartGoodsResponseVo.setChanged(CollectionUtils.isEmpty(cartGoodsList));
shoppingCartGoodsResponseVo.setToastMsg(CollectionUtils.isEmpty(cartGoodsList)?toastMsg:"");
shoppingCartGoodsResponseVo.setToastMsg(CollectionUtils.isEmpty(cartGoodsList) ? toastMsg : "");
}
}
// 更新和添加商品时不需要包装费
if (ShoppingCartConstant.ADD_AND_UPDATE.equals(opt)) {
shoppingCartGoodsResponseVo.setNewPackAmount(null);
return;
}
//========================== 购物车查询特有逻辑 =================================
// 到店自取包装费设为null,外卖要计算包装费,flag为1表示去结算
// 兼容老版本判断null
if (Objects.equals(shoppingCartInfoRequestVo.getOrderType(), CreateOrderType.COLLECT_GOODS.getCode())
&& (Objects.equals(shoppingCartInfoRequestVo.getReachStoreType(), null)
|| Objects.equals(shoppingCartInfoRequestVo.getReachStoreType(), OrderType.EAT_IN.getCode()))) {
if (shoppingCartGoodsResponseVo.getNewPackAmount() == null || shoppingCartGoodsResponseVo.getNewPackAmount() == 0L) {
return;
}
if (shoppingCartInfoRequestVo != null && Objects.equals(shoppingCartInfoRequestVo.getReachStoreType(), OrderType.EAT_IN.getCode())) {
shoppingCartGoodsResponseVo.setNewPackAmount(null);
} else if ((Objects.equals(shoppingCartInfoRequestVo.getOrderType(), CreateOrderType.TAKE_OUT.getCode())
|| Objects.equals(shoppingCartInfoRequestVo.getReachStoreType(), OrderType.COLLECT_GOODS.getCode()))
&& Objects.equals(shoppingCartInfoRequestVo.getFlag(), CouponFlag.YES.getCode())) {
Long packAmount = shoppingCartGoodsResponseVo.getNewPackAmount() == null ? 0 : shoppingCartGoodsResponseVo.getNewPackAmount();
} else {
Long packAmount = shoppingCartGoodsResponseVo.getNewPackAmount();
Long originalTotalAmount = shoppingCartGoodsResponseVo.getOriginalTotalAmount() + packAmount;
Long totalAmount = shoppingCartGoodsResponseVo.getTotalAmount() + packAmount;
shoppingCartGoodsResponseVo.setOriginalTotalAmount(originalTotalAmount);
shoppingCartGoodsResponseVo.setTotalAmount(totalAmount);
}
}
/**
* 在原价、现价、折扣价上增加第一次使用会员卡的费用
*/
// private void addNeedCardAmount(ShoppingCartInfoRequestVo shoppingCartInfoRequestVo, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
// ShoppingCartInfoRequestVo.BuyMemberCard buyMemberCard = shoppingCartInfoRequestVo.getBuyMemberCard();
// if (shoppingCartInfoRequestVo.getBuyMemberCard() == null || StringUtils.isEmpty(buyMemberCard.getPaidId()) || StringUtils.isEmpty(buyMemberCard.getRuleId())) {
// return;
// }
// GetPaidRuleRequestDto getPaidRuleRequestDto = new GetPaidRuleRequestDto();
// getPaidRuleRequestDto.setPartnerId(shoppingCartInfoRequestVo.getPartnerId());
// getPaidRuleRequestDto.setPaidId(buyMemberCard.getPaidId());
// getPaidRuleRequestDto.setRuleId(buyMemberCard.getRuleId());
// BaseResponse<GetPaidRuleResponseDto> baseResponse = customerApplicationClient.getPaidRule(getPaidRuleRequestDto);
// if (baseResponse == null || !ResponseResult.SUCCESS.getCode().equals(baseResponse.getCode()) || baseResponse.getResult() == null
// || baseResponse.getResult().getActivityPrice() == null) {
// return;
// }
// // 购买会员卡的金额
// Integer activityPrice = baseResponse.getResult().getActivityPrice();
// // 首次使用会员卡享受的折扣金额
// Integer firstCouponAmount = baseResponse.getResult().getFirstCouponAmount() == null ? 0 : baseResponse.getResult().getFirstCouponAmount();
// Long originalTotalAmount = shoppingCartGoodsResponseVo.getOriginalTotalAmount() + activityPrice;
// Long totalAmount = shoppingCartGoodsResponseVo.getTotalAmount() + (activityPrice - firstCouponAmount);
// Long totalDiscountAmount = shoppingCartGoodsResponseVo.getTotalDiscountAmount() + firstCouponAmount;
// shoppingCartGoodsResponseVo.setOriginalTotalAmount(originalTotalAmount);
// shoppingCartGoodsResponseVo.setTotalAmount(totalAmount);
// shoppingCartGoodsResponseVo.setTotalDiscountAmount(totalDiscountAmount);
// shoppingCartGoodsResponseVo.setCardOriginalAmount(activityPrice);
// shoppingCartGoodsResponseVo.setCardDiscountAmount(firstCouponAmount);
// }
private void addNeedCardAmount(ShoppingCartInfoRequestVo shoppingCartInfoRequestVo, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
ShoppingCartInfoRequestVo.BuyMemberCard buyMemberCard = shoppingCartInfoRequestVo.getBuyMemberCard();
if (shoppingCartInfoRequestVo.getBuyMemberCard() == null || StringUtils.isEmpty(buyMemberCard.getPaidId()) || StringUtils.isEmpty(buyMemberCard.getRuleId())) {
return;
}
GetPaidRuleRequestDto getPaidRuleRequestDto = new GetPaidRuleRequestDto();
getPaidRuleRequestDto.setPartnerId(shoppingCartInfoRequestVo.getPartnerId());
getPaidRuleRequestDto.setPaidId(buyMemberCard.getPaidId());
getPaidRuleRequestDto.setRuleId(buyMemberCard.getRuleId());
BaseResponse<GetPaidRuleResponseDto> baseResponse = customerApplicationClient.getPaidRule(getPaidRuleRequestDto);
if (baseResponse == null || !ResponseResult.SUCCESS.getCode().equals(baseResponse.getCode()) || baseResponse.getResult() == null
|| baseResponse.getResult().getActivityPrice() == null) {
return;
}
// 购买会员卡的金额
Integer activityPrice = baseResponse.getResult().getActivityPrice();
// 首次使用会员卡享受的折扣金额
Integer firstCouponAmount = baseResponse.getResult().getFirstCouponAmount() == null ? 0 : baseResponse.getResult().getFirstCouponAmount();
Long originalTotalAmount = shoppingCartGoodsResponseVo.getOriginalTotalAmount() + activityPrice;
Long totalAmount = shoppingCartGoodsResponseVo.getTotalAmount() + (activityPrice - firstCouponAmount);
Long totalDiscountAmount = shoppingCartGoodsResponseVo.getTotalDiscountAmount() + firstCouponAmount;
shoppingCartGoodsResponseVo.setOriginalTotalAmount(originalTotalAmount);
shoppingCartGoodsResponseVo.setTotalAmount(totalAmount);
shoppingCartGoodsResponseVo.setTotalDiscountAmount(totalDiscountAmount);
shoppingCartGoodsResponseVo.setCardOriginalAmount(activityPrice);
shoppingCartGoodsResponseVo.setCardDiscountAmount(firstCouponAmount);
}
private UserLoginInfoDto convert2UserLoginInfoDto(CustomerInfoVo assortmentCustomerInfoVo) {
if (assortmentCustomerInfoVo == null || assortmentCustomerInfoVo.getMemberId() == null) {
......@@ -1219,23 +1220,22 @@ public class ShoppingCartMCoffeeServiceImpl {
/**
* 获取优惠
*/
private ActivityCalculationDiscountResponseDto.CalculationDiscountResult getCalculationDiscountResult(String menuType
,String partnerId,String storeId,String userId,String appId,Integer orderType,boolean isMember
,List<CartGoods> cartGoodsList,List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons
,List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList,String receiveId,Long deliveryAmount){
// 获取优惠信息
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult=null;
//外卖场景下 查询门店配送信息
if(BusinessTypeEnum.SAAS_DELIVERY.getCode().equals(menuType)){
calculationDiscountResult = this.getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType,isMember, cartGoodsList, coupons, sendGoodsList,BusinessTypeEnum.getByType(menuType).getCode(),deliveryAmount);
}else{
calculationDiscountResult = this.getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType,isMember, cartGoodsList, coupons, sendGoodsList,BusinessTypeEnum.getByType(menuType).getCode(),null);
}
return calculationDiscountResult;
}
// private ActivityCalculationDiscountResponseDto.CalculationDiscountResult getCalculationDiscountResult(String menuType
// ,String partnerId,String storeId,String userId,String appId,Integer orderType,boolean isMember
// ,List<CartGoods> cartGoodsList,List<ActivityCalculationDiscountRequestDto.CalculationDiscountCoupon> coupons
// ,List<ShoppingCartInfoRequestVo.SendGoods> sendGoodsList,String receiveId,Long deliveryAmount){
// // 获取优惠信息
// ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult=null;
// //外卖场景下 查询门店配送信息
// if(BusinessTypeEnum.SAAS_DELIVERY.getCode().equals(menuType)){
//
// calculationDiscountResult = this.getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType,isMember, cartGoodsList, coupons, sendGoodsList,BusinessTypeEnum.getByType(menuType).getCode(),deliveryAmount);
// }else{
// calculationDiscountResult = this.getActivityCalculationDiscountResponse(partnerId, storeId, userId, appId, orderType,isMember, cartGoodsList, coupons, sendGoodsList,BusinessTypeEnum.getByType(menuType).getCode(),null);
// }
//
// return calculationDiscountResult;
// }
private Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, String wxappid, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
Long deliveryAmount = 0L;
if (StringUtils.isBlank(receiveId)) {
......@@ -1264,7 +1264,7 @@ public class ShoppingCartMCoffeeServiceImpl {
if (queryDeliverDetailResponse == null || !ResponseResult.SUCCESS.getCode().equals(queryDeliverDetailResponse.getCode()) || queryDeliverDetailResponse.getData() == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_NOT_DELIVERY);
}
if(queryDeliverDetailResponse.getData().getDeliveryAmount() == null) {
if (queryDeliverDetailResponse.getData().getDeliveryAmount() == null) {
throw new ServiceException(ResponseResult.STORE_DELIVERY_AMOUNT_ERROR);
}
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() != null ? queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() : 0);
......@@ -1342,5 +1342,4 @@ public class ShoppingCartMCoffeeServiceImpl {
}
}
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