Browse Source

fix 配置最高店铺分销提成校验

zoujiajian 2 years ago
parent
commit
4f0b16d888

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/CmsYhShopCommonService.java

@@ -17,7 +17,7 @@ public interface CmsYhShopCommonService {
 
 	void verifyYhShopApply(YhShopVerifyReq verifyReq);
 
-	void setYhShopGoodsRate(List<YhShopUserPlatDistributeRate> yhShopUserPlatDistributeRates, Long userId);
+	void setYhShopGoodsRate(List<YhShopUserPlatDistributeRate> yhShopUserPlatDistributeRates, Long businessId, Long userId);
 
 	void setYhShopBusiness(YhShop yhShop);
 

+ 18 - 1
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsYhShopCommonServiceImpl.java

@@ -63,6 +63,8 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 
 	private final BeanSearcher beanSearcher;
 
+	private final YhShopUserBusinessDefaultRateConfigMapper defaultRateConfigMapper;
+
 	@Override
 	public void setGeneralGoodsRate(List<YhShopGeneralGoodsRate> rates) {
 		List<YhShopGeneralGoodsRate> saveShopGoodsRate = new ArrayList<>(rates.size());
@@ -126,7 +128,7 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
-	public void setYhShopGoodsRate(List<YhShopUserPlatDistributeRate> yhShopUserPlatDistributeRates, Long userId) {
+	public void setYhShopGoodsRate(List<YhShopUserPlatDistributeRate> yhShopUserPlatDistributeRates, Long businessId, Long userId) {
 		yhShopUserPlatDistributeRates.forEach(data -> {
 			data.setUserId(userId);
 			Long goodsId = data.getGoodsId();
@@ -140,6 +142,10 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 			if (secondRate != null && (secondRate < 0 || secondRate > 100)) {
 				throw BusinessRuntimeException.getInstance("请输入正确的分销比例");
 			}
+			//店铺分销虚物分销比例且配置商务
+			if (businessId != null && goodsDon.getType() == 1) {
+				checkDistributorAndBusinessRate(data.getRate(), goodsDon.getId(), goodsDon.getTitle());
+			}
 		});
 		yhShopUserPlatDistributeRateService.saveOrUpdateBatch(yhShopUserPlatDistributeRates);
 	}
@@ -260,4 +266,15 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 		}
 		yhShopDistributeMoneyApplyMapper.updateById(distributeMoneyApply);
 	}
+
+	public void checkDistributorAndBusinessRate(Integer distributeGoodsRate, Long goodsId, String goodsName) {
+		YhShopUserBusinessDefaultRateConfig defaultGoodsRateConfig = defaultRateConfigMapper.selectOne(Wrappers.lambdaQuery(YhShopUserBusinessDefaultRateConfig.class)
+				.eq(YhShopUserBusinessDefaultRateConfig::getGoodsId, goodsId)
+				.last("limit 1"));
+		Optional.ofNullable(defaultGoodsRateConfig).ifPresent(config -> {
+			if (distributeGoodsRate > config.getMaxRate()) {
+				throw BusinessRuntimeException.getInstance(String.format("该%s平台最高可配置分销比例为%s", goodsName, config.getMaxRate()));
+			}
+		});
+	}
 }

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/shop/CmsYhShopGoodsController.java

@@ -109,7 +109,7 @@ public class CmsYhShopGoodsController {
     }
 
     /**
-     * 一键设置 店铺平台通用比例
+     * 一键设置 店铺平台通用浮动比例
      */
     @PutMapping("/oneKey/set/goods/rate")
     public Result<Void> setShopGoodsGeneralRate(@RequestBody GoodsDonShopRateReq req) {
@@ -245,7 +245,7 @@ public class CmsYhShopGoodsController {
         if (CollUtil.isEmpty(yhShopUserPlatDistributeRates)) {
             throw BusinessRuntimeException.getInstance("请选择店铺用户对应平台比例");
         }
-        cmsYhShopCommonService.setYhShopGoodsRate(yhShopUserPlatDistributeRates, yhShop.getUserId());
+        cmsYhShopCommonService.setYhShopGoodsRate(yhShopUserPlatDistributeRates,yhShop.getBusinessId(), yhShop.getUserId());
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/shop/YhShopUserController.java

@@ -130,7 +130,7 @@ public class YhShopUserController {
 	@GetMapping("/get/distribute/detail/data")
 	public Result<YhShopUserDistributeDetailView> getDistributeDetail() {
 		long yhShopUserId = StpYhShopManageUser.getLoginIdAsLong();
-		User user = beanSearcher.searchFirst(User.class, MapUtils.builder().field(User::getId, yhShopUserId).onlySelect(User::getPoints).build());
+		User user = beanSearcher.searchFirst(User.class, MapUtils.builder().field(User::getId, yhShopUserId).onlySelect(User::getYhsMoney).build());
 		BigDecimal wApplyMoney = user.getYhsMoney().divide(BigDecimal.valueOf(100));
 		//已提现
 		Number gotApplyMoney = beanSearcher.searchSum(YhShopDistributeMoneyApply.class, MapUtils.builder()