|
|
@@ -24,14 +24,15 @@ import java.util.List;
|
|
|
@AllArgsConstructor
|
|
|
public class OrderInfoService {
|
|
|
|
|
|
- private OrderInfoRepo orderInfoRepo;
|
|
|
- private SetMealRepo setMealRepo;
|
|
|
- private SetGoodsRepo setGoodsRepo;
|
|
|
- private UserSetRepo userSetRepo;
|
|
|
- private UserRepo userRepo;
|
|
|
- private SysConfigService sysConfigService;
|
|
|
+ private OrderInfoRepo orderInfoRepo;
|
|
|
+ private SetMealRepo setMealRepo;
|
|
|
+ private SetGoodsRepo setGoodsRepo;
|
|
|
+ private UserSetRepo userSetRepo;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
private CommissionRecordRepo commissionRecordRepo;
|
|
|
- private UserSetService userSetService;
|
|
|
+ private UserSetService userSetService;
|
|
|
+ private CompanyRepo companyRepo;
|
|
|
|
|
|
public Page<OrderInfo> all(PageQuery pageQuery) {
|
|
|
return orderInfoRepo.findAll(JpaUtils.toSpecification(pageQuery, OrderInfo.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -40,7 +41,7 @@ public class OrderInfoService {
|
|
|
/*
|
|
|
下订单
|
|
|
*/
|
|
|
- public OrderInfo order(Long userId, Long setInfoId, PayMethod payMethod) {
|
|
|
+ public OrderInfo creatOrder(Long userId, Long setInfoId, PayMethod payMethod) {
|
|
|
SetMeal setInfo = setMealRepo.findById(setInfoId).orElseThrow(new BusinessException("无套餐"));
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
String localTime = df.format(LocalDateTime.now());
|
|
|
@@ -75,24 +76,34 @@ public class OrderInfoService {
|
|
|
Long userId = order.getUserId();
|
|
|
userSetService.joinUserSet(userId, setGoodsList);
|
|
|
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ if (user.getParent() != null) {
|
|
|
+ // 上级分销
|
|
|
+ this.distribution(userId, user.getParent(), transactionId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
分销
|
|
|
+ 又有团队,员工自己又购买了套餐,企业是否有收益?
|
|
|
+ 企业拉员工,员工的上级是否改为企业领导人?
|
|
|
+ 如果上级和企业不是一个人,收益如何算?
|
|
|
*/
|
|
|
public void distribution(Long userId, Long parent, String transactionId) {
|
|
|
- User user = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
+ User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
// 判断是否可分享
|
|
|
- boolean flag = true;
|
|
|
+ boolean flag = false;
|
|
|
// 是否公司员工
|
|
|
- if (ObjectUtil.isEmpty(user.getCompanyId())) {
|
|
|
- flag = false;
|
|
|
+ if (ObjectUtil.isNotEmpty(parentUser.getCompanyId())) {
|
|
|
+ flag = true;
|
|
|
+ // 公司可得分销
|
|
|
+ this.companyDis(parentUser.getCompanyId(), transactionId, userId);
|
|
|
}
|
|
|
- if (flag) {
|
|
|
+ if (!flag) {
|
|
|
// 是否购买了套餐
|
|
|
List<UserSet> parentSets = userSetRepo.findAllByUserId(parent);
|
|
|
- if (CollUtil.isEmpty(parentSets)) {
|
|
|
- flag = false;
|
|
|
+ if (CollUtil.isNotEmpty(parentSets)) {
|
|
|
+ flag = true;
|
|
|
}
|
|
|
}
|
|
|
if (!flag) {
|
|
|
@@ -100,7 +111,8 @@ public class OrderInfoService {
|
|
|
}
|
|
|
|
|
|
BigDecimal personalAmount = sysConfigService.getBigDecimal("PERSONAL_AMOUNT");
|
|
|
- user.setAmount(user.getAmount().add(personalAmount));
|
|
|
+ parentUser.setAmount(parentUser.getAmount().add(personalAmount));
|
|
|
+ userRepo.save(parentUser);
|
|
|
|
|
|
// 个人佣金流水
|
|
|
commissionRecordRepo.save(CommissionRecord.builder()
|
|
|
@@ -108,7 +120,34 @@ public class OrderInfoService {
|
|
|
.amount(personalAmount)
|
|
|
.payMethod(PayMethod.YUE)
|
|
|
.fromUserId(userId)
|
|
|
- .transactionType(TransactionType.INCOME)
|
|
|
+ .transactionType(TransactionType.PROMOTE)
|
|
|
+ .transactionId(transactionId)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ 公司分销
|
|
|
+ */
|
|
|
+ public void companyDis(Long companyId, String transactionId, Long userId) {
|
|
|
+ Company company = companyRepo.findById(companyId).orElseThrow(new BusinessException("无企业"));
|
|
|
+ // 用户余额
|
|
|
+ User user = userRepo.findById(company.getUserId()).orElseThrow(new BusinessException("无用户"));
|
|
|
+ BigDecimal companyAmount = sysConfigService.getBigDecimal("COMPANY_AMOUNT");
|
|
|
+ user.setAmount(user.getAmount().add(companyAmount));
|
|
|
+ userRepo.save(user);
|
|
|
+ // 公司余额
|
|
|
+ company.setAmount(company.getAmount().add(companyAmount));
|
|
|
+ companyRepo.save(company);
|
|
|
+
|
|
|
+ // 佣金流水
|
|
|
+ commissionRecordRepo.save(CommissionRecord.builder()
|
|
|
+ .userId(company.getUserId())
|
|
|
+ .amount(companyAmount)
|
|
|
+ .payMethod(PayMethod.YUE)
|
|
|
+ .fromUserId(userId)
|
|
|
+ .transactionType(TransactionType.EMPLOYEES_PROMOTE)
|
|
|
.transactionId(transactionId)
|
|
|
.build());
|
|
|
|