mitao
2025-03-12 7a92c0228a9b282e4b3cb2ae4a0035cec34feb67
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/GoodsSkuServiceImpl.java
@@ -358,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);
@@ -406,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);
@@ -415,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);
@@ -429,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);
@@ -442,30 +442,32 @@
            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){
        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" );
        } else {
            wrapper3.last(",IF(isnull(sort_num),1,0), sort_num DESC,create_time DESC");
        }
        Page<GoodsSku> page1 = this.page(page, wrapper3);
        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())) {
            for (GoodsSku record : page1.getRecords()) {
                // 获取会员价格
                BigDecimal vipPrice = getVipPrice(record.getId(), member.getVipClassify());
                record.setPrice(vipPrice);
        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);
    }
@@ -473,6 +475,9 @@
    @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()));