| | |
| | | import com.mzl.flower.service.coupon.CouponTemplateCustomerService; |
| | | import com.mzl.flower.service.coupon.CouponTemplateService2; |
| | | import com.mzl.flower.service.menber.MemberService; |
| | | import com.mzl.flower.service.payment.RedisLockService; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | |
| | | @Autowired |
| | | private MemberService memberService; |
| | | |
| | | @Autowired |
| | | private RedisLockService lockService; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void exchangeCoupon(ExchangeCouponDTO dto) { |
| | | dto.setNum(1); |
| | | public void exchangeCoupon(ExchangeCouponDTO dto) { |
| | | |
| | | String key="EXCHANGE_COUPON:"+dto.getCouponId()+":"+SecurityUtils.getUserId(); |
| | | boolean lock = lockService.getObjectLock(key, ""); |
| | | if(!lock){ |
| | | throw new ValidationException("系统操作频繁,请稍后重试"); |
| | | } |
| | | try { |
| | | dto.setNum(1); |
| | | final CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getCouponId()); |
| | | if(couponTemplateDO==null){ |
| | | throw new ValidationException("优惠券不存在"); |
| | |
| | | |
| | | CustomerPoint cp = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>() |
| | | .eq(CustomerPoint::getUserId, SecurityUtils.getUserId())); |
| | | if(cp == null || (cp.getTotalPoint()-cp.getUsedPoint()-cp.getExpiredPoint()) < couponTemplateDO.getPoint() * dto.getNum()){ |
| | | if(cp == null || (cp.getTotalPoint()-cp.getUsedPoint()-cp.getExpiredPoint()- cp.getExpiredPoint()) < couponTemplateDO.getPoint() * dto.getNum()){ |
| | | throw new ValidationException("积分不足"); |
| | | } |
| | | |
| | |
| | | detail.setRemarks(couponTemplateDO.getCouponName()); |
| | | detail.create(SecurityUtils.getUserId()); |
| | | customerPointDetailMapper.insert(detail); |
| | | }catch (Exception e){ |
| | | throw new ValidationException("兑换失败"); |
| | | }finally { |
| | | lockService.releaseObjectLock(key,""); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |