|
@@ -128,7 +128,6 @@ public class OrderInfoService {
|
|
|
Long userId = order.getUserId();
|
|
Long userId = order.getUserId();
|
|
|
|
|
|
|
|
// 套餐内商品
|
|
// 套餐内商品
|
|
|
- Package aPackage = packageRepo.findById(order.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
|
|
List<PackageGoods> packageGoodsList = packageGoodsRepo.findAllByPackageId(order.getPackageId());
|
|
List<PackageGoods> packageGoodsList = packageGoodsRepo.findAllByPackageId(order.getPackageId());
|
|
|
if (order.isRepeatedly()) {
|
|
if (order.isRepeatedly()) {
|
|
|
// 多次使用加入套餐余额
|
|
// 多次使用加入套餐余额
|
|
@@ -149,7 +148,7 @@ public class OrderInfoService {
|
|
|
// 用户id和上级id相同
|
|
// 用户id和上级id相同
|
|
|
if (user.getParent() != null && !userId.equals(user.getParent())) {
|
|
if (user.getParent() != null && !userId.equals(user.getParent())) {
|
|
|
// 上级分销
|
|
// 上级分销
|
|
|
- this.distribution1(userId, user.getParent(), orderInfoId.toString(), order.getPrice(), aPackage);
|
|
|
|
|
|
|
+ this.distribution1(userId, user.getParent(), order);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -222,72 +221,80 @@ public class OrderInfoService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void distribution1(Long userId, Long parent, String transactionId, BigDecimal amount, Package aPackage) {
|
|
|
|
|
|
|
+ public void distribution1(Long userId, Long parent, OrderInfo orderInfo) {
|
|
|
|
|
+ Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
|
|
+
|
|
|
User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
Member member = parentUser.getMember();
|
|
Member member = parentUser.getMember();
|
|
|
if (Member.NORMAL.equals(member)) {
|
|
if (Member.NORMAL.equals(member)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+ BigDecimal amount = orderInfo.getPrice();
|
|
|
|
|
+ String transactionId = orderInfo.getId().toString();
|
|
|
|
|
|
|
|
- //直推
|
|
|
|
|
- // 达人分销
|
|
|
|
|
- BigDecimal directPush = aPackage.getPersonalRatio0();
|
|
|
|
|
- // 套餐有额外分销
|
|
|
|
|
- if (ObjectUtil.isNull(directPush)) {
|
|
|
|
|
- directPush = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
|
|
- }
|
|
|
|
|
- BigDecimal directPushAmount = amount.multiply(directPush);
|
|
|
|
|
-
|
|
|
|
|
- // 大达人分销
|
|
|
|
|
- BigDecimal bigExpertPush = aPackage.getBigExpertRatio();
|
|
|
|
|
- // 套餐有额外分销
|
|
|
|
|
- if (ObjectUtil.isNotNull(bigExpertPush)) {
|
|
|
|
|
- bigExpertPush = sysConfigService.getBigDecimal("BIG_EXPERT_RATIO");
|
|
|
|
|
- }
|
|
|
|
|
- BigDecimal bigExpertAmount = amount.multiply(bigExpertPush);
|
|
|
|
|
-
|
|
|
|
|
- // 暂存 保存大达人
|
|
|
|
|
- parentUser.setCacheAmount(bigExpertAmount);
|
|
|
|
|
- userRepo.save(parentUser);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ BigDecimal ratio;
|
|
|
// 保存流水
|
|
// 保存流水
|
|
|
switch (member) {
|
|
switch (member) {
|
|
|
case EXPERT:
|
|
case EXPERT:
|
|
|
- CommissionRecord commissionRecord1 = CommissionRecord.builder()
|
|
|
|
|
- .userId(parent)
|
|
|
|
|
- .amount(directPushAmount)
|
|
|
|
|
- .payMethod(PayMethod.YUE)
|
|
|
|
|
- .fromUserId(userId)
|
|
|
|
|
- .transactionType(TransactionType.PROMOTE)
|
|
|
|
|
- .transactionId(transactionId)
|
|
|
|
|
- .build();
|
|
|
|
|
- commissionRecordRepo.save(commissionRecord1);
|
|
|
|
|
- CommissionRecord commissionRecord2 = CommissionRecord.builder()
|
|
|
|
|
- .userId(parent)
|
|
|
|
|
- .amount(bigExpertAmount.subtract(directPushAmount))
|
|
|
|
|
- .payMethod(PayMethod.YUE)
|
|
|
|
|
- .fromUserId(userId)
|
|
|
|
|
- .transactionType(TransactionType.BIG_EXPERT)
|
|
|
|
|
- .transactionId(transactionId)
|
|
|
|
|
- .build();
|
|
|
|
|
- commissionRecordRepo.save(commissionRecord2);
|
|
|
|
|
|
|
+ // 达人分销
|
|
|
|
|
+ ratio = aPackage.getPersonalRatio0();
|
|
|
|
|
+ // 套餐有额外分销
|
|
|
|
|
+ if (ObjectUtil.isNull(ratio)) {
|
|
|
|
|
+ ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case GENERAL:
|
|
|
|
|
+ // 108将分销
|
|
|
|
|
+ ratio = aPackage.getGeneralRatio();
|
|
|
|
|
+ // 套餐有额外分销
|
|
|
|
|
+ if (ObjectUtil.isNull(ratio)) {
|
|
|
|
|
+ ratio = sysConfigService.getBigDecimal("GENERAL_RATIO");
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
- case BIG_EXPERT:
|
|
|
|
|
case MAKER:
|
|
case MAKER:
|
|
|
- CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
|
|
- .userId(parent)
|
|
|
|
|
- .amount(bigExpertAmount)
|
|
|
|
|
- .payMethod(PayMethod.YUE)
|
|
|
|
|
- .fromUserId(userId)
|
|
|
|
|
- .transactionType(TransactionType.PROMOTE)
|
|
|
|
|
- .transactionId(transactionId)
|
|
|
|
|
- .build();
|
|
|
|
|
- commissionRecordRepo.save(commissionRecord);
|
|
|
|
|
|
|
+ // 创客分销
|
|
|
|
|
+ ratio = aPackage.getMakerRatio();
|
|
|
|
|
+ // 套餐有额外分销
|
|
|
|
|
+ if (ObjectUtil.isNull(ratio)) {
|
|
|
|
|
+ ratio = sysConfigService.getBigDecimal("MAKER_RATIO");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case GENERAL_MAKER:
|
|
|
|
|
+ // 108将+创客分销
|
|
|
|
|
+ ratio = aPackage.getGeneralMakerRatio();
|
|
|
|
|
+ // 套餐有额外分销
|
|
|
|
|
+ if (ObjectUtil.isNull(ratio)) {
|
|
|
|
|
+ ratio = sysConfigService.getBigDecimal("PROMOTE_MAKER_RATIO");
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ ratio = BigDecimal.ZERO;
|
|
|
}
|
|
}
|
|
|
|
|
+ // 钱和流水
|
|
|
|
|
+ if (BigDecimal.ZERO.compareTo(ratio) < 0) {
|
|
|
|
|
+ BigDecimal directPushAmount = amount.multiply(ratio);
|
|
|
|
|
+ CommissionRecord commissionRecord1 = CommissionRecord.builder()
|
|
|
|
|
+ .userId(parent)
|
|
|
|
|
+ .amount(directPushAmount)
|
|
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
|
|
+ .fromUserId(userId)
|
|
|
|
|
+ .transactionType(TransactionType.PROMOTE)
|
|
|
|
|
+ .transactionId(transactionId)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ commissionRecordRepo.save(commissionRecord1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 间推
|
|
|
|
|
+ this.indirect(parentUser, aPackage, userId, transactionId, amount);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 间推
|
|
|
|
|
+ */
|
|
|
|
|
+ public void indirect(User parentUser, Package aPackage, Long userId, String transactionId, BigDecimal amount) {
|
|
|
//分销级别
|
|
//分销级别
|
|
|
int distributor = sysConfigService.getInt("DISTRIBUTOR");
|
|
int distributor = sysConfigService.getInt("DISTRIBUTOR");
|
|
|
-
|
|
|
|
|
// 间推
|
|
// 间推
|
|
|
for (int i = 1; i < distributor; i++) {
|
|
for (int i = 1; i < distributor; i++) {
|
|
|
if (ObjectUtil.isEmpty(parentUser.getParent())) {
|
|
if (ObjectUtil.isEmpty(parentUser.getParent())) {
|
|
@@ -382,4 +389,35 @@ public class OrderInfoService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 创客分销
|
|
|
|
|
+ 创客和108将捞到二者之一就停还是两个都捞到?
|
|
|
|
|
+ */
|
|
|
|
|
+ public void makerDistribution(User user, BigDecimal amount, Boolean isCache, Long orderId) {
|
|
|
|
|
+ BigDecimal makerRatio = sysConfigService.getBigDecimal("MAKER_RATIO");
|
|
|
|
|
+ BigDecimal maker = amount.multiply(makerRatio);
|
|
|
|
|
+
|
|
|
|
|
+ User parent = userRepo.findById(user.getParent()).orElse(null);
|
|
|
|
|
+ while (parent != null) {
|
|
|
|
|
+ if (Member.MAKER.equals(parent.getMember())) {
|
|
|
|
|
+ if (isCache) {
|
|
|
|
|
+ parent.setCacheAmount(parent.getCacheAmount().add(maker));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parent.setMaker(maker.add(parent.getCacheAmount()));
|
|
|
|
|
+ }
|
|
|
|
|
+ userRepo.save(parent);
|
|
|
|
|
+ commissionRecordRepo.save(CommissionRecord.builder()
|
|
|
|
|
+ .userId(parent.getId())
|
|
|
|
|
+ .fromUserId(user.getId())
|
|
|
|
|
+ .transactionType(TransactionType.MAKER)
|
|
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
|
|
+ .transactionId(orderId.toString())
|
|
|
|
|
+ .amount(maker)
|
|
|
|
|
+ .build());
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ parent = userRepo.findById(parent.getParent()).orElse(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|