From a9c9886210d41182bba50f440fac503b95b4d0d2 Mon Sep 17 00:00:00 2001 From: misworga831 Date: Mon, 10 Apr 2023 14:43:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E5=AF=B9=E4=BA=8E=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=9F=A5=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/GoodsSkuServiceImpl.java | 90 +++++++++++++------ .../cart/render/impl/CheckDataRender.java | 8 +- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index 878e3412..20962422 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -12,6 +12,7 @@ import cn.lili.common.enums.ResultCode; import cn.lili.common.event.TransactionCommitSendMQEvent; import cn.lili.common.exception.ServiceException; import cn.lili.common.properties.RocketmqCustomProperties; +import cn.lili.common.security.AuthUser; import cn.lili.common.security.context.UserContext; import cn.lili.common.utils.SnowFlake; import cn.lili.modules.goods.entity.dos.Goods; @@ -29,16 +30,22 @@ import cn.lili.modules.goods.entity.vos.GoodsSkuVO; import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.SpecValueVO; import cn.lili.modules.goods.mapper.GoodsSkuMapper; -import cn.lili.modules.goods.service.*; +import cn.lili.modules.goods.service.GoodsGalleryService; +import cn.lili.modules.goods.service.GoodsService; +import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.goods.service.WholesaleService; import cn.lili.modules.goods.sku.GoodsSkuBuilder; import cn.lili.modules.goods.sku.render.SalesModelRender; import cn.lili.modules.member.entity.dos.FootPrint; import cn.lili.modules.member.entity.dto.EvaluationQueryParams; import cn.lili.modules.member.entity.enums.EvaluationGradeEnum; import cn.lili.modules.member.service.MemberEvaluationService; +import cn.lili.modules.promotion.entity.dos.Coupon; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.dto.search.PromotionGoodsSearchParams; import cn.lili.modules.promotion.entity.enums.CouponGetEnum; +import cn.lili.modules.promotion.service.CouponService; +import cn.lili.modules.promotion.service.MemberCouponService; import cn.lili.modules.promotion.service.PromotionGoodsService; import cn.lili.modules.search.entity.dos.EsGoodsIndex; import cn.lili.modules.search.service.EsGoodsIndexService; @@ -80,7 +87,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i * 分类 */ @Autowired - private CategoryService categoryService; + private MemberCouponService memberCouponService; /** * 商品相册 */ @@ -121,6 +128,9 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Autowired private WholesaleService wholesaleService; + @Autowired + private CouponService couponService; + @Autowired private List salesModelRenders; @@ -166,7 +176,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //发送mq消息 String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.SKU_DELETE.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(oldSkuIds), RocketmqSendCallbackBuilder.commonCallback()); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(oldSkuIds), + RocketmqSendCallbackBuilder.commonCallback()); } else { skuList = new ArrayList<>(); for (Map map : goodsOperationDTO.getSkuList()) { @@ -183,7 +194,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i if (!skuList.isEmpty()) { LambdaQueryWrapper unnecessarySkuIdsQuery = new LambdaQueryWrapper<>(); unnecessarySkuIdsQuery.eq(GoodsSku::getGoodsId, goods.getId()); - unnecessarySkuIdsQuery.notIn(GoodsSku::getId, skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); + unnecessarySkuIdsQuery.notIn(GoodsSku::getId, + skuList.stream().map(BaseEntity::getId).collect(Collectors.toList())); this.remove(unnecessarySkuIdsQuery); this.saveOrUpdateBatch(skuList); this.updateStock(skuList); @@ -263,14 +275,16 @@ public class GoodsSkuServiceImpl extends ServiceImpl i if (goodsVO == null || goodsSku == null) { //发送mq消息 String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback()); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), + RocketmqSendCallbackBuilder.commonCallback()); throw new ServiceException(ResultCode.GOODS_NOT_EXIST); } //商品下架||商品未审核通过||商品删除,则提示:商品已下架 if (GoodsStatusEnum.DOWN.name().equals(goodsVO.getMarketEnable()) || !GoodsAuthEnum.PASS.name().equals(goodsVO.getAuthFlag()) || Boolean.TRUE.equals(goodsVO.getDeleteFlag())) { String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.GOODS_DELETE.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), RocketmqSendCallbackBuilder.commonCallback()); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(Collections.singletonList(goodsId)), + RocketmqSendCallbackBuilder.commonCallback()); throw new ServiceException(ResultCode.GOODS_NOT_EXIST); } @@ -284,15 +298,31 @@ public class GoodsSkuServiceImpl extends ServiceImpl i GoodsSkuVO goodsSkuDetail = this.getGoodsSkuVO(goodsSku); Map promotionMap = goodsIndex.getPromotionMap(); + AuthUser currentUser = UserContext.getCurrentUser(); //设置当前商品的促销价格 if (promotionMap != null && !promotionMap.isEmpty()) { promotionMap = promotionMap.entrySet().stream().parallel().filter(i -> { JSONObject jsonObject = JSONUtil.parseObj(i.getValue()); + if (i.getKey().contains(PromotionTypeEnum.COUPON.name()) && currentUser != null) { + Integer couponLimitNum = jsonObject.getInt("couponLimitNum"); + Coupon coupon = couponService.getById(jsonObject.getStr("id")); + if (coupon == null || (coupon.getPublishNum() != 0 && coupon.getReceivedNum() >= coupon.getPublishNum())) { + return false; + } + if (couponLimitNum > 0) { + Long count = memberCouponService.getMemberCouponNum(currentUser.getId(), jsonObject.getStr( + "id")); + if (count >= couponLimitNum) { + return false; + } + } + } // 过滤活动赠送优惠券和无效时间的活动 return (jsonObject.get("getType") == null || jsonObject.get("getType", String.class).equals(CouponGetEnum.FREE.name())) && (jsonObject.get("startTime") != null && jsonObject.get("startTime", Date.class).getTime() <= System.currentTimeMillis()) && (jsonObject.get("endTime") == null || jsonObject.get("endTime", Date.class).getTime() >= System.currentTimeMillis()); }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - Optional> containsPromotion = promotionMap.entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); + Optional> containsPromotion = + promotionMap.entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.SECKILL.name()) || i.getKey().contains(PromotionTypeEnum.PINTUAN.name())).findFirst(); if (containsPromotion.isPresent()) { JSONObject jsonObject = JSONUtil.parseObj(containsPromotion.get().getValue()); PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams(); @@ -312,8 +342,10 @@ public class GoodsSkuServiceImpl extends ServiceImpl i map.put("data", goodsSkuDetail); //获取分类 - map.put("wholesaleList", GoodsSalesModeEnum.WHOLESALE.name().equals(goodsVO.getSalesModel()) ? wholesaleService.findByGoodsId(goodsSkuDetail.getGoodsId()) : Collections.emptyList()); - map.put("categoryName", CharSequenceUtil.isNotEmpty(goodsIndex.getCategoryNamePath()) ? goodsIndex.getCategoryNamePath().split(",") : null); + map.put("wholesaleList", GoodsSalesModeEnum.WHOLESALE.name().equals(goodsVO.getSalesModel()) ? + wholesaleService.findByGoodsId(goodsSkuDetail.getGoodsId()) : Collections.emptyList()); + map.put("categoryName", CharSequenceUtil.isNotEmpty(goodsIndex.getCategoryNamePath()) ? + goodsIndex.getCategoryNamePath().split(",") : null); //获取规格信息 map.put("specs", this.groupBySkuAndSpec(goodsVO.getSkuList())); @@ -325,8 +357,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i } //记录用户足迹 - if (UserContext.getCurrentUser() != null) { - FootPrint footPrint = new FootPrint(UserContext.getCurrentUser().getId(), goodsIndex.getStoreId(), goodsId, skuId); + if (currentUser != null) { + FootPrint footPrint = new FootPrint(currentUser.getId(), goodsIndex.getStoreId(), goodsId, skuId); String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.VIEW_GOODS.name(); rocketMQTemplate.asyncSend(destination, footPrint, RocketmqSendCallbackBuilder.commonCallback()); } @@ -374,10 +406,13 @@ public class GoodsSkuServiceImpl extends ServiceImpl i boolean update = this.update(updateWrapper); if (Boolean.TRUE.equals(update)) { if (GoodsStatusEnum.UPPER.name().equals(marketEnable)) { - applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("生成店铺商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.GENERATOR_STORE_GOODS_INDEX.name(), storeId)); + applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("生成店铺商品", + rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.GENERATOR_STORE_GOODS_INDEX.name(), + storeId)); } else if (GoodsStatusEnum.DOWN.name().equals(marketEnable)) { cache.vagueDel(CachePrefix.GOODS_SKU.getPrefix()); - applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除店铺商品", rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.STORE_GOODS_DELETE.name(), storeId)); + applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("删除店铺商品", + rocketmqCustomProperties.getGoodsTopic(), GoodsTagsEnum.STORE_GOODS_DELETE.name(), storeId)); } } } @@ -443,9 +478,11 @@ public class GoodsSkuServiceImpl extends ServiceImpl i if ("images".equals(entry.getKey())) { specValueVO.setSpecName(entry.getKey()); if (entry.getValue().toString().contains("url")) { - List specImages = JSONUtil.toList(JSONUtil.parseArray(entry.getValue()), SpecValueVO.SpecImages.class); + List specImages = JSONUtil.toList(JSONUtil.parseArray(entry.getValue()), + SpecValueVO.SpecImages.class); specValueVO.setSpecImage(specImages); - goodsGalleryList = specImages.stream().map(SpecValueVO.SpecImages::getUrl).collect(Collectors.toList()); + goodsGalleryList = + specImages.stream().map(SpecValueVO.SpecImages::getUrl).collect(Collectors.toList()); } } else { specValueVO.setSpecName(entry.getKey()); @@ -496,7 +533,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i goodsIndexService.deleteIndexById(goodsSku.getId()); } goodsSku.setQuantity(quantity); - boolean update = this.update(new LambdaUpdateWrapper().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity)); + boolean update = + this.update(new LambdaUpdateWrapper().eq(GoodsSku::getId, skuId).set(GoodsSku::getQuantity, quantity)); if (update) { cache.remove(CachePrefix.GOODS.getPrefix() + goodsSku.getGoodsId()); } @@ -527,7 +565,8 @@ public class GoodsSkuServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = Exception.class) public void updateGoodsStuck(List goodsSkus) { - Map> groupByGoodsIds = goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId)); + Map> groupByGoodsIds = + goodsSkus.stream().collect(Collectors.groupingBy(GoodsSku::getGoodsId)); //获取相关的sku集合 LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.in(GoodsSku::getGoodsId, groupByGoodsIds.keySet()); @@ -572,9 +611,14 @@ public class GoodsSkuServiceImpl extends ServiceImpl i //修改规格索引,发送mq消息 - Map updateIndexFieldsMap = EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap()).put("id", goodsSku.getId()).build(), MapUtil.builder(new HashMap()).put("commentNum", goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build()); - String destination = rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); - rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), RocketmqSendCallbackBuilder.commonCallback()); + Map updateIndexFieldsMap = + EsIndexUtil.getUpdateIndexFieldsMap(MapUtil.builder(new HashMap()).put("id", + goodsSku.getId()).build(), MapUtil.builder(new HashMap()).put("commentNum", + goodsSku.getCommentNum()).put("highPraiseNum", highPraiseNum).put("grade", grade).build()); + String destination = + rocketmqCustomProperties.getGoodsTopic() + ":" + GoodsTagsEnum.UPDATE_GOODS_INDEX_FIELD.name(); + rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(updateIndexFieldsMap), + RocketmqSendCallbackBuilder.commonCallback()); //修改商品的评价数量 goodsService.updateGoodsCommentNum(goodsSku.getGoodsId()); @@ -608,11 +652,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl i public Long countSkuNum(String storeId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper - .eq(GoodsSku::getStoreId, storeId) - .eq(GoodsSku::getDeleteFlag, Boolean.FALSE) - .eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name()) - .eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name()); + queryWrapper.eq(GoodsSku::getStoreId, storeId).eq(GoodsSku::getDeleteFlag, Boolean.FALSE).eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name()).eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name()); return this.count(queryWrapper); } diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java index a39e99ae..e5cd8981 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CheckDataRender.java @@ -120,6 +120,9 @@ public class CheckDataRender implements CartRenderStep { if (checkGoodsStatus || checkGoodsValid) { + if (checkGoodsValid) { + cartSkuVO.rebuildBySku(dataSku); + } if (checkGoodsStatus) { //设置购物车未选中 cartSkuVO.setChecked(false); @@ -127,10 +130,9 @@ public class CheckDataRender implements CartRenderStep { cartSkuVO.setInvalid(true); //设置失效消息 cartSkuVO.setErrorMessage("商品已下架"); + continue; } - if (checkGoodsValid) { - cartSkuVO.rebuildBySku(dataSku); - } + } //商品库存判定