From 14c10d5021513463109aa800aeb3e8dbf479b05c Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期四, 28 八月 2025 10:58:11 +0800
Subject: [PATCH] update

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbOrderServiceImpl.java |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbOrderServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbOrderServiceImpl.java
index f02c5c7..336f207 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbOrderServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TbOrderServiceImpl.java
@@ -125,8 +125,8 @@
             order.setOutTradeNo(notifyResult.getOutTradeNo());
             order.setTransactionId(notifyResult.getTransactionId());
             TbCompany company = companyService.getById(order.getCompanyId());
-            // 生成记录  看是否分佣 金额 发布人
-            TbUser user = userService.getById(company.getUserId());
+            // 购买人  生成记录  看是否分佣 金额 发布人  如A用户售卖100元公司 C用户购买这个公司  B是C的上级 抽10%  平台抽成20%   那么A应得80  B得2  平台得18
+            TbUser user = userService.getById(order.getUserId());
             TbSystemConfig config = configService.getOne(new LambdaQueryWrapper<TbSystemConfig>().eq(TbSystemConfig::getType, 3));
             if(config!=null){
                 JSONObject jsonObject = JSONObject.parseObject(config.getContent());
@@ -134,19 +134,24 @@
                 BigDecimal userCommission = new BigDecimal(jsonObject.get("user").toString());
                 BigDecimal price = order.getPrice();
                 BigDecimal divide = platformCommission.divide(new BigDecimal("100"));
+                // 平台抽佣
                 BigDecimal platformCommissionMoney = divide.multiply(price).setScale(2, RoundingMode.HALF_UP);
 
                 // 购买人是否绑定了用户 且次数足够
                 if(StringUtils.isNotEmpty(user.getInviteId()) && user.getInviteNum()>0){
                     BigDecimal divide1 = userCommission.divide(new BigDecimal("100"));
-                    BigDecimal userCommissionMoney = divide1.multiply(price).setScale(2, RoundingMode.HALF_UP);
+                    BigDecimal userCommissionMoney = divide1.multiply(platformCommissionMoney).setScale(2, RoundingMode.HALF_UP);
                     order.setCommissionPrice(userCommissionMoney);
+
+                    platformCommissionMoney = platformCommissionMoney.subtract(userCommissionMoney);
+
                     if(userCommissionMoney.doubleValue()>0){
                         TbUser shareUser = userService.getById(user.getInviteId());
-                        BigDecimal add = shareUser.getBalance().add(order.getCommissionPrice());
-                        shareUser.setBalance(add);
-                        shareUser.updateById();
-
+                        if(shareUser!=null){
+                            BigDecimal add = shareUser.getBalance().add(order.getCommissionPrice());
+                            shareUser.setBalance(add);
+                            shareUser.updateById();
+                        }
                         TbAccountDetail accountDetail = new TbAccountDetail();
                         accountDetail.setUserId(user.getInviteId());
                         accountDetail.setType(1);

--
Gitblit v1.7.1