| | |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; |
| | | import cc.mrbird.febs.common.enumerates.StarRatingEnum; |
| | | import cc.mrbird.febs.mall.conversion.MallGoodsConversion; |
| | | import cc.mrbird.febs.mall.dto.*; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | |
| | | private final MallGoodsStyleMapper mallGoodsStyleMapper; |
| | | private final MallGoodsImagesMapper mallGoodsImagesMapper; |
| | | private final MallShoppingCartMapper mallShoppingCartMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Override |
| | | public IPage<AdminMallGoodsVo> getCategoryListInPage(MallGoods mallGoods, QueryRequest request) { |
| | |
| | | //新增商品 |
| | | MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto); |
| | | mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED); |
| | | //根据商品现价获取商品星级 |
| | | 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(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); |
| | | // } |
| | | mallGoodsMapper.insert(mallGoods); |
| | | |
| | | String thumbs = addMallGoodsDto.getThumbs(); |
| | |
| | | } |
| | | |
| | | if (addMallGoodsDto.getGoodsType() == 2) { |
| | | return new FebsResponse().success().message("添加成功"); |
| | | } |
| | | |
| | | // 单规格 |
| | | if (addMallGoodsDto.getIsSku() == 2) { |
| | | MallGoodsStyle style = new MallGoodsStyle(); |
| | | style.setGoodsId(mallGoods.getId()); |
| | | style.setName(mallGoods.getGoodsName()); |
| | | mallGoodsStyleMapper.insert(style); |
| | | |
| | | MallGoodsSku sku = new MallGoodsSku(); |
| | | sku.setGoodsId(mallGoods.getId()); |
| | | sku.setSkuImage(mallGoods.getThumb()); |
| | | sku.setSkuName(mallGoods.getGoodsName()); |
| | | sku.setCostPrice(mallGoods.getCostPrice()); |
| | | sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice())); |
| | | sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice())); |
| | | sku.setSkuVolume(mallGoods.getVolume()); |
| | | sku.setStock(mallGoods.getStock()); |
| | | sku.setStyleId(style.getId()); |
| | | mallGoodsSkuMapper.insert(sku); |
| | | return new FebsResponse().success().message("添加成功"); |
| | | } |
| | | |
| | |
| | | return new FebsResponse().fail().message("商品规格原价不能小于0"); |
| | | } |
| | | BigDecimal presentPrice = addSku.getPresentPrice(); |
| | | if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) { |
| | | if (presentPrice.compareTo(BigDecimal.ZERO) < 0) { |
| | | return new FebsResponse().fail().message("商品规格现价不能小于0"); |
| | | } |
| | | |
| | |
| | | |
| | | //新增商品 |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(mallGoodsUpdateDto.getId()); |
| | | |
| | | // 若原来不为多规格或编辑后也不为多规格,则清空样式和规格 |
| | | if (mallGoods.getIsSku() == 2 || mallGoodsUpdateDto.getIsSku() == 2) { |
| | | mallGoodsSkuMapper.deleteByGoodsId(mallGoods.getId()); |
| | | mallGoodsStyleMapper.deleteByGoodsId(mallGoods.getId()); |
| | | } |
| | | |
| | | BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods); |
| | | // 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 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(2,BigDecimal.ROUND_DOWN); |
| | | BigDecimal subsidyAmount = subsidyPercent.multiply(new BigDecimal(presentPrice)).setScale(2, BigDecimal.ROUND_DOWN); |
| | | mallGoods.setSubsidyAmount(subsidyAmount); |
| | | |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | |
| | | mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId()); |
| | |
| | | if (mallGoodsUpdateDto.getGoodsType() == 2) { |
| | | return new FebsResponse().success().message("编辑成功"); |
| | | } |
| | | |
| | | // 单规格 |
| | | if (mallGoodsUpdateDto.getIsSku() == 2) { |
| | | MallGoodsStyle style = new MallGoodsStyle(); |
| | | style.setGoodsId(mallGoods.getId()); |
| | | style.setName(mallGoods.getGoodsName()); |
| | | mallGoodsStyleMapper.insert(style); |
| | | |
| | | MallGoodsSku sku = new MallGoodsSku(); |
| | | sku.setGoodsId(mallGoods.getId()); |
| | | sku.setSkuImage(mallGoods.getThumb()); |
| | | sku.setSkuName(mallGoods.getGoodsName()); |
| | | sku.setCostPrice(mallGoods.getCostPrice()); |
| | | sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice())); |
| | | sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice())); |
| | | sku.setSkuVolume(mallGoods.getVolume()); |
| | | sku.setStock(mallGoods.getStock()); |
| | | sku.setStyleId(style.getId()); |
| | | mallGoodsSkuMapper.insert(sku); |
| | | return new FebsResponse().success().message("添加成功"); |
| | | } |
| | | |
| | | |
| | | |
| | | // 删除已存在sku |
| | | List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId(); |
| | |
| | | return mallGoodsMapper.getAllGoodsTree(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse goodsHot(Long id) { |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(id); |
| | | if (ObjectUtil.isEmpty(mallGoods)) { |
| | | return new FebsResponse().fail().message("商品不存在,请刷新当前页面"); |
| | | } |
| | | mallGoods.setIsHot(MallGoods.ISHOT_STATE_YES); |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse goodsNotHot(Long id) { |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(id); |
| | | if (ObjectUtil.isEmpty(mallGoods)) { |
| | | return new FebsResponse().fail().message("商品不存在,请刷新当前页面"); |
| | | } |
| | | mallGoods.setIsHot(MallGoods.ISHOT_STATE_NO); |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |