Cui Zhi Feng
2024-09-27 8479394c5ca736f8455a4e9247914fa237c6cff9
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,7 +247,17 @@
    public Long editFlowerAdmin(FlowerUpdateAdminDTO dto){
        Flower g = flowerMapper.selectById(dto.getId());
        g.setSales(dto.getSales());
        g.setLimited(dto.getLimited());
        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);
@@ -682,9 +693,10 @@
    public Page<FlowerShowListDTO> myCollect(Page page, FlowerShowQueryDTO dto) {
        dto.setUserId(SecurityUtils.getUserId());
        if (StringUtils.isNotEmpty(dto.getColumn())) {
            if(dto.getColumn().contains("sales")
                    || dto.getColumn().contains("stock")){
            if(dto.getColumn().contains("stock")){
                dto.setColumn(dto.getColumn() + " desc");
            } else if (dto.getColumn().contains("sales")) {
                dto.setColumn("ifnull(sales, 0) + ifnull(real_sales, 0) desc");
            }
        }
@@ -712,9 +724,9 @@
                s.setCollection(s.getCollectCount() > 0);
                s.setShopnum(s.getShopnum() == null ? 0 : s.getShopnum());
                if(s.getSales() != null && s.getRealSales() != null){
                /*if(s.getSales() != null && s.getRealSales() != null){
                    s.setSales(s.getSales() + s.getRealSales());
                }
                }*/
            }
        }
    }
@@ -883,7 +895,17 @@
        }
        for (Long id : ids) {
            Flower f = flowerMapper.selectById(id);
            f.setLimited(dto.getLimited());
            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);
        }
    }