1 changed files with 39 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||
package cn.chjyj.szwh.utils; |
|||
|
|||
import com.alibaba.fastjson2.JSONArray; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 购物车操作 |
|||
*/ |
|||
public class SzCarUtils { |
|||
/** |
|||
* add goods to shop car |
|||
* @param carkey |
|||
* @param ugmap goods_isli and user_isli map |
|||
* @return |
|||
*/ |
|||
public static JSONObject addCart(String carkey,String userIsli, Map ugmap){ |
|||
// get shopping car from redis
|
|||
Object shopCar = RedisUtil.get(carkey); |
|||
JSONObject shopCarJson = JSONObject.parseObject(shopCar.toString()); |
|||
JSONArray jsonArray = shopCarJson.getJSONArray("data"); |
|||
// good list
|
|||
List<JSONObject> carlist =new ArrayList<>(); |
|||
if(jsonArray.size()>0){ |
|||
for (int i=0;i<jsonArray.size();i++){ |
|||
carlist.add(jsonArray.getJSONObject(i)); |
|||
} |
|||
}else{ |
|||
carlist.add(new JSONObject(ugmap)); |
|||
} |
|||
JSONObject outjson = new JSONObject(); |
|||
outjson.put("user_isli",userIsli); |
|||
outjson.put("data",carlist); |
|||
return outjson; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue