| | |
| | | public boolean grantVipCouponRecordList() { |
| | | |
| | | try{ |
| | | |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime firstDayStart = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).withNano(0); |
| | | LocalDateTime lastDayEnd = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0); |
| | |
| | | return baseMapper.selectCount(queryWrapper)>0; |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public boolean useCoupon(String couponId, String orderId) { |
| | | // 优惠券为空 |
| | | if(StringUtils.isBlank(couponId)){ |
| | | throw new IllegalArgumentException("无效的优惠券"); |
| | | } |
| | | // 验证优惠券存在且有效 |
| | | final CouponRecordDO couponRecordDO = baseMapper.selectById(couponId); |
| | | if(null==couponRecordDO || StringUtils.isBlank(couponRecordDO.getOrderId()) ){ |
| | | throw new IllegalArgumentException("无效的优惠券"); |
| | | } |
| | | if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.USED.getType())){ |
| | | throw new IllegalArgumentException("优惠券已经被使用"); |
| | | } |
| | | if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.EXPIRED.getType()) || LocalDateTime.now().isAfter(couponRecordDO.getEffectiveEnd())){ |
| | | throw new IllegalArgumentException("优惠券已过期"); |
| | | } |
| | | if(StringUtils.isBlank(orderId)){ |
| | | throw new IllegalArgumentException("订单id不能为空"); |
| | | } |
| | | |
| | | // 优惠券使用操作 |
| | | couponRecordDO.setStatus(CouponUsedStatusEnum.USED.getType()); |
| | | couponRecordDO.setUsedTime(LocalDateTime.now()); |
| | | couponRecordDO.setOrderId(orderId); |
| | | |
| | | return baseMapper.updateById(couponRecordDO)>0; |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public boolean cancelCouponUsage(String couponId, String orderId) { |
| | | // 查询订单使用的优惠券 |
| | | final CouponRecordDO couponRecordDO = getCouponByOrderId(orderId); |
| | | // TODO |
| | | couponRecordDO.setStatus(CouponUsedStatusEnum.UNUSED.getType()); |
| | | couponRecordDO.setUsedTime(null); |
| | | couponRecordDO.setOrderId(null); |
| | | |
| | | return baseMapper.updateById(couponRecordDO)>0; |
| | | } |
| | | |
| | | @Override |
| | | public List<CouponRecordDO> getCouponListByOrderId(String orderId) { |
| | | QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda().eq(CouponRecordDO::getDeleted,TrueOrFalseEnum.FALSE.isFlag()) |
| | | .eq(CouponRecordDO::getOrderId,orderId); |
| | | |
| | | return baseMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public CouponRecordDO getCouponByOrderId(String orderId) { |
| | | final List<CouponRecordDO> couponRecordDOList = getCouponListByOrderId(orderId); |
| | | if(CollectionUtils.isNotEmpty(couponRecordDOList)){ |
| | | return couponRecordDOList.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | } |