= $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('id', $item)->find(); if($parent->team_level_id > 0 && $parent->team_level_id < 5){ //推广人数 $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) { $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($user_id, $config); } if($team_level_id > 1){ //直推 $teamCount = UserModel::where('parent_id', $user_id)->where('team_level_id','>=', $team_level_id)->count()-1; if($teamCount < $config[$team_level_id]['direct'] && $groupCount < $config[$team_level_id]['num']){ $result = true; $team_level_id -= 1; self::setIsOuLevelParent($user_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('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,string $asset, string $action) { $income = bcmul($num, config('team_level_inc'), 2); //收益 $parents_info = UserPathModel::where('p.user_id', $user_id) ->alias('p') ->join('user u', 'u.id = p.parent_id', 'left') ->field('u.id, u.address_level, u.team_level_id,u.parent_id, p.distance') ->where('u.team_level_id', '>', 0) ->order('p.distance asc') ->select(); if(empty($parents_info) || empty($income)) return true; //分享 1 个拿 3 层,分享 2 个拿 7 层 foreach ($parents_info as $parent){ $send_user_id = 0; //需要发放的会员ID列表 if($parent['team_level_id'] >= 1 && $parent['distance'] <= 3){ $send_user_id = $parent['id']; }else if($parent['team_level_id'] >= 2 && $parent['distance'] <= 7){ $send_user_id = $parent['id']; }else if($parent['team_level_id'] >= 3 && $parent['distance'] <= 13){ $send_user_id = $parent['id']; }else if($parent['team_level_id'] >= 4 && $parent['distance'] <= 21){ $send_user_id = $parent['id']; }else if($parent['team_level_id'] >= 5 && $parent['distance'] <= 31){ $send_user_id = $parent['id']; } if($send_user_id > 0) Loader::model('LedgerWalletModel')->changeWalletAccount($send_user_id, $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]; } } }