|
@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
|
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
@@ -13,15 +14,9 @@ import com.fs.erp.service.IErpGoodsService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
import com.fs.hisStore.config.FsErpConfig;
|
|
|
import com.fs.hisStore.config.MedicalMallConfig;
|
|
import com.fs.hisStore.config.MedicalMallConfig;
|
|
|
-import com.fs.hisStore.domain.FsStoreCartScrm;
|
|
|
|
|
-import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
|
|
-import com.fs.hisStore.domain.FsStoreProductGroupScrm;
|
|
|
|
|
-import com.fs.hisStore.domain.FsStoreScrm;
|
|
|
|
|
|
|
+import com.fs.hisStore.domain.*;
|
|
|
import com.fs.hisStore.dto.StoreProductGroupDTO;
|
|
import com.fs.hisStore.dto.StoreProductGroupDTO;
|
|
|
-import com.fs.hisStore.mapper.FsStoreCartScrmMapper;
|
|
|
|
|
-import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
|
|
|
|
|
-import com.fs.hisStore.mapper.FsStoreProductGroupScrmMapper;
|
|
|
|
|
-import com.fs.hisStore.mapper.FsStoreProductScrmMapper;
|
|
|
|
|
|
|
+import com.fs.hisStore.mapper.*;
|
|
|
import com.fs.hisStore.param.FsStoreCartCountParam;
|
|
import com.fs.hisStore.param.FsStoreCartCountParam;
|
|
|
import com.fs.hisStore.param.FsStoreCartDelParam;
|
|
import com.fs.hisStore.param.FsStoreCartDelParam;
|
|
|
import com.fs.hisStore.param.FsStoreCartNumParam;
|
|
import com.fs.hisStore.param.FsStoreCartNumParam;
|
|
@@ -35,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.hisStore.vo.FsStoreCartGroupStoreVO;
|
|
import com.fs.hisStore.vo.FsStoreCartGroupStoreVO;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -74,6 +70,9 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
private ISysConfigService configService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsStoreVerifyCodeScrmMapper verifyCodeScrmMapper;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -192,6 +191,11 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
.build();
|
|
.build();
|
|
|
storeCart.setCreateTime(new Date());
|
|
storeCart.setCreateTime(new Date());
|
|
|
checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
|
|
checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
|
|
|
|
|
+ if(cartParam.getType() == 1){//加入校验
|
|
|
|
|
+ if(checkCarNumber(storeCart.getProductId(),storeCart.getCartNum())){
|
|
|
|
|
+ return R.error("商品数量大于库存数量!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
fsStoreCartMapper.insertFsStoreCart(storeCart);
|
|
fsStoreCartMapper.insertFsStoreCart(storeCart);
|
|
|
return R.ok().put("id",storeCart.getId());
|
|
return R.ok().put("id",storeCart.getId());
|
|
|
}
|
|
}
|
|
@@ -200,6 +204,11 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
storeCart.setCartNum(cartParam.getCartNum() + cart.get(0).getCartNum());
|
|
storeCart.setCartNum(cartParam.getCartNum() + cart.get(0).getCartNum());
|
|
|
storeCart.setUpdateTime(new Date());
|
|
storeCart.setUpdateTime(new Date());
|
|
|
checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
|
|
checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
|
|
|
|
|
+ if(cartParam.getType() == 1){//加入校验
|
|
|
|
|
+ if(checkCarNumber(storeCart.getProductId(),storeCart.getCartNum())){
|
|
|
|
|
+ return R.error("商品数量大于库存数量!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
fsStoreCartMapper.updateFsStoreCart(storeCart);
|
|
fsStoreCartMapper.updateFsStoreCart(storeCart);
|
|
|
return R.ok().put("id",storeCart.getId());
|
|
return R.ok().put("id",storeCart.getId());
|
|
|
}
|
|
}
|
|
@@ -221,13 +230,34 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R changeNum(long userId, FsStoreCartNumParam cartParam) {
|
|
public R changeNum(long userId, FsStoreCartNumParam cartParam) {
|
|
|
- FsStoreCartScrm cart=fsStoreCartMapper.selectFsStoreCartById(cartParam.getId());
|
|
|
|
|
- checkProductStock(cart.getProductId(),cart.getProductAttrValueId());
|
|
|
|
|
- cart.setCartNum(cartParam.getNumber());
|
|
|
|
|
|
|
+ FsStoreCartScrm cart = fsStoreCartMapper.selectFsStoreCartById(cartParam.getId());
|
|
|
|
|
+ if (cart == null) {
|
|
|
|
|
+ return R.error("购物车商品不存在!");
|
|
|
|
|
+ }
|
|
|
|
|
+ int targetNum = cartParam.getNumber();
|
|
|
|
|
+ if(cartParam.getType() != null){
|
|
|
|
|
+ checkProductStock(cart.getProductId(), cart.getProductAttrValueId());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ Integer availableStock = verifyCodeScrmMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<FsStoreVerifyCodeScrm>()
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getProductId, cart.getProductId())
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getOutboundStatus, 0L)
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getIsDel, 0L)
|
|
|
|
|
+ .last("FOR UPDATE")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (targetNum > availableStock) {
|
|
|
|
|
+ FsStoreProductScrm product = fsStoreProductMapper.selectFsStoreProductById(cart.getProductId());
|
|
|
|
|
+ return R.error("商品" + product.getProductName() + ":库存不足!当前可用库存:" + availableStock);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cart.setCartNum(targetNum);
|
|
|
cart.setUpdateTime(new Date());
|
|
cart.setUpdateTime(new Date());
|
|
|
fsStoreCartMapper.updateFsStoreCart(cart);
|
|
fsStoreCartMapper.updateFsStoreCart(cart);
|
|
|
- return R.ok();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok("购物车数量修改成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -383,5 +413,19 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
|
|
|
return goodsService;
|
|
return goodsService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //校验购物车数量
|
|
|
|
|
+ public boolean checkCarNumber(Long productId,Integer num){
|
|
|
|
|
+ Integer availableStock = verifyCodeScrmMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<FsStoreVerifyCodeScrm>()
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getProductId, productId)
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getOutboundStatus, 0L)
|
|
|
|
|
+ .eq(FsStoreVerifyCodeScrm::getIsDel, 0L)
|
|
|
|
|
+ .last("FOR UPDATE")
|
|
|
|
|
+ );
|
|
|
|
|
+ if (num > availableStock) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|