|
|
@@ -41,6 +41,7 @@ public class OrderInfoService {
|
|
|
private final UserPackageFlowRepo userPackageFlowRepo;
|
|
|
private final UserService userService;
|
|
|
private final StockRepo stockRepo;
|
|
|
+ private final OrderDelayService orderDelayService;
|
|
|
|
|
|
public Page<OrderInfo> all(PageQuery pageQuery) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
|
@@ -87,7 +88,7 @@ public class OrderInfoService {
|
|
|
/*
|
|
|
下订单
|
|
|
*/
|
|
|
- public OrderInfo createOrder1(CreateOrder createOrder,Long userId) {
|
|
|
+ public OrderInfo createOrder1(CreateOrder createOrder, Long userId) {
|
|
|
Package aPackage = packageRepo.findById(createOrder.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
String localTime = df.format(LocalDateTime.now());
|
|
|
@@ -116,8 +117,9 @@ public class OrderInfoService {
|
|
|
price = stock.getPrice();
|
|
|
}
|
|
|
order.setPrice(price.multiply(new BigDecimal(createOrder.getNum())));
|
|
|
-
|
|
|
- return orderInfoRepo.save(order);
|
|
|
+ OrderInfo save = orderInfoRepo.save(order);
|
|
|
+ orderDelayService.orderDelay(save.getId(), save.getCreatedAt());
|
|
|
+ return save;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -183,35 +185,28 @@ public class OrderInfoService {
|
|
|
.content(goodsDTOS)
|
|
|
.build());
|
|
|
|
|
|
- // 用户
|
|
|
- User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
-// if (!user.isVip()) {
|
|
|
-// user.setVip(true);
|
|
|
-// userRepo.save(user);
|
|
|
-// }
|
|
|
-
|
|
|
- Long parent = user.getParent();
|
|
|
// 用户id和上级id相同
|
|
|
- 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, parent, order);
|
|
|
- }
|
|
|
+// 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.distribution2(order);
|
|
|
+ orderDelayService.remove(order.getId(), order.getCreatedAt());
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -303,40 +298,98 @@ public class OrderInfoService {
|
|
|
BigDecimal amount = orderInfo.getPrice();
|
|
|
|
|
|
// 无限级找创客/108将/团长
|
|
|
- this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
|
|
|
-
|
|
|
- // 不成为团长没有奖励
|
|
|
-// if (Member.NORMAL.equals(parentUser.getMember())) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
+// this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
|
|
|
|
|
|
String transactionId = orderInfo.getId().toString();
|
|
|
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-
|
|
|
// 间推
|
|
|
this.indirect(parentUser, aPackage, userId, transactionId, amount);
|
|
|
}
|
|
|
|
|
|
+ public void distribution2(OrderInfo orderInfo) {
|
|
|
+ Long userId = orderInfo.getUserId();
|
|
|
+ // 别人分享的链接
|
|
|
+ Long parentUserId = orderInfo.getParentUserId();
|
|
|
+ if (ObjectUtil.isNull(parentUserId)) {
|
|
|
+ // 自己购买的链接
|
|
|
+ parentUserId = userId;
|
|
|
+ }
|
|
|
+ BigDecimal amount = orderInfo.getPrice();
|
|
|
+
|
|
|
+
|
|
|
+ Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
+ //团长直推钱
|
|
|
+ BigDecimal headRatio = aPackage.getPersonalRatio0();
|
|
|
+ if (!aPackage.isSeparateDistribution() || ObjectUtil.isNull(headRatio)) {
|
|
|
+ headRatio = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
+ }
|
|
|
+ BigDecimal head = amount.multiply(headRatio);
|
|
|
+
|
|
|
+ // 团长或大团长
|
|
|
+ User user = null;
|
|
|
+ // 上级为空或上级为不为普通用户停止
|
|
|
+ Long parent1 = user.getParent();
|
|
|
+ while (ObjectUtil.isNotNull(parentUserId)) {
|
|
|
+ user = userRepo.findById(parentUserId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ // 如果是团长/大团长 拿直推钱
|
|
|
+ if (!Member.NORMAL.equals(user.getMember())) {
|
|
|
+ user.setAmount(user.getCacheAmount().add(head));
|
|
|
+ userRepo.save(user);
|
|
|
+
|
|
|
+ // 个人佣金流水
|
|
|
+ CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
+ .userId(parentUserId)
|
|
|
+ .amount(head)
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
+ .fromUserId(userId)
|
|
|
+ .transactionType(TransactionType.PROMOTE)
|
|
|
+ .transactionId(orderInfo.getTransactionId())
|
|
|
+ .build();
|
|
|
+ commissionRecordRepo.save(commissionRecord);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ parentUserId = parent1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存在团长或大团长+团长或大团长上级不为空
|
|
|
+ if (ObjectUtil.isNotNull(user) && ObjectUtil.isNotNull(parent1)) {
|
|
|
+ // 控制间退找几级
|
|
|
+ int i = 2;
|
|
|
+ if (Member.EXPERT.equals(user.getMember())) {
|
|
|
+ i = 1;
|
|
|
+ }
|
|
|
+ while (i < 3) {
|
|
|
+ User parent = userRepo.findById(parent1).orElseThrow(new BusinessException("无用户"));
|
|
|
+ if (Member.BIG_EXPERT.equals(parent.getMember())) {
|
|
|
+ String name = "PERSONAL_RATIO_" + i;
|
|
|
+ BigDecimal percentage = sysConfigService.getBigDecimal(name);
|
|
|
+ BigDecimal personalAmount = amount.multiply(percentage);
|
|
|
+
|
|
|
+ parent.setAmount(parent.getCacheAmount().add(personalAmount));
|
|
|
+ userRepo.save(parent);
|
|
|
+
|
|
|
+ // 个人佣金流水
|
|
|
+ CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
+ .userId(parent.getId())
|
|
|
+ .amount(personalAmount)
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
+ .fromUserId(userId)
|
|
|
+ .transactionType(TransactionType.CHILD_PROMOTE)
|
|
|
+ .transactionId(orderInfo.getTransactionId())
|
|
|
+ .build();
|
|
|
+ commissionRecordRepo.save(commissionRecord);
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ parent1 = parent.getParent();
|
|
|
+ if (ObjectUtil.isNull(parent1)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
间推
|
|
|
*/
|