Commit 373b94d7 by 王世昌

优化部分逻辑

parent b492fd51
...@@ -51,7 +51,9 @@ public class CalculationSharingAdapter { ...@@ -51,7 +51,9 @@ public class CalculationSharingAdapter {
GetCalculationDiscountBO.CalculationDiscountCoupon coupon = new GetCalculationDiscountBO.CalculationDiscountCoupon (); GetCalculationDiscountBO.CalculationDiscountCoupon coupon = new GetCalculationDiscountBO.CalculationDiscountCoupon ();
coupon.setCode(bo.getCouponCode()); coupon.setCode(bo.getCouponCode());
coupon.setActivityCode(bo.getActivityCode()); coupon.setActivityCode(bo.getActivityCode());
GetCalculationDiscountBO.CalculationDiscountCoupon calculationDiscountCoupon = coupons.stream().filter(p -> coupon.getActivityCode().equals(p.getActivityCode()) && coupon.getCode().equals(p.getCode())).findFirst().orElse(null); GetCalculationDiscountBO.CalculationDiscountCoupon calculationDiscountCoupon = coupons.stream()
.filter(p -> coupon.getActivityCode().equals(p.getActivityCode()) && coupon.getCode().equals(p.getCode()))
.findFirst().orElse(null);
if (calculationDiscountCoupon == null){ if (calculationDiscountCoupon == null){
coupons.add(coupon); coupons.add(coupon);
} }
......
package cn.freemud.demo.manager.coupon; package cn.freemud.demo.manager.coupon;
import cn.freemud.base.log.LogTreadLocal;
import cn.freemud.base.util.JsonUtil;
import cn.freemud.constant.ResponseCodeConstant; import cn.freemud.constant.ResponseCodeConstant;
import cn.freemud.demo.entities.bo.goods.ValidateShopProductRequestBO; import cn.freemud.demo.entities.bo.goods.ValidateShopProductRequestBO;
import cn.freemud.demo.entities.bo.coupon.CheckSpqBO; import cn.freemud.demo.entities.bo.coupon.CheckSpqBO;
...@@ -22,6 +24,7 @@ import cn.freemud.interceptor.ServiceException; ...@@ -22,6 +24,7 @@ import cn.freemud.interceptor.ServiceException;
import cn.freemud.redis.RedisCache; import cn.freemud.redis.RedisCache;
import cn.freemud.service.thirdparty.CardBinClient; import cn.freemud.service.thirdparty.CardBinClient;
import cn.freemud.service.thirdparty.CouponOnlineClient; import cn.freemud.service.thirdparty.CouponOnlineClient;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.RedisUtil; import cn.freemud.utils.RedisUtil;
import com.freemud.application.sdk.api.productcenter.request.product.valid.ValidateShopProductType; import com.freemud.application.sdk.api.productcenter.request.product.valid.ValidateShopProductType;
import com.freemud.card.sdk.comm.Finals; import com.freemud.card.sdk.comm.Finals;
...@@ -98,8 +101,9 @@ public class KgdCouponServiceImpl implements CouponService { ...@@ -98,8 +101,9 @@ public class KgdCouponServiceImpl implements CouponService {
CheckSpqBO result = new CheckSpqBO(); CheckSpqBO result = new CheckSpqBO();
GetCouponDetailBO getCouponDetail = convert2GetCouponDetailBO(getCheckSpqBo); GetCouponDetailBO getCouponDetail = convert2GetCouponDetailBO(getCheckSpqBo);
// 如果是商品券,获取商品券信息 // 如果是商品券/换购券,获取券信息
CouponDetailBO couponDetail = getCouponDetail(getCouponDetail); CouponDetailBO couponDetail = getCouponDetail(getCouponDetail);
LogUtil.info(LogTreadLocal.getTrackingNo(), "KgdCouponServiceImpl.getCouponDetail", JsonUtil.toJSONString(getCouponDetail), JsonUtil.toJSONString(couponDetail));
if (couponDetail == null || !couponDetail.getResult().equals(ResponseCodeConstant.RESPONSE_SUCCESS_1) || CollectionUtils.isEmpty(couponDetail.getDetails())) { if (couponDetail == null || !couponDetail.getResult().equals(ResponseCodeConstant.RESPONSE_SUCCESS_1) || CollectionUtils.isEmpty(couponDetail.getDetails())) {
return null; return null;
...@@ -109,30 +113,35 @@ public class KgdCouponServiceImpl implements CouponService { ...@@ -109,30 +113,35 @@ public class KgdCouponServiceImpl implements CouponService {
} }
Integer couponType = 0; Integer couponType = 0;
CouponDetailBO.Details couponActivityDetail = null; CouponDetailBO.Details couponActivityDetail = null;
// 多规格券
if (StringUtils.isNotBlank(getCheckSpqBo.getSkuId())){ if (StringUtils.isNotBlank(getCheckSpqBo.getSkuId())){
boolean productValid = false;
for (CouponDetailBO.Details detail : couponDetail.getDetails()) { for (CouponDetailBO.Details detail : couponDetail.getDetails()) {
if (productValid) break; if (Objects.nonNull(couponActivityDetail)) break;
if (!CouponStatus.STATUS_0.getCode().equals(detail.getStatus())) continue; if (!CouponStatus.STATUS_0.getCode().equals(detail.getStatus()) || !CouponStatus.STATUS_2.getCode().equals(detail.getStatus())){
continue;
}
for (CouponDetailBO.ActiveProduct activeProduct : detail.getActiveProduct()) { for (CouponDetailBO.ActiveProduct activeProduct : detail.getActiveProduct()) {
if (getCheckSpqBo.getSkuId().equals(activeProduct.getProductIdPartner())) { if (getCheckSpqBo.getSkuId().equals(activeProduct.getProductIdPartner())) {
productValid = true;
couponActivityDetail = detail; couponActivityDetail = detail;
// todo 和 CouponServiceImpl.checkSpqInfo不一致
couponType = detail.getType(); couponType = detail.getType();
break; break;
} }
} }
} }
//检查商品是否有效
if (!productValid) {
return null;
}
} else { } else {
// 单规格券
if (Objects.equals(couponDetail.getDetails().get(0).getStatus(), CouponStatus.STATUS_0.getCode())) {
couponActivityDetail = couponDetail.getDetails().get(0); couponActivityDetail = couponDetail.getDetails().get(0);
} }
}
if (Objects.isNull(couponActivityDetail)) {
return null;
}
// 判断该券是否在这个门店下(一个券可以在多个门店下使用) // 判断该券是否在这个门店下(一个券可以在多个门店下使用)
List<String> couPonstoreIds = Lists.newArrayList(); List<String> couPonstoreIds = Lists.newArrayList();
for (CouponDetailBO.Details detail : couponDetail.getDetails()) { for (CouponDetailBO.Details detail : couponDetail.getDetails()) {
// todo STATUS_2 的又不要了?
if (!CouponStatus.STATUS_0.getCode().equals(detail.getStatus())) continue; if (!CouponStatus.STATUS_0.getCode().equals(detail.getStatus())) continue;
for (CouponDetailBO.ActiveRestrictionVOS activeRestrictionVO : detail.getActiveRestrictionVOS()) { for (CouponDetailBO.ActiveRestrictionVOS activeRestrictionVO : detail.getActiveRestrictionVOS()) {
couPonstoreIds.add(activeRestrictionVO.getStoreIdPartner()); couPonstoreIds.add(activeRestrictionVO.getStoreIdPartner());
...@@ -141,17 +150,16 @@ public class KgdCouponServiceImpl implements CouponService { ...@@ -141,17 +150,16 @@ public class KgdCouponServiceImpl implements CouponService {
if (CollectionUtils.isNotEmpty(couPonstoreIds) && !couPonstoreIds.contains(getCheckSpqBo.getStoreId())) { if (CollectionUtils.isNotEmpty(couPonstoreIds) && !couPonstoreIds.contains(getCheckSpqBo.getStoreId())) {
return null; return null;
} }
// 券返回的商品id
//券返回的商品id
List<String> skuIds = Lists.newArrayList();
String skuId = getCheckSpqBo.getSkuId(); String skuId = getCheckSpqBo.getSkuId();
if (StringUtils.isBlank(skuId)){ if(StringUtils.isBlank(skuId)){
skuId = couponDetail.getDetails().get(0).getActiveProduct().get(0).getProductIdPartner(); skuId = couponActivityDetail.getActiveProduct().get(0).getProductIdPartner();
} }
skuIds.add(skuId);
// 通过skuid查询spuid // 通过skuid查询spuid
GetProductBySkuIdBO getProductBySkuIdBO = convert2GetProductBySkuIdBO(getCheckSpqBo); GetProductBySkuIdBO getProductBySkuIdBO = convert2GetProductBySkuIdBO(getCheckSpqBo,skuId);
Map<String, GetProductBySkuIdResponseBO> productsInfoBySkuIds = productManager.getProductsInfoBySkuIds(getProductBySkuIdBO, getCheckSpqBo.getProductService()); Map<String, GetProductBySkuIdResponseBO> productsInfoBySkuIds = productManager.getProductsInfoBySkuIds(getProductBySkuIdBO, getCheckSpqBo.getProductService());
LogUtil.info(LogTreadLocal.getTrackingNo(), "getProductBySkuIdBO >>>>", JsonUtil.toJSONString(getProductBySkuIdBO), JsonUtil.toJSONString(couponDetail));
GetProductBySkuIdResponseBO productsVo = productsInfoBySkuIds.get(skuId); GetProductBySkuIdResponseBO productsVo = productsInfoBySkuIds.get(skuId);
if (null == productsVo || !Objects.equals(productsVo.getStatus(), StoreItemStatus.PUT_ON_SALE.getCode())) { if (null == productsVo || !Objects.equals(productsVo.getStatus(), StoreItemStatus.PUT_ON_SALE.getCode())) {
return null; return null;
...@@ -236,13 +244,11 @@ public class KgdCouponServiceImpl implements CouponService { ...@@ -236,13 +244,11 @@ public class KgdCouponServiceImpl implements CouponService {
return getCouponDetailBO; return getCouponDetailBO;
} }
private GetProductBySkuIdBO convert2GetProductBySkuIdBO(GetCheckSpqBo getCheckSpqBo) { private GetProductBySkuIdBO convert2GetProductBySkuIdBO(GetCheckSpqBo getCheckSpqBo,String skuId) {
GetProductBySkuIdBO getProductBySkuIdBO = new GetProductBySkuIdBO(); GetProductBySkuIdBO getProductBySkuIdBO = new GetProductBySkuIdBO();
getProductBySkuIdBO.setMenuType(getCheckSpqBo.getMenuType()); getProductBySkuIdBO.setMenuType(getCheckSpqBo.getMenuType());
getProductBySkuIdBO.setPartnerId(getCheckSpqBo.getPartnerId()); getProductBySkuIdBO.setPartnerId(getCheckSpqBo.getPartnerId());
List<String> skuids = new ArrayList<>(); getProductBySkuIdBO.setSkuids(Collections.singletonList(skuId));
skuids.add(getCheckSpqBo.getSkuId());
getProductBySkuIdBO.setSkuids(skuids);
getProductBySkuIdBO.setStoreId(getCheckSpqBo.getStoreId()); getProductBySkuIdBO.setStoreId(getCheckSpqBo.getStoreId());
return getProductBySkuIdBO; return getProductBySkuIdBO;
} }
......
...@@ -2,6 +2,8 @@ package cn.freemud.demo.service.impl; ...@@ -2,6 +2,8 @@ package cn.freemud.demo.service.impl;
import cn.freemud.adapter.ActivityAdapter; import cn.freemud.adapter.ActivityAdapter;
import cn.freemud.base.entity.BaseResponse; import cn.freemud.base.entity.BaseResponse;
import cn.freemud.base.log.LogTreadLocal;
import cn.freemud.base.util.JsonUtil;
import cn.freemud.demo.entities.bo.promotion.GetActivityBO; import cn.freemud.demo.entities.bo.promotion.GetActivityBO;
import cn.freemud.demo.constant.ResponseConstant; import cn.freemud.demo.constant.ResponseConstant;
import cn.freemud.demo.entities.bo.goods.ShoppingCartGoodsBO; import cn.freemud.demo.entities.bo.goods.ShoppingCartGoodsBO;
...@@ -34,6 +36,7 @@ import cn.freemud.redis.RedisCache; ...@@ -34,6 +36,7 @@ import cn.freemud.redis.RedisCache;
import cn.freemud.service.impl.AssortmentSdkService; import cn.freemud.service.impl.AssortmentSdkService;
import cn.freemud.service.impl.calculate.CalculationCommonService; import cn.freemud.service.impl.calculate.CalculationCommonService;
import cn.freemud.utils.BeanUtil; import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.WebUtil; import cn.freemud.utils.WebUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -201,15 +204,15 @@ public abstract class AbstractAddGoodsService implements AddGoodsService { ...@@ -201,15 +204,15 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
bo.setIsMember(userInfo.getIsMember()); bo.setIsMember(userInfo.getIsMember());
baseRequestBO.setUserId(userInfo.getUserId()); baseRequestBO.setUserId(userInfo.getUserId());
// 获取商品信息
// 获取商品券换购券 // 获取商品券换购券
CheckSpqBO spqBO = getSpqInfo(baseRequestBO); CheckSpqBO spqBO = getSpqInfo(baseRequestBO);
GetProductBO getProductBO = convert2ProductBO(baseRequestBO, spqBO); GetProductBO getProductBO = convert2ProductBO(baseRequestBO, spqBO);
if (getProductBO == null){ // 获取商品信息
throw new ServiceException(ResponseResult.SHOPPING_CART_COUPON_MIX_NOT_EXIST);
}
List<ProductBO> productsInfoList = productManager.getProductsInfo(getProductBO, baseRequestBO.getManagerService().getProductService()); List<ProductBO> productsInfoList = productManager.getProductsInfo(getProductBO, baseRequestBO.getManagerService().getProductService());
LogUtil.info(LogTreadLocal.getTrackingNo(), "getProductsInfo >>>", JsonUtil.toJSONString(getProductBO), JsonUtil.toJSONString(productsInfoList));
ProductBO productsInfo = productsInfoList.get(0); ProductBO productsInfo = productsInfoList.get(0);
bo.setProduct(productsInfo); bo.setProduct(productsInfo);
...@@ -219,8 +222,12 @@ public abstract class AbstractAddGoodsService implements AddGoodsService { ...@@ -219,8 +222,12 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
if (CollectionUtils.isEmpty(allCartGoodsList)) { if (CollectionUtils.isEmpty(allCartGoodsList)) {
allCartGoodsList = new ArrayList<>(); allCartGoodsList = new ArrayList<>();
} }
List<CartGoods> oldCartGoodsList = BeanUtil.convertBeans(allCartGoodsList, CartGoods::new);
bo.setCartGoods(oldCartGoodsList);
// 转换商品券购物车添加的商品 // 转换商品券购物车添加的商品
if (CommonUtils.isProductCoupon(baseRequestBO.getCouponCode(), baseRequestBO.getSpuId())) { if (Objects.nonNull(spqBO)) {
CartGoods cartGoods = baseRequestBO.getAddGoods(); CartGoods cartGoods = baseRequestBO.getAddGoods();
cartGoods.setCartGoodsUid(baseRequestBO.getSpuId()); cartGoods.setCartGoodsUid(baseRequestBO.getSpuId());
cartGoods.setOriginalPrice(spqBO.getProductPrice()); cartGoods.setOriginalPrice(spqBO.getProductPrice());
...@@ -268,9 +275,6 @@ public abstract class AbstractAddGoodsService implements AddGoodsService { ...@@ -268,9 +275,6 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
cartGoods.setStockLimit(stockLimit); cartGoods.setStockLimit(stockLimit);
} }
List<CartGoods> oldCartGoodsList = BeanUtil.convertBeans(allCartGoodsList, CartGoods::new);
bo.setCartGoods(oldCartGoodsList);
return bo; return bo;
} }
...@@ -284,22 +288,24 @@ public abstract class AbstractAddGoodsService implements AddGoodsService { ...@@ -284,22 +288,24 @@ public abstract class AbstractAddGoodsService implements AddGoodsService {
} }
private CheckSpqBO getSpqInfo(BaseAddGoodsBO baseRequestBO) { private CheckSpqBO getSpqInfo(BaseAddGoodsBO baseRequestBO) {
CheckSpqBO checkSpqBO = null;
if (CommonUtils.isProductCoupon(baseRequestBO.getCouponCode(), baseRequestBO.getSpuId())) { if (CommonUtils.isProductCoupon(baseRequestBO.getCouponCode(), baseRequestBO.getSpuId())) {
return null;
}
String spuId = baseRequestBO.getSpuId(); String spuId = baseRequestBO.getSpuId();
String couponCode = CommonUtils.getCouponCode(baseRequestBO.getCouponCode(), spuId); String couponCode = CommonUtils.getCouponCode(baseRequestBO.getCouponCode(), spuId);
GetCheckSpqBo getCheckSpqBo = new GetCheckSpqBo(baseRequestBO.getPartnerId(), couponCode, GetCheckSpqBo getCheckSpqBo = new GetCheckSpqBo(baseRequestBO.getPartnerId(), couponCode,
baseRequestBO.getShopId(), baseRequestBO.getMenuType(), baseRequestBO.getSpuId(), baseRequestBO.getSkuId(), baseRequestBO.getManagerService().getProductService()); baseRequestBO.getShopId(), baseRequestBO.getMenuType(), baseRequestBO.getSpuId(), baseRequestBO.getSkuId(), baseRequestBO.getManagerService().getProductService());
checkSpqBO = couponService.checkSpq(getCheckSpqBo); // 验证商品券和换购券
if (checkSpqBO == null){ CheckSpqBO checkSpqBO = couponService.checkSpq(getCheckSpqBo);
return checkSpqBO; if (checkSpqBO == null) {
throw new ServiceException(ResponseResult.SHOPPING_CART_COUPON_MIX_NOT_EXIST);
} }
if (checkSpqBO.getDetails() != null){ if (checkSpqBO.getDetails() != null) {
checkSpqBO.setCouponName(checkSpqBO.getDetails().getTitle()); checkSpqBO.setCouponName(checkSpqBO.getDetails().getTitle());
} }
}
return checkSpqBO; return checkSpqBO;
} }
......
...@@ -792,17 +792,17 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -792,17 +792,17 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
return ResponseUtil.error(ResponseResult.PARAMETER_MISSING); return ResponseUtil.error(ResponseResult.PARAMETER_MISSING);
} }
//打包带走外卖 //打包带走外卖
if (StringUtils.isNotBlank(shoppingCartInfoRequestVo.getCardCode()) && shoppingCartInfoRequestVo.getOrderType() == 2 if (StringUtils.isNotBlank(shoppingCartInfoRequestVo.getCardCode()) && Objects.equals(shoppingCartInfoRequestVo.getOrderType(), 2)
&& StringUtils.isBlank(shoppingCartInfoRequestVo.getReceiveId())) { && StringUtils.isBlank(shoppingCartInfoRequestVo.getReceiveId())) {
return ResponseUtil.error(ResponseResult.PARAMETER_MISSING); return ResponseUtil.error(ResponseResult.PARAMETER_MISSING);
} }
String partnerId = shoppingCartInfoRequestVo.getPartnerId(); String partnerId = shoppingCartInfoRequestVo.getPartnerId();
String storeId = shoppingCartInfoRequestVo.getShopId(); String storeId = shoppingCartInfoRequestVo.getShopId();
// 是否走重构
if (SDKCommonBaseContextWare.getBean(ShoppingCartNewServiceImpl.class).newShoppingCartGray(shoppingCartInfoRequestVo.getPartnerId(), shoppingCartInfoRequestVo.getShopId())){ if (SDKCommonBaseContextWare.getBean(ShoppingCartNewServiceImpl.class).newShoppingCartGray(shoppingCartInfoRequestVo.getPartnerId(), shoppingCartInfoRequestVo.getShopId())){
Map requestMap = mapperFacade.map(shoppingCartInfoRequestVo, Map.class); Map requestMap = mapperFacade.map(shoppingCartInfoRequestVo, Map.class);
BaseResponse<BaseListCartGoodsVO> goodsList = null; BaseResponse<BaseListCartGoodsVO> goodsList = shoppingCartDemoController.listCartGoods(requestMap);
goodsList = shoppingCartDemoController.listCartGoods(requestMap);
if (goodsList == null || !ResponseResult.SUCCESS.getCode().equals(goodsList.getCode())) { if (goodsList == null || !ResponseResult.SUCCESS.getCode().equals(goodsList.getCode())) {
return goodsList; return goodsList;
......
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