|
@@ -26,6 +26,7 @@ import com.yonge.cooleshow.biz.dal.vo.coupon.CouponIssueWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper;
|
|
|
import com.yonge.cooleshow.common.enums.EStatus;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import com.yonge.toolset.base.string.MessageFormatter;
|
|
|
import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -36,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.text.MessageFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
@@ -167,6 +169,22 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
|
|
|
if (!throwE) return false;
|
|
|
throw new BizException("优惠券已被禁用");
|
|
|
}
|
|
|
+
|
|
|
+ List<Long> userIds = userParam.stream()
|
|
|
+ .map(UserParam::getUserId).distinct().collect(Collectors.toList());
|
|
|
+ // 判断用户领取数据限制
|
|
|
+ if (Optional.ofNullable(couponInfo.getQuantityLimit()).orElse(0) > 0
|
|
|
+ && CollectionUtils.isNotEmpty(userIds)) {
|
|
|
+
|
|
|
+ CouponInfoQuery.IssueStatQuery statQuery = CouponInfoQuery.IssueStatQuery.builder().userIds(userIds).build();
|
|
|
+ // 统计用户领取优惠券数量
|
|
|
+ List<StatGroupWrapper> groupWrappers = getBaseMapper().selectCouponIssueStatInfo(couponId, statQuery);
|
|
|
+
|
|
|
+ if (groupWrappers.stream().anyMatch(x -> x.getTotal() >= couponInfo.getQuantityLimit())) {
|
|
|
+ throw new BizException(MessageFormat.format("优惠券已领取,每人仅限{0}张", couponInfo.getQuantityLimit()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 判断优惠券类型 设置优惠券时间
|
|
|
Long startTime = null;
|
|
|
Long endTime = null;
|