| | |
| | | if (!cacheList.isEmpty()) { |
| | | for (ShoppingCartItem cartItem : cacheList) { |
| | | if (cartItem.getId().equals(id)) { |
| | | cartItem.setNum( num); |
| | | cartItem.setNum(num); |
| | | if (num==0){ |
| | | // 移除 |
| | | List<ShoppingCartItem> res = new ArrayList<>(); |
| | | for (ShoppingCartItem c : cacheList) { |
| | | if (c.getNum()==0){ |
| | | continue; |
| | | } |
| | | res.add(c); |
| | | } |
| | | redisCache.setCacheList("shopCart:"+userId, res); |
| | | return R.ok(); |
| | | } |
| | | redisCache.setCacheList("shopCart:"+userId, cacheList); |
| | | return R.ok(); |
| | | }else{ |
| | |
| | | cacheList = new ArrayList<>(); |
| | | cacheList.add(shoppingCartItem); |
| | | } |
| | | redisCache.setCacheList("shopCart:"+userId, cacheList); |
| | | List<ShoppingCartItem> res = new ArrayList<>(); |
| | | for (ShoppingCartItem cartItem : cacheList) { |
| | | if (cartItem.getNum()==0){ |
| | | continue; |
| | | } |
| | | res.add(cartItem); |
| | | } |
| | | redisCache.setCacheList("shopCart:"+userId, res); |
| | | return R.ok(); |
| | | } |
| | | |