zoujiajian il y a 2 ans
Parent
commit
44d87608f1

+ 1 - 1
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -177,7 +177,7 @@ public interface Constant {
 	/**
 	 * 渠道分销规则key
 	 */
-	String DISTRIBUTE_RULE_KEY = "DISTRIBUTE_RULE_KEY";
+	String DISTRIBUTE_RULE_KEY = "distribute_rule_key";
 
 	String ZERO_STR = "0";
 

+ 35 - 32
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -1394,48 +1394,51 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 					points = returnPoints;
 				}
 				//是否使用优惠券 且优惠券折扣小于低于9折
-				if (order.getCouponUserId() != 0) {
-					//优惠券折扣是否小于低于9折
-					CouponUser couponUser = couponUserMapper.getCouponByCouponUserId(order.getCouponUserId());
-					BigDecimal plat_discount = couponUser.getDiscount();
-					BigDecimal nineDis = BigDecimal.valueOf(0.90);
-					if (plat_discount != null && plat_discount.compareTo(BigDecimal.ZERO) > 0 && plat_discount.compareTo(nineDis) <= 0) {
-						//是否参与渠道分销规则
-						//用户下单订单 是否使用 优惠券小于低于9折
-						//分销利润金额 减去(规格原价 * 目前使用的折扣 - 规格原价 * 渠道自身折扣 /2)
-						BigDecimal realMoney = order.getRealMoney();
-						//查询渠道对应的折扣
-						Coupon coupon = couponDistributePopularizeMapper.selectDiscountCouponByUserId(userDistribute.getId());
-						//未配置对应折扣
-						//按优惠多少对半平摊
-						if (coupon == null) {
-							BigDecimal avg = realMoney.multiply(plat_discount).divide(BigDecimal.valueOf(2));
-							points = points.subtract(avg.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN));
-							if (points.compareTo(BigDecimal.ZERO) < 0) {
-								points = BigDecimal.ZERO;
-							}
-							distributeWaitingSendPoints.setIsRule(true);
-						}
-						if (coupon != null) {
-							BigDecimal distribute_discount = coupon.getDiscount();
-
-							BigDecimal ds_money = realMoney.multiply(distribute_discount);
-							BigDecimal plat_ds_money = realMoney.multiply(plat_discount);
-							BigDecimal subtractMoney = ds_money.subtract(plat_ds_money);
-							if (subtractMoney.compareTo(BigDecimal.ZERO) > 0) {
-								BigDecimal avg = subtractMoney.divide(BigDecimal.valueOf(2));
+				//是否开启了渠道规则分销
+				SysConfig ruleConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
+						.eq(SysConfig::getSysKey, Constant.DISTRIBUTE_RULE_KEY).last("limit 1"));
+				if (ruleConfig != null && StrUtil.equals(Constant.ONE_STR, ruleConfig.getSysValue())) {
+					if (order.getCouponUserId() != 0) {
+						//优惠券折扣是否小于低于9折
+						CouponUser couponUser = couponUserMapper.getCouponByCouponUserId(order.getCouponUserId());
+						BigDecimal plat_discount = couponUser.getDiscount();
+						BigDecimal nineDis = BigDecimal.valueOf(0.90);
+						if (plat_discount != null && plat_discount.compareTo(BigDecimal.ZERO) > 0 && plat_discount.compareTo(nineDis) <= 0) {
+							//是否参与渠道分销规则
+							//用户下单订单 是否使用 优惠券小于低于9折
+							//分销利润金额 减去(规格原价 * 目前使用的折扣 - 规格原价 * 渠道自身折扣 /2)
+							BigDecimal realMoney = order.getRealMoney();
+							//查询渠道对应的折扣
+							Coupon coupon = couponDistributePopularizeMapper.selectDiscountCouponByUserId(userDistribute.getId());
+							//未配置对应折扣
+							//按优惠多少对半平摊
+							if (coupon == null) {
+								BigDecimal avg = realMoney.multiply(plat_discount).divide(BigDecimal.valueOf(2));
 								points = points.subtract(avg.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN));
 								if (points.compareTo(BigDecimal.ZERO) < 0) {
 									points = BigDecimal.ZERO;
 								}
 								distributeWaitingSendPoints.setIsRule(true);
 							}
+							if (coupon != null) {
+								BigDecimal distribute_discount = coupon.getDiscount();
+
+								BigDecimal ds_money = realMoney.multiply(distribute_discount);
+								BigDecimal plat_ds_money = realMoney.multiply(plat_discount);
+								BigDecimal subtractMoney = ds_money.subtract(plat_ds_money);
+								if (subtractMoney.compareTo(BigDecimal.ZERO) > 0) {
+									BigDecimal avg = subtractMoney.divide(BigDecimal.valueOf(2));
+									points = points.subtract(avg.multiply(BigDecimal.valueOf(distributePointsExchangeMoney.getPoints())).divide(distributePointsExchangeMoney.getMoney(), 2, RoundingMode.HALF_DOWN));
+									if (points.compareTo(BigDecimal.ZERO) < 0) {
+										points = BigDecimal.ZERO;
+									}
+									distributeWaitingSendPoints.setIsRule(true);
+								}
+							}
 						}
 					}
 				}
 
-
-
 				distributeWaitingSendPoints.setPoints(points);
 				if (points != null && points.compareTo(BigDecimal.ZERO) > 0) {
 					log.info("用户{}邀请{},产生分销订单分发积分记录入库", userDistributeShared.getSharedId(), order.getUserId());

+ 1 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributeController.java

@@ -730,6 +730,7 @@ public class DistributeController {
 			ruleConfig.setSysValue(Constant.ZERO_STR);
 		}
 		sysConfigService.saveOrUpdate(ruleConfig);
+		//记录关闭打开状态
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}