Commit c814fa9f by ping.wu

购物车加入数量限制

parent a2a4bc16
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;
}
......@@ -87,6 +87,7 @@ public enum ResponseResult {
SHOPPING_CART_SEAT_EMPTY("44020", "键位为空"),
SHOPPING_CART_COUPON_USED("44021", "优惠券已加入餐盘"),
SHOPPING_CART_GOODS_COUPON_CAN_NOT_USE("44022", "已加入同样优惠券,第二张暂不可用"),
SHOPPING_CART_LIMIT_ADD("44025", "加购数量超过限制"),
/**
* 订单状态码
......
......@@ -30,6 +30,7 @@ import cn.freemud.entities.vo.*;
import cn.freemud.enums.*;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.interceptor.BizServiceException;
import cn.freemud.redis.RedisCache;
import cn.freemud.service.*;
import cn.freemud.service.thirdparty.*;
import cn.freemud.utils.PromotionFactory;
......@@ -39,6 +40,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.freemud.api.assortment.datamanager.entity.db.AssortmentOpenPlatformPartnerStoreDeliveryConfig;
import com.freemud.api.assortment.datamanager.entity.db.AssortmentOpenPlatformPartnerWxappConfig;
import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformPartnerStoreDeliveryConfigManager;
import com.freemud.api.assortment.datamanager.manager.customer.AssortmentCustomerInfoManager;
import com.freemud.application.sdk.api.log.ErrorLog;
......@@ -67,6 +69,8 @@ import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.awt.geom.Point2D;
......@@ -254,6 +258,8 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
allCartGoodsList.get(allCartGoodsList.indexOf(cartGoods)).getQty() + cartGoods.getQty() : cartGoods.getQty();
*/
Integer checkQty = this.checkSkuQty(allCartGoodsList, cartGoods);
//购物车添加数量限制
limitGoodsQty(checkQty,appId);
//查询多个商品库存信息
queryManyGoodsStocks(addShoppingCartGoodsRequestVo, productIds, productBeanListSpuClass, skuId, checkQty);
String productName = null;
......@@ -1627,4 +1633,46 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
shoppingCartGoodsResponseVo.setToastMsg("");
}
}
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RedisCache redisCache;
/**
* 查询生态配置限制加购开关与限制数量
*/
public void limitGoodsQty(Integer qty,String appid){
String redisKey = "ecology:kgd:wxappconfig:open_platform_partner_wxapp_config:appkey_"+appid;
BoundHashOperations<String, String, List<OpenPlatformPartnerWxappConfig>> operations = redisTemplate.boundHashOps(redisKey);
Object value = redisCache.hashGet(redisKey, "2");
List<AssortmentOpenPlatformPartnerWxappConfig> configs = null;
if (value == null) {
return ;
} else {
String json = JSONObject.toJSONString(value);
configs = JSONArray.parseArray(json, AssortmentOpenPlatformPartnerWxappConfig.class);
}
List<OpenPlatformPartnerWxappConfig> configs2 = operations.get("2");
if(CollectionUtils.isNotEmpty(configs)){
int cartLimitFlag = 0;
int cartLimitCount = 0;
for (AssortmentOpenPlatformPartnerWxappConfig config : configs){
if("cartLimitFlag".equals(config.getAppKey())){
cartLimitFlag= Integer.parseInt(config.getAppValue());
}
if("cartLimitCount".equals(config.getAppKey())){
cartLimitCount= Integer.parseInt(config.getAppValue());
}
}
if(cartLimitFlag == 1 && cartLimitCount != 0 && qty > cartLimitCount){
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