puzhibing
2023-06-23 7ee9bc8fb2e42ce2e82cd1eacb57ba584611dfc5
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java
@@ -187,8 +187,10 @@
                appUser.setStatus(1);
                appUser.setCreateTime(new Date());
                appUser.setIsException(1);
                if(null != signInToRegister.getInviterId()){
                appUser.setInviterId(signInToRegister.getInviterId());
                appUser.setInviterType(signInToRegister.getInviterType());
                }
                this.insert(appUser);
                //发送优惠券
                boolean lock = redisUtil.lock(5);
@@ -272,20 +274,18 @@
                .eq("coupon_state", 1).eq("status", 1).gt("remaining_quantity", 0));
        List<CouponWarpper> list = new ArrayList<>();
        for (Coupon coupon : coupons) {
            Integer num = coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ?
                    coupon.getRemainingQuantity() : coupon.getCouponSendQuantity();
            for (int i = 0; i < num; i++) {
            UserToCoupon userToCoupon = new UserToCoupon();
            userToCoupon.setCouponId(coupon.getId());
            userToCoupon.setCreateTime(new Date());
            userToCoupon.setUserId(userId);
            userToCoupon.setStatus(1);
            userToCoupon.setCouponTotal(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ?
                    coupon.getRemainingQuantity() : coupon.getCouponSendQuantity());
            userToCoupon.setValidCount(userToCoupon.getCouponTotal());
                userToCoupon.setCouponTotal(1);
                userToCoupon.setValidCount(1);
            userToCoupon.setExpireTime(new Date(System.currentTimeMillis() + (coupon.getCouponValidity().longValue() * 24L * 60L * 60L * 1000L)));
            userToCouponService.insert(userToCoupon);
            coupon.setRemainingQuantity(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? 0 :
                    coupon.getRemainingQuantity() - coupon.getCouponSendQuantity());
            couponService.updateById(coupon);
            CouponWarpper couponWarpper = new CouponWarpper();
            couponWarpper.setCouponConditionalAmount(coupon.getCouponConditionalAmount());
@@ -295,6 +295,10 @@
            couponWarpper.setExpirationDate(userToCoupon.getExpireTime().getTime());
            list.add(couponWarpper);
        }
            coupon.setRemainingQuantity(coupon.getCouponSendQuantity() > coupon.getRemainingQuantity() ? 0 :
                    coupon.getRemainingQuantity() - coupon.getCouponSendQuantity());
            couponService.updateById(coupon);
        }
        return list;
    }