From 4beed66d31755142dd69f0294fd8521f7797b66a Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 03 九月 2025 16:39:36 +0800
Subject: [PATCH] bug修改

---
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopServiceImpl.java |  185 ++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 160 insertions(+), 25 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..dfd9990 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;
 
 /**
@@ -74,6 +75,8 @@
     private GoodsShopMapper goodsShopMapper;
     @Resource
     private GoodsShopService goodsShopService;
+    @Resource
+    private GoodsEvaluateMapper goodsEvaluateMapper;
 
 
     /**
@@ -158,7 +161,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);
@@ -223,7 +227,9 @@
     public PageInfo<ShopBalanceStatementVO> getShopBalanceStatementList(Integer shopId, LocalDateTime startTime, LocalDateTime endTime, Integer type, Integer pageCurr, Integer pageSize) {
         PageInfo<ShopBalanceStatementVO> pageInfo = new PageInfo<>(pageCurr, pageSize);
         List<ShopBalanceStatementVO> ShopBalanceStatementList = shopBalanceStatementMapper.getShopBalanceStatementList(pageInfo, shopId, startTime, endTime, type);
+
         for (ShopBalanceStatementVO shopBalanceStatementVO : ShopBalanceStatementList) {
+            log.error(shopBalanceStatementVO.toString());
             BigDecimal historicalBalance = shopBalanceStatementVO.getHistoricalBalance();
             BigDecimal balance = shopBalanceStatementVO.getBalance();
             if (historicalBalance != null && balance != null) {
@@ -243,21 +249,32 @@
     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){
-                //秒杀活动
-                good.setSellingPrice(price.getCash());
-                good.setIntegral(price.getPoint());
-                good.setStartTime(price.getStartTime());
-                good.setEndTime(price.getEndTime());
-                good.setPurchaseLimit(price.getPurchaseLimit());
-            }
+//            Price price = getPrice( good.getGoodsId());
+//            if(null != price){
+//                //秒杀活动
+//                good.setSellingPrice(price.getCash());
+//                good.setIntegral(price.getPoint());
+//                good.setStartTime(price.getStartTime());
+//                good.setEndTime(price.getEndTime());
+//                good.setPurchaseLimit(price.getPurchaseLimit());
+//            }
+            Integer point = getPoint(good.getSellingPrice());
+            good.setIntegral(point);
             Integer data = orderClient.getGoodsSaleNum(good.getGoodsId(), 1).getData();
             good.setSaleNum(data);
         }
-        return goods;
+        return distinctGoods;
     }
 
     @Override
@@ -276,15 +293,22 @@
         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());
-            goodsVO.setEndTime(price.getEndTime());
-        }
+//        Price price = getPrice( goods.getId());
+//        if(null != price){
+//            //在秒杀活动时间段内
+//            goodsVO.setSellingPrice(price.getCash());
+//            goodsVO.setIntegral(price.getPoint());
+//            goodsVO.setStartTime(price.getStartTime());
+//            goodsVO.setEndTime(price.getEndTime());
+//        }
+        Integer point = getPoint(goodsVO.getSellingPrice());
+        goodsVO.setIntegral(point);
         //已售数量
         Integer data = orderClient.getGoodsSaleNum(goods.getId(), 1).getData();
         goodsVO.setSaleNum(data);
@@ -293,21 +317,47 @@
         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::getIsShelves,1)
+                .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());
+        }
+
+        //商品评价
+        GoodsEvaluate goodsEvaluateOne = goodsEvaluateMapper.getGoodsEvaluateOne(goods.getId());
+        if(goodsEvaluateOne != null){
+            AppUser appUserById = appUserClient.getAppUserById(goodsEvaluateOne.getAppUserId());
+            goodsEvaluateOne.setUserName(appUserById.getName());
+            goodsEvaluateOne.setAvatar(appUserById.getAvatar());
+            goodsVO.setGoodsEvaluate(goodsEvaluateOne);
+        }
         return goodsVO;
 
     }
+
 
     /**
      * 发布商品 门店后台-商品管理
      */
     @Override
-    public void addGoodsByShop(AddGoodsDTO addGoodsDTO) {
+    public Integer addGoodsByShop(AddGoodsDTO addGoodsDTO) {
         if(addGoodsDTO.getPurchaseLimit()==null){
             addGoodsDTO.setPurchaseLimit(-1);
         }
@@ -324,13 +374,16 @@
         goodsShop.setGoodsId(goods.getId());
         goodsShop.setShopId(addGoodsDTO.getShopId());
         Shop shop = shopMapper.selectById(addGoodsDTO.getShopId());
+        if(shop==null){
+            throw new ServiceException("门店不存在");
+        }
         goodsShop.setShopName(shop.getName());
         goodsShop.setOwnerName(shop.getShopManager());
         goodsShop.setPhone(shop.getPhone());
         goodsShop.setAddress(shop.getAddress());
         goodsShopService.save(goodsShop);
         //判断是否参加秒杀活动
-        if (addGoodsDTO.isActivity()){
+        if (addGoodsDTO.getIsActivity()==1){
             //秒杀活动
             SeckillActivityInfo seckillActivityInfo = new SeckillActivityInfo();
             seckillActivityInfo.setDelFlag(0);
@@ -348,6 +401,88 @@
             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();
+    }
+
+    @Override
+    public PageInfo<ShopBalanceListVO> getBalanceList(String name, Integer pageCurr, Integer pageSize) {
+        PageInfo<ShopBalanceListVO> pageInfo = new PageInfo<>(pageCurr, pageSize);
+
+        List<ShopBalanceListVO> list = shopMapper.getBalanceList(pageInfo,name);
+
+
+        pageInfo.setRecords(list);
+        return pageInfo;
     }
 
     /**

--
Gitblit v1.7.1