From 392b42c4891cf2e6beda57ab32c51598f290f4b7 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 14 三月 2025 20:56:27 +0800 Subject: [PATCH] bug修改 --- ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java | 143 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 100 insertions(+), 43 deletions(-) diff --git a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java index fa5106a..0f5d0c5 100644 --- a/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java +++ b/ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java @@ -10,6 +10,7 @@ import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.enums.AuctionOrderTypeEnum; import com.ruoyi.common.core.enums.ListingStatusEnum; +import com.ruoyi.common.core.enums.MemberVipClassifyEnum; import com.ruoyi.common.core.enums.OrderFromEnum; import com.ruoyi.common.core.enums.StartStatusEnum; import com.ruoyi.common.core.exception.ServiceException; @@ -18,6 +19,8 @@ import com.ruoyi.common.core.utils.page.Checker; import com.ruoyi.common.core.utils.page.CollUtils; import com.ruoyi.common.core.utils.page.PageDTO; +import com.ruoyi.common.security.service.TokenService; +import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.goods.controller.management.dto.GoodsInfoTitleValueDTO; import com.ruoyi.goods.controller.management.dto.GoodsSkuDTO; import com.ruoyi.goods.controller.management.dto.GoodsSkuQuery; @@ -25,6 +28,7 @@ import com.ruoyi.goods.domain.GoodsBrowseRecord; import com.ruoyi.goods.domain.GoodsInfoTitleValue; import com.ruoyi.goods.domain.MemberGoodsCollection; +import com.ruoyi.goods.mapper.GoodsGroupPurchaseInfoMapper; import com.ruoyi.goods.mapper.GoodsGroupPurchaseMapper; import com.ruoyi.goods.mapper.GoodsSeckillMapper; import com.ruoyi.goods.mapper.GoodsSkuMapper; @@ -42,6 +46,7 @@ import com.ruoyi.system.api.domain.GoodsSeckill; import com.ruoyi.system.api.domain.GoodsSeries; import com.ruoyi.system.api.domain.GoodsSku; +import com.ruoyi.system.api.domain.Member; import com.ruoyi.system.api.domain.Order; import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO; import com.ruoyi.system.api.domain.dto.HomeGoodsSkuDTO; @@ -52,7 +57,10 @@ import com.ruoyi.system.api.domain.vo.getHomeGoodsSkuXxiVO; import com.ruoyi.system.api.feignClient.AuctionClient; import com.ruoyi.system.api.feignClient.GoodsSkuClient; +import com.ruoyi.system.api.feignClient.MemberClient; import com.ruoyi.system.api.feignClient.OrderClient; +import com.ruoyi.system.api.model.LoginUser; +import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -68,6 +76,7 @@ import lombok.extern.slf4j.Slf4j; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -90,6 +99,7 @@ private final GoodsGroupPurchaseMapper goodsGroupPurchaseMapper; private final RedissonClient redissonClient; private final AuctionClient auctionClient; + private final GoodsGroupPurchaseInfoMapper goodsGroupPurchaseInfoMapper; @Resource private IGoodsBrowseRecordService iGoodsBrowseRecordService; @@ -103,8 +113,13 @@ @Resource private IMemberGoodsCollectionService iMemberGoodsCollectionService; + @Resource + private MemberClient memberClient; + private static final ObjectMapper objectMapper = new ObjectMapper(); + @Autowired + private TokenService tokenService; /** * 保存商品SKU信息。 @@ -343,47 +358,47 @@ page.setSize(homeGoodsSkuDTO.getPageSize()); page.setCurrent(homeGoodsSkuDTO.getPageCurr()); - LambdaQueryWrapper<GoodsSku> wrapper3= Wrappers.lambdaQuery(); - wrapper3.eq(GoodsSku::getListingStatus,0); + LambdaQueryWrapper<GoodsSku> wrapper3 = Wrappers.lambdaQuery(); + wrapper3.eq(GoodsSku::getListingStatus, 0); // if(homeGoodsSkuDTO.getId()!=null){ // List arr=new ArrayList<>(); // arr.add(homeGoodsSkuDTO.getId()); // wrapper3.notIn(GoodsSku::getId,arr); // } - if (homeGoodsSkuDTO.getSkuName()!=null&&homeGoodsSkuDTO.getSkuName()!=""){ - wrapper3.like(GoodsSku::getSkuName,homeGoodsSkuDTO.getSkuName()); + if (homeGoodsSkuDTO.getSkuName() != null && homeGoodsSkuDTO.getSkuName() != "") { + wrapper3.like(GoodsSku::getSkuName, homeGoodsSkuDTO.getSkuName()); } - if (homeGoodsSkuDTO.getGoodsSkuId()!=null){ - List<Long> id=new ArrayList<>(); + if (homeGoodsSkuDTO.getGoodsSkuId() != null) { + List<Long> id = new ArrayList<>(); id.add(homeGoodsSkuDTO.getGoodsSkuId()); - wrapper3.notIn(GoodsSku::getId,id); + wrapper3.notIn(GoodsSku::getId, id); } - if (homeGoodsSkuDTO.getBrandId()!=null){ - wrapper3.eq(GoodsSku::getBrandId,homeGoodsSkuDTO.getBrandId()); + if (homeGoodsSkuDTO.getBrandId() != null) { + wrapper3.eq(GoodsSku::getBrandId, homeGoodsSkuDTO.getBrandId()); } - if (homeGoodsSkuDTO.getCategoryId()!=null){ - wrapper3.eq(GoodsSku::getCategoryId,homeGoodsSkuDTO.getCategoryId()); + if (homeGoodsSkuDTO.getCategoryId() != null) { + wrapper3.eq(GoodsSku::getCategoryId, homeGoodsSkuDTO.getCategoryId()); } - if (homeGoodsSkuDTO.getSeriesId()!=null){ - wrapper3.eq(GoodsSku::getSeriesId,homeGoodsSkuDTO.getSeriesId()); + if (homeGoodsSkuDTO.getSeriesId() != null) { + wrapper3.eq(GoodsSku::getSeriesId, homeGoodsSkuDTO.getSeriesId()); } - if (homeGoodsSkuDTO.getFlavorTypeId()!=null){ - wrapper3.eq(GoodsSku::getFlavorTypeId,homeGoodsSkuDTO.getFlavorTypeId()); + if (homeGoodsSkuDTO.getFlavorTypeId() != null) { + wrapper3.eq(GoodsSku::getFlavorTypeId, homeGoodsSkuDTO.getFlavorTypeId()); } - if (homeGoodsSkuDTO.getSort()==2){ + if (homeGoodsSkuDTO.getSort() == 2) { wrapper3.orderByAsc(GoodsSku::getPrice); } - if (homeGoodsSkuDTO.getSort()==3){ + if (homeGoodsSkuDTO.getSort() == 3) { wrapper3.orderByDesc(GoodsSku::getPrice); } - if (homeGoodsSkuDTO.getSort()==4){ + if (homeGoodsSkuDTO.getSort() == 4) { wrapper3.orderByAsc(GoodsSku::getSoldQuantity); } - if (homeGoodsSkuDTO.getSort()==5){ + if (homeGoodsSkuDTO.getSort() == 5) { wrapper3.orderByDesc(GoodsSku::getSoldQuantity); } - if(homeGoodsSkuDTO.getYear()==2){ + if (homeGoodsSkuDTO.getYear() == 2) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime newTime7 = now.minusYears(30); @@ -391,7 +406,7 @@ LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay(); wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy")); } - if(homeGoodsSkuDTO.getYear()==3){ + if (homeGoodsSkuDTO.getYear() == 3) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime newTime7 = now.minusYears(30); @@ -400,12 +415,12 @@ LocalDateTime newTime15 = now.minusYears(15); String formattedDate15 = newTime15.format(formatter); - LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay(); + LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay(); wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy")) .gt(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy")); } - if(homeGoodsSkuDTO.getYear()==4){ + if (homeGoodsSkuDTO.getYear() == 4) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime newTime7 = now.minusYears(5); @@ -414,12 +429,12 @@ LocalDateTime newTime15 = now.minusYears(15); String formattedDate15 = newTime15.format(formatter); - LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay(); + LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay(); wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy")) .gt(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy")); } - if(homeGoodsSkuDTO.getYear()==5){ + if (homeGoodsSkuDTO.getYear() == 5) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime newTime7 = now.minusYears(1); @@ -427,26 +442,42 @@ LocalDateTime parseTime7 = LocalDate.parse(formattedDate7).atStartOfDay(); LocalDateTime newTime15 = now.minusYears(5); String formattedDate15 = newTime15.format(formatter); - LocalDateTime parseTime15= LocalDate.parse(formattedDate15).atStartOfDay(); + LocalDateTime parseTime15 = LocalDate.parse(formattedDate15).atStartOfDay(); wrapper3.le(GoodsSku::getYears, DateUtil.format(parseTime7, "yyyy")) .ge(GoodsSku::getYears, DateUtil.format(parseTime15, "yyyy")); } - if (homeGoodsSkuDTO.getSort()==1){ - wrapper3.last(" ORDER BY IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC"); - }else{ - wrapper3.last(",IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC" ); + if (homeGoodsSkuDTO.getSort() == 1) { + wrapper3.last(" ORDER BY IF(isnull(sort_num),1,0), sort_num ASC,create_time DESC"); + } else { + wrapper3.last(",IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC"); } - Page<GoodsSku> page1 = this.page(page, wrapper3); - PageDTO<HomeGoodsSkuListVO> articleCommentsVOPageDTO = PageDTO.of(page1, HomeGoodsSkuListVO.class); - return articleCommentsVOPageDTO; + + if (SecurityUtils.isLogin()) { + LoginUser loginUser = SecurityUtils.getLoginUser(); + Member member = memberClient.getMemberByUserId(loginUser.getUserid(), + SecurityConstants.INNER).getData(); + // 用户已登录 有会员等级 会员等级不为普通用户 则获取会员价格 + if (Objects.nonNull(member.getVipClassify()) + && !member.getVipClassify().equals(MemberVipClassifyEnum.NORMAL.getCode())) { + for (GoodsSku record : page1.getRecords()) { + // 获取会员价格 + BigDecimal vipPrice = getVipPrice(record.getId(), member.getVipClassify()); + record.setPrice(vipPrice); + } + } + } + return PageDTO.of(page1, HomeGoodsSkuListVO.class); } @Override public HomeGoodsSkuInfoVO getHomeGoodsSkuInfo(HomeGoodsSkuDTO homeGoodsSkuDTO) { GoodsSku byId = this.getById(homeGoodsSkuDTO.getGoodsSkuId()); + if (Objects.isNull(byId)) { + throw new ServiceException("当前商品已下架"); + } HomeGoodsSkuInfoVO homeGoodsSkuInfoVO=new HomeGoodsSkuInfoVO(); homeGoodsSkuInfoVO.setSkuName(byId.getSkuName()); homeGoodsSkuInfoVO.setYears(String.valueOf(byId.getYears().getYear())); @@ -466,7 +497,6 @@ if (data3!=null) { homeGoodsSkuInfoVO.setFlavorType(data3.getFlavorTypeName()); } - homeGoodsSkuInfoVO.setPrice(byId.getPrice()); homeGoodsSkuInfoVO.setSoldQuantity(byId.getSoldQuantity()); homeGoodsSkuInfoVO.setUnit(byId.getUnit()); homeGoodsSkuInfoVO.setSpec(byId.getSpec()); @@ -476,9 +506,17 @@ homeGoodsSkuInfoVO.setDescription(byId.getDescription()); homeGoodsSkuInfoVO.setStock(byId.getStock()); homeGoodsSkuInfoVO.setDetail(byId.getDetail()); - homeGoodsSkuInfoVO.setShareTitle(byId.getShareTitle()); - homeGoodsSkuInfoVO.setSharePic(byId.getSharePic()); - + homeGoodsSkuInfoVO.setPrice(byId.getPrice()); + if (StringUtils.isBlank(byId.getShareTitle())) { + homeGoodsSkuInfoVO.setShareTitle(byId.getSkuName()); + } else { + homeGoodsSkuInfoVO.setShareTitle(byId.getShareTitle()); + } + if (StringUtils.isBlank(byId.getSharePic())) { + homeGoodsSkuInfoVO.setSharePic(byId.getCoverPic()); + } else { + homeGoodsSkuInfoVO.setSharePic(byId.getSharePic()); + } LambdaQueryWrapper<GoodsGroupPurchase> queryWrapper1 =new LambdaQueryWrapper<>(); queryWrapper1.eq(GoodsGroupPurchase::getListingStatus, ListingStatusEnum.ON_SHELVES) @@ -503,7 +541,17 @@ "=============================没有查询到团购信息============================="); homeGoodsSkuInfoVO.setIsGoodsGroupPurchase(1); } - + // 获取会员价格 + LoginUser loginUser = SecurityUtils.getLoginUser(); + Member member = memberClient.getMemberByUserId(loginUser.getUserid(), + SecurityConstants.INNER).getData(); + // 用户已登录 有会员等级 会员等级不为普通用户 则获取会员价格 + if (SecurityUtils.isLogin() && Objects.nonNull(member.getVipClassify()) + && !member.getVipClassify().equals(MemberVipClassifyEnum.NORMAL.getCode())) { + // 获取会员价格 + BigDecimal vipPrice = getVipPrice(byId.getId(), member.getVipClassify()); + homeGoodsSkuInfoVO.setPrice(vipPrice); + } LambdaQueryWrapper<MemberGoodsCollection> wrapper3= Wrappers.lambdaQuery(); wrapper3.eq(MemberGoodsCollection::getDelFlag,0); @@ -516,13 +564,11 @@ }else{ homeGoodsSkuInfoVO.setIsCollection(1); } - List list1=new ArrayList<>(); - list1.add(0); - list1.add(1); LambdaQueryWrapper<GoodsGroupPurchase> queryWrapper2 =new LambdaQueryWrapper<>(); queryWrapper2.eq(GoodsGroupPurchase::getListingStatus, ListingStatusEnum.ON_SHELVES) - .eq(GoodsGroupPurchase::getGoodsSkuId, byId.getId()).in(GoodsGroupPurchase::getStartStatus, list1); + .eq(GoodsGroupPurchase::getGoodsSkuId, byId.getId()) + .eq(GoodsGroupPurchase::getStartStatus, StartStatusEnum.STARTED); GoodsGroupPurchase goodsGroupPurchase2 = goodsGroupPurchaseMapper.selectOne(queryWrapper2); if (goodsGroupPurchase2!=null){ homeGoodsSkuInfoVO.setGroupPurchaseGoods(2); @@ -539,7 +585,7 @@ wrapper4.ge(GoodsBrowseRecord::getCreateTime, newTime7) .le(GoodsBrowseRecord::getCreateTime,now ); List<GoodsBrowseRecord> list2 = iGoodsBrowseRecordService.list(wrapper4); - if (list2.size()==0){ + if (list2.isEmpty()){ GoodsBrowseRecord auctionBrowseRecord=new GoodsBrowseRecord(); auctionBrowseRecord.setMemberId(homeGoodsSkuDTO.getMemberId()); auctionBrowseRecord.setGoodsSkuId(homeGoodsSkuDTO.getGoodsSkuId()); @@ -550,6 +596,17 @@ return homeGoodsSkuInfoVO; } + private BigDecimal getVipPrice(Long goodsSkuId, Integer vipClassify) { + GoodsSku byId = getById(goodsSkuId); + BigDecimal price = BigDecimal.ZERO; + if (MemberVipClassifyEnum.VIP.getCode().equals(vipClassify)) { + price = byId.getVipPrice(); + } else if (MemberVipClassifyEnum.SUPER_VIP.getCode().equals(vipClassify)) { + price = byId.getSuperVipPrice(); + } + return price; + } + @Override public List<getHomeGoodsSkuXxiVO> getHomeGoodsSkuXxi(HomeGoodsSkuDTO homeGoodsSkuDTO) { List<getHomeGoodsSkuXxiVO> homeGoodsSkuXxiVOS=new ArrayList<>(); -- Gitblit v1.7.1