From 91ec2fe7b1087b18f40bba6ffda07ad601d562ed Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Thu, 22 Dec 2022 10:48:15 +0800 Subject: [PATCH] 20221222 --- src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java | 57 ++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java index 4465519..fde6ad8 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java @@ -112,19 +112,26 @@ //新增商品 MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto); mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED); - //根据商品原价获取商品星级 - String originalPrice = mallGoods.getOriginalPrice(); - String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice); + //根据商品现价获取商品星级 + String presentPrice = mallGoods.getPresentPrice(); + + Integer minValue = StarRatingEnum.NORMAL.getMinValue(); + Integer maxValue = StarRatingEnum.NORMAL.getMaxValue(); + if(new BigDecimal(presentPrice).compareTo(new BigDecimal(minValue)) < 0 + || new BigDecimal(presentPrice).compareTo(new BigDecimal(maxValue)) > 0){ + return new FebsResponse().fail().message("商品现价不能小于"+ minValue + "不能大于" + maxValue); + } + String starRating = StarRatingEnum.NORMAL.belongStarRating(presentPrice); mallGoods.setStarRating(starRating); - //根据商品原价获取商品补贴金额 + //根据商品现价获取商品补贴金额 DataDictionaryCustom subsidyPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SUBSIDY_PERCENT.getType() , DataDictionaryEnum.SUBSIDY_PERCENT.getCode()); - BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(BigDecimal.ROUND_DOWN,2); - BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(originalPrice)).setScale(BigDecimal.ROUND_DOWN, 2); + BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(presentPrice)).setScale(2, BigDecimal.ROUND_DOWN); mallGoods.setSubsidyAmount(subsidyAmount); - if (mallGoods.getHasCarriage() == 2) { - mallGoods.setCarriage(BigDecimal.ZERO); - } +// if (mallGoods.getHasCarriage() == 2) { +// mallGoods.setCarriage(BigDecimal.ZERO); +// } mallGoodsMapper.insert(mallGoods); String thumbs = addMallGoodsDto.getThumbs(); @@ -353,18 +360,26 @@ } BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods); - if (mallGoods.getHasCarriage() == 2) { - mallGoods.setCarriage(BigDecimal.ZERO); +// if (mallGoods.getHasCarriage() == 2) { +// mallGoods.setCarriage(BigDecimal.ZERO); +// } + + //根据商品现价获取商品星级 + String presentPrice = mallGoods.getPresentPrice(); + + Integer minValue = StarRatingEnum.NORMAL.getMinValue(); + Integer maxValue = StarRatingEnum.NORMAL.getMaxValue(); + if(new BigDecimal(presentPrice).compareTo(new BigDecimal(minValue)) < 0 + || new BigDecimal(presentPrice).compareTo(new BigDecimal(maxValue)) > 0){ + return new FebsResponse().fail().message("商品现价不能小于"+ minValue + "不能大于" + maxValue); } - //根据商品原价获取商品星级 - String originalPrice = mallGoods.getOriginalPrice(); - String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice); + String starRating = StarRatingEnum.NORMAL.belongStarRating(presentPrice); mallGoods.setStarRating(starRating); - //根据商品原价获取商品补贴金额 + //根据商品现价获取商品补贴金额 DataDictionaryCustom subsidyPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SUBSIDY_PERCENT.getType() , DataDictionaryEnum.SUBSIDY_PERCENT.getCode()); - BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(BigDecimal.ROUND_DOWN,2); - BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(originalPrice)).setScale(BigDecimal.ROUND_DOWN, 2); + BigDecimal subsidyPercent = new BigDecimal(subsidyPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(presentPrice)).setScale(2, BigDecimal.ROUND_DOWN); mallGoods.setSubsidyAmount(subsidyAmount); mallGoodsMapper.updateById(mallGoods); @@ -517,5 +532,13 @@ return new FebsResponse().success(); } + public static void main(String[] args) { + + //根据商品原价获取商品补贴金额 + BigDecimal subsidyPercent = new BigDecimal("5").multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal("1")).setScale(2,BigDecimal.ROUND_DOWN); + System.out.println(subsidyAmount); + } + } -- Gitblit v1.9.1