Commit a7fd7fdc by ping.wu

Merge branches 'develop' and 'feature/20200915_购物车添加限制数量_wuping' of…

Merge branches 'develop' and 'feature/20200915_购物车添加限制数量_wuping' of http://gitlab.freemud.com/order-group-application/order-group into develop
parents c382eab1 78c83097
package cn.freemud.entities.dto;
import lombok.Data;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @version V1.0
* @Title: OpenPlatformPartnerWxappConfig
* @Package cn.freemud.entities.dto
* @Description:
* @author: ping1.wu
* @date: 2020/9/15 15:59
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Data
public class OpenPlatformPartnerWxappConfig {
private String wxAppid;
private String appKey;
private String appValue;
private Integer state;
}
...@@ -33,6 +33,7 @@ import cn.freemud.interceptor.BizServiceException; ...@@ -33,6 +33,7 @@ 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.thirdparty.*; import cn.freemud.service.thirdparty.*;
import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.PromotionFactory; import cn.freemud.utils.PromotionFactory;
import cn.freemud.utils.PropertyConvertUtil; import cn.freemud.utils.PropertyConvertUtil;
import cn.freemud.utils.ResponseUtil; import cn.freemud.utils.ResponseUtil;
...@@ -69,8 +70,6 @@ import org.apache.commons.lang.ObjectUtils; ...@@ -69,8 +70,6 @@ import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
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.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
...@@ -143,6 +142,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -143,6 +142,11 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
private ProductService productService; private ProductService productService;
@Autowired @Autowired
private ActivityService activityService; private ActivityService activityService;
@Autowired
private RedisCache redisCache;
private static final String limitCartKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_";
/** /**
* 从微信卡券向购物车中添加商品 * 从微信卡券向购物车中添加商品
...@@ -232,6 +236,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -232,6 +236,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
String menuType = addShoppingCartGoodsRequestVo.getMenuType(); String menuType = addShoppingCartGoodsRequestVo.getMenuType();
Integer orderType = addShoppingCartGoodsRequestVo.getOrderType(); Integer orderType = addShoppingCartGoodsRequestVo.getOrderType();
String receiveId = addShoppingCartGoodsRequestVo.getReceiveId(); String receiveId = addShoppingCartGoodsRequestVo.getReceiveId();
String tableNumber = addShoppingCartGoodsRequestVo.getTableNumber();
CartGoods cartGoods = ShoppingCartConvertAdapter.convent2CartGoods(addShoppingCartGoodsRequestVo); CartGoods cartGoods = ShoppingCartConvertAdapter.convent2CartGoods(addShoppingCartGoodsRequestVo);
List<Long> productIds = new ArrayList<>(); List<Long> productIds = new ArrayList<>();
...@@ -253,6 +258,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -253,6 +258,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (CollectionUtils.isEmpty(allCartGoodsList)) { if (CollectionUtils.isEmpty(allCartGoodsList)) {
allCartGoodsList = new ArrayList<>(); allCartGoodsList = new ArrayList<>();
} }
List<CartGoods> oldCartGoodsList = BeanUtil.convertBeans(allCartGoodsList, CartGoods::new);
/** /**
Integer checkQty = allCartGoodsList.indexOf(cartGoods) != -1 ? Integer checkQty = allCartGoodsList.indexOf(cartGoods) != -1 ?
allCartGoodsList.get(allCartGoodsList.indexOf(cartGoods)).getQty() + cartGoods.getQty() : cartGoods.getQty(); allCartGoodsList.get(allCartGoodsList.indexOf(cartGoods)).getQty() + cartGoods.getQty() : cartGoods.getQty();
...@@ -278,7 +284,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -278,7 +284,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult ActivityCalculationDiscountResponseDto.CalculationDiscountResult calculationDiscountResult
=getCalculationDiscountResult(menuType,partnerId,storeId,userId,appId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(), allCartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount); =getCalculationDiscountResult(menuType,partnerId,storeId,userId,appId,userLoginInfoDto.getWxAppid(),orderType,assortmentCustomerInfoVo.isMemberPaid(), allCartGoodsList,new ArrayList(),new ArrayList<>(),null,deliveryAmount);
sendGoodsQtyCheck(checkQty,appId,partnerId, userId, storeId,tableNumber, oldCartGoodsList,shoppingCartBaseService,calculationDiscountResult.getSendGoods());
// 当商品数量被设为0时 // 当商品数量被设为0时
if (Objects.equals(cartGoods.getQty(), 0)) { if (Objects.equals(cartGoods.getQty(), 0)) {
assortmentSdkService.updateGoodsQtyBySdk(partnerId, userId, storeId, cartGoods.getCartGoodsUid(), 0, "", shoppingCartBaseService); assortmentSdkService.updateGoodsQtyBySdk(partnerId, userId, storeId, cartGoods.getCartGoodsUid(), 0, "", shoppingCartBaseService);
...@@ -379,6 +385,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -379,6 +385,7 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
shoppingCartGoodsResponseVo.setProducts(cartGoodsList); shoppingCartGoodsResponseVo.setProducts(cartGoodsList);
// return shoppingCartGoodsResponseVo; // return shoppingCartGoodsResponseVo;
} }
sendGoodsQtyCheckForUpdate(qty,cartGoods.getQty(),appId,partnerId, userId, storeId,null, cartGoodsUid,shoppingCartBaseService,calculationDiscountResult.getSendGoods());
ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, updateShoppingCartGoodsQtyRequestVo.getOrderType()); ActivityQueryDto activityQueryDto = activityAdapter.getActivityQueryDto(partnerId, storeId, userId, appId, updateShoppingCartGoodsQtyRequestVo.getOrderType());
...@@ -1637,20 +1644,13 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1637,20 +1644,13 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
} }
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RedisCache redisCache;
/** /**
* 查询生态配置限制加购开关与限制数量 * 查询生态配置限制加购开关与限制数量
*/ */
public void limitGoodsQty(Integer qty,String appid){ public void limitGoodsQty(Integer qty,String appid){
String redisKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_"+appid; String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2"); Object value = redisCache.hashGet(redisKey, "2");
List<AssortmentOpenPlatformPartnerWxappConfig> configs = null;
if (value == null) { if (value == null) {
return ; return ;
} else { } else {
...@@ -1673,4 +1673,86 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService { ...@@ -1673,4 +1673,86 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
} }
} }
/**
* 购物车添加完成后促销返回赠送商品总数量校验
*/
public void sendGoodsQtyCheck(Integer checkQty,String appid,String partnerId, String userId, String storeId, String tableNumber,List<CartGoods> oldCartGoodsList, ShoppingCartBaseService shoppingCartService,List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity> sendActivitys){
if(CollectionUtils.isEmpty(sendActivitys)){
return;
}
int sendQty = 0;
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity : sendActivitys){
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods sendGoods : sendActivity.getSendGoods()){
sendQty += sendGoods.getSendNumber();
}
}
String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2");
if (value == null) {
return ;
} else {
JSONArray jsonArray = (JSONArray)value;
int cartLimitFlag = 0;
int cartLimitCount = 0;
for (Object object : jsonArray){
JSONObject jsonObject = (JSONObject)object;
HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(),HashMap.class);
if("cartLimitFlag".equals(hashMap.get("appKey"))){
cartLimitFlag = Integer.parseInt((String)hashMap.get("appValue"));
}
if("cartLimitCount".equals(hashMap.get("appKey"))){
cartLimitCount = Integer.parseInt((String)hashMap.get("appValue"));
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && checkQty+sendQty > cartLimitCount){
assortmentSdkService.setShoppingCart( partnerId, storeId, userId, oldCartGoodsList, null, tableNumber, shoppingCartService);
throw new ServiceException(ResponseResult.SHOPPING_CART_LIMIT_ADD);
}
}
}
/**
* 购物车添加完成后促销返回赠送商品总数量校验
*/
public void sendGoodsQtyCheckForUpdate(Integer updateQty,Integer goodsQty,String appid,String partnerId, String userId, String storeId, String cartGoodsUid,String tableNumber, ShoppingCartBaseService shoppingCartService,List<ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity> sendActivitys){
if(CollectionUtils.isEmpty(sendActivitys)){
return;
}
int sendQty = 0;
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity sendActivity : sendActivitys){
for (ActivityCalculationDiscountResponseDto.CalculationDiscountResult.SendActivity.SendGoods sendGoods : sendActivity.getSendGoods()){
sendQty += sendGoods.getSendNumber();
}
}
String redisKey = limitCartKey + appid;
Object value = redisCache.hashGet(redisKey, "2");
if (value == null) {
return ;
} else {
JSONArray jsonArray = (JSONArray)value;
int cartLimitFlag = 0;
int cartLimitCount = 0;
for (Object object : jsonArray){
JSONObject jsonObject = (JSONObject)object;
HashMap hashMap = JSONObject.parseObject(jsonObject.toJSONString(),HashMap.class);
if("cartLimitFlag".equals(hashMap.get("appKey"))){
cartLimitFlag = Integer.parseInt((String)hashMap.get("appValue"));
}
if("cartLimitCount".equals(hashMap.get("appKey"))){
cartLimitCount = Integer.parseInt((String)hashMap.get("appValue"));
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && updateQty+sendQty > cartLimitCount){
assortmentSdkService.updateGoodsQtyBySdk(partnerId, userId, storeId, cartGoodsUid, goodsQty, "", shoppingCartBaseService);
throw new ServiceException(ResponseResult.SHOPPING_CART_LIMIT_ADD);
}
}
}
} }
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