WIN-2308041133\Administrator 5 months ago
parent
commit
45df569308
1 changed files with 22 additions and 1 deletions
  1. 22 1
      app/common/model/user/GiftLevel.php

+ 22 - 1
app/common/model/user/GiftLevel.php

@@ -22,7 +22,7 @@ class GiftLevel extends BaseModel
     {
     {
         if (in_array($uid, $pass)) return true;
         if (in_array($uid, $pass)) return true;
         $user = User::find($uid);
         $user = User::find($uid);
-        $group_users = get_group_user($user);
+        $group_users = $this->get_group_user($user);
         //Todo 获取在$group_users内所有用户的消费情况
         //Todo 获取在$group_users内所有用户的消费情况
         $achievement = 0;
         $achievement = 0;
         //获取该用户购买过的礼包商品的全部订单
         //获取该用户购买过的礼包商品的全部订单
@@ -45,4 +45,25 @@ class GiftLevel extends BaseModel
         if ($spread) return $this->checkLevel($spread['id'], $pass);
         if ($spread) return $this->checkLevel($spread['id'], $pass);
         return true;
         return true;
     }
     }
+    public function get_group_user($id, $init = true, $members = null){
+        if ($init) {
+            $us = \app\common\model\user\User::column('spread_uid', 'uid');
+            $members = [];
+            foreach ($us as $k => $v) {
+                if ($v > 0)
+                    $members[$v][] = $k;
+            }
+            $id = [$id];
+        }
+        $arr = array();
+        foreach ($id as $v) {
+            $child = $members[$v] ?? [];
+            $arr = array_merge($arr, $child);
+        }
+        if (count($arr)) {
+            return array_merge($arr, get_group_user($arr, false, $members));
+        } else {
+            return $arr;
+        }
+    }
 }
 }