From 8acc98732aba58ad5c710f92d72e6fa5bf888d11 Mon Sep 17 00:00:00 2001
From: luofl <1442745593@qq.com>
Date: 星期一, 24 二月 2025 01:08:06 +0800
Subject: [PATCH] 修改物流信息导入模板

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java |  195 +++++++++++++++++++++++++-----------------------
 1 files changed, 100 insertions(+), 95 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java
index 3926014..86acfe2 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/CommissionServiceImpl.java
@@ -58,19 +58,19 @@
     @Transactional(rollbackFor = Exception.class)
     public void calculationCommission() {
         List<Order> list = orderService.list(new LambdaQueryWrapper<Order>().eq(Order::getIsCommission, 0).isNotNull(Order::getAfterSaleTime)
-                .eq(Order::getDelFlag, 0).last(" and after_sale_time <= now()"));
+                .eq(Order::getDelFlag, 0).ne(Order::getPayMethod, 3).last(" and after_sale_time <= now()"));
         List<Long> collect = list.stream().map(Order::getId).collect(Collectors.toList());
         if(collect.size() == 0){
             return;
         }
     
         for (Order order : list) {
-            if(order.getPayMethod() == 3){
-                continue;
-            }
             List<OrderGood> orderGoods = orderGoodService.list(new LambdaQueryWrapper<OrderGood>()
                     .eq(OrderGood::getOrderId, order.getId()));
             AppUser appUser = appUserClient.getAppUserById(order.getAppUserId());
+            if(null == appUser){
+                continue;
+            }
             //直推上级分佣金额
             BigDecimal ztsj_price = BigDecimal.ZERO;
             //直帮上级分佣金额
@@ -143,61 +143,65 @@
                 bdmdsj_point += orderGood.getBoundShopSuperiorsPoints();
             }
             //直推上级
