From e90dc8cdf7d4ce7d08e1ab51fcde3c28fd2995a0 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 20 Dec 2022 16:30:35 +0800
Subject: [PATCH] 20221220 1、星级市场

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 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 ea09b5f..4465519 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
@@ -2,6 +2,8 @@
 
 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.*;
@@ -38,6 +40,7 @@
     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) {
@@ -109,7 +112,16 @@
         //新增商品
         MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto);
         mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED);
-
+        //根据商品原价获取商品星级
+        String originalPrice = mallGoods.getOriginalPrice();
+        String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice);
+        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);
+        mallGoods.setSubsidyAmount(subsidyAmount);
         if (mallGoods.getHasCarriage() == 2) {
             mallGoods.setCarriage(BigDecimal.ZERO);
         }
@@ -323,7 +335,7 @@
                         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");
                     }
 
@@ -344,6 +356,16 @@
         if (mallGoods.getHasCarriage() == 2) {
             mallGoods.setCarriage(BigDecimal.ZERO);
         }
+        //根据商品原价获取商品星级
+        String originalPrice = mallGoods.getOriginalPrice();
+        String starRating = StarRatingEnum.NORMAL.belongStarRating(originalPrice);
+        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);
+        mallGoods.setSubsidyAmount(subsidyAmount);
 
         mallGoodsMapper.updateById(mallGoods);
 
@@ -473,5 +495,27 @@
         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();
+    }
+
 
 }

--
Gitblit v1.9.1