限时折扣 互斥
This commit is contained in:
parent
a6a202ce46
commit
fbd98b52a5
|
|
@ -15,7 +15,7 @@ import com.czg.market.entity.MkDiscountActivity;
|
|||
public interface MkDiscountActivityService extends IService<MkDiscountActivity> {
|
||||
Page<MkDiscountActivityDTO> getActivityPage(TimeQueryParam param, Long shopId);
|
||||
|
||||
MkDiscountActivityDTO checkDiscountAct(Long shopId, boolean couponShare, boolean vipShare, boolean pointsShare);
|
||||
MkDiscountActivityDTO checkDiscountAct(Long shopId, boolean couponShare, boolean vipShare, boolean limitRateShare, boolean pointsShare);
|
||||
|
||||
MkDiscountActivityDTO getActivityByShopId(Long shopId);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,13 +62,18 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
}
|
||||
|
||||
@Override
|
||||
public MkDiscountActivityDTO checkDiscountAct(Long shopId, boolean couponShare, boolean vipShare, boolean pointsShare) {
|
||||
public MkDiscountActivityDTO checkDiscountAct(Long shopId, boolean couponShare, boolean vipShare, boolean limitRateShare, boolean pointsShare) {
|
||||
MkDiscountActivityDTO activityDTO = getActivityByShopId(shopId);
|
||||
AssertUtil.isNull(activityDTO, "店铺未配置满减活动");
|
||||
//检查是否开启了优惠券抵扣
|
||||
if (couponShare && activityDTO.getCouponShare() == 0) {
|
||||
throw new CzgException("满减活动与优惠券不可共用");
|
||||
}
|
||||
//检查是否开启了限时折扣
|
||||
if (limitRateShare && activityDTO.getDiscountShare() == 0) {
|
||||
throw new CzgException("满减活动与限时折扣不可共用");
|
||||
|
||||
}
|
||||
//检查是否开启了会员抵扣
|
||||
if (vipShare && activityDTO.getVipPriceShare() == 0) {
|
||||
throw new CzgException("满减活动与会员价不可共用");
|
||||
|
|
@ -87,7 +92,7 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
if (shopInfo.getIsEnableDiscount() == null || shopInfo.getIsEnableDiscount() == 0) {
|
||||
return null;
|
||||
}
|
||||
MkDiscountActivity activity = mapper.selectOneByShopId(shopId,CzgStrUtils.getStrWeek());
|
||||
MkDiscountActivity activity = mapper.selectOneByShopId(shopId, CzgStrUtils.getStrWeek());
|
||||
if (activity == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,7 +353,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
if (!param.isFreeDine() && param.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
//检查满减活动是否开启
|
||||
discountAct = discountActService.checkDiscountAct(orderInfo.getShopId(),
|
||||
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(),
|
||||
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(), param.getLimitRate() != null,
|
||||
param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0);
|
||||
}
|
||||
orderInfo.setSeatNum(param.getSeatNum());
|
||||
|
|
@ -425,10 +425,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
Map<Integer, MkShopCouponRecord> couponRecordMap = list.stream().collect(Collectors.toMap(MkShopCouponRecord::getType, t -> t));
|
||||
AtomicBoolean otherCouponShare = new AtomicBoolean(true);
|
||||
couponRecordMap.forEach((type, record) -> {
|
||||
ShopCoupon coupon = checkCoupon(record, param.isVipPrice());
|
||||
boolean isTimeDiscountShare = coupon.getDiscountShare() == 1;
|
||||
//1-满减券,2-商品兑换券,3-折扣券,4-第二件半价券, 6-买一送一券,
|
||||
// 7-固定价格券,8-免配送费券 暂时没有
|
||||
if (type == 2) {//商品券z
|
||||
ShopCoupon coupon = checkCoupon(record, param.isVipPrice());
|
||||
if (coupon.getOtherCouponShare() != 1) {
|
||||
otherCouponShare.set(false);
|
||||
}
|
||||
|
|
@ -443,12 +444,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
isAllFoods = false;
|
||||
}
|
||||
}
|
||||
foodsCalculate(orderDetails, isAllFoods, couponFoodIds, coupon.getDiscountNum(), "price_asc".equals(coupon.getUseRule()), prodCouponAmount);
|
||||
foodsCalculate(orderDetails, isAllFoods, couponFoodIds, coupon.getDiscountNum(),
|
||||
isTimeDiscountShare, "price_asc".equals(coupon.getUseRule()), prodCouponAmount);
|
||||
} else if (type == 4 || type == 6) {//4-第二件半价券, 6-买一送一券
|
||||
if (!otherCouponShare.get()) {
|
||||
throw new ValidateException("生成支付订单失败,商品券与其它券不可共用");
|
||||
}
|
||||
ShopCoupon coupon = checkCoupon(record, param.isVipPrice());
|
||||
boolean isAllFoods = true;
|
||||
List<Long> couponFoodIds = new ArrayList<>();
|
||||
if (StrUtil.isNotBlank(coupon.getFoods()) && !",".equals(coupon.getFoods())) {
|
||||
|
|
@ -458,15 +459,14 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
}
|
||||
}
|
||||
if (type == 6) {
|
||||
oneGiftCalculate(orderDetails, isAllFoods, couponFoodIds, "price_asc".equals(coupon.getUseRule()), oneGiftAmount);
|
||||
oneGiftCalculate(orderDetails, isAllFoods, couponFoodIds, isTimeDiscountShare, "price_asc".equals(coupon.getUseRule()), oneGiftAmount);
|
||||
} else {
|
||||
twoHalfCalculate(orderDetails, isAllFoods, couponFoodIds, "price_asc".equals(coupon.getUseRule()), twoHalfAmount);
|
||||
twoHalfCalculate(orderDetails, isAllFoods, couponFoodIds, isTimeDiscountShare, "price_asc".equals(coupon.getUseRule()), twoHalfAmount);
|
||||
}
|
||||
} else if (type == 1 || type == 3) {//1-满减券 3-折扣券
|
||||
if (!otherCouponShare.get()) {
|
||||
throw new ValidateException("生成支付订单失败,商品券与其它券不可共用");
|
||||
}
|
||||
ShopCoupon coupon = checkCoupon(record, param.isVipPrice());
|
||||
//计算门槛
|
||||
boolean isAllFoods = true;
|
||||
List<Long> couponFoodIds = new ArrayList<>();
|
||||
|
|
@ -690,13 +690,17 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
/**
|
||||
* 商品优惠券计算
|
||||
*/
|
||||
private void foodsCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds, int discountNum, boolean isAsc, BigDecimalDTO prodCouponAmount) {
|
||||
private void foodsCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds, int discountNum,
|
||||
boolean isTimeDiscountShare, boolean isAsc, BigDecimalDTO prodCouponAmount) {
|
||||
orderDetails = getDetailsSort(orderDetails, isAsc);
|
||||
// log.info("商品券 计算 orderDetails:{}", orderDetails);
|
||||
BigDecimal remaining = new BigDecimal(discountNum);
|
||||
for (OrderDetail detail : orderDetails) {
|
||||
if (detail.getIsTemporary() != 1 && (isAllFoods || couponFoodIds.contains(detail.getProductId())) && detail.getUnitPrice().compareTo(BigDecimal.ZERO) > 0) {
|
||||
if (remaining.compareTo(BigDecimal.ZERO) > 0) {
|
||||
if (isTimeDiscountShare && detail.getIsTimeDiscount() == 1) {
|
||||
throw new ValidateException("生成支付订单失败,商品:" + detail.getProductName() + " 抵扣券与限时折扣不可共用。");
|
||||
}
|
||||
if (remaining.compareTo(detail.getNum().subtract(detail.getReturnNum())) >= 0) {
|
||||
detail.setCouponNum(detail.getNum().subtract(detail.getReturnNum()).setScale(2, RoundingMode.CEILING));
|
||||
detail.setDiscountAmount(detail.getPayAmount());
|
||||
|
|
@ -721,12 +725,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
/**
|
||||
* 买一送一优惠券计算
|
||||
*/
|
||||
private void oneGiftCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds, boolean isAsc, BigDecimalDTO oneGiftAmount) {
|
||||
private void oneGiftCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds,
|
||||
boolean isTimeDiscountShare, boolean isAsc, BigDecimalDTO oneGiftAmount) {
|
||||
orderDetails = getDetailsSort(orderDetails, isAsc);
|
||||
for (OrderDetail detail : orderDetails) {
|
||||
if ((isAllFoods || couponFoodIds.contains(detail.getProductId()))
|
||||
&& detail.getUnitPrice().compareTo(BigDecimal.ZERO) > 0
|
||||
&& detail.getNum().subtract(detail.getReturnNum()).subtract(detail.getCouponNum()).compareTo(BigDecimal.TWO) >= 0) {
|
||||
if (isTimeDiscountShare && detail.getIsTimeDiscount() == 1) {
|
||||
throw new ValidateException("生成支付订单失败,商品:" + detail.getProductName() + " 买一送一券与限时折扣不可共用。");
|
||||
}
|
||||
detail.setCouponNum(detail.getCouponNum().add(BigDecimal.ONE));
|
||||
detail.setDiscountAmount(detail.getDiscountAmount().add(detail.getUnitPrice()));
|
||||
detail.setPayAmount(detail.getPayAmount().subtract(detail.getUnitPrice()));
|
||||
|
|
@ -739,12 +747,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
/**
|
||||
* 第二件半价优惠券计算
|
||||
*/
|
||||
private void twoHalfCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds, boolean isAsc, BigDecimalDTO oneGiftAmount) {
|
||||
private void twoHalfCalculate(List<OrderDetail> orderDetails, boolean isAllFoods, List<Long> couponFoodIds,
|
||||
boolean isTimeDiscountShare, boolean isAsc, BigDecimalDTO oneGiftAmount) {
|
||||
orderDetails = getDetailsSort(orderDetails, isAsc);
|
||||
for (OrderDetail detail : orderDetails) {
|
||||
if ((isAllFoods || couponFoodIds.contains(detail.getProductId()))
|
||||
&& detail.getUnitPrice().compareTo(BigDecimal.ZERO) > 0
|
||||
&& detail.getNum().subtract(detail.getReturnNum()).subtract(detail.getCouponNum()).compareTo(BigDecimal.TWO) >= 0) {
|
||||
if (isTimeDiscountShare && detail.getIsTimeDiscount() == 1) {
|
||||
throw new ValidateException("生成支付订单失败,商品:" + detail.getProductName() + " 抵扣券与限时折扣不可共用。");
|
||||
}
|
||||
detail.setHalfPriceCouponNum(BigDecimal.ONE);
|
||||
BigDecimal halfPrice = detail.getUnitPrice().divide(new BigDecimal("2")).setScale(2, RoundingMode.FLOOR);
|
||||
detail.setDiscountAmount(detail.getDiscountAmount().add(halfPrice));
|
||||
|
|
|
|||
Loading…
Reference in New Issue