gongzuming
2024-09-19 b61182b5c602d0bb4af7c68cb51dbfa1eb5a755f
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);
@@ -454,8 +460,6 @@
            detail.setRemarks(couponTemplateDO.getCouponName());
            detail.create(SecurityUtils.getUserId());
            customerPointDetailMapper.insert(detail);
        }catch (Exception e){
            throw new ValidationException("兑换失败");
        }finally {
            lockService.releaseObjectLock(key,"");
        }