From 231326e66ba99200bcf177cce5149440fc80309d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Fri, 21 Nov 2025 16:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E8=B4=B9=E8=B5=A0=E5=88=B8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MkDistributionUserServiceImpl.java | 3 ++ .../impl/MkShopConsumerCouponServiceImpl.java | 47 +++++++++++-------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java index a88b416ed..09a768e20 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionUserServiceImpl.java @@ -707,6 +707,9 @@ public class MkDistributionUserServiceImpl extends ServiceImpl implements MkShopConsumerCouponService { @@ -75,30 +77,35 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl= consumerCoupon.getGiftNum()) { - if (consumerCoupon.getGetLimit() == -10086 || consumerCoupon.getGetLimit() <= consumerCoupon.getGiveNum()) { + boolean canReceive = consumerCoupon.getGetLimit() == -10086; + // 限量发放,校验用户已经发放数量 + if (consumerCoupon.getGetLimit() != -10086) { long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getShopId, shopId) .eq(MkShopCouponRecord::getShopUserId, shopUserId) .eq(MkShopCouponRecord::getSourceId, consumerCoupon.getId())); - if (consumerCoupon.getGetLimit() >= count + giftCoupon.getNum()) { - MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO(); - giftDTO.setShopId(shopId); - giftDTO.setShopUserId(shopUserId); - giftDTO.setCouponId(giftCoupon.getCouponId()); - giftDTO.setSourceId(consumerCoupon.getId()); - giftDTO.setSourceFlowId(orderId); - giftDTO.setSource("消费赠券"); - //发放券 - recordService.receiveCoupon(giftDTO, giftCoupon.getNum(), false); - //更新优惠券信息 - consumerCoupon.setGiftNum(consumerCoupon.getGiftNum() + giftCoupon.getNum()); - if (consumerCoupon.getLeftNum() != -10086) { - consumerCoupon.setLeftNum(consumerCoupon.getLeftNum() - giftCoupon.getNum()); - } - updateById(new MkShopConsumerCoupon() - .setId(consumerCoupon.getId()) - .setLeftNum(consumerCoupon.getLeftNum()) - .setGiftNum(consumerCoupon.getGiftNum())); + log.info("用户: {}, 已经发放: {}, 限量: {}", shopUserId, count, consumerCoupon.getGetLimit()); + canReceive = consumerCoupon.getGetLimit() >= count + giftCoupon.getNum(); + } + + if (canReceive) { + MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO(); + giftDTO.setShopId(shopId); + giftDTO.setShopUserId(shopUserId); + giftDTO.setCouponId(giftCoupon.getCouponId()); + giftDTO.setSourceId(consumerCoupon.getId()); + giftDTO.setSourceFlowId(orderId); + giftDTO.setSource("消费赠券"); + //发放券 + recordService.receiveCoupon(giftDTO, giftCoupon.getNum(), false); + //更新优惠券信息 + consumerCoupon.setGiftNum(consumerCoupon.getGiftNum() + giftCoupon.getNum()); + if (consumerCoupon.getLeftNum() != -10086) { + consumerCoupon.setLeftNum(consumerCoupon.getLeftNum() - giftCoupon.getNum()); } + updateById(new MkShopConsumerCoupon() + .setId(consumerCoupon.getId()) + .setLeftNum(consumerCoupon.getLeftNum()) + .setGiftNum(consumerCoupon.getGiftNum())); } } }