|
@@ -1,8 +1,5 @@
|
|
|
package com.caimei365.order.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.order.components.ProductService;
|
|
@@ -90,18 +87,33 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 促销活动(总)
|
|
|
List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
|
List<Integer> promotionsIds = new ArrayList<>();
|
|
|
+ // 用户注册时间
|
|
|
+ Date registerTime = orderCommonMapper.getUserRegisterTime(userId);
|
|
|
// 用户可用优惠券(总)
|
|
|
List<CouponVo> couponList = orderCommonMapper.getClubCouponList(userId);
|
|
|
+ // 用户可领取优惠券(总)
|
|
|
+ List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId, registerTime);
|
|
|
+ List<CouponVo> totalCouponList = new ArrayList<>();
|
|
|
+ totalCouponList.addAll(couponList);
|
|
|
+ totalCouponList.addAll(preCouponList);
|
|
|
List<CartItemVo> cartAllProducts = new ArrayList<>();
|
|
|
- // 用户身份
|
|
|
+ // 用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构
|
|
|
Integer userIdentity = baseMapper.getIdentityByUserId(userId);
|
|
|
-
|
|
|
+ userIdentity = null == userIdentity ? 0 : userIdentity;
|
|
|
+ // 会员机构类型:1医美,2生美
|
|
|
+ Integer userClubType = 0;
|
|
|
+ if (null != userIdentity && userIdentity == 2) {
|
|
|
+ userClubType = cartClubMapper.getClubTypeById(userId);
|
|
|
+ userClubType = null == userClubType ? 0 : userClubType;
|
|
|
+ }
|
|
|
// 超级会员标识
|
|
|
Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
|
|
|
boolean svipUserFlag = null != svipUserId;
|
|
|
if (null != shopInfoList && shopInfoList.size() > 0) {
|
|
|
// 删除空数据
|
|
|
shopInfoList.removeIf(Objects::isNull);
|
|
|
+ Integer finalUserIdentity = userIdentity;
|
|
|
+ Integer finalUserClubType = userClubType;
|
|
|
// 遍历供应商列表
|
|
|
shopInfoList.forEach(shop -> {
|
|
|
// 默认未选中状态(前端要求)
|
|
@@ -120,7 +132,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
AtomicDouble shopOriginalPrice = new AtomicDouble(0);
|
|
|
// 供应商促销优惠活动,以活动分类排序,店铺>凑单>单品
|
|
|
PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
- if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen() == 2 && userIdentity == 1) {
|
|
|
+ if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen() == 2 && finalUserIdentity == 1) {
|
|
|
shopPromotion = null;
|
|
|
}
|
|
|
// 供应商下商品列表 ,购物车里的该供应商商品
|
|
@@ -132,14 +144,21 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
CartItemVo cartItemVo = productIterator.next();
|
|
|
// 设置商品图片及税费
|
|
|
boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
|
|
|
+ // 商品可见度: 3:所有人可见,2:普通机构可见,1:会员机构可见,4:仅医美机构可见
|
|
|
+ Integer visibility = cartItemVo.getVisibility();
|
|
|
+ boolean visibleFlag = visibility == 3 || visibility==2 || (visibility == 1 && (finalUserIdentity == 2 || svipUserFlag)) || (visibility == 4 && finalUserClubType == 1);
|
|
|
+ if (!visibleFlag) {
|
|
|
+ //不可见商品 不加入失效商品,直接去除
|
|
|
+ productIterator.remove();
|
|
|
+ }
|
|
|
// 已上架商品
|
|
|
- if (cartItemVo.getValidFlag() == 2) {
|
|
|
+ else if (cartItemVo.getValidFlag() == 2) {
|
|
|
// 设置商品有效
|
|
|
cartItemVo.setStatus(0);
|
|
|
// 默认所有商品未选中状态(前端要求)
|
|
|
cartItemVo.setIsChecked(false);
|
|
|
- // 价格是否可见
|
|
|
- boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (userIdentity == 2 || svipUserFlag)));
|
|
|
+ // 价格可见度: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
|
|
|
+ boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (finalUserIdentity == 2 || svipUserFlag)) || (cartItemVo.getPriceFlag() == 3 && finalUserClubType == 1));
|
|
|
// 是否库存充足
|
|
|
boolean isStocked = (cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber());
|
|
|
if (priceVisible && isStocked) {
|
|
@@ -159,7 +178,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取商品促销信息
|
|
|
promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
// 促销活动如果协销不可见直接置空
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && finalUserIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
/*
|
|
@@ -229,9 +248,12 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
if (cartItemVo.getPriceFlag() == 1) {
|
|
|
// 未公开价格
|
|
|
cartItemVo.setStatus(6);
|
|
|
- } else if (cartItemVo.getPriceFlag() == 2 && userIdentity == 4) {
|
|
|
+ } else if (cartItemVo.getPriceFlag() == 2 && finalUserIdentity == 4) {
|
|
|
// 价格仅会员可见
|
|
|
cartItemVo.setStatus(5);
|
|
|
+ } else if (cartItemVo.getPriceFlag() == 3 && finalUserClubType != 1) {
|
|
|
+ // 价格仅医美机构可见
|
|
|
+ cartItemVo.setStatus(8);
|
|
|
} else if (cartItemVo.getStock() == null || cartItemVo.getStock() == 0) {
|
|
|
// 售罄
|
|
|
cartItemVo.setStatus(4);
|
|
@@ -315,7 +337,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
}
|
|
|
}
|
|
|
// 是否可领取优惠券
|
|
|
- Boolean couponsLogo = setCouponsLogo(shop.getShopId(), source, productList, couponList);
|
|
|
+ Boolean couponsLogo = setCouponsLogo(shop.getShopId(), source, productList, totalCouponList);
|
|
|
shop.setCouponsLogo(couponsLogo);
|
|
|
|
|
|
// 供应商商品
|
|
@@ -332,6 +354,8 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
|
|
|
// 优惠总额
|
|
|
reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
|
|
|
+ // 超级会员优惠总额
|
|
|
+ svipReducedPrice.set(MathUtil.add(svipReducedPrice, shop.getSvipReducedPrice()).doubleValue());
|
|
|
// 总划线价
|
|
|
totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
|
|
|
// 商品种类
|
|
@@ -382,6 +406,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
resultMap.put("totalCount", totalCount);
|
|
|
resultMap.put("totalPrice", totalPrice);
|
|
|
resultMap.put("reducedPrice", reducedPrice);
|
|
|
+ resultMap.put("svipReducedPrice", svipReducedPrice);
|
|
|
resultMap.put("totalOriginalPrice", totalOriginalPrice);
|
|
|
resultMap.put("promotions", totalPromotions);
|
|
|
resultMap.put("couponList", couponList);
|
|
@@ -513,21 +538,36 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
List<Integer> promotionsIds = new ArrayList<>();
|
|
|
// 用户身份
|
|
|
Integer userIdentity = baseMapper.getIdentityByUserId(userId);
|
|
|
+ // 会员机构类型:1医美,2生美
|
|
|
+ Integer userClubType = 0;
|
|
|
+ if (null != userIdentity && userIdentity == 2) {
|
|
|
+ userClubType = cartClubMapper.getClubTypeById(userId);
|
|
|
+ userClubType = null == userClubType ? 0 : userClubType;
|
|
|
+ }
|
|
|
// 超级会员标识
|
|
|
Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
|
|
|
boolean svipUserFlag = null != svipUserId;
|
|
|
// 获取购物车商品列表(不区分供应商)
|
|
|
cartList = cartClubMapper.getCartProductList(userId);
|
|
|
if (null != cartList && cartList.size() > 0) {
|
|
|
- // 移除价格不可见商品
|
|
|
- cartList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (userIdentity == 2 || svipUserFlag))));
|
|
|
+ // 移除不可见商品,价格不可见商品,无库存
|
|
|
+ Integer finalUserClubType = userClubType;
|
|
|
+ Integer finalUserIdentity = userIdentity;
|
|
|
+ cartList.removeIf(cartItemVo -> !(
|
|
|
+ // visibility商品可见度: 3:所有人可见,2:普通机构可见,1:会员机构可见,4:仅医美机构可见
|
|
|
+ (cartItemVo.getVisibility() == 3 || cartItemVo.getVisibility()==2 || (cartItemVo.getVisibility() == 1 && (finalUserIdentity == 2 || svipUserFlag)) || (cartItemVo.getVisibility() == 4 && finalUserClubType == 1))
|
|
|
+ // 价格可见度: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
|
|
|
+ || (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (finalUserIdentity == 2 || svipUserFlag)) || (cartItemVo.getPriceFlag() == 3 && finalUserClubType == 1))
|
|
|
+ // 是否库存充足
|
|
|
+ || (cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber())
|
|
|
+ ));
|
|
|
cartList.forEach(cartItemVo -> {
|
|
|
// 设置商品图片及税费
|
|
|
boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
|
|
|
// 获取商品促销信息
|
|
|
PromotionsVo promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
// 如果促销活动协销不可见,移除促销
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 2 && finalUserIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
/*
|
|
@@ -759,11 +799,26 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
if (null != cartList && cartList.size() > 0) {
|
|
|
// 用户身份
|
|
|
Integer userIdentity = baseMapper.getIdentityByUserId(userId);
|
|
|
+ userIdentity = null == userIdentity ? 0 : userIdentity;
|
|
|
// 超级会员标识
|
|
|
Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
|
|
|
boolean svipUserFlag = null != svipUserId;
|
|
|
- // 移除价格不可见商品
|
|
|
- cartList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (userIdentity == 2 || svipUserFlag))));
|
|
|
+ // 会员机构类型:1医美,2生美
|
|
|
+ Integer userClubType = 0;
|
|
|
+ if (null != userIdentity && userIdentity == 2) {
|
|
|
+ userClubType = cartClubMapper.getClubTypeById(userId);
|
|
|
+ userClubType = null == userClubType ? 0 : userClubType;
|
|
|
+ }
|
|
|
+ int finalUserIdentity = userIdentity;
|
|
|
+ int finalUserClubType = userClubType;
|
|
|
+ cartList.removeIf(cartItemVo -> !(
|
|
|
+ // visibility商品可见度: 3:所有人可见,2:普通机构可见,1:会员机构可见,4:仅医美机构可见
|
|
|
+ (cartItemVo.getVisibility() == 3 || cartItemVo.getVisibility()==2 || (cartItemVo.getVisibility() == 1 && (finalUserIdentity == 2 || svipUserFlag)) || (cartItemVo.getVisibility() == 4 && finalUserClubType == 1))
|
|
|
+ // 价格可见度: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
|
|
|
+ || (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (finalUserIdentity == 2 || svipUserFlag)) || (cartItemVo.getPriceFlag() == 3 && finalUserClubType == 1))
|
|
|
+ // 是否库存充足
|
|
|
+ || (cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber())
|
|
|
+ ));
|
|
|
return cartList.size();
|
|
|
} else {
|
|
|
return 0;
|
|
@@ -1798,8 +1853,10 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
public ResponseJson<Map<String, Object>> getShopCoupons(Integer userId, Integer shopId, Integer source, Integer status) {
|
|
|
// 供应商下购物车商品列表
|
|
|
List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shopId, userId);
|
|
|
+ // 用户注册时间
|
|
|
+ Date registerTime = orderCommonMapper.getUserRegisterTime(userId);
|
|
|
// 未领取的优惠券
|
|
|
- List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId);
|
|
|
+ List<CouponVo> preCouponList = orderCommonMapper.getPrevCouponList(userId, registerTime);
|
|
|
//剔除超级会员优惠券
|
|
|
List<Integer> vipCoupon = cartClubMapper.findVipCoupon();
|
|
|
if (preCouponList != null && preCouponList.size() > 0) {
|