|
|
@@ -1012,6 +1012,37 @@ class StoreOrder extends BaseModel
|
|
|
}
|
|
|
|
|
|
//获取所有上级id
|
|
|
+// public static function get_spread_user($id, $init = true, $parentMap = null)
|
|
|
+// {
|
|
|
+// if ($init) {
|
|
|
+// // 获取所有用户的上级映射 (uid => spread_uid)
|
|
|
+// $us = User::column('spread_uid', 'uid');
|
|
|
+// $parentMap = $us; // 存储 uid->上级ID 的映射
|
|
|
+// $id = (array)$id; // 确保ID转为数组
|
|
|
+// }
|
|
|
+//
|
|
|
+// $result = []; // 存储所有上级ID
|
|
|
+// $visited = []; // 防止循环引用
|
|
|
+// $queue = (array)$id; // 初始化队列
|
|
|
+//
|
|
|
+// while (!empty($queue)) {
|
|
|
+// $current = array_shift($queue); // 取出当前用户ID
|
|
|
+//
|
|
|
+// // 如果当前用户未处理过且有上级
|
|
|
+// if (!isset($visited[$current]) && isset($parentMap[$current]) && $parentMap[$current] > 0) {
|
|
|
+// $parentId = $parentMap[$current]; // 获取直接上级ID
|
|
|
+// $visited[$current] = true; // 标记当前用户已访问
|
|
|
+//
|
|
|
+// // 避免重复处理
|
|
|
+// if (!isset($visited[$parentId])) {
|
|
|
+// $result[] = $parentId; // 添加到结果
|
|
|
+// $queue[] = $parentId; // 将上级加入队列继续查找
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return array_unique($result); // 返回去重后的上级ID列表
|
|
|
+// }
|
|
|
public static function get_spread_user($id, $init = true, $parentMap = null)
|
|
|
{
|
|
|
if ($init) {
|
|
|
@@ -1035,9 +1066,13 @@ class StoreOrder extends BaseModel
|
|
|
|
|
|
// 避免重复处理
|
|
|
if (!isset($visited[$parentId])) {
|
|
|
- $result[] = $parentId; // 添加到结果
|
|
|
+ $result[] = $current; // 修改:首先添加自己
|
|
|
+ $result[] = $parentId; // 然后添加上级
|
|
|
$queue[] = $parentId; // 将上级加入队列继续查找
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $result[] = $current; // 如果没有上级,添加自己
|
|
|
+ $visited[$current] = true; // 标记当前用户已访问
|
|
|
}
|
|
|
}
|
|
|
|