| | |
| | | |
| | | @Override |
| | | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { |
| | | // 校验发放数量不能小于每人限领数量(仅在 CouponTakeTypeEnum.USER 用户领取时) |
| | | validateTotalCountNotLessThanTakeLimitCount(createReqVO.getTakeType(), createReqVO.getTotalCount(), |
| | | createReqVO.getTakeLimitCount()); |
| | | // 校验商品范围 |
| | | validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues()); |
| | | // 插入 |
| | |
| | | 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()); |
| | |
| | | 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); |