|
@@ -13,6 +13,7 @@ import com.kmall.common.constant.Dict;
|
|
|
import com.kmall.common.utils.Constant;
|
|
|
import com.kmall.common.utils.MapUtils;
|
|
|
import com.kmall.common.utils.RRException;
|
|
|
+import com.kmall.common.utils.StringUtils;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -200,17 +201,11 @@ public class ApiCartService {
|
|
|
return cartDao.queryCartByGoodsBizType(goodsBizType);
|
|
|
}
|
|
|
|
|
|
- public Map<String, Object> getCartMoney(UserVo loginUser, String checkCart, Long storeId){
|
|
|
+ public Map<String, Object> getCartMoney(UserVo loginUser, CheckOutDto checkOutDto, Long storeId){
|
|
|
Map<String, Object> resultObj = Maps.newHashMap();
|
|
|
- //查询列表数据
|
|
|
- Map param = Maps.newHashMap();
|
|
|
- param.put("user_id", loginUser.getId());
|
|
|
- param.put("store_id", storeId);
|
|
|
- param.put("checkCart",checkCart);
|
|
|
- param.put("checked", "1");
|
|
|
- param.putAll(setIsStockShare(storeId));
|
|
|
- List<CartVo> cartList = cartDao.queryList(param);
|
|
|
- //获取购物车统计信息
|
|
|
+ Long goodsId = checkOutDto.getGoodsId();
|
|
|
+ Integer number = checkOutDto.getNumber();
|
|
|
+ String checkCart = checkOutDto.getCheckCart();
|
|
|
Integer goodsCount = 0;
|
|
|
BigDecimal goodsAmount = new BigDecimal(0.00);
|
|
|
Integer checkedGoodsCount = 0;
|
|
@@ -219,6 +214,45 @@ public class ApiCartService {
|
|
|
BigDecimal checkedGoodsAmount02 = new BigDecimal(0.00);
|
|
|
BigDecimal checkedGoodsAmount10 = new BigDecimal(0.00);
|
|
|
BigDecimal checkedGoodsAmount11 = new BigDecimal(0.00);
|
|
|
+ List<CartVo> cartList = new ArrayList<>();
|
|
|
+ //商品id不为空,则提交订单是从商品详情页立即购买过来的
|
|
|
+ if(goodsId != null){
|
|
|
+ GoodsVo goodsVo = apiGoodsMapper.queryObjectByStoreId(goodsId, storeId);
|
|
|
+ if(goodsVo != null){
|
|
|
+ if(goodsVo.getGoods_number() == 0){
|
|
|
+ logger.error("商品库存不足" );
|
|
|
+ throw new RRException("商品库存不足");
|
|
|
+ }
|
|
|
+ CartVo vo = new CartVo();
|
|
|
+ vo.setGoodsBizType(goodsVo.getGoodsBizType());
|
|
|
+ vo.setGoods_id(goodsVo.getId());
|
|
|
+ vo.setNumber(number);
|
|
|
+ vo.setUser_id(checkOutDto.getLoginUser().getId());
|
|
|
+ vo.setSku(goodsVo.getSku());
|
|
|
+ vo.setGoods_sn(goodsVo.getGoods_sn());
|
|
|
+ vo.setGoods_name(goodsVo.getName());
|
|
|
+ vo.setRetail_price(goodsVo.getRetail_price());
|
|
|
+ vo.setStore_id(Long.valueOf(goodsVo.getStoreId()));
|
|
|
+ vo.setChecked(1);
|
|
|
+ vo.setList_pic_url(goodsVo.getList_pic_url());
|
|
|
+ vo.setProduct_id(Long.valueOf(goodsVo.getProduct_id()));
|
|
|
+ vo.setMarket_price(goodsVo.getMarket_price());
|
|
|
+ cartList.add(vo);
|
|
|
+ }else {
|
|
|
+ logger.error("商品信息不存在" );
|
|
|
+ throw new RRException("商品信息不存在");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //查询列表数据
|
|
|
+ Map param = Maps.newHashMap();
|
|
|
+ param.put("user_id", loginUser.getId());
|
|
|
+ param.put("store_id", storeId);
|
|
|
+ param.put("checkCart",checkCart);
|
|
|
+ param.put("checked", "1");
|
|
|
+ param.putAll(setIsStockShare(storeId));
|
|
|
+ cartList = cartDao.queryList(param);
|
|
|
+ }
|
|
|
+ //获取购物车统计信息
|
|
|
for (CartVo cartItem : cartList) {
|
|
|
goodsCount += cartItem.getNumber();
|
|
|
goodsAmount = goodsAmount.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
|
|
@@ -279,14 +313,27 @@ public class ApiCartService {
|
|
|
* @param actualPrice
|
|
|
* @return
|
|
|
*/
|
|
|
- public BigDecimal mathActualPrice(UserCouponVo checkedCoupon, BigDecimal actualPrice){
|
|
|
+ public BigDecimal mathActualPrice(UserCouponVo checkedCoupon, BigDecimal actualPrice,List<CartVo> checkedGoodsList){
|
|
|
+ BigDecimal actualPrice2 = Constant.ZERO;
|
|
|
+ BigDecimal actualPrice3 = Constant.ZERO;
|
|
|
if(checkedCoupon != null){
|
|
|
if (checkedCoupon.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_00.getItem())) {
|
|
|
actualPrice = actualPrice.subtract(checkedCoupon.getTypeMoney());
|
|
|
}
|
|
|
if (checkedCoupon.getTickDiscType().equalsIgnoreCase(Dict.tickDiscType.item_01.getItem())) {
|
|
|
+ for(int i = 0; i < checkedGoodsList.size(); i++){
|
|
|
+ CartVo cartVo = checkedGoodsList.get(i);
|
|
|
+ List<Integer> goodsIds = checkedCoupon.getGoodsList();
|
|
|
+ for(int j=0;j<goodsIds.size();j++){
|
|
|
+ if(cartVo.getGoods_id().compareTo(Long.valueOf(goodsIds.get(j)))==0){
|
|
|
+ actualPrice2 = actualPrice2.add(cartVo.getRetail_price().multiply(BigDecimal.valueOf(cartVo.getNumber())));
|
|
|
+ }else{
|
|
|
+ actualPrice3 = actualPrice3.add(cartVo.getRetail_price().multiply(BigDecimal.valueOf(cartVo.getNumber())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//实付金额*(优惠券折扣*0.1) = 折扣后的实付金额
|
|
|
- actualPrice = actualPrice.multiply(checkedCoupon.getTypeMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP);//满多少打几折
|
|
|
+ actualPrice = actualPrice3.add(actualPrice2.multiply(checkedCoupon.getTypeMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP));//满多少打几折
|
|
|
}
|
|
|
}
|
|
|
return actualPrice;
|
|
@@ -298,14 +345,27 @@ public class ApiCartService {
|
|
|
* @param actualPrice
|
|
|
* @return
|
|
|
*/
|
|
|
- public BigDecimal mathActualPriceByCamp(CampMinusDto checkedCampMinus, BigDecimal actualPrice){
|
|
|
+ public BigDecimal mathActualPriceByCamp(CampMinusDto checkedCampMinus, BigDecimal actualPrice,List<CartVo> checkedGoodsList){
|
|
|
+ BigDecimal actualPrice2 = Constant.ZERO;
|
|
|
+ BigDecimal actualPrice3 = Constant.ZERO;
|
|
|
if(checkedCampMinus != null){
|
|
|
if (checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_00.getItem()) || checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_01.getItem())) {
|
|
|
actualPrice = actualPrice.subtract(checkedCampMinus.getMoney());
|
|
|
}
|
|
|
if (checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_10.getItem()) || checkedCampMinus.getCampMinusType().equalsIgnoreCase(Dict.campMinusType.item_11.getItem())) {
|
|
|
+ for(int i = 0; i < checkedGoodsList.size(); i++){
|
|
|
+ CartVo cartVo = checkedGoodsList.get(i);
|
|
|
+ List<Integer> goodsIds = checkedCampMinus.getGoodsIds();
|
|
|
+ for(int j=0;j<goodsIds.size();j++){
|
|
|
+ if(cartVo.getGoods_id().compareTo(Long.valueOf(goodsIds.get(j)))==0){
|
|
|
+ actualPrice2 = actualPrice2.add(cartVo.getRetail_price().multiply(BigDecimal.valueOf(cartVo.getNumber())));
|
|
|
+ }else{
|
|
|
+ actualPrice3 = actualPrice3.add(cartVo.getRetail_price().multiply(BigDecimal.valueOf(cartVo.getNumber())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//实付金额*(满减满折折扣*0.1) = 折扣后的实付金额
|
|
|
- actualPrice = actualPrice.multiply(checkedCampMinus.getMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP);//满多少打几折
|
|
|
+ actualPrice = actualPrice3.add(actualPrice2.multiply(checkedCampMinus.getMoney().multiply(new BigDecimal(0.1))).setScale(2, BigDecimal.ROUND_HALF_UP));//满多少打几折
|
|
|
}
|
|
|
}
|
|
|
return actualPrice;
|
|
@@ -434,6 +494,12 @@ public class ApiCartService {
|
|
|
userCouponDto00.setGoodsTotalPrice(goodsTotalPrice00);
|
|
|
userCouponDto00.setCartGoodsList(cartGoodsList);
|
|
|
userCouponDto00.setBizType(Dict.orderBizType.item_00.getItem());
|
|
|
+ if(campId00 != null && campId00 != 0){
|
|
|
+ userCouponDto00.setCampId(campId00);
|
|
|
+ }
|
|
|
+ if(tickDiscId00 != null && tickDiscId00 != 0){
|
|
|
+ userCouponDto00.setTickDiscId(Integer.parseInt(String.valueOf(tickDiscId00)));
|
|
|
+ }
|
|
|
couponList00 = apiUserCouponService.matchUserCouponList(userCouponDto00);
|
|
|
campList00 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto00);
|
|
|
}
|
|
@@ -444,6 +510,12 @@ public class ApiCartService {
|
|
|
userCouponDto02.setGoodsTotalPrice(goodsTotalPrice02);
|
|
|
userCouponDto02.setCartGoodsList(cartGoodsList);
|
|
|
userCouponDto02.setBizType(Dict.orderBizType.item_02.getItem());
|
|
|
+ if(campId02 != null && campId02 != 0){
|
|
|
+ userCouponDto02.setCampId(campId02);
|
|
|
+ }
|
|
|
+ if(tickDiscId02 != null && tickDiscId02 != 0){
|
|
|
+ userCouponDto02.setTickDiscId(Integer.parseInt(String.valueOf(tickDiscId02)));
|
|
|
+ }
|
|
|
couponList02 = apiUserCouponService.matchUserCouponList(userCouponDto02);
|
|
|
campList02 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto02);
|
|
|
}
|
|
@@ -454,6 +526,12 @@ public class ApiCartService {
|
|
|
userCouponDto10.setGoodsTotalPrice(goodsTotalPrice10);
|
|
|
userCouponDto10.setCartGoodsList(cartGoodsList);
|
|
|
userCouponDto10.setBizType(Dict.orderBizType.item_10.getItem());
|
|
|
+ if(campId10 != null && campId10 != 0){
|
|
|
+ userCouponDto10.setCampId(campId10);
|
|
|
+ }
|
|
|
+ if(tickDiscId10 != null && tickDiscId10 != 0){
|
|
|
+ userCouponDto10.setTickDiscId(Integer.parseInt(String.valueOf(tickDiscId10)));
|
|
|
+ }
|
|
|
couponList10 = apiUserCouponService.matchUserCouponList(userCouponDto10);
|
|
|
campList10 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto10);
|
|
|
}
|
|
@@ -464,6 +542,12 @@ public class ApiCartService {
|
|
|
userCouponDto11.setGoodsTotalPrice(goodsTotalPrice11);
|
|
|
userCouponDto11.setCartGoodsList(cartGoodsList);
|
|
|
userCouponDto11.setBizType(Dict.orderBizType.item_11.getItem());
|
|
|
+ if(campId11 != null && campId11 != 0){
|
|
|
+ userCouponDto11.setCampId(campId11);
|
|
|
+ }
|
|
|
+ if(tickDiscId11 != null && tickDiscId11 != 0){
|
|
|
+ userCouponDto11.setTickDiscId(Integer.parseInt(String.valueOf(tickDiscId11)));
|
|
|
+ }
|
|
|
couponList11 = apiUserCouponService.matchUserCouponList(userCouponDto11);
|
|
|
campList11 = apiMkStoreCampMinusService.matchUserCampMinusList(userCouponDto11);
|
|
|
}
|
|
@@ -483,15 +567,15 @@ public class ApiCartService {
|
|
|
BigDecimal actualPrice10 = goodsTotalPrice10;
|
|
|
BigDecimal actualPrice11 = goodsTotalPrice11;
|
|
|
|
|
|
- Map campMinusMap00 = checkedCampMinus(campList00, campMinusDto00, actualPrice00, campId00, isLoadStatus);
|
|
|
- Map campMinusMap02 = checkedCampMinus(campList02, campMinusDto02, actualPrice02, campId02, isLoadStatus);
|
|
|
- Map campMinusMap10 = checkedCampMinus(campList10, campMinusDto10, actualPrice10, campId10, isLoadStatus);
|
|
|
- Map campMinusMap11 = checkedCampMinus(campList11, campMinusDto11, actualPrice11, campId11, isLoadStatus);
|
|
|
+ Map campMinusMap00 = checkedCampMinus(campList00, checkedGoodsList, actualPrice00, campId00, isLoadStatus);
|
|
|
+ Map campMinusMap02 = checkedCampMinus(campList02, checkedGoodsList, actualPrice02, campId02, isLoadStatus);
|
|
|
+ Map campMinusMap10 = checkedCampMinus(campList10, checkedGoodsList, actualPrice10, campId10, isLoadStatus);
|
|
|
+ Map campMinusMap11 = checkedCampMinus(campList11, checkedGoodsList, actualPrice11, campId11, isLoadStatus);
|
|
|
|
|
|
- Map couponMap00 = checkedCoupon(couponList00, checkedCoupon00, tickDiscId00, campMinusMap00, isLoadStatus);
|
|
|
- Map couponMap02 = checkedCoupon(couponList02, checkedCoupon02, tickDiscId02, campMinusMap02, isLoadStatus);
|
|
|
- Map couponMap10 = checkedCoupon(couponList10, checkedCoupon10, tickDiscId10, campMinusMap10, isLoadStatus);
|
|
|
- Map couponMap11 = checkedCoupon(couponList11, checkedCoupon11, tickDiscId11, campMinusMap11, isLoadStatus);
|
|
|
+ Map couponMap00 = checkedCoupon(couponList00, checkedGoodsList, tickDiscId00, campMinusMap00, isLoadStatus);
|
|
|
+ Map couponMap02 = checkedCoupon(couponList02, checkedGoodsList, tickDiscId02, campMinusMap02, isLoadStatus);
|
|
|
+ Map couponMap10 = checkedCoupon(couponList10, checkedGoodsList, tickDiscId10, campMinusMap10, isLoadStatus);
|
|
|
+ Map couponMap11 = checkedCoupon(couponList11, checkedGoodsList, tickDiscId11, campMinusMap11, isLoadStatus);
|
|
|
|
|
|
campMinusDto00 = getCampMinusByMap(campMinusMap00);
|
|
|
campMinusDto02 = getCampMinusByMap(campMinusMap02);
|
|
@@ -516,6 +600,57 @@ public class ApiCartService {
|
|
|
|
|
|
BigDecimal actualPrice = actualPrice00.add(actualPrice02).add(actualPrice10).add(actualPrice11); //实付金额:商品销售价*数量-优惠金额+运费的总和
|
|
|
|
|
|
+ for(CartVo cartVo: checkedGoodsList){
|
|
|
+ List<Integer> goodsList = null;
|
|
|
+ List<Integer> goodsDiscountList = null;
|
|
|
+ if(cartVo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
|
|
|
+ if(campMinusDto00 != null) {
|
|
|
+ goodsList = campMinusDto00.getGoodsIds();
|
|
|
+ }
|
|
|
+ if(checkedCoupon00 != null) {
|
|
|
+ goodsDiscountList = checkedCoupon00.getGoodsList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(cartVo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_02.getItem())){
|
|
|
+ if(campMinusDto02 != null) {
|
|
|
+ goodsList = campMinusDto02.getGoodsIds();
|
|
|
+ }
|
|
|
+ if(checkedCoupon02 != null) {
|
|
|
+ goodsDiscountList = checkedCoupon02.getGoodsList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(cartVo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_10.getItem())){
|
|
|
+ if(campMinusDto10 != null) {
|
|
|
+ goodsList = campMinusDto10.getGoodsIds();
|
|
|
+ }
|
|
|
+ if(checkedCoupon10 != null) {
|
|
|
+ goodsDiscountList = checkedCoupon10.getGoodsList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(cartVo.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_11.getItem())){
|
|
|
+ if(campMinusDto11 != null) {
|
|
|
+ goodsList = campMinusDto11.getGoodsIds();
|
|
|
+ }
|
|
|
+ if(checkedCoupon11 != null) {
|
|
|
+ goodsDiscountList = checkedCoupon11.getGoodsList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(goodsList != null) {
|
|
|
+ for (Integer goodsId : goodsList) {
|
|
|
+ if (cartVo.getGoods_id().compareTo(Long.valueOf(goodsId)) == 0) {
|
|
|
+ cartVo.setIsCamp("true");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(goodsDiscountList != null) {
|
|
|
+ for (Integer goodsId : goodsDiscountList) {
|
|
|
+ if (cartVo.getGoods_id().compareTo(Long.valueOf(goodsId)) == 0) {
|
|
|
+ cartVo.setIsDiscount("true");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
resultObj.put("freightPrice00", freightPrice00);
|
|
|
resultObj.put("freightPrice02", freightPrice02);
|
|
|
resultObj.put("freightPrice10", freightPrice10);
|
|
@@ -569,19 +704,20 @@ public class ApiCartService {
|
|
|
/**
|
|
|
* 选择满减满折
|
|
|
* @param campList
|
|
|
- * @param campMinusDto
|
|
|
+ * @param checkedGoodsList
|
|
|
* @param actualPrice
|
|
|
* @param campId
|
|
|
* @param isLoadStatus 0则为进入页面加载优惠信息,默认选择最高层级促销活动,1为选择促销活动后加载优惠信息,2为选择优惠券时触发,优惠券不能与促销活动同时使用
|
|
|
*/
|
|
|
- private Map checkedCampMinus(List<CampMinusDto> campList, CampMinusDto campMinusDto, BigDecimal actualPrice, Integer campId, Integer isLoadStatus){
|
|
|
+ private Map checkedCampMinus(List<CampMinusDto> campList, List<CartVo> checkedGoodsList, BigDecimal actualPrice, Integer campId, Integer isLoadStatus){
|
|
|
Map campMap = new HashMap();
|
|
|
+ CampMinusDto campMinusDto = null;
|
|
|
if(campList != null && campList.size() > 0 && isLoadStatus != null){
|
|
|
if(isLoadStatus == 0){ //0则为进入页面加载优惠信息,默认选择最高层级促销活动
|
|
|
campMinusDto = campList.get(0);
|
|
|
if(campMinusDto.getCampMinusId().compareTo(0) > 0){
|
|
|
//商品销售价*数量-优惠金额
|
|
|
- actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice);
|
|
|
+ actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice, checkedGoodsList);
|
|
|
campMap.put("actualPrice", actualPrice);
|
|
|
campMap.put("isCamp", true);//满减活动是否满足该次订单
|
|
|
}else{
|
|
@@ -600,7 +736,7 @@ public class ApiCartService {
|
|
|
if (campId.compareTo(dto.getCampMinusId()) == 0) {
|
|
|
campMinusDto = dto;
|
|
|
//商品销售价*数量-优惠金额
|
|
|
- actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice);
|
|
|
+ actualPrice = mathActualPriceByCamp(campMinusDto, actualPrice, checkedGoodsList);
|
|
|
campMap.put("actualPrice", actualPrice);
|
|
|
campMap.put("isCamp", true);
|
|
|
campMap.put("campMinusDto", campMinusDto);
|
|
@@ -625,15 +761,16 @@ public class ApiCartService {
|
|
|
/**
|
|
|
* 选择优惠券
|
|
|
* @param couponList
|
|
|
- * @param checkedCoupon
|
|
|
+ * @param checkedGoodsList
|
|
|
* @param tickDiscId
|
|
|
* @param campMinusMap
|
|
|
* @param isLoadStatus 0则为进入页面加载优惠信息,默认选择最高层级促销活动,1为选择促销活动后加载优惠信息,2为选择优惠券时触发,优惠券不能与促销活动同时使用
|
|
|
*/
|
|
|
- private Map checkedCoupon(List<UserCouponVo> couponList, UserCouponVo checkedCoupon, Long tickDiscId, Map campMinusMap, Integer isLoadStatus){
|
|
|
+ private Map checkedCoupon(List<UserCouponVo> couponList, List<CartVo> checkedGoodsList, Long tickDiscId, Map campMinusMap, Integer isLoadStatus){
|
|
|
BigDecimal actualPrice = MapUtils.getBigDecimal("actualPrice", campMinusMap);
|
|
|
Boolean isCamp = (Boolean)campMinusMap.get("isCamp");
|
|
|
Map couponMap = new HashMap();
|
|
|
+ UserCouponVo checkedCoupon = null;
|
|
|
//满减活动不与优惠券同时使用,当isCamp为false时可使用优惠券
|
|
|
if(isCamp == false) {
|
|
|
if (null != couponList && couponList.size() > 0) {
|
|
@@ -652,7 +789,7 @@ public class ApiCartService {
|
|
|
if (null != tickDiscId && tickDiscId.equals(userCouponVo.getId())) {
|
|
|
checkedCoupon = userCouponVo;
|
|
|
//商品销售价*数量-优惠金额
|
|
|
- actualPrice = mathActualPrice(checkedCoupon, actualPrice);
|
|
|
+ actualPrice = mathActualPrice(checkedCoupon, actualPrice, checkedGoodsList);
|
|
|
couponMap.put("actualPrice", actualPrice);
|
|
|
couponMap.put("checkedCoupon", checkedCoupon);
|
|
|
}
|