liyong
10 天以前 450bcae3cfffe9923dc09dea2a4e89312bb373d7
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
@@ -52,6 +52,9 @@
    @Override
    public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) {
        // 校验发放数量不能小于每人限领数量(仅在 CouponTakeTypeEnum.USER 用户领取时)
        validateTotalCountNotLessThanTakeLimitCount(createReqVO.getTakeType(), createReqVO.getTotalCount(),
                createReqVO.getTakeLimitCount());
        // 校验商品范围
        validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues());
        // 插入
@@ -66,8 +69,11 @@
    public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) {
        // 校验存在
        CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId());
        // 校验发放数量不能小于每人限领数量(仅在 CouponTakeTypeEnum.USER 用户领取时)
        validateTotalCountNotLessThanTakeLimitCount(updateReqVO.getTakeType(), updateReqVO.getTotalCount(),
                updateReqVO.getTakeLimitCount());
        // 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时)
        if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
        if (CouponTakeTypeEnum.isUser(updateReqVO.getTakeType())
                && !isTotalCountUnlimited(updateReqVO.getTotalCount()) // 非不限制总发放数量
                && updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) {
            throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount());
@@ -104,6 +110,16 @@
        return couponTemplate;
    }
    private void validateTotalCountNotLessThanTakeLimitCount(Integer takeType, Integer totalCount, Integer takeLimitCount) {
        // 修复 https://gitee.com/yudaocode/yudao-mall-uniapp/issues/IJLP6Q 反馈
        if (CouponTakeTypeEnum.isUser(takeType)
                && !isTakeLimitCountUnlimited(takeLimitCount)
                && !isTotalCountUnlimited(totalCount)
                && takeLimitCount > totalCount) {
            throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
        }
    }
    private void validateProductScope(Integer productScope, List<Long> productScopeValues) {
        if (Objects.equals(PromotionProductScopeEnum.SPU.getScope(), productScope)) {
            productSpuApi.validateSpuList(productScopeValues);