nickname); $today=Carbon::today()->toDateTimeString(); $month=Carbon::now()->firstOfMonth()->toDateTimeString(); $user_all=User::whereIn('cert_status',[3,6])->where('created_at','>',$today)->get(); $num=0; foreach ($user_all as $k=>$v){ if ($v->agent_id==null){ }else{ if ($v->agent_id==$user->id){ $num=$num+1; }else{ $arr=User::where('id',$v->agent_id)->first(); if ($arr->agent_id==$user->id){ $num=$num+1; } } } } $user_all=User::whereIn('cert_status',[3,6])->where('created_at','>',$month)->get(); $num_all=0; foreach ($user_all as $k=>$v){ if ($v->agent_id==null){ }else{ if ($v->agent_id==$user->id){ $num_all=$num_all+1; }else{ $arr=User::where('id',$v->agent_id)->first(); if ($arr->agent_id==$user->id){ $num_all=$num_all+1; } } } } $data=['num'=>$num,'all_num'=>$num_all]; // Log::error('{-0-----新增代理-------}'.json_encode($data)); return $this->success($data); } /* * 直属代理 * */ public function level_count(Request $request){ $user=Auth::user(); // $page=($request->page)-1; $data=[]; if ($request->has('page')){ $page=($request->page)-1; }else{ $page=0; } if ($request->type==0){ $user_all=User::where('agent_id',$user->id)->where('status',0)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->orderBy('id')->get(); $arr_per=[]; foreach ($user_all as $k=>$v){ $arr_per[$k]['id']=$v->id; $arr_per[$k]['avatar']=$v->headimgurl; $arr_per[$k]['nickname']=$v->nickname; $arr_per[$k]['level_name']=judge_level($v->level); } $num=count($arr_per); $num1=$num-$page*15; if ($num1>=15){ $j=15; }else{ $j=$num1; } for ($i=0;$i<$j;$i++){ $data[$i]['id']=$arr_per[$page*15+$i]['id']; $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar']; $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname']; $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name']; } // return $this->success($data); }else{ $user_all=User::where('agent_id',$user->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get(); // $user_all_1=User::where('agent_id',$user->id)->where('recom_id',$user->id)->where('status',0)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->orderBy('id')->get(); $user_data=[]; $arr_per=[]; $all=[]; $all_1=[]; // foreach ($user_all as $k=>$v){ // $arr=[]; // $arr_per[$k]['id']=$v->id; // $arr_per[$k]['avatar']=$v->headimgurl; // $arr_per[$k]['nickname']=$v->nickname; // $arr_per[$k]['level_name']=judge_level($v->level); // $user_per=User::where('agent_id',$v->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get(); // if ($user){ // foreach ($user_per as $key=>$value){ // $arr[$key]['id']=$value->id; // $arr[$key]['avatar']=$value->headimgurl; // $arr[$key]['nickname']=$value->nickname; // $arr[$key]['level_name']=judge_level($value->level); // } // $all=array_merge($all,$arr); // } // } // $user_data=array_merge($all,$arr_per); foreach ($user_all as $k=>$v){ $arr_per=[]; $user_per=User::where('agent_id',$v->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get(); if ($user){ foreach ($user_per as $key=>$value){ $arr_per[$key]['id']=$value->id; $arr_per[$key]['avatar']=$value->headimgurl; $arr_per[$key]['nickname']=$value->nickname; $arr_per[$key]['level_name']=judge_level($value->level); } $all_1=array_merge($all_1,$arr_per); } } $user_data=array_merge($user_data,$all_1); $num=count($user_data); $num1=$num-$page*15; if ($num1>=15){ $j=15; }else{ $j=$num1; } for ($i=0;$i<$j;$i++){ $data[$i]['id']=$user_data[$page*15+$i]['id']; $data[$i]['avatar']=$user_data[$page*15+$i]['avatar']; $data[$i]['nickname']=$user_data[$page*15+$i]['nickname']; $data[$i]['level_name']=$user_data[$page*15+$i]['level_name']; } // return $this->success($data); } $arr=$this->num_test(); // $re= $arr->original; $res=[ 'today_new'=>count($arr[0]), 'month_new'=>count($arr[1]), 'size'=>15, 'total'=>$num, 'list'=>$data ]; // Log::error('{-------代理数量-----}'.json_encode($res)); return $this->success($res); // return $this->success_list($data,'',$total['total']); } /*名片信息*/ public function card_data(Request $request){ $user=User::find($request->id); if ($user->recom_id==null){ $users["recom_nickname"]= ''; }else{ $users["recom_nickname"]= $user->recom_user->nickname; } $users["id"]=$user->id; $users["nickname"]=$user->nickname; $users["real_name"]= $user->realname; $users["avatar"]= $user->headimgurl; $users["level"]= judge_level($user->level); $users["mobile"]= $user->mobile; $users["up_nickname"]= $user->agent_user->nickname; $users["team_num"]= User::where('agent_id',$user->id)->count(); if ($user->cert_status==3||$user->cert_status==6){ if ($user->auth_startime &&$user->auth_code){ $users['status']=0; }else{ $users['status']=1; } }else{ $users['status']=1; } return $this->success($users); } /*---团队业绩---*/ public function money(Request $request){ $user=Auth::user(); if ($request->type==0){ $user_all=User::where('agent_id',$user->id)->orderByDesc('created_at')->where('deleted_at','=',null)->paginate(15); }elseif ($request->type==1){ $user_all=User::where('agent_id',$user->id)->orderByDesc('created_at')->where('deleted_at','=',null)->where('level',2)->paginate(15); }else{ $user_all=User::where('agent_id',$user->id)->orderByDesc('created_at')->where('deleted_at','=',null)->where('level',1)->paginate(15); } if ($request->time==0){ $time=Carbon::now()->toDateTimeString(); }elseif ($request->time==1){ $time=Carbon::now()->startOfDay()->toDateTimeString(); }else{ $time=Carbon::now()->startOfMonth()->toDateTimeString(); } $total=$user_all->toArray(); $data=[]; $money=0; foreach ($user_all as $k=>$v){ $data[$k]['money']=IncomExpenses::where('user_id',$v->id) ->where('created_at','>=',$time)->sum('totalprice'); $money=$money+$data[$k]['money']; $data[$k]['avatar']=$v->headimgurl; $data[$k]['level']=judge_level($v->level); $data[$k]['nickname']=$v->nickname; } return $this->success_list($data,'',$total['total'],$money,'money'); } /*我的邀请*/ public function invite(Request $request){ $id=Auth::user()->id; if ($request->type==0){ $type='='; $user_all=User::where('recom_id',$id)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->where('status',0)->paginate(15); }elseif ($request->type==1){ $type='<>'; $user_all=User::where('recom_id',$id)->whereIn('cert_status',[1,2,4,5])->where('deleted_at','=',null)->where('status',0)->paginate(15); } $total=$user_all->toArray(); $data=[]; foreach ($user_all as $k=>$v){ $data[$k]['id']=$v->id; $data[$k]['avatar']=$v->headimgurl; $data[$k]['level']=judge_level($v->level); $data[$k]['nickname']=$v->nickname; $data[$k]['created_at']=Carbon::parse($v->created_at)->toDateTimeString(); } $count=User::where('agent_id',$id)->where('status',0)->whereIn('cert_status',[3,6])->count(); // $arr=$this->new_per(); // $re= $arr->original; $res=[ // 'today_new'=>$re['data']['num'], // 'month_new'=>$re['data']['all_num'], 'size'=>15, 'total'=>$user_all->total(), 'list'=>$data ]; return $this->success($res); } public function add_list(Request $request){ if ($request->has('page')){ $page=($request->page)-1; }else{ $page=0; } $re=$this->num_test(); if ($request->type==0){ $num=count($re[0]); $arr_per=$re[0]; $num1=$num-$page*15; if ($num1>=15){ $j=15; }else{ $j=$num1; } $data=[]; for ($i=0;$i<$j;$i++){ $data[$i]['id']=$arr_per[$page*15+$i]['id']; $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar']; $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname']; $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name']; } return $this->success_list($data); }else{ $num=count($re[1]); $arr_per=$re[1]; $num1=$num-$page*15; if ($num1>=15){ $j=15; }else{ $j=$num1; } $data=[]; for ($i=0;$i<$j;$i++){ $data[$i]['id']=$arr_per[$page*15+$i]['id']; $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar']; $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname']; $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name']; } return $this->success_list($data); } } public function num_test(){ $id=Auth::user()->id; // $id=DB::table('users')->where('mobile',13009681680)->value('id'); $user=User::with(['recom_user:id,nickname,mobile','agent_user:id,nickname,mobile' // ,'childAgent'=>function($query){$query->select('id','agent_id','nickname','level','mobile');} ])->find($id); //,'childAgent'=>function($query){$query->select('id','agent_id','nickname','level','mobile');} if($user){ if($user->level=='3'){ $childAgent=User::where('agent_id',$user->id)->select('id', 'nickname','level','mobile','created_at','headimgurl as avatar')->orderBy('id')->get()->toArray(); $childAgentIds=array_column($childAgent,'id'); if($childAgentIds){ $childChildAgent=User::whereIn('agent_id',$childAgentIds)->select('id', 'nickname','level','mobile','created_at','headimgurl as avatar')->orderBy('id')->get()->toArray(); $agent=array_merge($childAgent,$childChildAgent); }else{ $agent=$childAgent; } $re=[]; $res=[]; $i=0; $j=0; foreach ($agent as $k=>$v){ if (strtotime($v['created_at'])>mktime(0,0,0,date('m'),1,date('Y'))){ // $re[$i]=$v; $re[$i]['nickname']=$v['nickname']; $re[$i]['id']=$v['id']; $re[$i]['avatar']=$v['avatar']; $re[$i]['level_name']=judge_level($v['level']); // $re[$i]['up']=User::where('id',$v['recom_id'])->value('nickname'); $i++; } if (strtotime($v['created_at'])>Carbon::today()->timestamp){ // $res[$j]=$v; $res[$j]['nickname']=$v['nickname']; $res[$j]['id']=$v['id']; $res[$j]['avatar']=$v['avatar']; $res[$j]['level_name']=judge_level($v['level']); // $re[$j]['up']=User::where('id',$v['recom_id'])->value('nickname'); $j++; } } }elseif($user->level=='2'){ $user->child_agent=User::where('agent_id',$user->id)->select('id', 'nickname','level','mobile','created_at','headimgurl as avatar')->orderBy('id')->get()->toArray(); $agent=$user->child_agent; $re=[]; $res=[]; $i=0; $j=0; foreach ($agent as $k=>$v){ if (strtotime($v['created_at'])>mktime(0,0,0,date('m'),1,date('Y'))){ // $re[$i]=$v; $re[$i]['nickname']=$v['nickname']; $re[$i]['id']=$v['id']; $re[$i]['avatar']=$v['avatar']; $re[$i]['level_name']=judge_level($v['level']); // $re[$i]['up']=User::where('id',$v['recom_id'])->value('nickname'); $i++; } if (strtotime($v['created_at'])>Carbon::today()->timestamp){ // $res[$j]=$v; $res[$j]['nickname']=$v['nickname']; $res[$j]['id']=$v['id']; $res[$j]['avatar']=$v['avatar']; $res[$j]['level_name']=judge_level($v['level']); // $re[$j]['up']=User::where('id',$v['recom_id'])->value('nickname'); $j++; } } }else{ $re=[]; $res=[]; } // Cache::put('team_list'.$id,[$re,$res]); // return [count($re),count($res)]; // return $this->success_list($re); return [$res,$re]; }else{ return []; } } /**邀请码**/ public function invite_code(){ $user=Auth::user(); $invite_num=UserCert::where('agent_id',$user->id)->where('agent_audit',0)->count(); $team_num=User::where('agent_id',$user->id)->count(); return $this->success([ 'invite_code'=>$user->recom_code, 'incite_num'=>(int)$invite_num, 'team_num'=>$team_num ]); } public function GetUserTeamListNum(Request $request){ $user=Auth::user(); $id=$user->id; $totay_num=$this->GetNewUserTotal($id,Carbon::today()); $month_num=$this->GetNewUserTotal($id,Carbon::now()->startOfMonth()); $counts=$this->getStore($id); $applyCount=ApplyUser::where('user_id',$id)->count(); $levelUp=0; if ($user->level==3){ $id_arr=User::where('agent_id',$user->id)->where('level',2)->pluck('id'); $levelUp=\DB::table('agent_operation_log')->whereIn('user_id',$id_arr)->where('type',2) ->where('created_at','>',Carbon::now()->startOfYear()->toDateTimeString())->count(); } $data=[ 'totay_num'=>$totay_num, 'month_num'=>$month_num, 'store_no_num'=>$counts, 'year_num'=>$this->GetNewUserTotal($id,Carbon::now()->startOfYear()), 'level_up'=>$levelUp, 'applyCount'=>$applyCount, ]; return $this->success($data); } public function GetUserTeamList(Request $request){ $user=Auth::user(); $arr=['crown'=>0,'manager'=>0,'lowest'=>0]; // if ($user->level==1){ // $data=[ // 'totay_num'=>0, // 'month_num'=>0, // 'group'=>$arr // ]; // return $this->success($data); // } $id=$user->id; // if ($id==39516){ // $user=User::where('mobile',18753967396)->first(); // $id=$user->id; // } $s=false; if ($user->level==1){ $s=true; } $type=$request->type; // $id=7; if ($type==0){ $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('recom_id',$id) ->when($s,function ($q){ return $q->where('level','<>',3); }) ->select('users.level',\DB::raw('count(*) as total'))->groupBy('level')->get(); }else{ $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->whereIn('agent_id',$arrs) ->select('users.level',\DB::raw('count(*) as total'))->groupBy('level')->get(); } foreach ($data as $k=>$v){ if ($v->level==1){ $arr['lowest']=$v->total; } if ($v->level==2){ $arr['manager']=$v->total; } if ($v->level==3){ $arr['crown']=$v->total; } } // $totay_num=$this->GetNewUserTotal($id,Carbon::today()); // $month_num=$this->GetNewUserTotal($id,Carbon::now()->startOfMonth()); // $counts=$this->getStore($id); // $applyCount=ApplyUser::where('user_id',$id)->count(); // $levelUp=0; // if ($user->level==3){ // $id_arr=User::where('agent_id',$user->id)->where('level',2)->pluck('id'); // $levelUp=\DB::table('agent_operation_log')->whereIn('user_id',$id_arr)->where('type',2) // ->where('created_at','>',Carbon::now()->startOfYear()->toDateTimeString())->count(); // } $data=[ // 'totay_num'=>$totay_num, // 'month_num'=>$month_num, // 'store_no_num'=>$counts, // 'year_num'=>$this->GetNewUserTotal($id,Carbon::now()->startOfYear()), 'group'=>$arr, // 'level_up'=>$levelUp, // 'applyCount'=>$applyCount, ]; return $this->success($data); } public function GetLevelUp(){ $user=Auth::user(); $id_arr=User::where('agent_id',$user->id)->where('level',2)->pluck('id'); $query=\DB::table('agent_operation_log')->whereIn('user_id',$id_arr)->where('type',2); $query1=clone $query; $query2=clone $query; $yesterday=$query->where('created_at','>',Carbon::yesterday()->toDateTimeString())->count(); $month=$query1->where('created_at','>',Carbon::now()->startOfMonth()->toDateTimeString())->count(); $year=$query2->where('created_at','>',Carbon::now()->startOfYear()->toDateTimeString())->count(); return $this->success(['yesterday'=>$yesterday,'month'=>$month,'year'=>$year]); } public function GetLevelUpList(Request $request){ $page_index=$request->input('page_index'); $page_size=$request->input('page_size'); $num=($page_index-1)*$page_size; $search_name=$request->input('search_name')??''; $type=$request->input('type'); $start_time=$request->input('time_start')??''; $end_time=$request->input('time_end')??''; $user=Auth::user(); $id_arr=User::where('agent_id',$user->id)->where('level',2)->pluck('id'); if ($search_name){ $id_arr=User::whereIn('id',$id_arr)->where('mobile','like',"%$search_name%") ->orwhere('nickname','like',"%$search_name%")->pluck('id'); } $query=AgentOperationLog::whereIn('user_id',$id_arr)->where('type',2); if ($type==0){ $query->where('created_at','>',Carbon::yesterday()->toDateTimeString()); }elseif($type==1){ $query->where('created_at','>',Carbon::now()->startOfMonth()->toDateTimeString()); }elseif($type==2){ if ($start_time){ $query->where('created_at','>',Carbon::now()->format('Y').'-'.$start_time.' 00:00:00') ->where('created_at','<',Carbon::now()->format('Y').'-'.$end_time.' 23:59:59'); }else{ $query->where('created_at','>',Carbon::now()->startOfYear()->toDateTimeString()); } } $count=$query->count(); $data=$query->with(['user'=>function($q){ $q->select('id','nickname','level','mobile','headimgurl','realname','recom_id')->with(['recom_user:id,nickname']); }])->select('user_id') ->take($page_size)->skip($num)->get(); return $this->success_list($data,'',$count); } public function GetUserTeamLists(Request $request){ // $user=Auth::user(); $arr=['crown'=>0,'manager'=>0,'lowest'=>0]; // if ($user->level==1){ // $data=[ // 'totay_num'=>0, // 'month_num'=>0, // 'group'=>$arr // ]; // return $this->success($data); // } // $id=$user->id; $user=User::where('mobile','15538160193')->first(); $id=$user->id; $s=false; if ($user->level==1){ $s=true; } $type=$request->type; // $id=7; if ($type==0){ $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('recom_id',$id) ->when($s,function ($q){ return $q->where('level','<>',3); }) ->select('users.level',\DB::raw('count(*) as total'))->groupBy('level')->get(); }else{ $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->whereIn('agent_id',$arrs) ->select('users.level',\DB::raw('count(*) as total'))->groupBy('level')->get(); } foreach ($data as $k=>$v){ if ($v->level==1){ $arr['lowest']=$v->total; } if ($v->level==2){ $arr['manager']=$v->total; } if ($v->level==3){ $arr['crown']=$v->total; } } $totay_num=$this->GetNewUserTotal($id,Carbon::today()); $month_num=$this->GetNewUserTotal($id,Carbon::now()->startOfMonth()); $counts=$this->getStore($id); $applyCount=ApplyUser::where('user_id',$id)->count(); $data=[ 'totay_num'=>$totay_num, 'month_num'=>$month_num, 'store_no_num'=>$counts, 'year_num'=>$this->GetNewUserTotal($id,Carbon::now()->startOfYear()), 'group'=>$arr, 'applyCount'=>$applyCount, ]; return $this->success($data); } public function getStore($id){ $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereIn('agent_id',$arrs) ->whereNull('deleted_at')->pluck('id')->toArray(); $arrs=array_merge($arrs,$data); $arrs=array_diff($arrs,[$id]); array_unique($arrs); $w_ids=Store::where('is_apply',3)->pluck('user_id')->toArray(); array_unique($w_ids); $count=count(array_unique(array_diff($arrs,$w_ids))); return $count; } public function GetUserTeamLevelDetail(Request $request){ $user=Auth::user(); $id=$user->id; // $id=7; // if ($id==39516){ // $user=User::where('mobile',18753967396)->first(); // $id=$user->id; // } $input=$request->all(); $page_index=$input['page_index']; $page_size=$input['page_size']; $level=$input['level']; $type=$input['type']; $search_name=$input['search_name']; // $search_type=$request->input('search_type',0); $s=0; if ($level<$user->level){ if ($level!=1){ $s=1; } } if ($type==0){ $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('level',$level) ->where('recom_id',$id) ->with(['cert_user:id,user_id,recom_updated_at,agent_updated_at,company_updated_at']) ->with(['agent_user:id,nickname'])->with(['get_store:id,user_id,is_apply'])->with(['recom_user:id,nickname']) ->select('level','id','headimgurl','mobile','nickname','recom_id','agent_id','realname','created_at','service_end_time',\DB::raw("if($s,1,0) as status"),'service_status','in_group'); }else{ $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('level',$level) ->whereIn('agent_id',$arrs) ->with(['cert_user:id,user_id,recom_updated_at,agent_updated_at,company_updated_at']) ->with(['agent_user:id,nickname'])->with(['get_store:id,user_id,is_apply'])->with(['recom_user:id,nickname']) ->select('level','headimgurl','mobile','nickname','recom_id','agent_id','realname','id','created_at','service_end_time',\DB::raw("if($s,1,0) as status"),'service_status','in_group'); } if ($search_name){ $wheres=function ($q)use($search_name){ $q->where('nickname','like',"%$search_name%")->orwhere('mobile','like',"%$search_name%")->orwhere('realname','like',"%$search_name%"); }; $data=$data->where($wheres); } $total=$data->count(); $data=$data->take($page_size)->skip(($page_index-1)*$page_size)->get(); foreach($data as $key=>$val){ if(empty($val->service_end_time)){ if(!empty($val->cert_user)){ $cert_user=$val->cert_user; $data[$key]->pass_time=$cert_user->company_updated_at?:$cert_user->agent_updated_at?:$cert_user->recom_updated_at?:date("Y-m-d H:i:s",strtotime($val->created_at)); }else{ $data[$key]->pass_time=date("Y-m-d H:i:s",strtotime($val->created_at)); } }else{ $data[$key]->pass_time=$val->service_end_time; } } if ($level==2){ foreach ($data as $k=>$v){ $data[$k]->up_time=\DB::table('agent_operation_log')->orderByDesc('id')->where('user_id',$v->id)->where('type',2)->value('created_at'); } } return $this->success_list($data,'',$total); } /**未开通微店**/ public function StoreNoOpen(Request $request){ $id=Auth::user()->id; $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereIn('agent_id',$arrs) ->whereNull('deleted_at')->pluck('id')->toArray(); $arrs=array_merge($arrs,$data); $arrs=array_diff($arrs,[$id]); array_unique($arrs); $w_ids=Store::where('is_apply',3)->pluck('user_id')->toArray(); array_unique($w_ids); $ids=array_unique(array_diff($arrs,$w_ids)); $search_name=$request->input('search_name',''); $page_index=$request->input('page_index',0); $page_size=$request->input('page_size',20); $data=User::whereIn('id',$ids)->with(['agent_user:id,nickname'])->with(['get_store:id,user_id,is_apply'])->with(['recom_user:id,nickname']) ->select('level','headimgurl','mobile','nickname','recom_id','agent_id','realname','id',\DB::raw("if(level=1,0,1) as status"),'service_status','in_group'); if ($search_name){ $wheres=function ($q)use($search_name){ $q->where('nickname','like',"%$search_name%")->orwhere('mobile','like',"%$search_name%")->orwhere('realname','like',"%$search_name%"); }; $data=$data->where($wheres); } $total=$data->count(); $data=$data->take($page_size)->skip(($page_index-1)*$page_size)->get(); return $this->success_list($data,'',$total); } public function SearchUserTeamLevelDetail(Request $request){ $user=Auth::user(); $id=$user->id; $input=$request->all(); $page_index=$input['page_index']; $page_size=$input['page_size']; $search_name=$input['search_name']; $arrs=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arrs,$id); $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->whereIn('agent_id',$arrs) ->with(['agent_user:id,nickname'])->with(['get_store:id,user_id,is_apply'])->with(['recom_user:id,nickname'])->select('level','headimgurl','mobile','nickname','recom_id','agent_id','realname','id',\DB::raw("if(level=1,0,1) as status")); if ($search_name){ $wheres=function ($q)use($search_name){ $q->where('nickname','like',"%$search_name%")->orwhere('mobile','like',"%$search_name%")->orwhere('realname','like',"%$search_name%"); }; $data=$data->where($wheres); } $total=$data->count(); $data=$data->take($page_size)->skip(($page_index-1)*$page_size)->get(); return $this->success_list($data,'',$total); } public function GetTeamList(Request $request){ $page_size=$request->page_size; $page_index=$request->page_index; $data=User::where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('level',1) ->where('agent_id',$request->id) ->with(['agent_user:id,nickname'])->with(['recom_user:id,nickname'])->select('level','headimgurl','mobile','nickname','recom_id','agent_id','realname'); $total=$data->count(); $data=$data->take($page_size)->skip(($page_index-1)*$page_size)->get(); return $this->success_list($data,'',$total); } public function GetNewUserTotal($id,$time){ $arr=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arr,$id); $total=User::whereIn('agent_id',$arr)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('created_at','>=',$time) ->count(); return $total; } public function GetNewUserDetail(Request $request){ // $id=39516; $id=Auth::user()->id; $input=$request->all(); $page_index=$input['page_index']; $page_size=$input['page_size']; $type=$input['type']; $search_name=$input['search_name']; if ($type==0){ $time=Carbon::today(); }elseif($type==1){ $time=Carbon::now()->startOfMonth(); }else{ $time=Carbon::now()->startOfYear(); } $arr=User::where('agent_id',$id)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->pluck('id')->toArray(); array_push($arr,$id); $query=User::whereIn('agent_id',$arr)->where('status',0) ->where('service_status',0) ->whereNull('deleted_at') ->where('created_at','>=',$time); if ($search_name){ $wheres=function ($q)use($search_name){ $q->where('mobile','like',"%$search_name%") ->orwhere('nickname','like',"%$search_name%") ->orwhere('realname','like',"%$search_name%"); }; $query->where($wheres); } $total=$query->count(); $data=$query->with(['get_store:id,user_id,is_apply']) ->with(['agent_user:id,nickname'])->with(['recom_user:id,nickname']) ->select('level','headimgurl','mobile','nickname','recom_id','agent_id','realname','id','service_status','in_group') ->take($page_size) ->skip(($page_index-1)*$page_size) ->get(); return $this->success_list($data,'',$total); } /****/ public function GetNewTeam(Request $request){ $page_index=$request->input('page_index'); $page_size=$request->input('page_size'); $num=($page_index-1)*$page_size; // $re=User::where('agent_id',39516)->whereNull('deleted_at'); $re=User::where('agent_id',Auth::user()->id)->whereIn('cert_status',[3,6])->where('in_group',1)->whereNull('deleted_at'); $count=$re->count(); $data=$re->select('headimgurl','nickname','mobile','created_at')->orderByDesc('created_at')->take($page_size)->skip($num)->get(); foreach ($data as $k=>$v){ $v->mobile=hide_phone($v->mobile); } return $this->success_list($data,'',$count); } /****/ public function GetSearchNewTeam(Request $request){ $page_index=$request->input('page_index'); $page_size=$request->input('page_size'); $search_name=$request->input('search_name'); $num=($page_index-1)*$page_size; // $re=User::where('agent_id',39516)->whereNull('deleted_at'); $re=User::where('agent_id',Auth::user()->id)->whereIn('cert_status',[3,6])->where('in_group',1)->whereNull('deleted_at'); if ($search_name){ if (is_numeric($search_name)){ if (mb_strlen($search_name)<4){ return $this->errormsg(500214,'','请输入至少四位手机号'); } } $where=function ($q)use ($search_name){ $q->where('mobile','like',"%$search_name%")->orwhere('nickname','like',"%$search_name%"); }; $re->where($where); } $count=$re->count(); $data=$re->select('headimgurl','nickname','mobile','created_at','recom_id')->with(['recom_user:id,nickname,mobile'])->take($page_size)->skip($num)->get(); $arr=[]; foreach ($data as $k=>$v){ if ($v->recom_user){ $arr[]=[ 'nickname'=>$v->nickname, 'headimgurl'=>$v->headimgurl, 'created_at'=>$v->created_at->toDateTimeString(), 'mobile'=>hide_phone($v->mobile), 'user_nickname'=>$v->recom_user->nickname, 'user_mobile'=>hide_phone($v->recom_user->mobile) ]; }else{ $arr[]=[ 'nickname'=>$v->nickname, 'headimgurl'=>$v->headimgurl, 'created_at'=>$v->created_at->toDateTimeString(), 'mobile'=>hide_phone($v->mobile), 'user_nickname'=>'', 'user_mobile'=>'' ]; } } return $this->success_list($arr,'',$count); } }