1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- *
- * User: anyluck
- * Date: 2020/6/4
- * Time: 10:43
- */
- namespace app\web\model;
- use app\common\model\User;
- class Team
- {
- // 团队
- // 给团队加人数
- public static function all_tem($user_id)
- {
- $user = User::cache(true, 60)->field("id,pid")->select()->toArray();
- $GetTeamMember = self::get_downline($user, $user_id);
- $count = 0;
- if ($GetTeamMember) {
- foreach ($GetTeamMember as $k => $v) {
- $count += 1;
- }
- }
- return $count;
- }
- public static function father($pid, $id)
- {
- $get_fu= self::get_fu($id);
- if ($get_fu){
- $get_id=array_column($get_fu,"id");
- $in_array=in_array($pid,$get_id);
- if ($in_array){
- return true;
- }else{// 没有不存在查看一下下级
- $user=User::field("id,pid")->cache(true,600)->select();
- $get_xia=self::get_downline($user->toArray(),$id);
- $get_xia_id=array_column($get_xia,"id");
- $in_arrays=in_array($pid,$get_xia_id);
- if ($in_arrays){
- return true;
- }else{
- return false;
- }
- }
- }
- }
- // 查找无限上级
- public static function get_fu($id)
- {
- static $data=[];
- if ($id){
- $where["id"]=$id;
- $user=User::where($where)->field("id,pid")->cache(true,600)->find();
- if ($user){
- $data[]=$user->toArray();
- if ($user->pid){
- self::get_fu($user->pid);
- }
- }
- }
- return $data;
- }
- //获取用户的所有下级ID
- public static function get_downline($data, $mid, $level = 0)
- {
- $arr = array();
- foreach ($data as $key => $v) {
- if ($v['pid'] == $mid) { //pid为0的是顶级分类
- $v['level'] = $level + 1;
- $arr[] = $v;
- $arr = array_merge($arr, self::get_downline($data, $v['id'], $level + 1));
- }
- }
- return $arr;
- }
- }
|