|
@@ -595,9 +595,10 @@ public class CartClubServiceImpl implements CartClubService {
|
|
*
|
|
*
|
|
* @param userId 用户ID
|
|
* @param userId 用户ID
|
|
* @param productIds 商品ids,逗号隔开
|
|
* @param productIds 商品ids,逗号隔开
|
|
|
|
+ * @param source 来源 : 1 网站 ; 2 小程序
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds) {
|
|
|
|
|
|
+ public ResponseJson<Map<String, Object>> settlementShoppingCart(Integer userId, String productIds, Integer source) {
|
|
log.info("¥¥¥¥¥¥¥¥¥¥ > 商品结算");
|
|
log.info("¥¥¥¥¥¥¥¥¥¥ > 商品结算");
|
|
// 商品种类
|
|
// 商品种类
|
|
AtomicInteger kindCount = new AtomicInteger(0);
|
|
AtomicInteger kindCount = new AtomicInteger(0);
|
|
@@ -613,7 +614,8 @@ public class CartClubServiceImpl implements CartClubService {
|
|
List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
// 是否包含充值商品,默认false
|
|
// 是否包含充值商品,默认false
|
|
AtomicBoolean includeRecharge = new AtomicBoolean(false);
|
|
AtomicBoolean includeRecharge = new AtomicBoolean(false);
|
|
-
|
|
|
|
|
|
+ //所有的商品数据
|
|
|
|
+ List<CartItemVo> totalProductList = new ArrayList<>();
|
|
// 促销活动Id集合,用于合并促销活动
|
|
// 促销活动Id集合,用于合并促销活动
|
|
List<Integer> promotionsIds = new ArrayList<>();
|
|
List<Integer> promotionsIds = new ArrayList<>();
|
|
// 供应商Id集合,用户判断赠品供应商是否在当前供应商中
|
|
// 供应商Id集合,用户判断赠品供应商是否在当前供应商中
|
|
@@ -762,6 +764,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
// 商品种类
|
|
// 商品种类
|
|
kindCount.updateAndGet(v -> v + shopKindCount.get());
|
|
kindCount.updateAndGet(v -> v + shopKindCount.get());
|
|
}
|
|
}
|
|
|
|
+ totalProductList.addAll(productList);
|
|
}
|
|
}
|
|
// 供应商下商品种类
|
|
// 供应商下商品种类
|
|
shop.setCount(shopKindCount.get());
|
|
shop.setCount(shopKindCount.get());
|
|
@@ -803,6 +806,59 @@ public class CartClubServiceImpl implements CartClubService {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ // 用户可用优惠券(总)
|
|
|
|
+ List<CouponVo> couponList = cartClubMapper.getClubCouponList(userId);
|
|
|
|
+ Iterator<CouponVo> iterator = couponList.iterator();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ CouponVo coupon = iterator.next();
|
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO;
|
|
|
|
+ Integer couponType = coupon.getCouponType();
|
|
|
|
+ for (CartItemVo item : totalProductList) {
|
|
|
|
+ if (couponType == 0) {
|
|
|
|
+ if (coupon.getProductType() == 1) {
|
|
|
|
+ //活动券-全商城商品
|
|
|
|
+ BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
|
|
|
|
+ totalAmount = MathUtil.add(price, totalAmount);
|
|
|
|
+ } else if (coupon.getProductType() == 2) {
|
|
|
|
+ //活动券-指定商品
|
|
|
|
+ List<Integer> couponProductIds = cartClubMapper.getCouponProductIds(coupon.getCouponId(), source);
|
|
|
|
+ if (couponProductIds.contains(item.getProductId())) {
|
|
|
|
+ BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
|
|
|
|
+ totalAmount = MathUtil.add(price, totalAmount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (couponType == 1) {
|
|
|
|
+ //品类券
|
|
|
|
+ if (coupon.getCategoryType().equals(item.getCommodityType())) {
|
|
|
|
+ BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
|
|
|
|
+ totalAmount = MathUtil.add(price, totalAmount);
|
|
|
|
+ }
|
|
|
|
+ } else if (couponType == 2 || couponType == 4) {
|
|
|
|
+ //用户专享券或新用户券
|
|
|
|
+ BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
|
|
|
|
+ totalAmount = MathUtil.add(price, totalAmount);
|
|
|
|
+ } else 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);
|
|
|
|
+ }
|
|
|
|
+ if (coupon.getShopId().equals(item.getShopId())) {
|
|
|
|
+ BigDecimal price = MathUtil.mul(item.getPrice(), item.getNumber());
|
|
|
|
+ totalAmount = MathUtil.add(price, totalAmount);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (MathUtil.compare(totalAmount, coupon.getTouchPrice()) < 0) {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ couponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
|
|
|
|
+
|
|
// 发票信息
|
|
// 发票信息
|
|
InvoiceVo invoice = baseMapper.getUserInvoice(userId);
|
|
InvoiceVo invoice = baseMapper.getUserInvoice(userId);
|
|
// 可用余额
|
|
// 可用余额
|
|
@@ -822,6 +878,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
resultData.put("userMoney", availableMoney);
|
|
resultData.put("userMoney", availableMoney);
|
|
resultData.put("userBeans", userBeans);
|
|
resultData.put("userBeans", userBeans);
|
|
resultData.put("includeRecharge", includeRecharge);
|
|
resultData.put("includeRecharge", includeRecharge);
|
|
|
|
+ resultData.put("couponList", couponList);
|
|
return ResponseJson.success(resultData);
|
|
return ResponseJson.success(resultData);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -832,6 +889,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
* userId 用户ID
|
|
* userId 用户ID
|
|
* productId 商品id
|
|
* productId 商品id
|
|
* productCount 商品数量
|
|
* productCount 商品数量
|
|
|
|
+ * source 来源 : 1 网站 ; 2 小程序
|
|
* }
|
|
* }
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@@ -860,7 +918,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
cartClubMapper.insertCart(cart);
|
|
cartClubMapper.insertCart(cart);
|
|
}
|
|
}
|
|
// 结算商品
|
|
// 结算商品
|
|
- return settlementShoppingCart(cartDto.getUserId(), cartDto.getProductId().toString());
|
|
|
|
|
|
+ return settlementShoppingCart(cartDto.getUserId(), cartDto.getProductId().toString(), cartDto.getSource());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|