|
@@ -809,7 +809,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
// 获取赠品供应商
|
|
// 获取赠品供应商
|
|
- CartShopVo giftShop = baseMapper.getPromotionGiftsShop(gift.getProductId());
|
|
|
|
|
|
+ CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
|
|
shopIds.add(giftShop.getShopId());
|
|
shopIds.add(giftShop.getShopId());
|
|
giftShop.setCartList(new ArrayList<>());
|
|
giftShop.setCartList(new ArrayList<>());
|
|
giftShop.getCartList().add(gift);
|
|
giftShop.getCartList().add(gift);
|
|
@@ -825,7 +825,221 @@ public class CartClubServiceImpl implements CartClubService {
|
|
Double availableMoney = baseMapper.getAbleUserMoney(userId);
|
|
Double availableMoney = baseMapper.getAbleUserMoney(userId);
|
|
// 可用采美豆
|
|
// 可用采美豆
|
|
Integer userBeans = baseMapper.getUserBeans(userId);
|
|
Integer userBeans = baseMapper.getUserBeans(userId);
|
|
|
|
+ // 用户可用优惠券(总)
|
|
|
|
+ List<CouponVo> couponList = getUserCartCoupons(totalProductList, source, userId);
|
|
|
|
|
|
|
|
+ // 包装返回数据
|
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
|
+ resultData.put("list", shopList);
|
|
|
|
+ resultData.put("kindCount", kindCount);
|
|
|
|
+ resultData.put("totalCount", totalCount);
|
|
|
|
+ resultData.put("totalPrice", totalPrice);
|
|
|
|
+ resultData.put("reducedPrice", reducedPrice);
|
|
|
|
+ resultData.put("totalOriginalPrice", totalOriginalPrice);
|
|
|
|
+ resultData.put("promotions", totalPromotions);
|
|
|
|
+ resultData.put("invoice", invoice);
|
|
|
|
+ resultData.put("userMoney", availableMoney);
|
|
|
|
+ resultData.put("userBeans", userBeans);
|
|
|
|
+ resultData.put("includeRecharge", includeRecharge);
|
|
|
|
+ resultData.put("couponList", couponList);
|
|
|
|
+ return ResponseJson.success(resultData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 立即购买
|
|
|
|
+ *
|
|
|
|
+ * @param cartDto {
|
|
|
|
+ * userId 用户ID
|
|
|
|
+ * productId 商品id
|
|
|
|
+ * productCount 商品数量
|
|
|
|
+ * source 来源 : 1 网站 ; 2 小程序
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Map<String, Object>> buyNowProduct(CartDto cartDto) {
|
|
|
|
+ log.info("¥¥¥¥¥¥¥¥¥¥ > 立即购买");
|
|
|
|
+ // 供应商信息
|
|
|
|
+ CartShopVo shop = baseMapper.getShopByProductId(cartDto.getProductId());
|
|
|
|
+ if (null == shop) {
|
|
|
|
+ return ResponseJson.error("商品供应商异常!", null);
|
|
|
|
+ }
|
|
|
|
+ CartItemVo cartItemVo = cartClubMapper.getCartItemByProductId(cartDto.getProductId());
|
|
|
|
+ if (null == cartItemVo) {
|
|
|
|
+ return ResponseJson.error("商品数据异常!", null);
|
|
|
|
+ }
|
|
|
|
+ // 用户身份
|
|
|
|
+ Integer userIdentity = baseMapper.getIdentityByUserId(cartDto.getUserId());
|
|
|
|
+ // 价格不可见商品
|
|
|
|
+ if (!(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2))) {
|
|
|
|
+ return ResponseJson.error("商品价格不可见!", null);
|
|
|
|
+ }
|
|
|
|
+ cartItemVo.setNumber(cartDto.getProductCount());
|
|
|
|
+ // 库存不足商品
|
|
|
|
+ if(!(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber())){
|
|
|
|
+ return ResponseJson.error("商品库存不足!", null);
|
|
|
|
+ }
|
|
|
|
+ // 设置商品图片及税费
|
|
|
|
+ boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
|
|
|
|
+ // 促销活动(总)
|
|
|
|
+ List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
|
|
+ // 统计商品总金额
|
|
|
|
+ final Double[] totalPrice = {MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice()).doubleValue()};
|
|
|
|
+ // 统计总促销满减
|
|
|
|
+ final Double[] reducedPrice = {0d};
|
|
|
|
+ // 供应商促销优惠活动
|
|
|
|
+ PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
|
+ // 获取商品促销信息
|
|
|
|
+ PromotionsVo productPromotions = null;
|
|
|
|
+ // 没有店铺促销时,商品促销才有效
|
|
|
|
+ if (null == shopPromotion) {
|
|
|
|
+ // 获取商品促销信息
|
|
|
|
+ productPromotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
|
+ /*
|
|
|
|
+ * 设置商品促销优惠
|
|
|
|
+ */
|
|
|
|
+ if (null != productPromotions) {
|
|
|
|
+ // 当前促销活动的价格计算列表
|
|
|
|
+ List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(productPromotions, cartItemVo, taxFlag);
|
|
|
|
+ // 更新到总促销列表
|
|
|
|
+ if (productPromotions.getMode() == 3) {
|
|
|
|
+ // 获取赠品
|
|
|
|
+ List<CartItemVo> giftList = baseMapper.getPromotionGifts(productPromotions.getId());
|
|
|
|
+ productPromotions.setGiftList(giftList);
|
|
|
|
+ }
|
|
|
|
+ productPromotions.setProductList(promotionPriceList);
|
|
|
|
+ // 添加到总促销
|
|
|
|
+ totalPromotions.add(productPromotions);
|
|
|
|
+ //单品满减-计算供应商总价/满减金额
|
|
|
|
+ if (productPromotions.getType() == 1 && productPromotions.getMode() == 2) {
|
|
|
|
+ BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
|
|
|
|
+ if (MathUtil.compare(totalAmount, productPromotions.getTouchPrice()) > -1) {
|
|
|
|
+ // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
|
|
|
|
+ totalPrice[0] = MathUtil.sub(totalPrice[0], productPromotions.getReducedPrice()).doubleValue();
|
|
|
|
+ reducedPrice[0] = MathUtil.add(reducedPrice[0], productPromotions.getReducedPrice()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cartItemVo.setPromotions(productPromotions);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (null != productPromotions || null != shopPromotion) {
|
|
|
|
+ // 商品处于活动状态
|
|
|
|
+ cartItemVo.setActStatus(1);
|
|
|
|
+ // 关闭阶梯价格,活动优先
|
|
|
|
+ cartItemVo.setLadderFlag(0);
|
|
|
|
+ } else {
|
|
|
|
+ if (cartItemVo.getLadderFlag() == 1) {
|
|
|
|
+ // 设置阶梯价
|
|
|
|
+ productService.setCartLadderPrices(cartItemVo, taxFlag);
|
|
|
|
+ } else {
|
|
|
|
+ // 复购价
|
|
|
|
+ Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), cartDto.getUserId());
|
|
|
|
+ if (null != repurchase && repurchase > 0) {
|
|
|
|
+ cartItemVo.setPrice(repurchase);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 店铺促销
|
|
|
|
+ if (null != shopPromotion) {
|
|
|
|
+ shop.setPromotions(shopPromotion);
|
|
|
|
+ // 店铺满赠
|
|
|
|
+ if (shopPromotion.getMode() == 3) {
|
|
|
|
+ // 获取赠品
|
|
|
|
+ List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
|
|
|
|
+ shopPromotion.setGiftList(giftList);
|
|
|
|
+ }
|
|
|
|
+ // 设置该优惠下的商品列表
|
|
|
|
+ List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
|
|
|
|
+ PromotionPriceVo promotionPrice = new PromotionPriceVo();
|
|
|
|
+ promotionPrice.setProductId(cartItemVo.getProductId());
|
|
|
|
+ promotionPrice.setNumber(cartItemVo.getNumber());
|
|
|
|
+ promotionPrice.setPrice(cartItemVo.getPrice());
|
|
|
|
+ promotionPriceList.add(promotionPrice);
|
|
|
|
+ shopPromotion.setProductList(promotionPriceList);
|
|
|
|
+ // 添加到总促销
|
|
|
|
+ totalPromotions.add(shopPromotion);
|
|
|
|
+ // 店铺满减-计算供应商总价/满减金额
|
|
|
|
+ if (shopPromotion.getMode() == 2 && MathUtil.compare(totalPrice[0], shopPromotion.getTouchPrice()) > -1) {
|
|
|
|
+ // 该供应商总价 - 满减金额
|
|
|
|
+ totalPrice[0] = MathUtil.sub(totalPrice[0], shopPromotion.getReducedPrice()).doubleValue();
|
|
|
|
+ // 该供应商优惠总额 + 满减金额
|
|
|
|
+ reducedPrice[0] = MathUtil.add(reducedPrice[0], shopPromotion.getReducedPrice()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 供应商商品
|
|
|
|
+ List<CartItemVo> cartList = new ArrayList<>(1);
|
|
|
|
+ cartList.add(cartItemVo);
|
|
|
|
+ shop.setCartList(cartList);
|
|
|
|
+ shop.setCount(1);
|
|
|
|
+ // 供应商总价
|
|
|
|
+ shop.setTotalPrice(totalPrice[0]);
|
|
|
|
+ // 供应商总优惠
|
|
|
|
+ shop.setReducedPrice(reducedPrice[0]);
|
|
|
|
+ // 供应商划线价
|
|
|
|
+ shop.setOriginalPrice(MathUtil.add(totalPrice[0], reducedPrice[0]).doubleValue());
|
|
|
|
+ List<CartShopVo> shopList = new ArrayList<>();
|
|
|
|
+ shopList.add(shop);
|
|
|
|
+ // 总促销计算
|
|
|
|
+ totalPromotions.forEach(promotions -> {
|
|
|
|
+ // 该促销内商品总价
|
|
|
|
+ double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
|
|
|
|
+ // 凑单满减
|
|
|
|
+ if (promotions.getType() == 2 && promotions.getMode() == 2) {
|
|
|
|
+ if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
|
|
|
|
+ // 总价 - 满减金额
|
|
|
|
+ totalPrice[0] = MathUtil.sub(totalPrice[0], promotions.getReducedPrice()).doubleValue();
|
|
|
|
+ // 优惠总额 + 满减金额
|
|
|
|
+ reducedPrice[0] = MathUtil.add(reducedPrice[0], promotions.getReducedPrice()).doubleValue();
|
|
|
|
+ }
|
|
|
|
+ } else if (promotions.getMode() == 3) {
|
|
|
|
+ // 全部满赠
|
|
|
|
+ promotions.getGiftList().forEach(gift -> {
|
|
|
|
+ if (shop.getShopId().equals(gift.getShopId())) {
|
|
|
|
+ // 赠品在当前订单内的供应商下
|
|
|
|
+ if (shop.getShopId().equals(gift.getShopId())) {
|
|
|
|
+ shop.getCartList().add(gift);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 获取赠品供应商
|
|
|
|
+ CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
|
|
|
|
+ giftShop.setCartList(new ArrayList<>());
|
|
|
|
+ giftShop.getCartList().add(gift);
|
|
|
|
+ shopList.add(giftShop);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 是否充值商品
|
|
|
|
+ boolean includeRecharge = false;
|
|
|
|
+ boolean recharge = productService.isRechargeProduct(cartDto.getProductId());
|
|
|
|
+ if (recharge) {
|
|
|
|
+ includeRecharge = true;
|
|
|
|
+ }
|
|
|
|
+ // 发票信息
|
|
|
|
+ InvoiceVo invoice = baseMapper.getUserInvoice(cartDto.getUserId());
|
|
|
|
+ // 可用余额
|
|
|
|
+ Double availableMoney = baseMapper.getAbleUserMoney(cartDto.getUserId());
|
|
|
|
+ // 可用采美豆
|
|
|
|
+ Integer userBeans = baseMapper.getUserBeans(cartDto.getUserId());
|
|
|
|
+ // 获取用户可用优惠券
|
|
|
|
+ List<CouponVo> couponList = getUserCartCoupons(cartList, cartDto.getSource(), cartDto.getUserId());
|
|
|
|
+ // 包装返回数据
|
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
|
+ resultData.put("list", shopList);
|
|
|
|
+ resultData.put("kindCount", 1);
|
|
|
|
+ resultData.put("totalCount", cartDto.getProductCount());
|
|
|
|
+ resultData.put("totalPrice", totalPrice[0]);
|
|
|
|
+ resultData.put("reducedPrice", reducedPrice[0]);
|
|
|
|
+ resultData.put("totalOriginalPrice", shop.getOriginalPrice());
|
|
|
|
+ resultData.put("invoice", invoice);
|
|
|
|
+ resultData.put("userMoney", availableMoney);
|
|
|
|
+ resultData.put("userBeans", userBeans);
|
|
|
|
+ resultData.put("includeRecharge", includeRecharge);
|
|
|
|
+ resultData.put("promotions", totalPromotions);
|
|
|
|
+ resultData.put("couponList", couponList);
|
|
|
|
+ return ResponseJson.success(resultData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<CouponVo> getUserCartCoupons(List<CartItemVo> cartList, Integer source, Integer userId) {
|
|
// 用户可用优惠券(总)
|
|
// 用户可用优惠券(总)
|
|
List<CouponVo> couponList = orderCommonMapper.getClubCouponList(userId);
|
|
List<CouponVo> couponList = orderCommonMapper.getClubCouponList(userId);
|
|
Iterator<CouponVo> iterator = couponList.iterator();
|
|
Iterator<CouponVo> iterator = couponList.iterator();
|
|
@@ -833,7 +1047,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
CouponVo coupon = iterator.next();
|
|
CouponVo coupon = iterator.next();
|
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
|
Integer couponType = coupon.getCouponType();
|
|
Integer couponType = coupon.getCouponType();
|
|
- for (CartItemVo item : totalProductList) {
|
|
|
|
|
|
+ for (CartItemVo item : cartList) {
|
|
if (couponType == 0) {
|
|
if (couponType == 0) {
|
|
if (coupon.getProductType() == 1) {
|
|
if (coupon.getProductType() == 1) {
|
|
//活动券-全商城商品
|
|
//活动券-全商城商品
|
|
@@ -877,63 +1091,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
couponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
|
|
couponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
|
|
-
|
|
|
|
- // 包装返回数据
|
|
|
|
- Map<String, Object> resultData = new HashMap<>();
|
|
|
|
- resultData.put("list", shopList);
|
|
|
|
- resultData.put("kindCount", kindCount);
|
|
|
|
- resultData.put("totalCount", totalCount);
|
|
|
|
- resultData.put("totalPrice", totalPrice);
|
|
|
|
- resultData.put("reducedPrice", reducedPrice);
|
|
|
|
- resultData.put("totalOriginalPrice", totalOriginalPrice);
|
|
|
|
- resultData.put("promotions", totalPromotions);
|
|
|
|
- resultData.put("invoice", invoice);
|
|
|
|
- resultData.put("userMoney", availableMoney);
|
|
|
|
- resultData.put("userBeans", userBeans);
|
|
|
|
- resultData.put("includeRecharge", includeRecharge);
|
|
|
|
- resultData.put("couponList", couponList);
|
|
|
|
- return ResponseJson.success(resultData);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 立即购买
|
|
|
|
- *
|
|
|
|
- * @param cartDto {
|
|
|
|
- * userId 用户ID
|
|
|
|
- * productId 商品id
|
|
|
|
- * productCount 商品数量
|
|
|
|
- * source 来源 : 1 网站 ; 2 小程序
|
|
|
|
- * }
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public ResponseJson<Map<String, Object>> buyNowProduct(CartDto cartDto) {
|
|
|
|
- CartPo cart = cartClubMapper.getCartPo(cartDto);
|
|
|
|
- if (cart != null) {
|
|
|
|
- // 购物车已存在该商品,更新数量
|
|
|
|
- cart.setProductCount(cartDto.getProductCount());
|
|
|
|
- cart.setAddTime(new Date());
|
|
|
|
- cartClubMapper.updateCart(cart);
|
|
|
|
- } else {
|
|
|
|
- // 添加新购物车
|
|
|
|
- cart = new CartPo();
|
|
|
|
- cart.setUserId(cartDto.getUserId());
|
|
|
|
- cart.setProductId(cartDto.getProductId());
|
|
|
|
- cart.setProductCount(cartDto.getProductCount());
|
|
|
|
- Integer shopId = baseMapper.getShopIdByproductId(cartDto.getProductId());
|
|
|
|
- cart.setShopId(shopId);
|
|
|
|
- //判断是否是再次购买
|
|
|
|
- Double repurchase = baseMapper.getRepurchasePrice(cartDto.getProductId(), cartDto.getUserId());
|
|
|
|
- if (null != repurchase && repurchase > 0) {
|
|
|
|
- // 再次购买
|
|
|
|
- cart.setReBuyFlag(1);
|
|
|
|
- } else {
|
|
|
|
- cart.setReBuyFlag(0);
|
|
|
|
- }
|
|
|
|
- cart.setAddTime(new Date());
|
|
|
|
- cartClubMapper.insertCart(cart);
|
|
|
|
- }
|
|
|
|
- // 结算商品
|
|
|
|
- return settlementShoppingCart(cartDto.getUserId(), cartDto.getProductId().toString(), cartDto.getSource());
|
|
|
|
|
|
+ return couponList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|