From 85193ef9fceaac85f57dc531f80fcfdc204bfc23 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期三, 02 四月 2025 18:22:44 +0800 Subject: [PATCH] 商城 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java | 100 ++++++++++++++++---------------------------------- 1 files changed, 32 insertions(+), 68 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java index 6ecba98..98b1cd2 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/GoodsServiceImpl.java @@ -87,10 +87,10 @@ List<NearbyShopVO> nearbyShopVOS = shopService.nearbyShopList(search.getLongitude(), search.getLatitude(), new Shop()); shopIds = nearbyShopVOS.subList(0, 10).stream().map(NearbyShopVO::getId).collect(Collectors.toList()); } - - List<GoodsVO> list = this.baseMapper.goodsList(search.getGoodsCategoryId(), search.getName(),shopIds);//查找所有商品 + //查找满足条件的商品 分类、名称、附近十家店 + List<GoodsVO> list = this.baseMapper.goodsList(search.getGoodsCategoryId(), search.getName(),shopIds); for (GoodsVO goods : list) { - System.out.println(goods.getSellingPrice()); + //计算所需价格和积分 Price price = getPrice( goods.getGoodsId(), 1); if(null != price){ @@ -100,13 +100,13 @@ goods.setStartTime(price.getStartTime()); goods.setEndTime(price.getEndTime()); } - //已售 + //已售数量 Integer data = orderClient.getGoodsSaleNum(goods.getGoodsId(), 1).getData(); goods.setSaleNum(data); } //手动排序 if(StringUtils.isNotEmpty(search.getOrderByColumn())){ - if("tgs.selling_price".equals(search.getOrderByColumn())){ + if("tgs.selling_price".equals(search.getOrderByColumn())){//价格排序 list.sort(new Comparator<GoodsVO>() { @Override public int compare(GoodsVO o1, GoodsVO o2) { @@ -123,7 +123,7 @@ } }); } - /*if("integral".equals(search.getOrderByColumn())){ + if("integral".equals(search.getOrderByColumn())){//积分排序 list.sort(new Comparator<GoodsVO>() { @Override public int compare(GoodsVO o1, GoodsVO o2) { @@ -139,8 +139,8 @@ return 0; } }); - }*/ - if("sale_num".equals(search.getOrderByColumn())){ + } + if("sale_num".equals(search.getOrderByColumn())){//销量 list.sort(new Comparator<GoodsVO>() { @Override public int compare(GoodsVO o1, GoodsVO o2) { @@ -179,23 +179,9 @@ } @Override - public GoodsVO goodsDetail(Long goodsId, Integer shopId, String longitude, String latitude) { - /*if (goodsId == null || goodsId <= 0) { + public GoodsVO goodsDetail(Long goodsId) { + if (goodsId == null || goodsId <= 0) { throw new NullPointerException("商品ID不能为空"); - } - - Integer vipId = 0; - String provinceCode = null; - String cityCode = null; - String districtCode = null; - String token = SecurityUtils.getToken(ServletUtils.getRequest()); - if(StringUtils.isNotEmpty(token)){ - Long userid = tokenService.getLoginUserApplet().getUserid(); - AppUser appUser = appUserClient.getAppUserById(userid); - vipId = appUser.getVipId(); - provinceCode = appUser.getProvinceCode(); - cityCode = appUser.getCityCode(); - districtCode = appUser.getDistrictCode(); } Goods goods = this.getById(goodsId); @@ -205,59 +191,37 @@ if(goods.getStatus() == 1){ throw new RuntimeException("商品已被下架"); } - if(!goods.getCommodityAuthority().contains("-1") && !goods.getCommodityAuthority().contains(vipId.toString())){ - throw new RuntimeException("权限不足"); - } + GoodsVO goodsVO = new GoodsVO(); BeanUtils.copyBeanProp(goodsVO, goods); goodsVO.setGoodsId(goods.getId()); goodsVO.setGoodsName(goods.getName()); - Price price = getPrice(vipId, goods.getId(), shopId, 1, provinceCode, cityCode, districtCode); + + //计算所需价格和积分 + Price price = getPrice( goods.getId(), 1); if(null != price){ - goodsVO.setPointPayment(price.getPointPayment() ? 1 : 0); - goodsVO.setCashPayment(price.getCashPayment() ? 1 : 0); + //秒杀活动 goodsVO.setSellingPrice(price.getCash()); goodsVO.setIntegral(price.getPoint()); + goodsVO.setStartTime(price.getStartTime()); + goodsVO.setEndTime(price.getEndTime()); } - - if(goods.getType() == 1){ - if(goods.getAppointStore() == 2){ - List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>() - .in(Shop::getDelFlag, 0)); - goodsVO.setShopList(shopList); - }else{ - List<GoodsShop> goodsShopList = goodsShopMapper.selectList(new LambdaQueryWrapper<GoodsShop>() - .eq(GoodsShop::getGoodsId, goodsId)); - if (!CollectionUtils.isEmpty(goodsShopList)){ - List<Integer> shopIds = goodsShopList.stream().map(GoodsShop::getShopId).collect(Collectors.toList()); - List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>() - .in(Shop::getId, shopIds)); - goodsVO.setShopList(shopList); - } - } - }else{ - List<Shop> shopList = shopMapper.selectList(new LambdaQueryWrapper<Shop>() - .in(Shop::getDelFlag, 0)); - goodsVO.setShopList(shopList); - } - if(StringUtils.isNotEmpty(longitude) && StringUtils.isNotEmpty(latitude)){ - List<Shop> shopList = goodsVO.getShopList(); - for (Shop shop : shopList) { - Double wgs84 = GeodesyUtil.getDistance(longitude + "," + latitude, shop.getLongitude() + "," + shop.getLatitude()).get("WGS84"); - shop.setDistance(wgs84); - } - shopList.sort(new Comparator<Shop>() { - @Override - public int compare(Shop o1, Shop o2) { - return o1.getDistance().compareTo(o2.getDistance()); - } - }); - goodsVO.setShopList(shopList); - } + //已售数量 + Integer data = orderClient.getGoodsSaleNum(goods.getId(), 1).getData(); + goodsVO.setSaleNum(data); + //一个商品对应一个门店 + //查找门店 + GoodsShop goodsShop = goodsShopMapper.selectOne(new LambdaQueryWrapper<GoodsShop>() + .eq(GoodsShop::getGoodsId, goodsId)); + Shop shop1 = shopMapper.selectById(goodsShop.getShopId()); + ArrayList<Shop> shops = new ArrayList<>(); + shops.add(shop1); + goodsVO.setShopList(shops); + //已售数量 Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 1).getData(); goodsVO.setSaleNum(integer); - return goodsVO;*/ - return null; + return goodsVO; + } @@ -371,7 +335,7 @@ * @return */ public Price getPrice( Integer goodsId, Integer type){ - //判断是否有秒杀活动 + //判断是否有在秒杀活动时间中 Price price = new Price(); SeckillActivityInfo one = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>().eq(SeckillActivityInfo::getGoodId, goodsId) .eq(SeckillActivityInfo::getIsShelves, 1).eq(SeckillActivityInfo::getDelFlag, 0) -- Gitblit v1.7.1