Commit e982f002 by 孙昱

Merge branch 'feature/20210301_月享卡有效性校验_yu.sun'

parents 2a1aba20 649f9f51
package cn.freemud.entities.dto.product;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ProductBindingCouponType {
@ApiModelProperty(name = "优惠券CODE")
private String activityCode;
@ApiModelProperty(name = "数量")
private Integer num;
@ApiModelProperty(name = "排序")
private Integer sequence;
@ApiModelProperty(name = "ID(修改时必传)")
private Long Id;
@ApiModelProperty("卡编号")
private String cardId;
@ApiModelProperty("虚拟券号")
private String virtualCouponCode;
}
...@@ -45,6 +45,7 @@ public class ProductTypeBeanDTO { ...@@ -45,6 +45,7 @@ public class ProductTypeBeanDTO {
private String taxId; private String taxId;
private Integer openMemberDiscount; private Integer openMemberDiscount;
private Integer memberDiscount; private Integer memberDiscount;
private List<ProductBindingCouponType> productBindingCouponTypes;
private List<ProductAttributeGroupListBean> productAttributeGroupList; private List<ProductAttributeGroupListBean> productAttributeGroupList;
private List<ProductPictureListBean> productPictureList; private List<ProductPictureListBean> productPictureList;
private List<SkuProductBean> skuList; private List<SkuProductBean> skuList;
......
...@@ -58,6 +58,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -58,6 +58,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -170,28 +171,11 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -170,28 +171,11 @@ public class ShoppingCartMCoffeeServiceImpl {
oldCartGoodsList = new ArrayList<>(); oldCartGoodsList = new ArrayList<>();
} }
//种子券商品数量不可大于购买的券数量 //种子券商品信息校验
if (addShoppingCartGoodsRequestVo.getIsMonthCard()< 1 && addShoppingCartGoodsRequestVo.getIsSeedCouponGoods() > 0) { if (addShoppingCartGoodsRequestVo.getIsMonthCard()< 1 && addShoppingCartGoodsRequestVo.getIsSeedCouponGoods() > 0) {
if (CollectionUtils.isEmpty(oldCartGoodsList)) { seedCouponGoodsValidate(addShoppingCartGoodsRequestVo, oldCartGoodsList);
throw new ServiceException(ResponseResult.SHOPPING_CART_SEED_COUPON_VALID);
}else{
int seedCouponCount = 0;
int seedCouponGoodsCount = 0;
for (CartGoods cartGoods : oldCartGoodsList) {
if (cartGoods.getIsMonthCard()>0){
seedCouponCount = seedCouponCount + cartGoods.getQty();
}
if (cartGoods.getIsSeedCouponGoods()>0 && cartGoods.getIsMonthCard()<1){
seedCouponGoodsCount = seedCouponGoodsCount + cartGoods.getQty();
}
}
if ((seedCouponGoodsCount+addShoppingCartGoodsRequestVo.getQty()) > seedCouponCount){
throw new ServiceException(ResponseResult.SHOPPING_CART_SEED_COUPON_VALID);
}
}
} }
//加锁,防止重复请求导致的加购数量错误 //加锁,防止重复请求导致的加购数量错误
synchronized (oldCartGoodsList) { synchronized (oldCartGoodsList) {
//餐具和月享卡数量限制 //餐具和月享卡数量限制
...@@ -1917,6 +1901,8 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1917,6 +1901,8 @@ public class ShoppingCartMCoffeeServiceImpl {
checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true); checkCartRequest.getShoppingCartGoodsResponseVo().setChanged(true);
ValiadShopProductResult validaProduct = validateResult.getFailureList().get(i); ValiadShopProductResult validaProduct = validateResult.getFailureList().get(i);
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods : checkCartRequest.getCartGoodsList()) { for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods : checkCartRequest.getCartGoodsList()) {
//如果购物车中存在月享卡,则将商品返回的卡券信息替换购物车中的卡券信息
replaceMonthCardInfo(validaProduct,cartGoods);
if (cartGoods.getSkuId().equals(validaProduct.getSkuId())) { if (cartGoods.getSkuId().equals(validaProduct.getSkuId())) {
String spuName = null == validaProduct.getProductType() ? cartGoods.getSpuName() : validaProduct.getProductType().getName(); String spuName = null == validaProduct.getProductType() ? cartGoods.getSpuName() : validaProduct.getProductType().getName();
String couponName = StringUtils.isNotEmpty(cartGoods.getCouponName()) ? cartGoods.getCouponName() : ""; String couponName = StringUtils.isNotEmpty(cartGoods.getCouponName()) ? cartGoods.getCouponName() : "";
...@@ -1985,6 +1971,8 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -1985,6 +1971,8 @@ public class ShoppingCartMCoffeeServiceImpl {
continue; continue;
} }
for (ValiadShopProductResult valiadShopProductResult : validateResult.getSuccessList()){ for (ValiadShopProductResult valiadShopProductResult : validateResult.getSuccessList()){
//如果购物车中存在月享卡,则将商品返回的卡券信息替换购物车中的卡券信息
replaceMonthCardInfo(valiadShopProductResult,cartGoods);
ProductTypeBeanDTO productType = valiadShopProductResult.getProductType(); ProductTypeBeanDTO productType = valiadShopProductResult.getProductType();
if(ObjectUtils.equals(productType.getPid(), cartGoods.getSpuId())){ if(ObjectUtils.equals(productType.getPid(), cartGoods.getSpuId())){
//多规格商品更新套餐价格为商品返回 //多规格商品更新套餐价格为商品返回
...@@ -2230,4 +2218,62 @@ public class ShoppingCartMCoffeeServiceImpl { ...@@ -2230,4 +2218,62 @@ public class ShoppingCartMCoffeeServiceImpl {
singleUpdateRequest.setChannelType(requestVo.getChannelType()); singleUpdateRequest.setChannelType(requestVo.getChannelType());
return singleUpdateRequest; return singleUpdateRequest;
} }
/**
* 根据商品校验校验接口返回的卡券信息替换前段传递的
* @param result
* @param cartGoods
*/
private void replaceMonthCardInfo(ValiadShopProductResult result,com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods){
if (null == result.getProductType() || CollectionUtils.isEmpty(result.getProductType().getProductBindingCouponTypes())){
return;
}
List<ProductBindingCouponType> productBindingCouponTypes = result.getProductType().getProductBindingCouponTypes();
if (cartGoods.getIsMonthCard() > 0 && null != cartGoods.getMonthCardInfo() && result.getSkuId().equals(cartGoods.getSkuId())){
for (ProductBindingCouponType productBindingCouponType : productBindingCouponTypes) {
cartGoods.getMonthCardInfo().setCardCode(productBindingCouponType.getVirtualCouponCode());
cartGoods.getMonthCardInfo().setCardNo(productBindingCouponType.getCardId());
cartGoods.getMonthCardInfo().setType(cartGoods.getMonthCardInfo().getType());
log.info("【月享卡】信息替换成功,cartGoods:{},productInfo:{}",cartGoods.toString(),result.toString());
}
}
}
/**
* 种子加购逻辑校验
* 1.种子券商品券信息与月卡信息一致
* 2.种子券商品数量不可大于种子券数量
* @param addShoppingCartGoodsRequestVo
* @param oldCartGoodsList
*/
private void seedCouponGoodsValidate(MCoffeeAddGoodsRequestVo addShoppingCartGoodsRequestVo,List<CartGoods> oldCartGoodsList){
//若加购种子券商品,则券号不可为空
if (StringUtils.isEmpty(addShoppingCartGoodsRequestVo.getCouponCode())){
throw new ServiceException(ResponseResult.SHOPPING_CART_ADD_ERROR);
}
//加购种子券商品,购物车中必须已有月卡不可为空
if (CollectionUtils.isEmpty(oldCartGoodsList)) {
throw new ServiceException(ResponseResult.SHOPPING_CART_SEED_COUPON_VALID);
}
int seedCouponCount = 0;
int seedCouponGoodsCount = 0;
for (CartGoods cartGoods : oldCartGoodsList) {
//1.种子券商品券信息与月卡信息一致
if (null != cartGoods.getMonthCardInfo() && !addShoppingCartGoodsRequestVo.getCouponCode().equals(cartGoods.getMonthCardInfo().getCardCode())){
throw new ServiceException(ResponseResult.SHOPPING_CART_COUPON_NOT_EXIST);
}
if (cartGoods.getIsMonthCard()>0){
seedCouponCount = seedCouponCount + cartGoods.getQty();
}
if (cartGoods.getIsSeedCouponGoods()>0 && cartGoods.getIsMonthCard()<1){
seedCouponGoodsCount = seedCouponGoodsCount + cartGoods.getQty();
}
}
//2.种子券商品数量不可大于种子券数量
if ((seedCouponGoodsCount+addShoppingCartGoodsRequestVo.getQty()) > seedCouponCount){
throw new ServiceException(ResponseResult.SHOPPING_CART_SEED_COUPON_VALID);
}
}
} }
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