Browse Source

调整购物车逻辑

master
xyiege 3 years ago
parent
commit
da4c049fa8
  1. 103
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java
  2. 21
      src/main/java/cn/chjyj/szwh/utils/SzCarUtils.java

103
src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

@ -654,9 +654,9 @@ public class GoodsServiceImpl implements GoodsService {
} }
//购物车添加成功 //购物车添加成功
JSONObject retjson =SzCarUtils.addCart(shopRedisKey,userIsli,cimap); JSONObject retjson =SzCarUtils.addCart(shopRedisKey,userIsli,cimap);
carjson.put("user_isli",userIsli); // carjson.put("user_isli",userIsli);
carjson.put("data",retjson); // carjson.put("data",retjson);
RedisUtil.set(shopRedisKey, carjson.toJSONString()); // RedisUtil.set(shopRedisKey, carjson.toJSONString());
retmap.put("code", 200); retmap.put("code", 200);
retmap.put("msg", "成功"); retmap.put("msg", "成功");
@ -687,7 +687,7 @@ public class GoodsServiceImpl implements GoodsService {
AccountRatioDetail accountRatioDetail = accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(), 2); AccountRatioDetail accountRatioDetail = accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(), 2);
//循环枚举 //循环枚举
if (jsonArray.size() > 0) { if (jsonArray!=null && jsonArray.size() > 0) {
//goods information //goods information
for (int x =0; x<jsonArray.size(); x++) { for (int x =0; x<jsonArray.size(); x++) {
Map<String, Object> retmap = new HashMap<>(); Map<String, Object> retmap = new HashMap<>();
@ -695,58 +695,57 @@ public class GoodsServiceImpl implements GoodsService {
String goodsIsli = jsonObject.getString("goods_isli"); String goodsIsli = jsonObject.getString("goods_isli");
//goods //goods
Goods goods = goodsMapper.getGoodsByIsli(goodsIsli); Goods goods = goodsMapper.getGoodsByIsli(goodsIsli);
// 将good 实体中 压扁,变成k-v形式
retmap = JSONObject.parseObject(JSON.toJSONString(goods)); retmap = JSONObject.parseObject(JSON.toJSONString(goods));
// retmap.put("goods_islicode",goodsIsli); if(goods!=null) {
// retmap.put("username",goods.getUsername()); //goods detail
// GoodsListVo goodsListVo = goodsMapper.getSingleGoodsListVOByGoodsIsli(goodsIsli); GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId());
// retmap =JSONObject.parseObject(JSON.toJSONString(goodsListVo)); Map gdmap = new HashMap();
gdmap.put("goods_image", goodsDetail.getGoodsImage());
//goods detail gdmap.put("goods_name", goodsDetail.getGoodsName());
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId()); gdmap.put("goods_entrust", goodsDetail.getGoodsEntrust());
Map gdmap = new HashMap(); gdmap.put("charges_type", goodsDetail.getChargesType());
gdmap.put("goods_image",goodsDetail.getGoodsImage()); gdmap.put("price", goodsDetail.getPrice());
gdmap.put("goods_name",goodsDetail.getGoodsName()); retmap.put("detail", gdmap);
gdmap.put("goods_entrust",goodsDetail.getGoodsEntrust());
gdmap.put("charges_type",goodsDetail.getChargesType()); // 计算服务费
gdmap.put("price",goodsDetail.getPrice()); Integer count = jsonObject.getInteger("use_years");
retmap.put("detail", gdmap); if (goodsDetail.getGoodsEntrust() == 1) {
// 计算服务费 count = 1;
Integer count = jsonObject.getInteger("use_years"); }
if (goodsDetail.getGoodsEntrust() == 1) { BigDecimal serviceCharge = new BigDecimal(0);
count = 1; BigDecimal totalMoney = new BigDecimal(0);
} if (goodsDetail.getChargesType() == 2) {
BigDecimal serviceCharge = new BigDecimal(0); if (accountRatioDetail.getCalculate() == 1) {
BigDecimal totalMoney = new BigDecimal(0); BigDecimal rate = accountRatioDetail.getRatio().divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
if (goodsDetail.getChargesType() == 2) { serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice())
if (accountRatioDetail.getCalculate() == 1) { .multiply(rate);
BigDecimal rate = accountRatioDetail.getRatio().divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP); } else {
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice())
.multiply(rate); .add(accountRatioDetail.getAmount());
}
totalMoney = new BigDecimal(count).multiply(goodsDetail.getPrice())
.add(serviceCharge)
.add(goodsDetail.getEarnestMoney());
}
BigDecimal goodsPrice = new BigDecimal(count).multiply(goodsDetail.getPrice()).setScale(2);
retmap.put("service_charge", serviceCharge);
retmap.put("total_money", totalMoney);
retmap.put("goods_price", goodsPrice);
//
if (goodsDetail.getGoodsEntrust() == 1 || (goodsDetail.getChargesType() == 1 && goodsDetail.getGoodsEntrust() == 2)) {
retmap.put("transaction_count", "-");
} else { } else {
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) retmap.put("transaction_count", count);
.add(accountRatioDetail.getAmount());
} }
totalMoney = new BigDecimal(count).multiply(goodsDetail.getPrice()) //GOODS SOURCE
.add(serviceCharge) List<GoodsSourceVo> goodsSourcevo = goodsSourceMapper.getGoodsSourceVOByIsli(goods.getGoodsIslicode());
.add(goodsDetail.getEarnestMoney()); retmap.put("source", goodsSourcevo);
} //
BigDecimal goodsPrice = new BigDecimal(count).multiply(goodsDetail.getPrice()).setScale(2); JSONObject userjson = SzwhApiUtils.getApiUser(userIsli);
retmap.put("service_charge", serviceCharge); Map umap = JSONObject.parseObject(userjson.getString("data"));
retmap.put("total_money", totalMoney); retmap.put("user", umap);
retmap.put("goods_price", goodsPrice);
//
if (goodsDetail.getGoodsEntrust() == 1 || (goodsDetail.getChargesType() == 1 && goodsDetail.getGoodsEntrust() == 2)) {
retmap.put("transaction_count", "-");
} else {
retmap.put("transaction_count", count);
} }
//GOODS SOURCE
List<GoodsSourceVo> goodsSourcevo = goodsSourceMapper.getGoodsSourceVOByIsli(goods.getGoodsIslicode());
retmap.put("source", goodsSourcevo);
//
JSONObject userjson = SzwhApiUtils.getApiUser(userIsli);
Map umap = JSONObject.parseObject(userjson.getString("data"));
retmap.put("user", umap);
// add retlist // add retlist
retlist.add(retmap); retlist.add(retmap);

