@Override
public ResponseServer addCar(Integer id, Integer count) {
Long carLength = 0L;
Vip vip = (Vip) request.getAttribute(ConstantData.USER_LOGIN_NAME);
Jedis jedis = RedisPools.getJedis();
String cartInfo = jedis.get(ConstantData.USER_CAR_PRO + vip.getPhone() + id + “”);
Product pro = productService.getProductById(id);
if (cartInfo == null) {
Car car = new Car();
car.setProduct(pro);
car.setCount(count);
//计算小计金额
BigDecimal bigDecimal = BigDecimal.valueOf(0.00);
BigDecimal countt = new BigDecimal(count);
BigDecimal subtotal = bigDecimal.add(pro.getPrice()).multiply(countt);
car.setSubtotal(subtotal);
jedis.hset(ConstantData.USER_CAR_PRO + vip.getPhone(), id + "", JSONObject.toJSONString(car));
}else{
Car car = JSONObject.parseObject(cartInfo, Car.class);
Integer count1 = car.getCount();
count1=count1+count;
if (count1<0){
jedis.hdel(ConstantData.USER_CAR_PRO+vip.getPhone(),id+"");
}else{
car.setSubtotal(car.getProduct().getPrice().multiply(new BigDecimal(count1)));
}
}
Long hlen = jedis.hlen(ConstantData.USER_CAR_PRO + vip.getPhone());
RedisPools.returnJedis(jedis);
return ResponseServer.success(hlen);
}