|
|
|
@ -623,55 +623,41 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
//shop car infomation
|
|
|
|
String shopRedisKey = "car_" + userIsli; |
|
|
|
JSONObject carjson = new JSONObject(); |
|
|
|
// 购物车列表
|
|
|
|
List carList = new ArrayList(); |
|
|
|
// car item
|
|
|
|
Map cimap = new HashMap(); |
|
|
|
// {"user_isli":"ssss",data:["sss","sss","sss"]}
|
|
|
|
//object
|
|
|
|
Object shopCar = RedisUtil.get(shopRedisKey); |
|
|
|
|
|
|
|
// 购物车中有记录的
|
|
|
|
if (shopCar != null) { |
|
|
|
carjson = JSONObject.parseObject(shopCar.toString()); |
|
|
|
// 提取节点转为jsonarray
|
|
|
|
JSONArray jsonArray = carjson.getJSONArray("data"); |
|
|
|
if (jsonArray == null) { //为空需要添新的元素
|
|
|
|
cimap.put("goods_isli", goodsIsli); |
|
|
|
cimap.put("use_years", userYears); |
|
|
|
carList.add(cimap); |
|
|
|
} else { |
|
|
|
//抽取出goods_isli
|
|
|
|
if (jsonArray != null) { //为空需要添新的元素
|
|
|
|
List cgilist = new ArrayList(); |
|
|
|
for (int x = 0; x < jsonArray.size(); x++) { |
|
|
|
JSONObject tmpjson = (JSONObject) jsonArray.get(x); |
|
|
|
// goods_isli insert into list for checking has exist
|
|
|
|
cgilist.add(tmpjson.getString("goods_isli")); |
|
|
|
} |
|
|
|
// goods_isli has been exist in car?
|
|
|
|
if(cgilist.contains(goodsIsli)){ |
|
|
|
retmap.put("code", 400); |
|
|
|
retmap.put("msg", "该标的已添加到购物车"); |
|
|
|
}else { |
|
|
|
cimap.put("goods_isli", goodsIsli); |
|
|
|
cimap.put("use_years", userYears); |
|
|
|
carList.add(cimap); |
|
|
|
JSONObject retjson =SzCarUtils.addCart(shopRedisKey,userIsli,cimap); |
|
|
|
// goods_isli has been exist in car?
|
|
|
|
if(cgilist.contains(goodsIsli)){ |
|
|
|
retmap.put("code", 400); |
|
|
|
retmap.put("msg", "该标的已添加到购物车"); |
|
|
|
return retmap; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 添加到购物车json
|
|
|
|
//carjson.put("user_isli",userIsli);
|
|
|
|
//carjson.put("data",carList);
|
|
|
|
RedisUtil.set(shopRedisKey, carjson.toJSONString()); |
|
|
|
//
|
|
|
|
} else { |
|
|
|
//first biuld car item
|
|
|
|
cimap.put("user_isli",goodsIsli); |
|
|
|
cimap.put("goods_isli",goodsIsli); |
|
|
|
cimap.put("use_years",userYears); |
|
|
|
// second add to carlist
|
|
|
|
carList.add(cimap); |
|
|
|
//third add new wraper
|
|
|
|
carjson.put("user_isli",userIsli); |
|
|
|
carjson.put("data",carList); |
|
|
|
RedisUtil.set(shopRedisKey, carjson.toJSONString()); |
|
|
|
} |
|
|
|
//购物车添加成功
|
|
|
|
JSONObject retjson =SzCarUtils.addCart(shopRedisKey,userIsli,cimap); |
|
|
|
carjson.put("user_isli",userIsli); |
|
|
|
carjson.put("data",retjson); |
|
|
|
RedisUtil.set(shopRedisKey, carjson.toJSONString()); |
|
|
|
|
|
|
|
retmap.put("code", 200); |
|
|
|
retmap.put("msg", "成功"); |
|
|
|
return retmap; |
|
|
|
|