From 19df67e19f23cd2a04d1c7f355e1e656f4140af4 Mon Sep 17 00:00:00 2001
From: huliguo <2023611923@qq.com>
Date: 星期四, 17 四月 2025 20:04:14 +0800
Subject: [PATCH] 后台:首页统计、系统管理、广告管理、用户管理、商品分类管理

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java |  122 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java
index 82704d2..ac388e0 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java
@@ -32,6 +32,7 @@
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -158,7 +159,8 @@
         }
 
         // 计算距离
-        if (shopDetailVO.getLongitude() != null && shopDetailVO.getLatitude() != null){
+        if (shopDetailVO.getLongitude() != null && shopDetailVO.getLatitude() != null
+            && longitude != null && latitude != null) {
             String shopLocation = String.format("%s,%s", shopDetailVO.getLongitude(), shopDetailVO.getLatitude());
             String userLocation = String.format("%s,%s", longitude.toString(), latitude.toString());
             Map<String, Double> distanceMap = GeodesyUtil.getDistance(userLocation, shopLocation);
@@ -243,7 +245,16 @@
     public List<GoodsVO> getGoodsListByShopId(PageInfo<GoodsVO> pageInfo, Integer shopId) {
         //查询该门店商品
         List<GoodsVO> goods = shopMapper.selectListByShopId(pageInfo, shopId);
-        for (GoodsVO good : goods) {
+        if(null == goods){
+            return null;
+        }
+        // 根据id去重
+        List<GoodsVO> distinctGoods = goods.stream()
+                .collect(Collectors.collectingAndThen(
+                        Collectors.toMap(GoodsVO::getGoodsId, Function.identity(), (existing, replacement) -> existing),
+                        map -> new ArrayList<>(map.values())
+                ));
+        for (GoodsVO good : distinctGoods) {
             //价格
             Price price = getPrice( good.getGoodsId());
             if(null != price){
@@ -257,7 +268,7 @@
             Integer data = orderClient.getGoodsSaleNum(good.getGoodsId(), 1).getData();
             good.setSaleNum(data);
         }
-        return goods;
+        return distinctGoods;
     }
 
     @Override
@@ -276,10 +287,15 @@
         goodsVO.setGoodsId(goods.getId());
         goodsVO.setGoodsName(goods.getName());
 
+        //商品活动前售价(编辑商品回显)
+        goodsVO.setEditPrice(goods.getSellingPrice());
+        //限购数量(编辑商品回显)
+        goodsVO.setEditNum(goods.getPurchaseLimit());
+
         //计算所需价格和积分
         Price price = getPrice( goods.getId());
         if(null != price){
-            //秒杀活动
+            //在秒杀活动时间段内
             goodsVO.setSellingPrice(price.getCash());
             goodsVO.setIntegral(price.getPoint());
             goodsVO.setStartTime(price.getStartTime());
@@ -293,21 +309,38 @@
         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);
+        goodsVO.setShop(shop1);
         //已售数量
         Integer integer = orderClient.getGoodsSaleNum(goods.getId(), 1).getData();
         goodsVO.setSaleNum(integer);
+        //分类id
+        goodsVO.setGoodsCategoryId(goods.getGoodsCategoryId());
+
+        //一个商品只有一个秒杀活动
+        SeckillActivityInfo seckillActivityInfo = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>()
+                .eq(SeckillActivityInfo::getGoodId, goodsId)
+                .eq(SeckillActivityInfo::getDelFlag, 0));
+        //商品是否开启秒杀活动
+        goodsVO.setIsSkillActivity(0);
+        if (seckillActivityInfo != null) {
+            goodsVO.setIsSkillActivity(1);
+            //活动限购数量
+            goodsVO.setEditActivityNum(seckillActivityInfo.getMaxNum());
+            GoodsSeckill one = goodsSeckillService.getOne(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, seckillActivityInfo.getId()));
+            //有秒杀活动,查看秒杀价格
+            goodsVO.setEditActivityPrice(one.getSellingPrice());
+        }
+
         return goodsVO;
 
     }
+
 
     /**
      * 发布商品 门店后台-商品管理
      */
     @Override
-    public void addGoodsByShop(AddGoodsDTO addGoodsDTO) {
+    public Integer addGoodsByShop(AddGoodsDTO addGoodsDTO) {
         if(addGoodsDTO.getPurchaseLimit()==null){
             addGoodsDTO.setPurchaseLimit(-1);
         }
@@ -330,7 +363,7 @@
         goodsShop.setAddress(shop.getAddress());
         goodsShopService.save(goodsShop);
         //判断是否参加秒杀活动
-        if (addGoodsDTO.isActivity()){
+        if (addGoodsDTO.getIsActivity()==1){
             //秒杀活动
             SeckillActivityInfo seckillActivityInfo = new SeckillActivityInfo();
             seckillActivityInfo.setDelFlag(0);
@@ -348,6 +381,77 @@
             goodsSeckill.setSeckillActivityInfoId(seckillActivityInfo.getId());
             goodsSeckillService.save(goodsSeckill);
         }
+        return goods.getId();
+    }
+
+
+    /**
+     * 编辑商品
+     * @param addGoodsDTO
+     * @return
+     */
+
+    @Override
+    public Integer editGoodsByShop(AddGoodsDTO addGoodsDTO) {
+        if(addGoodsDTO.getPurchaseLimit()==null){
+            addGoodsDTO.setPurchaseLimit(-1);
+        }
+        //先修改商品
+        Goods goods = new Goods();
+        BeanUtils.copyProperties(addGoodsDTO, goods);
+        goods.setStatus(GoodsStatus.DOWN.getCode());//下架状态
+        goods.setId(addGoodsDTO.getGoodId());
+        goods.setIntegral(getPoint(addGoodsDTO.getSellingPrice()));//积分
+        goods.setDelFlag(0);
+        goods.setCreateTime(LocalDateTime.now());
+        goodsService.updateById(goods);//添加商品
+
+
+        //门店关系不变
+
+        //判断是否参加秒杀活动
+        if (addGoodsDTO.getIsActivity()==1){//参加
+            //一个商品只有一个秒杀活动
+            SeckillActivityInfo seckillActivityInfo = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>()
+                    .eq(SeckillActivityInfo::getGoodId, addGoodsDTO.getGoodId())
+                    .eq(SeckillActivityInfo::getDelFlag, 0));
+            if (seckillActivityInfo != null) {
+                //删除原本活动
+                goodsSeckillService.remove(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, seckillActivityInfo.getId()));
+                //删除主表
+                seckillActivityInfoService.removeById(seckillActivityInfo.getId());
+            }
+            //新增
+            //秒杀活动
+            SeckillActivityInfo seckillActivityInfo1 = new SeckillActivityInfo();
+            seckillActivityInfo1.setDelFlag(0);
+            seckillActivityInfo1.setCreateTime(LocalDateTime.now());
+            seckillActivityInfo1.setGoodId(goods.getId());
+            seckillActivityInfo1.setMaxNum(addGoodsDTO.getMaxNum());
+            seckillActivityInfo1.setStartTime(addGoodsDTO.getStartTime());
+            seckillActivityInfo1.setEndTime(addGoodsDTO.getEndTime());
+            seckillActivityInfo1.setIsShelves(1);//默认上架
+            seckillActivityInfoService.save(seckillActivityInfo1);
+            //秒杀活动价格
+            GoodsSeckill goodsSeckill = new GoodsSeckill();
+            goodsSeckill.setSellingPrice(addGoodsDTO.getActivityPrice());
+            goodsSeckill.setIntegral(getPoint(addGoodsDTO.getActivityPrice()));
+            goodsSeckill.setSeckillActivityInfoId(seckillActivityInfo1.getId());
+            goodsSeckillService.save(goodsSeckill);
+        }else{
+            //不参加秒杀活动,删除之前的活动
+            //一个商品只有一个秒杀活动
+            SeckillActivityInfo seckillActivityInfo = seckillActivityInfoService.getOne(new LambdaQueryWrapper<SeckillActivityInfo>()
+                    .eq(SeckillActivityInfo::getGoodId, addGoodsDTO.getGoodId())
+                    .eq(SeckillActivityInfo::getDelFlag, 0));
+            if (seckillActivityInfo != null) {
+                //删除原本活动
+                goodsSeckillService.remove(new LambdaQueryWrapper<GoodsSeckill>().eq(GoodsSeckill::getSeckillActivityInfoId, seckillActivityInfo.getId()));
+                //删除主表
+                seckillActivityInfoService.removeById(seckillActivityInfo.getId());
+            }
+        }
+        return goods.getId();
     }
 
     /**

--
Gitblit v1.7.1