gongzuming
2024-09-19 1bcd5a3c6447a0a00dc450b8b7780dadbb8e0e56
src/main/java/com/mzl/flower/service/impl/coupon/CouponTemplateServiceImpl2.java
@@ -421,7 +421,9 @@
            if(couponTemplateDO==null){
                throw new ValidationException("优惠券不存在");
            }
            if(couponTemplateDO.getCouponAmount()<=0 ){
               throw new ValidationException("优惠券已兑换完");
            }
            CustomerPoint cp = customerPointMapper.selectOne(new LambdaQueryWrapper<CustomerPoint>()
                    .eq(CustomerPoint::getUserId, SecurityUtils.getUserId()));
            if(cp == null || (cp.getTotalPoint()-cp.getUsedPoint()-cp.getExpiredPoint()- cp.getExpiredPoint()) < couponTemplateDO.getPoint() * dto.getNum()){
@@ -439,6 +441,10 @@
            recordDTO.setCustomerId(customer.getId());
            couponRecordService.createCouponRecord(recordDTO);
            //更新优惠券数量
            couponTemplateDO.setCouponAmount(couponTemplateDO.getCouponAmount()-dto.getNum());
            couponTemplateService.updateById(couponTemplateDO);
            //更新积分汇总
            cp.setUsedPoint(cp.getUsedPoint()+couponTemplateDO.getPoint());
            customerPointMapper.updateById(cp);
@@ -455,6 +461,7 @@
            detail.create(SecurityUtils.getUserId());
            customerPointDetailMapper.insert(detail);
        }catch (Exception e){
            log.error("兑换失败",e);
            throw new ValidationException("兑换失败");
        }finally {
            lockService.releaseObjectLock(key,"");