|
@@ -12,6 +12,7 @@ import com.caimei365.order.utils.MathUtil;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.util.concurrent.AtomicDouble;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -46,9 +47,10 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
* 购物车列表详细数据
|
|
|
*
|
|
|
* @param userId 用户Id
|
|
|
+ * @param source 来源 : 1 网站 ; 2 小程序
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseJson<Map<String, Object>> getShoppingCartList(Integer userId) {
|
|
|
+ public ResponseJson<Map<String, Object>> getShoppingCartList(Integer userId, Integer source) {
|
|
|
/*
|
|
|
* 初始化返回数据
|
|
|
*/
|
|
@@ -72,6 +74,9 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 促销活动(总)
|
|
|
List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
|
List<Integer> promotionsIds = new ArrayList<>();
|
|
|
+ // 用户可用优惠券(总)
|
|
|
+ List<CouponVo> couponList = cartClubMapper.getClubCouponList(userId);
|
|
|
+ List<CartItemVo> cartAllProducts = new ArrayList<>();
|
|
|
// 用户身份
|
|
|
Integer userIdentity = baseMapper.getIdentityByUserId(userId);
|
|
|
if (null != shopInfoList && shopInfoList.size()>0) {
|
|
@@ -191,6 +196,8 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
productIterator.remove();
|
|
|
}
|
|
|
}
|
|
|
+ cartAllProducts.addAll(productList);
|
|
|
+
|
|
|
// 供应商下商品种类
|
|
|
shop.setCount(shopKindCount.get());
|
|
|
if (shopKindCount.get() > 0) {
|
|
@@ -226,6 +233,10 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 是否可领取优惠券
|
|
|
+ Boolean couponsLogo = setCouponsLogo(shop.getShopId(), source, productList, couponList);
|
|
|
+ shop.setCouponsLogo(couponsLogo);
|
|
|
+
|
|
|
// 供应商商品
|
|
|
shop.setCartList(productList);
|
|
|
// 供应商总价
|
|
@@ -261,6 +272,8 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ // 过滤与当前购物车商品无关的优惠券
|
|
|
+ filterCoupon(source, cartAllProducts, couponList);
|
|
|
/*
|
|
|
* 返回结果
|
|
|
*/
|
|
@@ -273,10 +286,109 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
resultMap.put("reducedPrice", reducedPrice);
|
|
|
resultMap.put("totalOriginalPrice", totalOriginalPrice);
|
|
|
resultMap.put("promotions", totalPromotions);
|
|
|
+ resultMap.put("couponList", couponList);
|
|
|
// 返回数据
|
|
|
return ResponseJson.success(resultMap);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 过滤与当前商品列表无关的优惠券
|
|
|
+ */
|
|
|
+ private void filterCoupon(Integer source, List<CartItemVo> cartItems, List<CouponVo> couponList) {
|
|
|
+ if (couponList != null && couponList.size() > 0) {
|
|
|
+ Iterator<CouponVo> iterator = couponList.iterator();
|
|
|
+ A:
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ CouponVo coupon = iterator.next();
|
|
|
+ if (coupon.getCouponType() == 0 && coupon.getProductType() == 2) {
|
|
|
+ // 活动券商品Ids
|
|
|
+ List<Integer> productIds = cartClubMapper.getCouponProductIds(coupon.getCouponId(), source);
|
|
|
+ coupon.setProductIds(productIds);
|
|
|
+ for (CartItemVo item : cartItems) {
|
|
|
+ if (!productIds.contains(item.getProductId())) {
|
|
|
+ iterator.remove();
|
|
|
+ continue A;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 1) {
|
|
|
+ for (CartItemVo item : cartItems) {
|
|
|
+ if (!coupon.getCategoryType().equals(item.getCommodityType())) {
|
|
|
+ iterator.remove();
|
|
|
+ continue A;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 3) {
|
|
|
+ for (CartItemVo item : cartItems) {
|
|
|
+ if (!coupon.getShopId().equals(item.getShopId())) {
|
|
|
+ iterator.remove();
|
|
|
+ continue A;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 3 && coupon.getShopId() != null) {
|
|
|
+ //店铺券
|
|
|
+ String shopName = baseMapper.getShopNameById(coupon.getShopId());
|
|
|
+ if (StringUtils.isNotBlank(shopName)) {
|
|
|
+ if (shopName.length() > 7) {
|
|
|
+ shopName = shopName.substring(0, 6) + "...";
|
|
|
+ }
|
|
|
+ coupon.setShopName(shopName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券标识是否显示
|
|
|
+ */
|
|
|
+ public Boolean setCouponsLogo(Integer shopId, Integer source, List<CartItemVo> cartItems, List<CouponVo> couponList) {
|
|
|
+ boolean couponsLogo = false;
|
|
|
+ if (couponList != null && couponList.size() > 0) {
|
|
|
+ A:
|
|
|
+ for (CouponVo coupon : couponList) {
|
|
|
+ if (coupon.getCouponType() == 4 || coupon.getCouponType() == 2) {
|
|
|
+ //用户券与用户专享券
|
|
|
+ couponsLogo = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 0) {
|
|
|
+ if (coupon.getProductType() == 1) {
|
|
|
+ //活动券-全商城商品
|
|
|
+ couponsLogo = true;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ // 活动券商品Ids
|
|
|
+ List<Integer> productIds = cartClubMapper.getCouponProductIds(coupon.getCouponId(), source);
|
|
|
+ for (CartItemVo item : cartItems) {
|
|
|
+ if (productIds.contains(item.getProductId())) {
|
|
|
+ couponsLogo = true;
|
|
|
+ break A;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 3 && shopId.equals(coupon.getShopId())) {
|
|
|
+ //店铺券
|
|
|
+ couponsLogo = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (coupon.getCouponType() == 1) {
|
|
|
+ //品类券
|
|
|
+ for (CartItemVo item : cartItems) {
|
|
|
+ if (coupon.getCategoryType().equals(item.getCommodityType())) {
|
|
|
+ couponsLogo = true;
|
|
|
+ break A;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return couponsLogo;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 网站顶部购物车数据
|
|
|
*
|