|
|
@@ -7,10 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.jiashanxia.domain.*;
|
|
|
import com.izouma.jiashanxia.domain.Package;
|
|
|
-import com.izouma.jiashanxia.dto.GoodsDTO;
|
|
|
-import com.izouma.jiashanxia.dto.OrderInfoVO;
|
|
|
-import com.izouma.jiashanxia.dto.PackageGoodsDTO;
|
|
|
-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.*;
|
|
|
@@ -43,6 +40,7 @@ public class OrderInfoService {
|
|
|
private final WithdrawService withdrawService;
|
|
|
private final UserPackageFlowRepo userPackageFlowRepo;
|
|
|
private final UserService userService;
|
|
|
+ private final StockRepo stockRepo;
|
|
|
|
|
|
public Page<OrderInfo> all(PageQuery pageQuery) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
|
@@ -89,52 +87,37 @@ public class OrderInfoService {
|
|
|
/*
|
|
|
下订单
|
|
|
*/
|
|
|
- public OrderInfo createOrder1(OrderInfo orderInfo) {
|
|
|
- Package aPackage = packageRepo.findById(orderInfo.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
+ public OrderInfo createOrder1(CreateOrder createOrder) {
|
|
|
+ Package aPackage = packageRepo.findById(createOrder.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
String localTime = df.format(LocalDateTime.now());
|
|
|
- String num = String.format("%05d", orderInfoRepo.orderNum() + 1);
|
|
|
-
|
|
|
-// if (ObjectUtil.isNotEmpty(orderInfo.getSpecification())) {
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-// OrderInfo order = OrderInfo.builder()
|
|
|
-// .packageId(packageId)
|
|
|
-// .status(OrderInfoStatus.UNPAID)
|
|
|
-// .userId(userId)
|
|
|
-// .payMethod(payMethod)
|
|
|
-// .orderNumber(localTime + num)
|
|
|
-// .price(aPackage.getAmount())
|
|
|
-// .name(aPackage.getName())
|
|
|
-// .repeatedly(aPackage.isRepeatedly())
|
|
|
-// .num(1)
|
|
|
-// .build();
|
|
|
- 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;
|
|
|
+ String orderNum = String.format("%05d", orderInfoRepo.orderNum() + 1);
|
|
|
+ BigDecimal price = aPackage.getAmount();
|
|
|
+ OrderInfo order = OrderInfo.builder()
|
|
|
+ .packageId(createOrder.getPackageId())
|
|
|
+ .status(OrderInfoStatus.UNPAID)
|
|
|
+ .userId(createOrder.getUserId())
|
|
|
+ .payMethod(createOrder.getPayMethod())
|
|
|
+ .orderNumber(localTime + orderNum)
|
|
|
+ .name(aPackage.getName())
|
|
|
+ .repeatedly(aPackage.isRepeatedly())
|
|
|
+ .num(createOrder.getNum())
|
|
|
+ .build();
|
|
|
+ if (ObjectUtil.isNotEmpty(createOrder.getStockId())) {
|
|
|
+ // 保存规格
|
|
|
+ Stock stock = stockRepo.findById(createOrder.getStockId()).orElseThrow(new BusinessException("无规格"));
|
|
|
+ if (createOrder.getNum() > stock.getInventory()) {
|
|
|
+ throw new BusinessException("无库存");
|
|
|
+ }
|
|
|
+ order.setStockId(createOrder.getStockId());
|
|
|
+ order.setPrice(stock.getPrice().multiply(BigDecimal.valueOf(createOrder.getNum())));
|
|
|
+ order.setDay(stock.getDay());
|
|
|
+ order.setSpecification(stock.getSpecification());
|
|
|
+ price = stock.getPrice();
|
|
|
}
|
|
|
- // 保存
|
|
|
- user.setParent(parent);
|
|
|
- userRepo.save(user);
|
|
|
+ order.setPrice(price.multiply(new BigDecimal(createOrder.getNum())));
|
|
|
+
|
|
|
+ return orderInfoRepo.save(order);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -177,6 +160,12 @@ public class OrderInfoService {
|
|
|
order.setPaidAt(LocalDateTime.now());
|
|
|
orderInfoRepo.save(order);
|
|
|
|
|
|
+ if (ObjectUtil.isNotEmpty(order.getStockId())) {
|
|
|
+ Stock stock = stockRepo.findById(order.getStockId()).orElseThrow(new BusinessException("无规格"));
|
|
|
+ stock.setInventory(stock.getInventory() - order.getNum());
|
|
|
+ stockRepo.save(stock);
|
|
|
+ }
|
|
|
+
|
|
|
Long userId = order.getUserId();
|
|
|
|
|
|
// 套餐内商品
|
|
|
@@ -196,10 +185,10 @@ public class OrderInfoService {
|
|
|
|
|
|
// 用户
|
|
|
User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
- if (!user.isVip()) {
|
|
|
- user.setVip(true);
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
+// if (!user.isVip()) {
|
|
|
+// user.setVip(true);
|
|
|
+// userRepo.save(user);
|
|
|
+// }
|
|
|
|
|
|
Long parent = user.getParent();
|
|
|
// 用户id和上级id相同
|
|
|
@@ -476,6 +465,18 @@ public class OrderInfoService {
|
|
|
boolean isMaker = true;
|
|
|
boolean isHead = true;
|
|
|
|
|
|
+ // 收益为0元 直接跳出
|
|
|
+ if (BigDecimal.ZERO.compareTo(maker) >= 0) {
|
|
|
+ isMaker = false;
|
|
|
+ }
|
|
|
+ if (BigDecimal.ZERO.compareTo(general) >= 0) {
|
|
|
+ isGeneral = false;
|
|
|
+ }
|
|
|
+ if (BigDecimal.ZERO.compareTo(head) >= 0) {
|
|
|
+ isHead = false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
CommissionRecord record = CommissionRecord.builder()
|
|
|
.userId(parent.getId())
|
|
|
.fromUserId(userId)
|
|
|
@@ -484,6 +485,9 @@ public class OrderInfoService {
|
|
|
.build();
|
|
|
|
|
|
while (parent != null) {
|
|
|
+ if (!isGeneral && !isMaker && !isHead) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
switch (parent.getMember()) {
|
|
|
case MAKER:
|
|
|
if (isMaker) {
|
|
|
@@ -546,7 +550,7 @@ public class OrderInfoService {
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- if (!isGeneral && !isMaker) {
|
|
|
+ if (ObjectUtil.isNull(parent.getParent())) {
|
|
|
return;
|
|
|
}
|
|
|
parent = userRepo.findById(parent.getParent()).orElse(null);
|