|
|
|
@ -671,39 +671,56 @@ 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) { |
|
|
|
JSONArray jsonArray = carjson.getJSONArray("data"); |
|
|
|
// 检查goods_isli
|
|
|
|
List goodsIsliList =new ArrayList(); |
|
|
|
if (jsonArray == null) { //为空需要添新的元素
|
|
|
|
cimap.put("goods_isli", goodsIsli); |
|
|
|
cimap.put("use_years", userYears); |
|
|
|
carList.add(cimap); |
|
|
|
} else { |
|
|
|
//抽取出goods_isli
|
|
|
|
List cgilist = new ArrayList(); |
|
|
|
for (int x = 0; x < jsonArray.size(); x++) { |
|
|
|
JSONObject tmpjson = (JSONObject) jsonArray.get(x); |
|
|
|
String tgoodsisli = tmpjson.getString("goods_islid"); |
|
|
|
goodsIsliList.add(tgoodsisli); |
|
|
|
cgilist.add(tmpjson.getString("goods_isli")); |
|
|
|
} |
|
|
|
//检查是否在列表中
|
|
|
|
if(goodsIsliList.contains(goodsIsli)){ |
|
|
|
// 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); |
|
|
|
} |
|
|
|
} |
|
|
|
List tmpCarItem = new ArrayList(); |
|
|
|
Map tmpcar = new HashMap(); |
|
|
|
tmpcar.put("goods_isli",goodsIsli); |
|
|
|
tmpcar.put("use_years",userYears); |
|
|
|
tmpCarItem.add(tmpcar); |
|
|
|
carjson.put("data",tmpCarItem); |
|
|
|
// 添加到购物车json
|
|
|
|
carjson.put("user_isli",userIsli); |
|
|
|
carjson.put("data",carList); |
|
|
|
RedisUtil.set(shopRedisKey, carjson.toJSONString()); |
|
|
|
} else { |
|
|
|
Map tmpCar = new HashMap(); |
|
|
|
tmpCar.put("goods_islicode",goodsIsli); |
|
|
|
tmpCar.put("use_years",userYears); |
|
|
|
List carItem = new ArrayList(); |
|
|
|
carItem.add(tmpCar); |
|
|
|
carjson.put("data",carItem); |
|
|
|
|
|
|
|
//first biuld car item
|
|
|
|
cimap.put("user_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()); |
|
|
|
} |
|
|
|
//购物车添加成功
|
|
|
|
retmap.put("code", 200); |
|
|
|
retmap.put("msg", "成功"); |
|
|
|
return retmap; |
|
|
|
} |
|
|
|
|
|
|
|
@ -727,6 +744,7 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
AccountRatioSetting accountRatioSetting = acrlist.get(0); |
|
|
|
AccountRatioDetail accountRatioDetail = accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(), 2); |
|
|
|
|
|
|
|
if (jsonArray.size() > 0) { |
|
|
|
//goods information
|
|
|
|
for (int x = 0; x < jsonArray.size(); x++) { |
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(x); |
|
|
|
@ -775,7 +793,7 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
//
|
|
|
|
retmap.put("goods", goods); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return retmap; |
|
|
|
} |
|
|
|
|
|
|
|
|