afa 5 місяців тому
батько
коміт
57fac150d5
1 змінених файлів з 35 додано та 22 видалено
  1. 35 22
      application/api/logic/CommonLogic.php

+ 35 - 22
application/api/logic/CommonLogic.php

@@ -26,7 +26,7 @@ class CommonLogic
                   if($address_level >= $config[$team_level_id]['direct']) {
                         $result = true;
                         $team_level_id += 1;
-                        self::setIsUpLevelParent($parent_id, $config);
+                        self::setIsUpLevelParent($user_id, $config);
                   }
             }else{
                   //组合套数
@@ -36,23 +36,30 @@ class CommonLogic
                   if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){
                         $result = true;
                         $team_level_id += 1; //+1
-                        self::setIsUpLevelParent($parent_id, $config);
+                        self::setIsUpLevelParent($user_id, $config);
                   }
             }
             return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false;
       }
 
       //上级升级
-      public static function setIsUpLevelParent(int $parent_id, array $config){
-            $parent = UserModel::where('id', $parent_id)->find();
-            if($parent->team_level_id > 0){
-                  //推广人数
-                  $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
-                  //组合套数
-                  $groupCount = UserPledge::getPledgeCount($parent_id);
-                  if($teamCount >= $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
-                        $parent->team_level_id +=1;
-                        $parent->save();
+      public static function setIsUpLevelParent(int $user_id, array $config)
+      {
+            $pathId  = UserPathModel::where('user_id', $user_id)->order('distance', 'asc')->column('parent_id');
+            $userModel = Loader::model('UserModel');
+            $userPledge = Loader::model('UserPledge');
+            foreach ($pathId as $item) 
+            {
+                  $parent = $userModel::where('parent_id', $item)->find();
+                  if($parent->team_level_id > 0){
+                        //推广人数
+                        $teamCount = $userModel::where('parent_id', $item)->where('team_level_id', $parent->team_level_id)->count() +1;
+                        //组合套数
+                        $groupCount = $userPledge::getPledgeCount($item);
+                        if($teamCount >= $config[$parent->team_level_id]['direct'] && $groupCount >= $config[$parent->team_level_id]['num']){
+                              $parent->team_level_id +=1;
+                              $parent->save();
+                        }
                   }
             }
       }
@@ -84,16 +91,22 @@ class CommonLogic
       }
 
       //上级降低级
-      public static function setIsOuLevelParent(int $parent_id, array $config){
-            $parent = UserModel::where('id', $parent_id)->find();
-            if($parent->team_level_id > 0){
-                  //推广人数
-                  $teamCount = UserModel::where('parent_id', $parent_id)->where('team_level_id', $parent->team_level_id)->count() +1;
-                  //组合套数
-                  $groupCount = UserPledge::getPledgeCount($parent_id);
-                  if($teamCount < $config[$parent->team_level_id]['direct'] || $groupCount < $config[$parent->team_level_id]['num']){
-                        $parent->team_level_id -=1;
-                        $parent->save();
+      public static function setIsOuLevelParent(int $user_id, array $config){
+            $pathId  = UserPathModel::where('user_id', $user_id)->order('distance', 'asc')->column('parent_id');
+            $userModel = Loader::model('UserModel');
+            $userPledge= Loader::model('UserPledge');
+            foreach ($pathId as $item) 
+            {
+                  $parent = $userModel::where('parent_id', $item)->find();
+                  if($parent->team_level_id > 0){
+                        //推广人数
+                        $teamCount = $userModel::where('parent_id', $item)->where('team_level_id', $parent->team_level_id)->count()-1;
+                        //组合套数
+                        $groupCount = $userPledge::getPledgeCount($item);
+                        if($teamCount < $config[$parent->team_level_id]['direct'] || $groupCount < $config[$parent->team_level_id]['num']){
+                              $parent->team_level_id -=1;
+                              $parent->save();
+                        }
                   }
             }
       }