Commit e8935d75 by 刘鹏飞

针对coco需求,拓展固定配送费

parent 004525d2
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery;
public interface DeliveryFactory {
/**
* 获取运费计算类
* @param orderType
* @param receiveId
* @return
*/
DeliveryService getCalculateDeliveryAmount(Integer orderType,String receiveId);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
public interface DeliveryService {
/**
* 计算运费
* @param receiveId
* @param partnerId
* @param storeId
* @param shoppingCartGoodsResponseVo
* @return
*/
Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery.impl;
import cn.freemud.service.delivery.DeliveryService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractDeliveryServiceImpl implements DeliveryService {
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery.impl;
import cn.freemud.enums.CreateOrderType;
import cn.freemud.enums.ResponseResult;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.delivery.DeliveryFactory;
import cn.freemud.service.delivery.DeliveryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class DeliveryFactoryImpl implements DeliveryFactory {
/**
* 梯度运费
*/
@Autowired
@Qualifier("gradDeliveryService")
DeliveryService gradDeliveryService;
/**
* 固定运费
*/
@Autowired
@Qualifier("fixDeliveryService")
DeliveryService fixDeliveryServiceImpl;
@Override
public DeliveryService getCalculateDeliveryAmount(Integer orderType,String receiveId) {
// 如果订单的收获地址为空,且订单是外卖单,使用固定运费
if (StringUtils.isBlank(receiveId) && Objects.equals(orderType, CreateOrderType.TAKE_OUT.getCode())) {
return fixDeliveryServiceImpl;
}else if(StringUtils.isNotBlank(receiveId)){
return gradDeliveryService;
}
throw new ServiceException(ResponseResult.STORE_DELIVERY_AMOUNT_ERROR);
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery.impl;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import cn.freemud.enums.CreateOrderType;
import cn.freemud.enums.ResponseResult;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.delivery.DeliveryService;
import cn.freemud.utils.ResponseUtil;
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;
import com.freemud.application.sdk.api.storecenter.request.QueryDeliveryRequest;
import com.freemud.application.sdk.api.storecenter.request.StoreInfoRequest;
import com.freemud.application.sdk.api.storecenter.response.QueryDeliverDetailResponse;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service("fixDeliveryService")
public class FixDeliveryServiceImpl extends AbstractDeliveryServiceImpl implements DeliveryService {
@Autowired
private StoreCenterService storeCenterService;
@Override
public Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
String trackingNo = LogThreadLocal.getTrackingNo();
// 获取门店信息,查询基础配送费用
StoreInfoRequest storeInfoRequest = new StoreInfoRequest(partnerId, storeId,null);
StoreResponse storeResponse = storeCenterService.getStoreInfo(storeInfoRequest, trackingNo);
if (storeResponse == null || storeResponse.getBizVO() == null) {
throw new ServiceException (ResponseResult.STORE_NOT_FOUND);
}
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(0);
return new Double(storeResponse.getBizVO().getDeliveryPrice()).longValue() * 100;
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CouponService
* @Package cn.freemud.service
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.delivery.impl;
import cn.freemud.entities.vo.ShoppingCartGoodsResponseVo;
import cn.freemud.enums.ResponseResult;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.delivery.DeliveryService;
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;
import com.freemud.application.sdk.api.membercenter.service.MemberCenterService;
import com.freemud.application.sdk.api.storecenter.request.QueryDeliveryRequest;
import com.freemud.application.sdk.api.storecenter.response.QueryDeliverDetailResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service("gradDeliveryService")
public class GradDeliveryServiceImpl extends AbstractDeliveryServiceImpl implements DeliveryService {
@Autowired
private MemberCenterService memberCenterService;
@Autowired
private StoreCenterService storeCenterService;
@Override
public Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) {
String trackingNo = LogThreadLocal.getTrackingNo();
QueryReceiveAddressRequest queryReceive = new QueryReceiveAddressRequest(receiveId, partnerId);
//查询会员收获地址经纬度
com.freemud.application.sdk.api.base.BaseResponse<QueryReceiveAddressResponse> queryReceiveAddressResponse = memberCenterService.queryReceiveAddressById(queryReceive, trackingNo);
if (!ResponseResult.SUCCESS.getCode().equals(queryReceiveAddressResponse.getCode()) || queryReceiveAddressResponse.getData() == null) {
throw new ServiceException(ResponseResult.USER_GETRECEIVEADDRESS_ERROR);
}
// 查询运费详情
QueryDeliveryRequest queryDeliveryRequest = new QueryDeliveryRequest();
queryDeliveryRequest.setPartnerId(partnerId);
queryDeliveryRequest.setStoreCode(storeId);
queryDeliveryRequest.setUserLatitude(queryReceiveAddressResponse.getData().getLatitude());
queryDeliveryRequest.setUserLongitude(queryReceiveAddressResponse.getData().getLongitude());
com.freemud.application.sdk.api.base.BaseResponse<QueryDeliverDetailResponse> queryDeliverDetailResponse = storeCenterService.queryDeliverDetail(queryDeliveryRequest, trackingNo);
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) {
throw new ServiceException(ResponseResult.STORE_DELIVERY_AMOUNT_ERROR);
}
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() != null ? queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() : 0);
return queryDeliverDetailResponse.getData().getDeliveryAmount();
}
}
...@@ -35,6 +35,8 @@ import cn.freemud.interceptor.ServiceException; ...@@ -35,6 +35,8 @@ import cn.freemud.interceptor.ServiceException;
import cn.freemud.interceptor.BizServiceException; import cn.freemud.interceptor.BizServiceException;
import cn.freemud.redis.RedisCache; import cn.freemud.redis.RedisCache;
import cn.freemud.service.*; import cn.freemud.service.*;
import cn.freemud.service.delivery.DeliveryFactory;
import cn.freemud.service.delivery.DeliveryService;
import cn.freemud.service.impl.calculate.CalculateCenter; import cn.freemud.service.impl.calculate.CalculateCenter;
import cn.freemud.service.impl.calculate.CalculationSharingCartService; import cn.freemud.service.impl.calculate.CalculationSharingCartService;
import cn.freemud.service.impl.calculate.CalculationSharingDiscountService; import cn.freemud.service.impl.calculate.CalculationSharingDiscountService;
...@@ -152,6 +154,9 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -152,6 +154,9 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
@Autowired
private DeliveryFactory deliveryFactory;
private static final String limitCartKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_"; private static final String limitCartKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_";
...@@ -299,7 +304,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -299,7 +304,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
this.addProductGoods(addShoppingCartGoodsRequestVo, cartGoods, spuId2, userId, shoppingCartGoodsResponseVo, this.addProductGoods(addShoppingCartGoodsRequestVo, cartGoods, spuId2, userId, shoppingCartGoodsResponseVo,
spuId, allCartGoodsList, productBeanListSpuClass, StringUtils.isNotBlank(skuId) ? true : false); spuId, allCartGoodsList, productBeanListSpuClass, StringUtils.isNotBlank(skuId) ? true : false);
} }
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo); Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo,addShoppingCartGoodsRequestVo.getOrderType());
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, addShoppingCartGoodsRequestVo.getOrderType()); ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, addShoppingCartGoodsRequestVo.getOrderType());
if (grayPush(partnerId,storeId,"2")) { if (grayPush(partnerId,storeId,"2")) {
...@@ -420,7 +425,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -420,7 +425,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
// 重新存储最新购物车 // 重新存储最新购物车
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, updateShoppingCartGoodsQtyRequestVo.getSessionId(), "", shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, updateShoppingCartGoodsQtyRequestVo.getSessionId(), "", shoppingCartBaseService);
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo); Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo,updateShoppingCartGoodsQtyRequestVo.getOrderType());
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, updateShoppingCartGoodsQtyRequestVo.getOrderType()); ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, updateShoppingCartGoodsQtyRequestVo.getOrderType());
if (grayPush(partnerId,storeId,"2")) { if (grayPush(partnerId,storeId,"2")) {
...@@ -552,7 +557,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -552,7 +557,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, assortmentCustomerInfoVo.getSessionId(), "", this.shoppingCartBaseService); assortmentSdkService.setShoppingCart(partnerId, storeId, userId, cartGoodsList, assortmentCustomerInfoVo.getSessionId(), "", this.shoppingCartBaseService);
} }
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo); Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo,shoppingCartInfoRequestVo.getOrderType());
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType()); ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType());
CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto); CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto);
...@@ -768,7 +773,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -768,7 +773,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType()); ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, shoppingCartInfoRequestVo.getOrderType());
CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto); CouponPromotionVO couponPromotionVO = couponAdapter.getCouponPromotionVO(shoppingCartInfoRequestVo, userLoginInfoDto);
Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo); Long deliveryAmount = calculateDeliveryAmount(receiveId, partnerId, storeId, userLoginInfoDto.getWxAppid(), shoppingCartGoodsResponseVo,shoppingCartInfoRequestVo.getOrderType());
if (grayPush(partnerId,storeId,"2")) { if (grayPush(partnerId,storeId,"2")) {
List<CalculationSharingDiscountRequestDto.CalculationDiscountCoupon> coupons = new ArrayList<>(); List<CalculationSharingDiscountRequestDto.CalculationDiscountCoupon> coupons = new ArrayList<>();
// 当couponCode不为空时,需参与价格计算 // 当couponCode不为空时,需参与价格计算
...@@ -1712,33 +1717,19 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1712,33 +1717,19 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
return amount; return amount;
} }
private Long getNewDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) { private Long getNewDeliveryAmount(String receiveId, String partnerId, String storeId, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo,Integer orderType) {
String trackingNo = LogThreadLocal.getTrackingNo(); //String trackingNo = LogThreadLocal.getTrackingNo();
Long amount = 0L; Long amount = 0L;
if (StringUtils.isBlank(receiveId)) { // 如果订单的收获地址为空,且订单是外卖单,返回运费
// 主要是为了兼容coco不传收获地址,需要获取固定运费的情况
if (StringUtils.isBlank(receiveId) && !Objects.equals(orderType, CreateOrderType.TAKE_OUT.getCode())) {
return amount; return amount;
} }
QueryReceiveAddressRequest queryReceive = new QueryReceiveAddressRequest(receiveId, partnerId);
//查询会员后货地址经纬度
com.freemud.application.sdk.api.base.BaseResponse<QueryReceiveAddressResponse> queryReceiveAddressResponse = memberCenterService.queryReceiveAddressById(queryReceive, trackingNo);
if (!ResponseResult.SUCCESS.getCode().equals(queryReceiveAddressResponse.getCode()) || queryReceiveAddressResponse.getData() == null) {
throw new ServiceException(ResponseResult.USER_GETRECEIVEADDRESS_ERROR);
}
QueryDeliveryRequest queryDeliveryRequest = new QueryDeliveryRequest(); DeliveryService deliveryService = deliveryFactory.getCalculateDeliveryAmount(orderType,receiveId);
queryDeliveryRequest.setPartnerId(partnerId); amount = deliveryService.calculateDeliveryAmount(receiveId,partnerId,storeId,shoppingCartGoodsResponseVo);
queryDeliveryRequest.setStoreCode(storeId);
queryDeliveryRequest.setUserLatitude(queryReceiveAddressResponse.getData().getLatitude()); return amount;
queryDeliveryRequest.setUserLongitude(queryReceiveAddressResponse.getData().getLongitude());
com.freemud.application.sdk.api.base.BaseResponse<QueryDeliverDetailResponse> queryDeliverDetailResponse = storeCenterService.queryDeliverDetail(queryDeliveryRequest, trackingNo);
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) {
throw new ServiceException(ResponseResult.STORE_DELIVERY_AMOUNT_ERROR);
}
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() != null ? queryDeliverDetailResponse.getData().getDeliveryFeeZeroReason() : 0);
return queryDeliverDetailResponse.getData().getDeliveryAmount();
} }
/** /**
...@@ -1785,9 +1776,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1785,9 +1776,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
return calculationDiscountResult; return calculationDiscountResult;
} }
private Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, String wxappid, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo) { private Long calculateDeliveryAmount(String receiveId, String partnerId, String storeId, String wxappid, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo,Integer orderType) {
Long deliveryAmount = 0L; Long deliveryAmount = 0L;
if (StringUtils.isBlank(receiveId)) { // 如果订单的收获地址为空,且订单是外卖单,返回运费
// 主要是为了兼容coco不传收获地址,需要获取固定运费的情况
if (StringUtils.isBlank(receiveId) && !Objects.equals(orderType, CreateOrderType.TAKE_OUT.getCode())) {
return deliveryAmount; return deliveryAmount;
} }
log.info("获取配送配逻辑 tackingNo:{},storeDeliveryUseOld:{},receiveId:{},partnerId:{},storeId:{}", LogThreadLocal.getTrackingNo(), storeDeliveryUseOld, receiveId, partnerId, storeId); log.info("获取配送配逻辑 tackingNo:{},storeDeliveryUseOld:{},receiveId:{},partnerId:{},storeId:{}", LogThreadLocal.getTrackingNo(), storeDeliveryUseOld, receiveId, partnerId, storeId);
...@@ -1795,7 +1788,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1795,7 +1788,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
deliveryAmount = Long.parseLong(getDeliveryAmount(receiveId, partnerId, storeId).toString()); deliveryAmount = Long.parseLong(getDeliveryAmount(receiveId, partnerId, storeId).toString());
shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(0); shoppingCartGoodsResponseVo.setDeliveryFeeZeroReason(0);
} else { } else {
deliveryAmount = getNewDeliveryAmount(receiveId, partnerId, storeId, shoppingCartGoodsResponseVo); deliveryAmount = getNewDeliveryAmount(receiveId, partnerId, storeId, shoppingCartGoodsResponseVo,orderType);
} }
return deliveryAmount; return deliveryAmount;
......
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