|
|
|
@ -23,12 +23,12 @@ public class SzCarUtils { |
|
|
|
// get shopping car from redis
|
|
|
|
Object shopCar = RedisUtil.get(carkey); |
|
|
|
// 对象存在
|
|
|
|
if(shopCar!=null) { |
|
|
|
if (shopCar != null) { |
|
|
|
JSONObject shopCarJson = JSONObject.parseObject(shopCar.toString()); |
|
|
|
JSONArray jsonArray = shopCarJson.getJSONArray("data"); |
|
|
|
if (jsonArray != null) { |
|
|
|
for (int x = 0; x < jsonArray.size(); x++) { |
|
|
|
carItem.add((JSONObject)jsonArray.get(x)); |
|
|
|
carItem.add((JSONObject) jsonArray.get(x)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -41,4 +41,45 @@ public class SzCarUtils { |
|
|
|
RedisUtil.set(carkey, outjson.toJSONString()); |
|
|
|
return outjson; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 删除购物中的商品 |
|
|
|
* |
|
|
|
* @param userIsli redis键名,用户编号 |
|
|
|
* @param goodsIsli 删除的商品编号 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static JSONObject delCart(String userIsli, String goodsIsli) { |
|
|
|
// get shopping car from redis
|
|
|
|
String carkey = "car_" + userIsli; |
|
|
|
Object shopCar = RedisUtil.get(carkey); |
|
|
|
if (shopCar == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
List ncarlist = new ArrayList(); |
|
|
|
//find jsonarray
|
|
|
|
JSONObject shopCarJson = JSONObject.parseObject(shopCar.toString()); |
|
|
|
JSONArray jsonArray = shopCarJson.getJSONArray("data"); |
|
|
|
if (jsonArray == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
// loop and check
|
|
|
|
for (int x = 0; x < jsonArray.size(); x++) { |
|
|
|
JSONObject tmpCarItem = (JSONObject) jsonArray.get(x); |
|
|
|
String tgisli = tmpCarItem.getString("goods_isli"); |
|
|
|
if (!tgisli.equals(goodsIsli)) { |
|
|
|
ncarlist.add(tmpCarItem); |
|
|
|
} |
|
|
|
} |
|
|
|
// 返回结果
|
|
|
|
JSONObject outjson = new JSONObject(); |
|
|
|
outjson.put("user_isli", userIsli); |
|
|
|
outjson.put("data", ncarlist); |
|
|
|
//1 del original car
|
|
|
|
RedisUtil.del(carkey); |
|
|
|
// 2 add new
|
|
|
|
RedisUtil.set(carkey, outjson.toJSONString()); |
|
|
|
// 3 retun result
|
|
|
|
return outjson; |
|
|
|
} |
|
|
|
} |
|
|
|
|