Преглед изворни кода

下架店铺不在后台设置规格浮动区间

zoujiajian пре 2 година
родитељ
комит
3e4e3c1a6c

+ 4 - 4
netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopGoodsSkuMapper.java

@@ -20,12 +20,12 @@ public interface YhShopGoodsSkuMapper extends BaseMapper<YhShopGoodsSku> {
 			" inner join goods_don_sku sku on sku.id = ygs.sku_id")
 	GoodsDonSku selectGoodsDonSkuBySkuIdAndYhsId(@Param("yhsId") Long yhsId, @Param("skuId") Long skuId);
 
-	@Update("update yh_shop_goods_sku set status = 0 where sku_id = #{skuId} and price < #{minPrice}")
-	Integer setBelowPriceShopSkuDown(@Param("skuId") Long skuId, @Param("minPrice") BigDecimal minPrice);
+	@Update("update yh_shop_goods_sku set status = 0 where sku_id = #{skuId} and price not between #{minPrice} and #{maxPrice}")
+	Integer setBelowPriceShopSkuDown(@Param("skuId") Long skuId, @Param("minPrice") BigDecimal minPrice, @Param("maxPrice") BigDecimal maxPrice);
 
 	@Select("select sku_id,price from yh_shop_goods_sku where yhs_id = #{yhsId} and goods_id = #{goodsId} and deleted is true and status is true order by price limit 1")
 	YhShopGoodsSku selectMinPriceSkuByYhsId(@Param("yhsId") Long yhsId, @Param("goodsId") Long goodsId);
 
-	@Select("select * from yh_shop_goods_sku where sku_id = #{skuId} and price < #{minPrice} and status = 1")
-	List<YhShopGoodsSku> getBelowPriceShopSku(@Param("skuId") Long skuId, @Param("minPrice") BigDecimal minPrice);
+	@Select("select * from yh_shop_goods_sku where sku_id = #{skuId} and price not between #{minPrice} and #{maxPrice} and status = 1")
+	List<YhShopGoodsSku> getBelowPriceShopSku(@Param("skuId") Long skuId, @Param("minPrice") BigDecimal minPrice, @Param("maxPrice") BigDecimal maxPrice);
 }

+ 7 - 5
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonSkuServiceImpl.java

@@ -132,14 +132,16 @@ public class CmsGoodsDonSkuServiceImpl extends ServiceImpl<GoodsDonSkuMapper,Goo
 				.eq(YhShopGoodsRate::getSkuId, skuId)
 				.last("limit 1"));
 		if (yhShopGoodsRate != null) {
-			BigDecimal oriDiscount = BigDecimal.valueOf(100).subtract(BigDecimal.valueOf(yhShopGoodsRate.getRate()));
-			BigDecimal minPrice = newPrice.multiply(oriDiscount.divide(BigDecimal.valueOf(100)));
+			BigDecimal differPrice = newPrice.multiply(BigDecimal.valueOf(yhShopGoodsRate.getRate()).divide(BigDecimal.valueOf(100)));
+			BigDecimal minPrice = newPrice.subtract(differPrice);
+			BigDecimal maxPrice = newPrice.add(differPrice);
+			//不在设置的价格区间店铺 统统下架
 			//记录那些店铺规格被下架
-			List<YhShopGoodsSku> yhShopGoodsSkus = yhShopGoodsSkuMapper.getBelowPriceShopSku(skuId, minPrice);
+			List<YhShopGoodsSku> yhShopGoodsSkus = yhShopGoodsSkuMapper.getBelowPriceShopSku(skuId, minPrice, maxPrice);
 			if (CollUtil.isNotEmpty(yhShopGoodsSkus)) {
 				yhShopSkuSysTakeDownRecordMapper.batchInsert(yhShopGoodsSkus, minPrice);
-				Integer update = yhShopGoodsSkuMapper.setBelowPriceShopSkuDown(skuId, minPrice);
-				log.info("变更skuId:{}规格价格,店铺数量:{}低于价格:{}下架", skuId, update, minPrice);
+				Integer update = yhShopGoodsSkuMapper.setBelowPriceShopSkuDown(skuId, minPrice, maxPrice);
+				log.info("变更skuId:{}规格价格,店铺数量:{}低于价格区间:{}-{}下架", skuId, update, minPrice, maxPrice);
 			}
 		}
 	}

+ 3 - 5
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/CmsGoodsDonSkuController.java

@@ -171,11 +171,9 @@ public class CmsGoodsDonSkuController {
         //前后两次价格不同 下架店铺低于这个折扣最低价格
         BigDecimal oldPrice = dbSku.getPrice();
         BigDecimal newPrice = sku.getPrice();
-        //规格新价 变高
-        if (newPrice.compareTo(oldPrice) > 0) {
-            //下架店铺低于这个规格价格的品
-            goodsDonSkuService.setBelowPriceShopSkuDown(skuId, newPrice);
-        }
+        //规格变化
+        //下架店铺不在平台设置的价格区间
+        goodsDonSkuService.setBelowPriceShopSkuDown(skuId, newPrice);
         refreshCacheService.refreshYhHomePageCache();
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }