rabin 2 年之前
父节点
当前提交
597888cdc5
共有 1 个文件被更改,包括 19 次插入1 次删除
  1. 19 1
      lib/Relation.php

+ 19 - 1
lib/Relation.php

@@ -34,7 +34,25 @@ class Relation
         }
     }
 
-    # 重置上级
+    # 更换上级 效率较高
+    public function replaceParent($uid, $old_parent, $new_parent)
+    {
+        $info = Dever::db('invite/relation')->find(array('to_uid' => $uid, 'uid' => $old_parent));
+        if ($info) {
+            $state = Dever::db('invite/relation')->update(array('where_id' => $info['id'], 'uid' => $new_parent));
+            if ($state) {
+                $child = $this->getChild($uid, 1);
+                if ($child) {
+                    foreach ($child as $k => $v) {
+                        $this->replaceParent($v['to_uid'], $old_parent, $new_parent);
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    # 重置上级 效率较低
     public function resetParent($uid, $parent)
     {
         Dever::db('invite/relation')->delete(array('to_uid' => $uid));