| | |
| | | @Override |
| | | public boolean createCouponRecord(CreateCouponRecordDTO dto) { |
| | | |
| | | // TODO 需要控制超领 |
| | | |
| | | final Customer customer = customerMapper.selectById(dto.getCustomerId()); |
| | | if(null==customer){ |
| | | throw new ValidationException("商户信息不存在"); |
| | |
| | | throw new ValidationException("优惠券不存在"); |
| | | } |
| | | |
| | | // TODO 活动优惠券和积分优惠券需要根据库存来控制- 根据优惠券的发放数量来控制有没有超发 |
| | | // 活动优惠券和积分优惠券需要根据库存来控制- 根据优惠券的发放数量来控制有没有超发 |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) && ( |
| | | couponTemplateDO.getCategory().equals(CouponCategoryEnum.ACTIVITY.getStatus()) || couponTemplateDO.getCategory().equals(CouponCategoryEnum.POINT.getStatus()) |
| | | )){ |
| | | // 获取当前优惠券已经领取的数量 |
| | | final Integer gainTotal = getExistGainCouponRecordAmountById(couponTemplateDO.getId()); |
| | | if(couponTemplateDO.getCouponAmount().compareTo(gainTotal)<=0){ |
| | | throw new ValidationException("当前优惠券已经领完!"); |
| | | } |
| | | } |
| | | |
| | | // 根据用户领取设置的getLimit 查看当前用户是否已经超领优惠券 |
| | | if(StringUtils.isNotBlank(couponTemplateDO.getCategory()) && couponTemplateDO.getCategory().equals(CouponCategoryEnum.ACTIVITY.getStatus()) ){ |
| | | // 查看当前优惠券的领取时间在不在设置的领取时间范围类 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 判断当前时间是否在领取时间范围内 |
| | | if (!(now.isAfter(couponTemplateDO.getGetStartDate()) && now.isBefore(couponTemplateDO.getGetEndDate()))) { |
| | | throw new ValidationException("当前时间不在优惠券的领取时间范围内,无法操作!"); |
| | | } |
| | | |
| | | // TODO 根据用户领取设置的getLimit 查看当前用户是否已经超领优惠券 |
| | | // 获取当前优惠券已经领取的数量 |
| | | final Integer customGainTotal = getUserGainCouponRecordAmountById(couponTemplateDO.getId(),customer.getId()); |
| | | if(couponTemplateDO.getGetLimit().compareTo(customGainTotal)<=0){ |
| | | throw new ValidationException("超出个人领取限制,每人限领"+couponTemplateDO.getGetLimit()+"张!"); |
| | | } |
| | | } |
| | | |
| | | |
| | | CouponRecordDO couponRecordDO=new CouponRecordDO(); |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | return baseMapper.insert(couponRecordDO)>0; |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int getExistCouponAmount(QueryExistCouponDTO dto) { |
| | | public Integer getExistCouponAmount(QueryExistCouponDTO dto) { |
| | | QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda().eq(CouponRecordDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag()) |
| | | .eq(StringUtils.isNotBlank(dto.getCouponId()), CouponRecordDO::getCouponId,dto.getCouponId()) |
| | | .eq(StringUtils.isNotBlank(dto.getCustomerId()),CouponRecordDO::getCustomerId,dto.getCustomerId()) |
| | | .eq(null!=dto.getCustomerId(),CouponRecordDO::getCustomerId,dto.getCustomerId()) |
| | | .eq(StringUtils.isNotBlank(dto.getCategory()),CouponRecordDO::getCategory,dto.getCategory()); |
| | | |
| | | return baseMapper.selectCount(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getExistGainCouponRecordAmountById(String couponId) { |
| | | QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda().eq(CouponRecordDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag()) |
| | | .eq(StringUtils.isNotBlank(couponId), CouponRecordDO::getCouponId,couponId) |
| | | ; |
| | | return baseMapper.selectCount(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getUserGainCouponRecordAmountById(String couponId, Long customerId) { |
| | | QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda().eq(CouponRecordDO::getDeleted, TrueOrFalseEnum.FALSE.isFlag()) |
| | | .eq(StringUtils.isNotBlank(couponId), CouponRecordDO::getCouponId,couponId) |
| | | .eq(null!=customerId,CouponRecordDO::getCustomerId,customerId) |
| | | ; |
| | | |
| | | return baseMapper.selectCount(queryWrapper); |
| | | } |
| | | } |