Browse Source

商品购物车操作

master
xyiege 3 years ago
parent
commit
fdc172d33b
  1. 17
      src/main/java/cn/chjyj/szwh/controller/api/GoodsController.java
  2. 7
      src/main/java/cn/chjyj/szwh/service/GoodsService.java
  3. 107
      src/main/java/cn/chjyj/szwh/service/impl/GoodsServiceImpl.java

17
src/main/java/cn/chjyj/szwh/controller/api/GoodsController.java

@ -4,6 +4,7 @@ import cn.chjyj.szwh.bean.Goods;
import cn.chjyj.szwh.controller.BaseController;
import cn.chjyj.szwh.service.GoodsService;
import com.alibaba.fastjson2.JSONObject;
import javafx.beans.binding.ObjectBinding;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -50,6 +51,22 @@ public class GoodsController extends BaseController {
return jsonObject;
}
@RequestMapping("/getShoppingCar")
public JSONObject getShoppingCar(HttpServletRequest request){
long start = System.currentTimeMillis();
String userIsli =request.getParameter("user_isli");
String goodsIsli = request.getParameter("goods_isli");
String useYears = request.getParameter("use_years");
String appkey = request.getParameter("appkey");
String timestamp = request.getParameter("timestamp");
//
Map<String, Object> retmap =goodsService.getShoppingCar(userIsli);
jsonObject.put("code",200);
jsonObject.put("msg","成功");
jsonObject.put("data",retmap);
return jsonObject;
}
/**
* 手工导入商品信息
* post 方式提价

7
src/main/java/cn/chjyj/szwh/service/GoodsService.java

@ -121,4 +121,11 @@ public interface GoodsService {
* @return
*/
Map<String,Object> addShopCar(String userIsli,String goodsIsli,Integer userYears);
/**
* 查询购物车
* @param userIsli
* @return
*/
Map<String,Object> getShoppingCar(String userIsli);
}

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

@ -18,7 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
@ -43,6 +45,10 @@ public class GoodsServiceImpl implements GoodsService {
private UserMapper userMapper;
@Autowired
private OrderMapper orderMapper;
@Autowired
private AccountRatioSettingMapper accountRatioSettingMapper;
@Autowired
private AccountRatioDetailMapper accountRatioDetailMapper;
@Override
public List<Goods> getGoodsList(int page) {
@ -668,20 +674,111 @@ public class GoodsServiceImpl implements GoodsService {
//object
Object shopCar = RedisUtil.get(shopRedisKey);
if(shopCar!=null){
carjson =JSONObject.parseObject(shopCar.toString());
String tmpGoodsIsli= carjson.getString("goods_islicode");
if(goodsIsli.equals(tmpGoodsIsli)){
JSONArray jsonArray =carjson.getJSONArray("data");
// 检查goods_isli
List goodsIsliList =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);
}
//检查是否在列表中
if(goodsIsliList.contains(goodsIsli)){
retmap.put("code",400);
retmap.put("msg","该标的已添加到购物车");
}
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);
RedisUtil.set(shopRedisKey,carjson.toJSONString());
}else{
carjson.put("goods_islicode",goodsIsli);
carjson.put("use_years",userYears);
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);
RedisUtil.set(shopRedisKey,carjson.toJSONString());
}
return retmap;
}
@Override
public Map<String, Object> getShoppingCar(String userIsli) {
Map<String,Object> retmap =new HashMap<>();
String shopRedisKey="car_"+userIsli;
Object shopCar =RedisUtil.get(shopRedisKey);
JSONObject shopCarJson =JSONObject.parseObject(shopCar.toString());
JSONArray jsonArray = shopCarJson.getJSONArray("data");
//JSONObject carjson =JSONObject.parseObject(shopCar.toString());
if(shopCar==null){
//null
return retmap;
}
//fenpei
Map acrmap = new HashMap();
acrmap.put("is_deleted",0);
acrmap.put("status",1);
List<AccountRatioSetting> acrlist = accountRatioSettingMapper.getRatioSettingList(acrmap,0,1);
AccountRatioSetting accountRatioSetting = acrlist.get(0);
AccountRatioDetail accountRatioDetail =accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(),2);
//goods information
for(int x=0;x<jsonArray.size();x++){
JSONObject jsonObject = jsonArray.getJSONObject(x);
String goodsIsli= jsonObject.getString("goods_isli");
Goods goods = goodsMapper.getGoodsFuelByIsLi(goodsIsli);
//
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId());
retmap.put("detial",goodsDetail);
// 计算服务费
Integer count = jsonObject.getInteger("use_years");
if(goodsDetail.getGoodsEntrust()==1){
count=1;
}
BigDecimal serviceCharge=new BigDecimal(0);
BigDecimal totalMoney =new BigDecimal(0);
if(goodsDetail.getChargesType()==2){
if(accountRatioDetail.getCalculate()==1){
BigDecimal rate =accountRatioDetail.getRatio().divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice())
.multiply(rate);
}else{
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice())
.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{
retmap.put("transaction_count",count);
}
//GOODS SOURCE
List<GoodsSource> goodsSource = goodsSourceMapper.getGoodsSourceByIsli(goods.getGoodsIslicode());
retmap.put("source",goodsSource);
//
JSONObject userjson = SzwhApiUtils.getApiUser(userIsli);
Map umap = JSONObject.parseObject(userjson.getString("data"));
retmap.put("user",umap);
//
retmap.put("goods",goods);
}
return retmap;
}
/**
* query rank list
*

Loading…
Cancel
Save