21
src/main/java/cn/chjyj/szwh/utils/SzCarUtils.java

@ -13,28 +13,33 @@ import java.util.Map;
public class SzCarUtils { public class SzCarUtils {
/** /**
* add goods to shop car * add goods to shop car
*
* @param carkey * @param carkey
* @param ugmap goods_isli and user_isli map * @param ugmap goods_isli and user_isli map
* @return * @return
*/ */
public static JSONObject addCart(String carkey,String userIsli, Map ugmap){ public static JSONObject addCart(String carkey, String userIsli, Map ugmap) {
List carItem = new ArrayList(); List carItem = new ArrayList();
// get shopping car from redis // get shopping car from redis
Object shopCar = RedisUtil.get(carkey); Object shopCar = RedisUtil.get(carkey);
// 对象存在
if(shopCar!=null) { if(shopCar!=null) {
JSONObject shopCarJson = JSONObject.parseObject(shopCar.toString()); JSONObject shopCarJson = JSONObject.parseObject(shopCar.toString());
JSONArray jsonArray = shopCarJson.getJSONArray("data"); JSONArray jsonArray = shopCarJson.getJSONArray("data");
if(jsonArray!=null) { if (jsonArray != null) {
for (int x = 0; x < jsonArray.size(); x++) { for (int x = 0; x < jsonArray.size(); x++) {
carItem.add(jsonArray.getJSONObject(x)); //carItem.add(jsonArray.getJSONObject(x));
carItem.add(jsonArray.get(x));
} }
} }
}else{
carItem.add(new JSONObject(ugmap));
} }
// add new
carItem.add(new JSONObject(ugmap));
JSONObject outjson = new JSONObject(); JSONObject outjson = new JSONObject();
outjson.put("user_isli",userIsli); outjson.put("user_isli", userIsli);
outjson.put("data",carItem); outjson.put("data", carItem);
RedisUtil.set(carkey, outjson.toJSONString());
return outjson; return outjson;
} }
} }

Loading…
Cancel
Save