devolp 3 лет назад
Родитель
Сommit
7f3f78984f
1 измененных файлов с 18 добавлено и 10 удалено
  1. 18 10
      app/admin/logic/UserLogic.php

+ 18 - 10
app/admin/logic/UserLogic.php

@@ -11,6 +11,7 @@ use app\common\model\UserModel;
 use app\common\model\UserMoneyModel;
 use think\facade\Cache;
 use think\facade\Db;
+use function Qiniu\explodeUpToken;
 
 class UserLogic
 {
@@ -284,7 +285,7 @@ class UserLogic
                 $result = $this->modifypidByResetTopLevel($user['id'], $user['path'], $pid, $parentUser['path'], $prefixPath);
             } else {
                 // 正常,迭代修改下级
-                $result = $this->modifypidByUpdateNextLevel($user['id'], $user['path'], $pid, $parentUser['path']);
+                $result = $this->modifypidByUpdateNextLevel($user['id'], $user['pid'], $user['path'], $pid, $parentUser['path']);
             }
 
             if (!$result) {
@@ -301,6 +302,10 @@ class UserLogic
 
         // 升级,abcdef,e升级到b后 分为两种情况 1.abef 2.abcd
 
+        // 插入位置的 path 作为新的path
+        // 插入位置的 前一位的 作为新的pid
+        // 迭代修改父节点的子节点
+
         // 降级 abcdef,c降级到e后 分为两种情况 1. ecf 2.abcd
 
         // 插入 abcdef,插入j到b后 分为两种情况 1.abj 2.abcdef
@@ -467,16 +472,19 @@ class UserLogic
         return [false, null];
     }
 
-    private function modifypidByUpdateNextLevel($id, $path, $pid, $parentUserPath)
+    private function modifypidByUpdateNextLevel($id, $userPid, $path, $pid, $parentUserPath)
     {
-        $parentUserPathArr = explode(',', $parentUserPath);
-        $newUserPathArr    = $parentUserPathArr;
-        $newUserPathArr[]  = $pid;
-
-        $result = $this->iteraMidifyPathByPid($newUserPathArr, $id);
-        if (!$result) return false;
-        // 更新用户Pid,Path
-        return User::modifyUserPidAndPath($id, $pid, implode(',', $newUserPathArr));
+        $userPath = explode(',', $path);
+        // 上级的节点信息
+        User::modifyUserPidAndPath($pid, $userPid, $path);
+        $this->iteraMidifyPathByPid($userPath, $pid);
+
+        // 更新被修改的节点信息
+        $newUserPathArr   = $userPath;
+        $newUserPathArr[] = $pid;
+        User::modifyUserPidAndPath($id, $pid, implode(',', $newUserPathArr));
+        $this->iteraMidifyPathByPid($newUserPathArr, $id);
+        return true;
     }
 
     private function iteraMidifyPathByPid($newUserPathArr, $pid)