cloudroam
2024-09-20 a1416117c7478a66971cca278e9909811e0000d5
src/main/java/com/mzl/flower/service/flower/FlowerService.java
@@ -215,6 +215,7 @@
        } else {
            g.setPrice(dto.getPrice());
            g.setStock(dto.getStock());
            g.setLimited(dto.getLimited());
        }
        g.update(SecurityUtils.getUserId());
@@ -246,6 +247,17 @@
    public Long editFlowerAdmin(FlowerUpdateAdminDTO dto){
        Flower g = flowerMapper.selectById(dto.getId());
        g.setSales(dto.getSales());
        if (!org.springframework.util.StringUtils.isEmpty(dto.getLimited())) {
            if (g.getStock() == 0 || org.springframework.util.StringUtils.isEmpty(g.getStock())) {
                throw new ValidationException("库存为0或者空时不能修改限购数量");
            }
            if(g.getStock()<dto.getLimited()){
                throw new ValidationException("限购数量不能大于库存");
            }
            g.setLimited(dto.getLimited());
        }else{
            g.setLimited(null);
        }
        g.update(SecurityUtils.getUserId());
        flowerMapper.updateById(g);
@@ -875,5 +887,27 @@
        return flowerDeleteDO;
    }
    public void setFlowersLimited(FlowerLimitedDTO dto) {
        List<Long> ids = dto.getIds();
        if (ids == null || ids.size() == 0) {
            throw new ValidationException("请选择商品");
        }
        for (Long id : ids) {
            Flower f = flowerMapper.selectById(id);
            if (!org.springframework.util.StringUtils.isEmpty(dto.getLimited())) {
                if (f.getStock() == 0 || org.springframework.util.StringUtils.isEmpty(f.getStock())) {
                    throw new ValidationException("商品" + f.getName() + "库存为0或者空时不能修改限购数量");
                }
                if(f.getStock()<dto.getLimited()){
                    throw new ValidationException("商品" + f.getName() + "限购数量不能大于库存");
                }
                f.setLimited(dto.getLimited());
            }else{
                f.setLimited(null);
            }
            flowerMapper.updateById(f);
        }
    }
}