dever пре 3 година
родитељ
комит
3549acc8ef
3 измењених фајлова са 43 додато и 0 уклоњено
  1. 13 0
      database/relation.php
  2. 23 0
      lib/Relation.php
  3. 7 0
      src/Api.php

+ 13 - 0
database/relation.php

@@ -116,5 +116,18 @@ return array
 			'order' => array('id' => 'desc'),
 			'col' => '*',
 		),
+
+		'getParent' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'to_uid' => 'yes',
+				'level' => array('yes', '<='),
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => '*',
+		),
 	)
 );

+ 23 - 0
lib/Relation.php

@@ -34,6 +34,29 @@ class Relation
         }
     }
 
+    # 重置上级
+    public function resetParent($uid, $parent)
+    {
+        Dever::db('invite/relation')->delete(array('to_uid' => $uid));
+        $this->set($parent, $uid);
+
+        $child = $this->getChild($uid);
+        if ($child) {
+            foreach ($child as $k => $v) {
+
+                $child_parent = $this->getParentAll($v['uid']);
+                if ($child_parent) {
+                    foreach ($child_parent as $k1 => $v1) {
+                        if ($v1['level'] > $v['level']) {
+                            Dever::db('invite/relation')->update(array('where_id' => $v['id'], 'uid' => $parent));
+                        }
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
     # 清理邀请关系
     public function dropParent($uid, $parent)
     {

+ 7 - 0
src/Api.php

@@ -59,6 +59,13 @@ class Api
 		return true;
 	}
 
+    # 重新设置关系
+    public function resetRelation($uid, $parent)
+    {
+        $relation = new Relation();
+        return $relation->resetParent($uid, $parent);
+    }
+
 	# 删除邀请关系
 	public function dropRelation($uid, $parent)
 	{