|
|
@@ -396,7 +396,7 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
// ---- 11. 可用优惠券列表 ----
|
|
|
List<Map<String, Object>> availableCouponMaps = buildAvailableCoupons(storeId, userId,
|
|
|
originalAmount, afterPromotion, promotionReduce, itemsWithPrice,
|
|
|
- rulesByProduct, activityMap);
|
|
|
+ rulesByProduct, activityMap, priceMap, nameMap);
|
|
|
response.setAvailableCoupons(availableCouponMaps.stream()
|
|
|
.map(this::toAvailableCoupon)
|
|
|
.collect(Collectors.toList()));
|
|
|
@@ -469,6 +469,13 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
ac.setDiscountRate((BigDecimal) couponMap.get("discountRate"));
|
|
|
ac.setUsable((Boolean) couponMap.get("usable"));
|
|
|
ac.setConflictWithPromotion((Boolean) couponMap.get("conflictWithPromotion"));
|
|
|
+ ac.setCouponPreviewReduce((BigDecimal) couponMap.get("couponPreviewReduce"));
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<Map<String, Object>> productPreview = (List<Map<String, Object>>) couponMap.get("productPreview");
|
|
|
+ if (productPreview != null && !productPreview.isEmpty())
|
|
|
+ {
|
|
|
+ ac.setProductPreview(productPreview.stream().map(this::toLineItem).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
ac.setExpireTime((java.util.Date) couponMap.get("expireTime"));
|
|
|
return ac;
|
|
|
}
|
|
|
@@ -826,7 +833,9 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
BigDecimal promotionReduce,
|
|
|
List<Map<String, Object>> itemsWithPrice,
|
|
|
Map<Long, List<PromotionActivityRule>> rulesByProduct,
|
|
|
- Map<Long, PromotionActivity> activityMap)
|
|
|
+ Map<Long, PromotionActivity> activityMap,
|
|
|
+ Map<Long, BigDecimal> priceMap,
|
|
|
+ Map<Long, String> nameMap)
|
|
|
{
|
|
|
List<Map<String, Object>> available = new ArrayList<>();
|
|
|
if (userId == null)
|
|
|
@@ -883,6 +892,16 @@ public class PromotionCalcServiceImpl implements IPromotionCalcService
|
|
|
|
|
|
if (batch.getCouponType() != null && batch.getCouponType() == 2 && rule.getProductId() != null)
|
|
|
{
|
|
|
+ // 预览: 该商品券作用于的商品能优惠多少(名称/原价/优惠后价)
|
|
|
+ CouponCalcResult preview = calcCouponReduce(rule, batch, itemsWithPrice, afterPromotion, priceMap, nameMap);
|
|
|
+ if (preview.reduce.compareTo(BigDecimal.ZERO) > 0)
|
|
|
+ {
|
|
|
+ couponInfo.put("couponPreviewReduce", preview.reduce);
|
|
|
+ }
|
|
|
+ if (!preview.items.isEmpty())
|
|
|
+ {
|
|
|
+ couponInfo.put("productPreview", preview.items);
|
|
|
+ }
|
|
|
boolean inCart = itemsWithPrice.stream()
|
|
|
.anyMatch(i -> rule.getProductId().equals(toLong(i.get("productId"))));
|
|
|
if (!inCart)
|