|
|
@@ -6,10 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.izouma.jiashanxia.domain.Package;
|
|
|
import com.izouma.jiashanxia.domain.*;
|
|
|
-import com.izouma.jiashanxia.dto.CreateOrder;
|
|
|
-import com.izouma.jiashanxia.dto.OrderInfoDTO;
|
|
|
-import com.izouma.jiashanxia.dto.OrderInfoVO;
|
|
|
-import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
+import com.izouma.jiashanxia.dto.*;
|
|
|
import com.izouma.jiashanxia.enums.*;
|
|
|
import com.izouma.jiashanxia.exception.BusinessException;
|
|
|
import com.izouma.jiashanxia.repo.*;
|
|
|
@@ -35,19 +32,22 @@ import java.util.stream.Collectors;
|
|
|
@AllArgsConstructor
|
|
|
public class OrderInfoService {
|
|
|
|
|
|
- private final OrderInfoRepo orderInfoRepo;
|
|
|
- private final PackageRepo packageRepo;
|
|
|
- private final PackageGoodsRepo packageGoodsRepo;
|
|
|
- private final UserRepo userRepo;
|
|
|
- private final SysConfigService sysConfigService;
|
|
|
- private final CommissionRecordRepo commissionRecordRepo;
|
|
|
- private final UserPackageService userPackageService;
|
|
|
- private final CompanyRepo companyRepo;
|
|
|
- private final WithdrawService withdrawService;
|
|
|
- private final UserService userService;
|
|
|
- private final StockRepo stockRepo;
|
|
|
- private final SmsService smsService;
|
|
|
- private final ShoppingCartRepo shoppingCartRepo;
|
|
|
+ private final OrderInfoRepo orderInfoRepo;
|
|
|
+ private final PackageRepo packageRepo;
|
|
|
+ private final PackageGoodsRepo packageGoodsRepo;
|
|
|
+ private final UserRepo userRepo;
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
+ private final CommissionRecordRepo commissionRecordRepo;
|
|
|
+ private final UserPackageService userPackageService;
|
|
|
+ private final CompanyRepo companyRepo;
|
|
|
+ private final WithdrawService withdrawService;
|
|
|
+ private final UserService userService;
|
|
|
+ private final StockRepo stockRepo;
|
|
|
+ private final SmsService smsService;
|
|
|
+ private final ShoppingCartRepo shoppingCartRepo;
|
|
|
+ private final CommissionRecordService commissionRecordService;
|
|
|
+ private final CouponRepo couponRepo;
|
|
|
+ private final UserCouponRepo userCouponRepo;
|
|
|
|
|
|
public Page<OrderInfo> all(PageQuery pageQuery) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
|
@@ -163,11 +163,6 @@ 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);
|
|
|
-// }
|
|
|
|
|
|
// 加入套餐商品
|
|
|
userPackageService.joinUserPackage(userId, setGoodsList, order.getNum(), PackageType.PERSONAL);
|
|
|
@@ -203,7 +198,6 @@ public class OrderInfoService {
|
|
|
|
|
|
Long userId = order.getUserId();
|
|
|
|
|
|
-
|
|
|
if (order.isRepeatedly()) {
|
|
|
// 套餐内商品
|
|
|
List<PackageGoods> packageGoodsList = packageGoodsRepo.findAllByPackageId(order.getPackageId());
|
|
|
@@ -320,7 +314,7 @@ public class OrderInfoService {
|
|
|
BigDecimal amount = orderInfo.getPrice();
|
|
|
|
|
|
// 无限级找创客/108将/团长
|
|
|
-// this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
|
|
|
+ this.makerGeneralDistribution(parentUser, amount, orderInfo.getId(), userId, aPackage);
|
|
|
|
|
|
String transactionId = orderInfo.getId().toString();
|
|
|
|
|
|
@@ -338,7 +332,6 @@ public class OrderInfoService {
|
|
|
}
|
|
|
BigDecimal amount = orderInfo.getPrice();
|
|
|
|
|
|
-
|
|
|
Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
//团长直推钱
|
|
|
BigDecimal headRatio = aPackage.getPersonalRatio0();
|
|
|
@@ -368,7 +361,7 @@ public class OrderInfoService {
|
|
|
.payMethod(PayMethod.YUE)
|
|
|
.fromUserId(userId)
|
|
|
.transactionType(TransactionType.PROMOTE)
|
|
|
- .transactionId(orderInfo.getTransactionId())
|
|
|
+ .transactionId(orderInfo.getId().toString())
|
|
|
.build();
|
|
|
commissionRecordRepo.save(commissionRecord);
|
|
|
}
|
|
|
@@ -444,11 +437,14 @@ public class OrderInfoService {
|
|
|
if (ObjectUtil.isNull(one)) {
|
|
|
return;
|
|
|
}
|
|
|
+ this.getDistribution(orderInfo, one, 1, balanceAmount, aPackage, TransactionType.PROMOTE);
|
|
|
+ } else {
|
|
|
+ this.getDistribution(orderInfo, one, 1, balanceAmount, aPackage, TransactionType.SELF_PURCHASE);
|
|
|
}
|
|
|
- this.getDistribution(orderInfo, one, 1, balanceAmount, aPackage);
|
|
|
+
|
|
|
two = this.getParent(one);
|
|
|
if (ObjectUtil.isNotNull(two)) {
|
|
|
- this.getDistribution(orderInfo, two, 2, balanceAmount, aPackage);
|
|
|
+ this.getDistribution(orderInfo, two, 2, balanceAmount, aPackage, TransactionType.CHILD_PROMOTE);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -466,8 +462,8 @@ public class OrderInfoService {
|
|
|
}
|
|
|
|
|
|
// 用户得到的分销
|
|
|
- private void getDistribution(OrderInfo orderInfo, User user, int level, BigDecimal balance, Package aPackage) {
|
|
|
- BigDecimal amount;
|
|
|
+ private void getDistribution(OrderInfo orderInfo, User user, int level, BigDecimal balance, Package aPackage, TransactionType type) {
|
|
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
|
|
|
boolean separateDis = aPackage.isSeparateDistribution();
|
|
|
// 个人佣金流水
|
|
|
@@ -475,8 +471,8 @@ public class OrderInfoService {
|
|
|
.userId(user.getId())
|
|
|
.payMethod(PayMethod.YUE)
|
|
|
.fromUserId(orderInfo.getUserId())
|
|
|
- .transactionType(TransactionType.PROMOTE)
|
|
|
- .transactionId(orderInfo.getTransactionId())
|
|
|
+ .transactionType(type)
|
|
|
+ .transactionId(orderInfo.getId().toString())
|
|
|
.build();
|
|
|
|
|
|
switch (user.getMember()) {
|
|
|
@@ -488,13 +484,8 @@ public class OrderInfoService {
|
|
|
BigDecimal personalRatio0 = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
amount = balance.multiply(personalRatio0);
|
|
|
}
|
|
|
- if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
// 加用户余额
|
|
|
- user.setAmount(user.getAmount().add(amount));
|
|
|
- // 直推类型
|
|
|
- commission.setTransactionType(TransactionType.PROMOTE);
|
|
|
+// user.setAmount(user.getAmount().add(amount));
|
|
|
} else {
|
|
|
if (separateDis && ObjectUtil.isNotEmpty(aPackage.getPersonalRatio1())) {
|
|
|
amount = balance.multiply(aPackage.getPersonalRatio1());
|
|
|
@@ -502,15 +493,12 @@ public class OrderInfoService {
|
|
|
BigDecimal personalRatio1 = sysConfigService.getBigDecimal("PERSONAL_RATIO_1");
|
|
|
amount = balance.multiply(personalRatio1);
|
|
|
}
|
|
|
- if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
// 二级收益暂存
|
|
|
- user.setCacheAmount(user.getCacheAmount().add(amount));
|
|
|
- // 间推类型
|
|
|
- commission.setTransactionType(TransactionType.CHILD_PROMOTE);
|
|
|
+// user.setCacheAmount(user.getCacheAmount().add(amount));
|
|
|
+ }
|
|
|
+ if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
- userRepo.save(user);
|
|
|
commission.setAmount(amount);
|
|
|
commissionRecordRepo.save(commission);
|
|
|
break;
|
|
|
@@ -522,11 +510,6 @@ public class OrderInfoService {
|
|
|
BigDecimal personalRatio0 = sysConfigService.getBigDecimal("BIG_EXPERT_RATIO_0");
|
|
|
amount = balance.multiply(personalRatio0);
|
|
|
}
|
|
|
- if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 直推类型
|
|
|
- commission.setTransactionType(TransactionType.PROMOTE);
|
|
|
} else {
|
|
|
if (separateDis && ObjectUtil.isNotEmpty(aPackage.getBigExpertRatio1())) {
|
|
|
amount = balance.multiply(aPackage.getBigExpertRatio1());
|
|
|
@@ -534,20 +517,21 @@ public class OrderInfoService {
|
|
|
BigDecimal personalRatio1 = sysConfigService.getBigDecimal("BIG_EXPERT_RATIO_1");
|
|
|
amount = balance.multiply(personalRatio1);
|
|
|
}
|
|
|
- if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 间推类型
|
|
|
- commission.setTransactionType(TransactionType.CHILD_PROMOTE);
|
|
|
}
|
|
|
- user.setAmount(user.getAmount().add(amount));
|
|
|
- userRepo.save(user);
|
|
|
+ if (BigDecimal.ZERO.compareTo(amount) <= 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+// user.setAmount(user.getAmount().add(amount));
|
|
|
+// userRepo.save(user);
|
|
|
commission.setAmount(amount);
|
|
|
commissionRecordRepo.save(commission);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ // 全部放代入帐
|
|
|
+ user.setCacheAmount(user.getCacheAmount().add(amount));
|
|
|
+ userRepo.save(user);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -618,7 +602,6 @@ public class OrderInfoService {
|
|
|
.transactionType(TransactionType.EMPLOYEES_PROMOTE)
|
|
|
.transactionId(transactionId)
|
|
|
.build());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -849,4 +832,47 @@ public class OrderInfoService {
|
|
|
});
|
|
|
return dto;
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ 核销
|
|
|
+ */
|
|
|
+ public OrderInfo writeOff(Long id, Long writeOffUserId) {
|
|
|
+
|
|
|
+ // 核销订单类的
|
|
|
+ OrderInfo orderInfo = orderInfoRepo.findById(id)
|
|
|
+ .orElseThrow(new BusinessException("无订单"));
|
|
|
+
|
|
|
+ if (orderInfo.getUserId().equals(writeOffUserId)) {
|
|
|
+ throw new BusinessException("不可自己核销自己");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OrderInfoStatus.USED.equals(orderInfo.getStatus())) {
|
|
|
+ throw new BusinessException("已核销");
|
|
|
+ }
|
|
|
+
|
|
|
+ orderInfo.setStatus(OrderInfoStatus.USED);
|
|
|
+ orderInfo.setWriteOffUserId(writeOffUserId);
|
|
|
+ orderInfoRepo.save(orderInfo);
|
|
|
+
|
|
|
+ // 上级分销变 可提现
|
|
|
+ commissionRecordService.canWithdraw(id);
|
|
|
+
|
|
|
+ // 获得优惠券
|
|
|
+ Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
+ if (CollUtil.isNotEmpty(aPackage.getCouponId())) {
|
|
|
+ List<Coupon> coupons = couponRepo.findAllByIdInAndPeriodAfter(aPackage.getCouponId(), LocalDateTime
|
|
|
+ .now());
|
|
|
+ if (CollUtil.isNotEmpty(coupons)) {
|
|
|
+ UserCoupon build = UserCoupon.builder()
|
|
|
+ .period(coupons.get(0).getPeriod())
|
|
|
+ .couponId(coupons.get(0).getId())
|
|
|
+ .isUse(false)
|
|
|
+ .userId(orderInfo.getUserId())
|
|
|
+ .build();
|
|
|
+ userCouponRepo.save(build);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return orderInfo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|