|
|
@@ -9,10 +9,7 @@ import com.izouma.jiashanxia.domain.Package;
|
|
|
import com.izouma.jiashanxia.dto.OrderInfoVO;
|
|
|
import com.izouma.jiashanxia.dto.PackageGoodsDTO;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
-import com.izouma.jiashanxia.enums.OrderInfoStatus;
|
|
|
-import com.izouma.jiashanxia.enums.PackageType;
|
|
|
-import com.izouma.jiashanxia.enums.PayMethod;
|
|
|
-import com.izouma.jiashanxia.enums.TransactionType;
|
|
|
+import com.izouma.jiashanxia.enums.*;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
|
import com.izouma.jiashanxia.repo.*;
|
|
|
import com.izouma.jiashanxia.utils.JpaUtils;
|
|
|
@@ -66,7 +63,7 @@ public class OrderInfoService {
|
|
|
下订单
|
|
|
*/
|
|
|
public OrderInfo createOrder(Long userId, Long packageId, PayMethod payMethod) {
|
|
|
- Package setInfo = packageRepo.findById(packageId).orElseThrow(new BusinessException("无套餐"));
|
|
|
+ Package aPackage = packageRepo.findById(packageId).orElseThrow(new BusinessException("无套餐"));
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
String localTime = df.format(LocalDateTime.now());
|
|
|
String num = String.format("%05d", orderInfoRepo.orderNum() + 1);
|
|
|
@@ -77,8 +74,8 @@ public class OrderInfoService {
|
|
|
.userId(userId)
|
|
|
.payMethod(payMethod)
|
|
|
.orderNumber(localTime + num)
|
|
|
- .price(setInfo.getAmount())
|
|
|
- .name(setInfo.getName())
|
|
|
+ .price(aPackage.getAmount())
|
|
|
+ .name(aPackage.getName())
|
|
|
.num(1)
|
|
|
.build();
|
|
|
return orderInfoRepo.save(order);
|
|
|
@@ -101,18 +98,18 @@ public class OrderInfoService {
|
|
|
Long userId = order.getUserId();
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
// 设置用户为vip
|
|
|
- if (!user.isVip()) {
|
|
|
- user.setVip(true);
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
+// if (!user.isVip()) {
|
|
|
+// user.setVip(true);
|
|
|
+// userRepo.save(user);
|
|
|
+// }
|
|
|
|
|
|
// 加入套餐商品
|
|
|
- userPackageService.joinUserPackage(userId, setGoodsList, 1, PackageType.PERSONAL);
|
|
|
+ userPackageService.joinUserPackage(userId, setGoodsList, order.getNum(), PackageType.PERSONAL);
|
|
|
|
|
|
// 用户id和上级id相同
|
|
|
if (user.getParent() != null && !userId.equals(user.getParent())) {
|
|
|
// 上级分销
|
|
|
- this.distribution(userId, user.getParent(), transactionId, order.getPrice());
|
|
|
+ this.distribution(userId, user.getParent(), orderInfoId.toString(), order.getPrice());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -185,6 +182,89 @@ public class OrderInfoService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void distribution1(Long userId, Long parent, String transactionId, BigDecimal amount) {
|
|
|
+ User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
+ Member member = parentUser.getMember();
|
|
|
+
|
|
|
+ //直推
|
|
|
+ // 达人分销
|
|
|
+ BigDecimal directPush = sysConfigService.getBigDecimal("PERSONAL_AMOUNT_0");
|
|
|
+ BigDecimal directPushAmount = amount.multiply(directPush);
|
|
|
+ // 大达人分销
|
|
|
+ BigDecimal bigExpertPush = sysConfigService.getBigDecimal("BIG_EXPERT_AMOUNT");
|
|
|
+ BigDecimal bigExpertAmount = amount.multiply(bigExpertPush);
|
|
|
+ // 暂存 保存大达人
|
|
|
+ parentUser.setCacheAmount(bigExpertAmount);
|
|
|
+ userRepo.save(parentUser);
|
|
|
+
|
|
|
+ // 保存流水
|
|
|
+ switch (member){
|
|
|
+ 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);
|
|
|
+ case BIG_EXPERT:
|
|
|
+ CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
+ .userId(parentUser.getId())
|
|
|
+ .amount(bigExpertAmount)
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
+ .fromUserId(userId)
|
|
|
+ .transactionType(TransactionType.PROMOTE)
|
|
|
+ .transactionId(transactionId)
|
|
|
+ .build();
|
|
|
+ commissionRecordRepo.save(commissionRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ //分销级别
|
|
|
+ int distributor = sysConfigService.getInt("DISTRIBUTOR");
|
|
|
+
|
|
|
+ // 间推
|
|
|
+ for (int i = 1; i < distributor; i++) {
|
|
|
+ if (ObjectUtil.isEmpty(parentUser.getParent())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ parentUser = userRepo.findById(parentUser.getParent()).orElse(null);
|
|
|
+ if (parentUser == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Member.NORMAL.equals(member)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String name = "PERSONAL_AMOUNT_" + i;
|
|
|
+ // 百分比
|
|
|
+ BigDecimal percentage = sysConfigService.getBigDecimal(name);
|
|
|
+ BigDecimal personalAmount = amount.multiply(percentage);
|
|
|
+ parentUser.setAmount(parentUser.getCacheAmount().add(personalAmount));
|
|
|
+ userRepo.save(parentUser);
|
|
|
+
|
|
|
+ // 个人佣金流水
|
|
|
+ CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
+ .userId(parentUser.getId())
|
|
|
+ .amount(personalAmount)
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
+ .fromUserId(userId)
|
|
|
+ .transactionType(TransactionType.CHILDREN_PROMOTE)
|
|
|
+ .transactionId(transactionId)
|
|
|
+ .build();
|
|
|
+ commissionRecordRepo.save(commissionRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
公司分销
|
|
|
先算个人
|
|
|
@@ -243,25 +323,4 @@ public class OrderInfoService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public List<OrderInfoVO> toVO(List<OrderInfo> orderInfos) {
|
|
|
- List<OrderInfoVO> orderInfoVOS = new ArrayList<>();
|
|
|
- Set<Long> packageIds = orderInfos.stream().map(OrderInfo::getPackageId).collect(Collectors.toSet());
|
|
|
- Map<Long, Package> packageMap = packageRepo.findAllById(packageIds)
|
|
|
- .stream()
|
|
|
- .collect(Collectors.toMap(Package::getId, apackage -> apackage));
|
|
|
-// Map<Long, String> goodsMap = goodsInfoRepo.findAll()
|
|
|
-// .stream()
|
|
|
-// .collect(Collectors.toMap(GoodsInfo::getId, GoodsInfo::getName));
|
|
|
-
|
|
|
- orderInfos.forEach(orderInfo -> {
|
|
|
- OrderInfoVO vo = new OrderInfoVO();
|
|
|
- BeanUtil.copyProperties(orderInfo, vo);
|
|
|
- vo.setAPackage(packageMap.get(orderInfo.getPackageId()));
|
|
|
-// List<PackageGoods> packageGoods = packageGoodsRepo.findAllByPackageId(orderInfo.getPackageId());
|
|
|
- List<PackageGoodsDTO> packageGoodsDTOS = packageGoodsRepo.packageGoods(orderInfo.getPackageId());
|
|
|
- vo.setGoods(packageGoodsDTOS);
|
|
|
- orderInfoVOS.add(vo);
|
|
|
- });
|
|
|
- return orderInfoVOS;
|
|
|
- }
|
|
|
}
|