|
|
@@ -114,6 +114,29 @@ public class OrderInfoService {
|
|
|
return orderInfoRepo.save(orderInfo);
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 新用户点进分享链接
|
|
|
+ */
|
|
|
+ public void saveParent(Long parent, Long userId) {
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ // 判断上级是否为空
|
|
|
+ if (ObjectUtil.isNotEmpty(user.getParent())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 判断新用户
|
|
|
+ List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
|
|
|
+ long count = orderInfos.stream()
|
|
|
+ .filter(orderInfo -> !OrderInfoStatus.CANCELLED.equals(orderInfo.getStatus()) || !OrderInfoStatus.UNPAID
|
|
|
+ .equals(orderInfo.getStatus()))
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 保存
|
|
|
+ user.setParent(parent);
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
完成付款
|
|
|
*/
|
|
|
@@ -178,10 +201,27 @@ public class OrderInfoService {
|
|
|
userRepo.save(user);
|
|
|
}
|
|
|
|
|
|
+ Long parent = user.getParent();
|
|
|
// 用户id和上级id相同
|
|
|
- if (user.getParent() != null && !userId.equals(user.getParent())) {
|
|
|
+ if (!userId.equals(parent)) {
|
|
|
+ // 如果是别人分享的链接购买的
|
|
|
+ if (ObjectUtil.isNotEmpty(order.getParentUserId())) {
|
|
|
+ parent = order.getParentUserId();
|
|
|
+ // 是否设为上级
|
|
|
+ if (ObjectUtil.isEmpty(user.getParent())) {
|
|
|
+ List<OrderInfo> orderInfos = orderInfoRepo.findAllByUserId(userId);
|
|
|
+ long count = orderInfos.stream()
|
|
|
+ .filter(orderInfo -> !OrderInfoStatus.UNPAID.equals(orderInfo.getStatus()) || !OrderInfoStatus.CANCELLED
|
|
|
+ .equals(orderInfo.getStatus()))
|
|
|
+ .count();
|
|
|
+ if (count <= 0) {
|
|
|
+ user.setParent(parent);
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
// 上级分销
|
|
|
- this.distribution1(userId, user.getParent(), order);
|
|
|
+ this.distribution1(userId, parent, order);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -273,36 +313,36 @@ public class OrderInfoService {
|
|
|
User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
BigDecimal amount = orderInfo.getPrice();
|
|
|
|
|
|
- // 无限级找创客/108将
|
|
|
+ // 无限级找创客/108将/团长
|
|
|
this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
|
|
|
|
|
|
- // 不成为佳客没有奖励
|
|
|
- if (Member.NORMAL.equals(parentUser.getMember())) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ // 不成为团长没有奖励
|
|
|
+// if (Member.NORMAL.equals(parentUser.getMember())) {
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
String transactionId = orderInfo.getId().toString();
|
|
|
|
|
|
- BigDecimal ratio = aPackage.getPersonalRatio0();
|
|
|
- if (ObjectUtil.isNull(ratio) || !aPackage.isSeparateDistribution()) {
|
|
|
- ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
- }
|
|
|
+// BigDecimal ratio = aPackage.getPersonalRatio0();
|
|
|
+// if (ObjectUtil.isNull(ratio) || !aPackage.isSeparateDistribution()) {
|
|
|
+// ratio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
+// }
|
|
|
|
|
|
// 钱和流水
|
|
|
- if (BigDecimal.ZERO.compareTo(ratio) < 0) {
|
|
|
- BigDecimal directPushAmount = amount.multiply(ratio);
|
|
|
- parentUser.setCacheAmount(directPushAmount.add(parentUser.getCacheAmount()));
|
|
|
- userRepo.save(parentUser);
|
|
|
- CommissionRecord commissionRecord1 = CommissionRecord.builder()
|
|
|
- .userId(parent)
|
|
|
- .amount(directPushAmount)
|
|
|
- .payMethod(PayMethod.YUE)
|
|
|
- .fromUserId(userId)
|
|
|
- .transactionType(TransactionType.PROMOTE)
|
|
|
- .transactionId(transactionId)
|
|
|
- .build();
|
|
|
- commissionRecordRepo.save(commissionRecord1);
|
|
|
- }
|
|
|
+// if (BigDecimal.ZERO.compareTo(ratio) < 0) {
|
|
|
+// BigDecimal directPushAmount = amount.multiply(ratio);
|
|
|
+// parentUser.setCacheAmount(directPushAmount.add(parentUser.getCacheAmount()));
|
|
|
+// userRepo.save(parentUser);
|
|
|
+// 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);
|
|
|
@@ -409,7 +449,7 @@ public class OrderInfoService {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- 创客和108将分销
|
|
|
+ 创客和108将分销和团长
|
|
|
*/
|
|
|
public void makerGeneralDistribution(User parent, BigDecimal amount, Long orderId, Long userId, Package aPackage) {
|
|
|
// 创客比例
|
|
|
@@ -425,8 +465,16 @@ public class OrderInfoService {
|
|
|
}
|
|
|
BigDecimal general = amount.multiply(generalRatio);
|
|
|
|
|
|
+ // 团长比例
|
|
|
+ BigDecimal headRatio = aPackage.getPersonalRatio0();
|
|
|
+ if (ObjectUtil.isNull(headRatio) || !aPackage.isSeparateDistribution()) {
|
|
|
+ headRatio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
+ }
|
|
|
+ BigDecimal head = amount.multiply(headRatio);
|
|
|
+
|
|
|
boolean isGeneral = true;
|
|
|
boolean isMaker = true;
|
|
|
+ boolean isHead = true;
|
|
|
|
|
|
CommissionRecord record = CommissionRecord.builder()
|
|
|
.userId(parent.getId())
|
|
|
@@ -484,6 +532,17 @@ public class OrderInfoService {
|
|
|
isGeneral = false;
|
|
|
}
|
|
|
break;
|
|
|
+ case EXPERT:
|
|
|
+ if (isHead) {
|
|
|
+ parent.setCacheAmount(parent.getCacheAmount().add(head));
|
|
|
+ userRepo.save(parent);
|
|
|
+ // 流水
|
|
|
+ record.setAmount(head);
|
|
|
+ record.setTransactionType(TransactionType.PROMOTE);
|
|
|
+ commissionRecordRepo.save(record);
|
|
|
+ isHead = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
default:
|
|
|
break;
|
|
|
}
|