|
|
@@ -4,8 +4,10 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
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;
|
|
|
@@ -39,6 +41,7 @@ public class OrderInfoService {
|
|
|
private final UserPackageService userPackageService;
|
|
|
private final CompanyRepo companyRepo;
|
|
|
private final WithdrawService withdrawService;
|
|
|
+ private final UserPackageFlowRepo userPackageFlowRepo;
|
|
|
|
|
|
public Page<OrderInfo> all(PageQuery pageQuery) {
|
|
|
pageQuery.setSort("createdAt,desc");
|
|
|
@@ -76,6 +79,7 @@ public class OrderInfoService {
|
|
|
.orderNumber(localTime + num)
|
|
|
.price(aPackage.getAmount())
|
|
|
.name(aPackage.getName())
|
|
|
+ .repeatedly(aPackage.isRepeatedly())
|
|
|
.num(1)
|
|
|
.build();
|
|
|
return orderInfoRepo.save(order);
|
|
|
@@ -113,6 +117,42 @@ public class OrderInfoService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void completed1(Long orderInfoId, String transactionId) {
|
|
|
+ // 修改订单状态
|
|
|
+ OrderInfo order = orderInfoRepo.findById(orderInfoId).orElseThrow(new BusinessException("无订单"));
|
|
|
+ order.setStatus(OrderInfoStatus.PAID);
|
|
|
+ order.setTransactionId(transactionId);
|
|
|
+ order.setPaidAt(LocalDateTime.now());
|
|
|
+ orderInfoRepo.save(order);
|
|
|
+
|
|
|
+ Long userId = order.getUserId();
|
|
|
+
|
|
|
+ // 套餐内商品
|
|
|
+ Package aPackage = packageRepo.findById(order.getPackageId()).orElseThrow(new BusinessException("无套餐"));
|
|
|
+ List<PackageGoods> packageGoodsList = packageGoodsRepo.findAllByPackageId(order.getPackageId());
|
|
|
+ if (order.isRepeatedly()) {
|
|
|
+ // 多次使用加入套餐余额
|
|
|
+ userPackageService.joinUserPackage1(userId, packageGoodsList, order.getNum());
|
|
|
+ }
|
|
|
+ // 记录套餐流水 (没有*数量)
|
|
|
+ List<GoodsDTO> goodsDTOS = JSONObject.parseArray(JSONObject.toJSONString(packageGoodsList), GoodsDTO.class);
|
|
|
+ userPackageFlowRepo.save(UserPackageFlow.builder()
|
|
|
+ .userId(userId)
|
|
|
+ .type(FlowType.BUY)
|
|
|
+ .orderInfoId(orderInfoId)
|
|
|
+ .content(goodsDTOS)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ // 用户
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+
|
|
|
+ // 用户id和上级id相同
|
|
|
+ if (user.getParent() != null && !userId.equals(user.getParent())) {
|
|
|
+ // 上级分销
|
|
|
+ this.distribution1(userId, user.getParent(), orderInfoId.toString(), order.getPrice(), aPackage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
取消订单
|
|
|
*/
|
|
|
@@ -153,7 +193,7 @@ public class OrderInfoService {
|
|
|
//分销级别
|
|
|
int distributor = sysConfigService.getInt("DISTRIBUTOR");
|
|
|
for (int i = 0; i < distributor; i++) {
|
|
|
- String name = "PERSONAL_AMOUNT_" + i;
|
|
|
+ String name = "PERSONAL_RATIO_" + i;
|
|
|
// 百分比
|
|
|
BigDecimal percentage = sysConfigService.getBigDecimal(name);
|
|
|
BigDecimal personalAmount = amount.multiply(percentage);
|
|
|
@@ -182,23 +222,36 @@ public class OrderInfoService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void distribution1(Long userId, Long parent, String transactionId, BigDecimal amount) {
|
|
|
+ public void distribution1(Long userId, Long parent, String transactionId, BigDecimal amount, Package aPackage) {
|
|
|
User parentUser = userRepo.findById(parent).orElseThrow(new BusinessException("无用户"));
|
|
|
Member member = parentUser.getMember();
|
|
|
+ if (Member.NORMAL.equals(member)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
//直推
|
|
|
// 达人分销
|
|
|
- BigDecimal directPush = sysConfigService.getBigDecimal("PERSONAL_AMOUNT_0");
|
|
|
+ BigDecimal directPush = aPackage.getPersonalRatio0();
|
|
|
+ // 套餐有额外分销
|
|
|
+ if (ObjectUtil.isNull(directPush)) {
|
|
|
+ directPush = sysConfigService.getBigDecimal("PERSONAL_RATIO_0");
|
|
|
+ }
|
|
|
BigDecimal directPushAmount = amount.multiply(directPush);
|
|
|
+
|
|
|
// 大达人分销
|
|
|
- BigDecimal bigExpertPush = sysConfigService.getBigDecimal("BIG_EXPERT_AMOUNT");
|
|
|
+ BigDecimal bigExpertPush = aPackage.getBigExpertRatio();
|
|
|
+ // 套餐有额外分销
|
|
|
+ if (ObjectUtil.isNotNull(bigExpertPush)) {
|
|
|
+ bigExpertPush = sysConfigService.getBigDecimal("BIG_EXPERT_RATIO");
|
|
|
+ }
|
|
|
BigDecimal bigExpertAmount = amount.multiply(bigExpertPush);
|
|
|
+
|
|
|
// 暂存 保存大达人
|
|
|
parentUser.setCacheAmount(bigExpertAmount);
|
|
|
userRepo.save(parentUser);
|
|
|
|
|
|
// 保存流水
|
|
|
- switch (member){
|
|
|
+ switch (member) {
|
|
|
case EXPERT:
|
|
|
CommissionRecord commissionRecord1 = CommissionRecord.builder()
|
|
|
.userId(parent)
|
|
|
@@ -218,9 +271,11 @@ public class OrderInfoService {
|
|
|
.transactionId(transactionId)
|
|
|
.build();
|
|
|
commissionRecordRepo.save(commissionRecord2);
|
|
|
+ break;
|
|
|
case BIG_EXPERT:
|
|
|
+ case MAKER:
|
|
|
CommissionRecord commissionRecord = CommissionRecord.builder()
|
|
|
- .userId(parentUser.getId())
|
|
|
+ .userId(parent)
|
|
|
.amount(bigExpertAmount)
|
|
|
.payMethod(PayMethod.YUE)
|
|
|
.fromUserId(userId)
|
|
|
@@ -242,12 +297,16 @@ public class OrderInfoService {
|
|
|
if (parentUser == null) {
|
|
|
return;
|
|
|
}
|
|
|
- if (Member.NORMAL.equals(member)) {
|
|
|
+ if (Member.NORMAL.equals(parentUser.getMember())) {
|
|
|
continue;
|
|
|
}
|
|
|
- String name = "PERSONAL_AMOUNT_" + i;
|
|
|
- // 百分比
|
|
|
- BigDecimal percentage = sysConfigService.getBigDecimal(name);
|
|
|
+ BigDecimal percentage = aPackage.getPersonalRatio1();
|
|
|
+ if (ObjectUtil.isNull(percentage)) {
|
|
|
+ String name = "PERSONAL_RATIO_" + i;
|
|
|
+ // 百分比
|
|
|
+ percentage = sysConfigService.getBigDecimal(name);
|
|
|
+ }
|
|
|
+
|
|
|
BigDecimal personalAmount = amount.multiply(percentage);
|
|
|
parentUser.setAmount(parentUser.getCacheAmount().add(personalAmount));
|
|
|
userRepo.save(parentUser);
|
|
|
@@ -258,7 +317,7 @@ public class OrderInfoService {
|
|
|
.amount(personalAmount)
|
|
|
.payMethod(PayMethod.YUE)
|
|
|
.fromUserId(userId)
|
|
|
- .transactionType(TransactionType.CHILDREN_PROMOTE)
|
|
|
+ .transactionType(TransactionType.CHILD_PROMOTE)
|
|
|
.transactionId(transactionId)
|
|
|
.build();
|
|
|
commissionRecordRepo.save(commissionRecord);
|
|
|
@@ -274,7 +333,7 @@ public class OrderInfoService {
|
|
|
// 用户余额
|
|
|
User user = userRepo.findById(company.getUserId()).orElseThrow(new BusinessException("无用户"));
|
|
|
// 百分比
|
|
|
- BigDecimal percentage = sysConfigService.getBigDecimal("COMPANY_AMOUNT");
|
|
|
+ BigDecimal percentage = sysConfigService.getBigDecimal("COMPANY_RATIO");
|
|
|
BigDecimal companyAmount = amount.multiply(percentage);
|
|
|
user.setAmount(user.getAmount().add(companyAmount));
|
|
|
userRepo.save(user);
|