huliguo
2025-04-21 17abf0608f62cdd318dba3e7b12a32ea486cb482
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;
/**
@@ -244,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){
@@ -258,7 +268,7 @@
            Integer data = orderClient.getGoodsSaleNum(good.getGoodsId(), 1).getData();
            good.setSaleNum(data);
        }
        return goods;
        return distinctGoods;
    }
    @Override
@@ -277,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());
@@ -294,15 +309,32 @@
        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;
    }
    /**
     * 发布商品 门店后台-商品管理
@@ -352,6 +384,87 @@
        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;
    }
    /**
     * 获取商品当前的价格,就是看当前商品是否在秒杀活动中
     */