= $config[$team_level_id]['direct']) { $result = true; $team_level_id += 1; self::setIsUpLevelParent($user_id, $config); } }else{ //组合套数 $groupCount = UserPledge::getPledgeCount($user_id) + 1; //直推 $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count(); if($teamCount >= $config[$team_level_id]['direct'] && $groupCount >= $config[$team_level_id]['num']){ $result = true; $team_level_id += 1; //+1 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 $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(); } } } } //降级 public static function setIsOuLevelSave($user_id, $team_level_id, $address_level, $parent_id) { $config = config('team_level_where'); $result = false; //组合套数 $groupCount = UserPledge::getPledgeCount($user_id) -1 ; if($team_level_id == 1 && ($groupCount == 0 || $address_level < $config[0]['direct'])){ $result = true; $team_level_id = 0; self::setIsOuLevelParent($parent_id, $config); } if($team_level_id > 1){ //直推 $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id', $team_level_id)->count(); if($teamCount < $config[$team_level_id]['direct'] && $groupCount < $config[$team_level_id]['num']){ $result = true; $team_level_id -= 1; self::setIsOuLevelParent($parent_id, $config); } } return $result? UserModel::where('id', $user_id)->update(['team_level_id'=> $team_level_id]): false; } //上级降低级 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(); } } } } //发放层级收益 public static function setTeamLevelIncome(int $user_id, float $num, int $team_level_id, string $asset, string $action) { $config = config('team_level_where'); $team_level_id = $team_level_id - 1; $paths = UserPathModel::where('user_id', $user_id)->where('distance', '<=', $config[$team_level_id]['level'])->order('distance', 'asc')->column('parent_id'); $income = bcmul($num, config('team_level_inc'), 2); //收益 if(count($paths) > 0 && $income > 0){ //余额记录 foreach($paths as $pathId){ if(!empty(Loader::model('UserModel')::getTeamLevelId($pathId))) { Loader::model('LedgerWalletModel')->changeWalletAccount($pathId, $asset, $income, $action, $user_id); } } } return true; } //判断发放茶宝数量 public static function getFrozenIsChabao($token, $frozen){ //标记茶宝 if(bccomp(bcmul($frozen, config('team_level_inc'), 6) , 0.0001, 6) == -1) { return [$token, Asset::TOKEN, LedgerTokenChangeModel::TeamLevel]; }else{ //标记茶宝 return [$frozen, Asset::FROZEN, LedgerFrozenChangeModel::TeamLevel]; } } }