-            AppUser inviteUser = appUserClient.getAppUserById(appUser.getInviteUserId());
-            if(null != inviteUser){
-                BigDecimal balance = inviteUser.getBalance();
-                Integer lavePoint = inviteUser.getLavePoint();
-                if(ztsj_price.compareTo(BigDecimal.ZERO) > 0){
-                    inviteUser.setTotalDistributionAmount(inviteUser.getTotalDistributionAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
-                    inviteUser.setBalance(inviteUser.getBalance().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
-                    inviteUser.setWithdrawableAmount(inviteUser.getWithdrawableAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
-                }
-                if(ztsj_point > 0){
-                    PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
-                    int earnPoint1 = 0;
-                    //计算可用积分比例
-                    if(null != pointSetting && 1 == pointSetting.getSharePointOpen()){
-                        earnPoint1 = new BigDecimal(ztsj_point).multiply(pointSetting.getSharePoint().divide(new BigDecimal(100))).intValue();
+            if(null != appUser.getInviteUserId()){
+                AppUser inviteUser = appUserClient.getAppUserById(appUser.getInviteUserId());
+                if(null != inviteUser){
+                    BigDecimal balance = inviteUser.getBalance();
+                    Integer lavePoint = inviteUser.getLavePoint();
+                    if(ztsj_price.compareTo(BigDecimal.ZERO) > 0){
+                        inviteUser.setTotalDistributionAmount(inviteUser.getTotalDistributionAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
+                        inviteUser.setBalance(inviteUser.getBalance().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
+                        inviteUser.setWithdrawableAmount(inviteUser.getWithdrawableAmount().add(ztsj_price).setScale(2, BigDecimal.ROUND_HALF_EVEN));
                     }
-                    inviteUser.setSharePoint(inviteUser.getSharePoint() + ztsj_point);
-                    inviteUser.setLavePoint(inviteUser.getLavePoint() + ztsj_point);
-                    inviteUser.setAvailablePoint(inviteUser.getAvailablePoint() + earnPoint1);
-                    inviteUser.setTotalAvailablePoint(inviteUser.getTotalAvailablePoint() + earnPoint1);
-                    if(null != pointSetting && 1 == pointSetting.getSharePointGift()){
-                        inviteUser.setTransferablePoint(inviteUser.getTransferablePoint() + earnPoint1);
+                    if(ztsj_point > 0){
+                        PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
+                        int earnPoint1 = 0;
+                        //计算可用积分比例
+                        if(null != pointSetting && 1 == pointSetting.getSharePointOpen()){
+                            earnPoint1 = new BigDecimal(ztsj_point).multiply(pointSetting.getSharePoint().divide(new BigDecimal(100))).intValue();
+                        }
+                        inviteUser.setSharePoint(inviteUser.getSharePoint() + ztsj_point);
+                        inviteUser.setLavePoint(inviteUser.getLavePoint() + ztsj_point);
+                        inviteUser.setAvailablePoint(inviteUser.getAvailablePoint() + earnPoint1);
+                        inviteUser.setTotalAvailablePoint(inviteUser.getTotalAvailablePoint() + earnPoint1);
+                        if(null != pointSetting && 1 == pointSetting.getSharePointGift()){
+                            inviteUser.setTransferablePoint(inviteUser.getTransferablePoint() + earnPoint1);
+                        }
+                        inviteUser.setTotalPoint(inviteUser.getTotalPoint() + ztsj_point);
                     }
-                    inviteUser.setTotalPoint(inviteUser.getTotalPoint() + ztsj_point);
-                }
-                appUserClient.editAppUserById(inviteUser);
-                //添加明细记录
-                if(!inviteUser.getBalance().equals(balance)){
-                    BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
-                    balanceChangeRecord.setAppUserId(inviteUser.getId());
-                    balanceChangeRecord.setOrderId(order.getId());
-                    balanceChangeRecord.setChangeType(4);
-                    balanceChangeRecord.setBeforeAmount(balance);
-                    balanceChangeRecord.setChangeAmount(ztsj_price);
-                    balanceChangeRecord.setAfterAmount(inviteUser.getBalance());
-                    balanceChangeRecord.setDelFlag(0);
-                    balanceChangeRecord.setCreateTime(LocalDateTime.now());
-                    balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord);
-                }
-                //添加积分明细
-                if(!inviteUser.getLavePoint().equals(lavePoint)){
-                    UserPoint userPoint = new UserPoint();
-                    userPoint.setType(2);
-                    userPoint.setHistoricalPoint(lavePoint);
-                    userPoint.setVariablePoint(ztsj_point);
-                    userPoint.setBalance(inviteUser.getLavePoint());
-                    userPoint.setCreateTime(LocalDateTime.now());
-                    userPoint.setAppUserId(inviteUser.getId());
-                    userPoint.setObjectId(order.getId());
-                    userPoint.setExtention(order.getOrderNumber());
-                    userPointClient.saveUserPoint(userPoint);
-                    //变更等级
-                    appUserClient.vipUpgrade(inviteUser.getId());
+                    appUserClient.editAppUserById(inviteUser);
+                    //添加明细记录
+                    if(!inviteUser.getBalance().equals(balance)){
+                        BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
+                        balanceChangeRecord.setAppUserId(inviteUser.getId());
+                        balanceChangeRecord.setVipId(inviteUser.getVipId());
+                        balanceChangeRecord.setOrderId(order.getId());
+                        balanceChangeRecord.setChangeType(4);
+                        balanceChangeRecord.setBeforeAmount(balance);
+                        balanceChangeRecord.setChangeAmount(ztsj_price);
+                        balanceChangeRecord.setAfterAmount(inviteUser.getBalance());
+                        balanceChangeRecord.setDelFlag(0);
+                        balanceChangeRecord.setCreateTime(LocalDateTime.now());
+                        balanceChangeRecordClient.saveBalanceChangeRecord(balanceChangeRecord);
+                    }
+                    //添加积分明细
+                    if(!inviteUser.getLavePoint().equals(lavePoint)){
+                        UserPoint userPoint = new UserPoint();
+                        userPoint.setType(2);
+                        userPoint.setHistoricalPoint(lavePoint);
+                        userPoint.setVariablePoint(ztsj_point);
+                        userPoint.setBalance(inviteUser.getLavePoint());
+                        userPoint.setCreateTime(LocalDateTime.now());
+                        userPoint.setAppUserId(inviteUser.getId());
+                        userPoint.setObjectId(order.getId());
+                        userPoint.setExtention(order.getOrderNumber());
+                        userPointClient.saveUserPoint(userPoint);
+                        //变更等级
+                        appUserClient.vipUpgrade(inviteUser.getId());
+                    }
                 }
             }
+
             //直帮上级
             AppUser superiorLeader = appUserClient.getSuperiorLeader(appUser.getId()).getData();
             if(null != superiorLeader){
@@ -229,6 +233,7 @@
                 if(!superiorLeader.getBalance().equals(balance)){
                     BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord();
                     balanceChangeRecord.setAppUserId(superiorLeader.getId());
+                    balanceChangeRecord.setVipId(superiorLeader.getVipId());
                     balanceChangeRecord.setOrderId(order.getId());
                     balanceChangeRecord.setChangeType(4);
                     balanceChangeRecord.setBeforeAmount(balance);
@@ -308,7 +313,7 @@
                 //添加积分明细
                 if(!shopAppUser.getLavePoint().equals(lavePoint)){
                     UserPoint userPoint = new UserPoint();
-                    userPoint.setType(9);
+                    userPoint.setType(8);
                     userPoint.setHistoricalPoint(lavePoint);
                     userPoint.setVariablePoint(hxmd_point);
                     userPoint.setBalance(shopAppUser.getLavePoint());
@@ -341,44 +346,47 @@
                 Technician technician = technicianClient.shopdetail(order.getTechnicianId()).getData();
                 if(null != technician){
                     AppUser technicianAppUser = appUserClient.getAppUserById(technician.getAppUserId());
-                    Integer lavePoint = technicianAppUser.getLavePoint();
-                    if(js_point > 0){
-                        PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
-                        int earnPoint1 = 0;
-                        //计算可用积分比例
-                        if(null != pointSetting && 1 == pointSetting.getPersonPointOpen()){
-                            earnPoint1 = new BigDecimal(js_point).multiply(pointSetting.getPersonPoint().divide(new BigDecimal(100))).intValue();
+                    if(null != technicianAppUser){
+                        Integer lavePoint = technicianAppUser.getLavePoint();
+                        if(js_point > 0){
+                            PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
+                            int earnPoint1 = 0;
+                            //计算可用积分比例
+                            if(null != pointSetting && 1 == pointSetting.getPersonPointOpen()){
+                                earnPoint1 = new BigDecimal(js_point).multiply(pointSetting.getPersonPoint().divide(new BigDecimal(100))).intValue();
+                            }
+                            technicianAppUser.setLavePoint(technicianAppUser.getLavePoint() + js_point);
+                            technicianAppUser.setAvailablePoint(technicianAppUser.getAvailablePoint() + earnPoint1);
+                            technicianAppUser.setTotalAvailablePoint(technicianAppUser.getTotalAvailablePoint() + earnPoint1);
+                            if(null != pointSetting && 1 == pointSetting.getPersonPointGift()){
+                                technicianAppUser.setTransferablePoint(technicianAppUser.getTransferablePoint() + earnPoint1);
+                            }
+                            technicianAppUser.setTotalPoint(technicianAppUser.getTotalPoint() + js_point);
+                            technicianAppUser.setTotalPerformancePoint(technicianAppUser.getTotalPerformancePoint() + js_point);
                         }
-                        technicianAppUser.setLavePoint(technicianAppUser.getLavePoint() + js_point);
-                        technicianAppUser.setAvailablePoint(technicianAppUser.getAvailablePoint() + earnPoint1);
-                        technicianAppUser.setTotalAvailablePoint(technicianAppUser.getTotalAvailablePoint() + earnPoint1);
-                        if(null != pointSetting && 1 == pointSetting.getPersonPointGift()){
-                            technicianAppUser.setTransferablePoint(technicianAppUser.getTransferablePoint() + earnPoint1);
+                        appUserClient.editAppUserById(technicianAppUser);
+                        //添加积分明细
+                        if(!technicianAppUser.getLavePoint().equals(lavePoint)){
+                            UserPoint userPoint = new UserPoint();
+                            userPoint.setType(10);
+                            userPoint.setHistoricalPoint(lavePoint);
+                            userPoint.setVariablePoint(js_point);
+                            userPoint.setBalance(technicianAppUser.getLavePoint());
+                            userPoint.setCreateTime(LocalDateTime.now());
+                            userPoint.setAppUserId(technicianAppUser.getId());
+                            userPoint.setObjectId(order.getId());
+                            userPoint.setExtention(order.getOrderNumber());
+                            userPointClient.saveUserPoint(userPoint);
+                            //变更等级
+                            appUserClient.vipUpgrade(technicianAppUser.getId());
                         }
-                        technicianAppUser.setTotalPoint(technicianAppUser.getTotalPoint() + js_point);
-                        technicianAppUser.setTotalPerformancePoint(technicianAppUser.getTotalPerformancePoint() + js_point);
                     }
-                    appUserClient.editAppUserById(technicianAppUser);
-                    //添加积分明细
-                    if(!technicianAppUser.getLavePoint().equals(lavePoint)){
-                        UserPoint userPoint = new UserPoint();
-                        userPoint.setType(10);
-                        userPoint.setHistoricalPoint(lavePoint);
-                        userPoint.setVariablePoint(js_point);
-                        userPoint.setBalance(technicianAppUser.getLavePoint());
-                        userPoint.setCreateTime(LocalDateTime.now());
-                        userPoint.setAppUserId(technicianAppUser.getId());
-                        userPoint.setObjectId(order.getId());
-                        userPoint.setExtention(order.getOrderNumber());
-                        userPointClient.saveUserPoint(userPoint);
-                        //变更等级
-                        appUserClient.vipUpgrade(technicianAppUser.getId());
-                    }
+                    
                 }
             }
             
-            //绑定门店分佣
-            Shop shop1 = shopClient.getShopById(appUser.getShopId()).getData();
+            //服务商分佣
+            Shop shop1 = shopClient.getServiceProvider(appUser.getId()).getData();
             if(null != shop1){
                 AppUser bdShopAppUser = appUserClient.getAppUserById(shop1.getAppUserId());
                 if(null != bdShopAppUser){
@@ -460,9 +468,8 @@
                 }
             }
     
-            //上级门店分佣
-            Integer pid = shop1.getPid();
-            Shop shop2 = shopClient.getShopById(pid).getData();
+            //高级服务商
+            Shop shop2 = shopClient.getSuperiorServiceProvider(order.getAppUserId()).getData();
             if(null != shop2){
                 AppUser sjShopAppUser = appUserClient.getAppUserById(shop2.getAppUserId());
                 if(null != sjShopAppUser){
@@ -527,7 +534,7 @@
                         //变更等级
                         appUserClient.vipUpgrade(sjShopAppUser.getId());
                     }
-        
+
                     if(!shop2.getLavePoint().equals(shopLavePoint)){
                         ShopPoint shopPoint = new ShopPoint();
                         shopPoint.setShopId(shop2.getId());
@@ -543,11 +550,9 @@
                     }
                 }
             }
+
             order.setIsCommission(1);
             orderService.updateById(order);
         }
-        
-
-
     }
 }

--
Gitblit v1.7.1