all())); $user=User::find($users->id); if ($user->freeze_status==1){ return $this->error(20014); } $user->login_at=Carbon::now(); $user->save(); $recom_num=UserCert::where('recom_id',$user->id)->where('recom_audit',0)->count(); $agent_num=UserCert::where('agent_id',$user->id)->where('agent_audit',0)->count(); $u_ids=User::where('cert_status',3)->where('crown_id',$user->id)->where('service_status',1)->pluck('id'); $company_num= UserCert::whereIn('user_id',$u_ids)->where('agent_audit',1)->count(); // $company_num= UserCert::whereHas('user_info',function($query)use($user){ // $query->where('crown_id',$user->id)->where('service_status',1); // })->where('agent_audit',1)->count(); // $recom_num=0; // $agent_num=0; // $company_num=0; // $num=0; $num=Ordertest::whereIn('pay_status',[0,1])->where('user_id',$users->id)->where('is_deleted',0)->sum('no_pay_money'); if ($user->recom_id==null){ $users->recom_nickname=''; $users->recom_mobile=''; }else{ $users->recom_nickname=$user->recom_user->nickname; $users->recom_mobile=hide_phone($user->recom_user->mobile); } if ($users->cert_status==4){ $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('recom_audit_desc'); }elseif ($users->cert_status==5){ $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('agent_audit_desc'); } if ($user->openid){ $users->openid=$user->openid; }else{ $users->openid=$user->openid; } //测试微聊 if(in_array($users->mobile,['15138929587','15238617326','18838980968','15236877164'])){//,'15286818088','15236877164' $users->is_weiliao=1; }else{ $users->is_weiliao=0; } //获取账号余额 // $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('is_apply',3)->where('user_id',$users->id)->value('sub_mchid'); //// $sub_mchid=null; // if($sub_mchid){ // Log::info($sub_mchid); // $mini=new Mini(); // $result=$mini->getAccount($sub_mchid); //// Log:info($users); // $users->pending_amount=$result['pending_amount']; // $users->available_amount=$result['available_amount']; // Log::info($user->mobile.'/////'.$user->deleted_at.'///'.$result['pending_amount'].'///'.$result['available_amount']); // }else{ // $users->pending_amount=0; // $users->available_amount=0; // } $users->uuid = '1002'.substr($user->mobile,5,6); $users->status=$users->status==0?1:0; $users->recom_num=$recom_num; $users->agent_num=$agent_num; $users->company_num=$company_num; $users->no_money=$num; // $users->deleted_at=null; // Log::error($users->id); return $this->success($users); } //app首页获取信息专用接口 public function getAppAgentInfo(){ $users=Auth::user(); $user=User::find($users->id); if ($user->freeze_status==1){ return $this->error('450001','账号已冻结'); } $user->login_at=Carbon::now(); $user->save(); // $users->headimgurl=$user->headimgurl; $recom_num=UserCert::where('recom_id',$user->id)->where('recom_audit',0)->count(); $agent_num=UserCert::where('agent_id',$user->id)->where('recom_audit',1)->where('agent_audit',0)->count(); $num=Ordertest::whereIn('pay_status',[0,1])->where('user_id',$users->id)->where('is_deleted',0)->sum('no_pay_money'); if ($user->recom_id==null){ $users->recom_nickname=''; $users->recom_headimgurl=''; $users->recom_mobile=''; }else{ $users->recom_headimgurl=$user->recom_user->headimgurl; $users->recom_nickname=$user->recom_user->nickname; $users->recom_mobile=$user->recom_user->mobile; } if ($user->agent_id==null){ $users->agent_nickname=''; $users->agent_mobile=''; $users->agent_headimgurl=''; }else{ $users->agent_headimgurl=$user->agent_user->headimgurl; $users->agent_nickname=$user->agent_user->nickname; $users->agent_mobile=$user->agent_user->mobile; } if ($users->cert_status==4){ $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('recom_audit_desc'); }elseif ($users->cert_status==5){ $users->reject_reason=UserCert::where('user_id',$users->id)->orderByDesc('created_at')->value('agent_audit_desc'); } if ($user->openid){ $users->openid=$user->openid; }else{ $users->openid=$user->openid; } //测试微聊 if(in_array($users->mobile,['15138929587','15238617326','18838980968','15236877164'])){//,'15286818088','15236877164' $users->is_weiliao=1; }else{ $users->is_weiliao=0; } //获取账号余额 $sub_mchid=Store::withTrashed()->where('is_failure',0)->where('user_id',$users->id)->value('sub_mchid'); if($sub_mchid){ Log::info($sub_mchid); $mini=new Mini(); $result=$mini->getAccount($sub_mchid); $users->pending_amount=$result['pending_amount']; $users->available_amount=$result['available_amount']; Log::info($user->mobile.'/////'.$user->deleted_at.'///'.$result['pending_amount'].'///'.$result['available_amount']); }else{ $users->pending_amount=0; $users->available_amount=0; } $users->status=$users->status==0?1:0; $users->recom_num=$recom_num; $users->agent_num=$agent_num; $users->no_money=$num; $users->level= judge_level($user->level); $users->agent_level= $user->level; $users->store = $user->store==null?false:true; $users->order_num1=Order::where('agent_id',$user->id)->where('status','=',0)->count();//待审核订单数量 $users->order_num2= Order::where('agent_id',$user->id)->where('status','=',2)->count();// 待收货订单数量 $users->order_num3=Order::where('agent_id',$user->id)->whereIn('status',[3,4,5])->count();//已完成订单数量 $users->openid=$user->openid; $users->warea=Warea::where('id',$user->warea_id)->value('name'); $users->warea_info=Warea::where('id',$user->warea_id)->select('avatar','qrcode','admin_name')->first(); if ($user->password==md5($user->mobile)){ $users->pass_status=true; }else{ $users->pass_status=false; } if($user->status==0 && $user->cert_status==6 && $user->service_status==0 && empty($user->deleted_at)){ $users->show_store=true; }else{ $users->show_store=false; } return $this->success($users); } /**获取openid**/ public function get_openid(Request $request){ // $wechat=app('wechat.') } /*实名认证的提交*/ public function submit_user(Request $request,UserCert $userCert){ if(empty($request->cre_num)){ return $this->new_error(300,'身份证为必填项'); }; // if(strlen($request->cre_num) != 18){ // return $this->new_error(300,'身份证号码有误'); // }; if(strlen($request->cre_num) == 18){ $year = substr($request->cre_num, 6, 4); $age = date('Y') - $year; if($age > 60){ return $this->new_error(300,'很抱歉,您的年龄已超过60岁,无法注册。'); } } // $year = substr($request->cre_num, 6, 4); // $age = date('Y') - $year; // if($age > 65){ // return $this->new_error(300,'很抱歉,您的年龄已超过65岁,无法注册。'); // } $data=User::where('cre_num',$request->cre_num)->where('id','!=',Auth::user()->id)->first(); if ($data){ if ($data->deleted_at!=null){ return $this->new_error(300,'当前身份证号已被禁用'); } return $this->new_error(300,'当前身份证号已被使用'); } $is_five_type=1; $user=User::find(Auth::user()->id); if(empty($user->nickname)){ $user->nickname=$request->wechatname; $user->name=$request->wechatname; } $user->realname=$request->realname; $user->cre_num=$request->cre_num; // $user->password=md5($request); $share=ShareUser::where('phone',$user->mobile)->first(); $recom=User::find($user->recom_id); if ($recom->level==2){ if ($share){ $share->status=1; } $user->agent_id=$recom->agent_id; $user->crown_id=$recom->agent_id; $userCert->recom_audit=1; $userCert->agent_id=$recom->agent_id; $userCert->recom_updated_at=Carbon::now()->toDateTimeString(); $user->cert_status=2; }elseif ($recom->level==3){ if ($share){ $share->status=2; } $userCert->recom_audit=1; $userCert->recom_updated_at=Carbon::now()->toDateTimeString(); $userCert->agent_id=$recom->id; $userCert->agent_updated_at=Carbon::now()->toDateTimeString(); $userCert->agent_audit=1; $userCert->company_audit=1; $userCert->company_updated_at=Carbon::now()->toDateTimeString(); $user->cert_status=3; $user->agent_id=$recom->id; $user->crown_id=$recom->id; $user->service_status=0; } $user->warea_id=$recom->warea_id; if ($share){ $share->save(); } $userCert->recom_id=$user->recom_id; $userCert->user_id=$user->id; $userCert->is_five_type=$is_five_type; $userCert->save(); $user->save(); if ($recom->level==2){ $recom=User::where('id',$user->agent_id)->first(); if($recom->openid){ $mes['openid']=$recom->openid; $mes['data']=[ 'first' => '注册信息已提交,请您及时审核', 'keyword1' => $user->nickname, 'keyword2' => $user->mobile, 'keyword3' => date("Y-m-d H:i"), 'remark' => '点击链接进入系统,查看详情', ]; event(new RegisterApplyEvent($mes)); } } return $this->success([]); } /* * 获取用户信息 */ public function per_data(Request $request){ $users=Auth::user(); $user=User::find($users->id); if(empty($user)){ return $this->error('300',[],'代理信息不存在'); } // $users->up_nickname=$user->agent_user->wechatname; // $users->recom_nickname=$user->recom_user->wechatname; // $users->level=judge_level($users->level); $re["id"]=$user->id; $re['uuid']= '1002'.substr($user->mobile,5,6); $re["nickname"]= $user->nickname; $re["avatar"]= $user->headimgurl; $re["money"]= $user->money; $re["level"]= judge_level($users->level); $re["agent_level"]= $users->level; $re["mobile"]= $user->mobile; $re["level_change"]= $user->level_change; $re["store"]= $user->store==null?false:true; $re["order_num1"]=Order::where('agent_id',$user->id)->where('status','=',0)->count();//待审核订单数量 $re["order_num2"]= Order::where('agent_id',$user->id)->where('status','=',2)->count();// 待收货订单数量 $re["order_num3"]=Order::where('agent_id',$user->id)->whereIn('status',[3,4,5])->count();//已完成订单数量 $re['openid']=$user->openid; $re['warea']=Warea::where('id',$user->warea_id)->value('name'); $re['warea_info']=Warea::where('id',$user->warea_id)->select('avatar','qrcode','admin_name')->first(); // if ($user->password==md5($user->mobile)){ // $re['pass_status']=true; // }else{ // $re['pass_status']=false; // } $re['pass_status']=false; $user->level_change=0; $user->save(); //测试人员 // $test_user=TestUserW::pluck('phone')->toArray(); // if(in_array($user->mobile,$test_user)){ // $re['show_store']=true; // }else{ // $re['show_store']=false; // } //正式开放 if($user->status==0 && $user->cert_status==6 && $user->service_status==0 && empty($user->deleted_at)){ $re['show_store']=true; }else{ $re['show_store']=false; } return $this->success($re); } /*更改手机号*/ public function change_num(Request $request){ try { $login=new LoginController(); // $code = $login->judge_code('verificationCode_' . MD5($request->mobile), $request->verify_code); // Cache::forget('verificationCode_' . MD5($request->mobile)); $code = $login->judge_code('verificationCode_' . MD5($request->code.'-'.$request->mobile), $request->verify_code); Cache::forget('verificationCode_' . MD5($request->code.'-'.$request->mobile)); if ($code==300||$code==400){ return $this->new_error(300,'验证码不正确或过期'); } $user=User::find(Auth::user()->id); $mobile=$user->mobile; $user->mobile=$request->mobile; $user->area_code=$request->code; $user->save(); try{ $u=UserZ::where('phone',$mobile)->first(); if ($u){ $u->phone=$request->mobile; $u->save(); } }catch (\Exception $exception){ Log::error('这是手机号更改的地方出错了'.$exception); } return $this->success([]); }catch (\Exception $exception){ Log::error('-----更改手机号出错------'); return $this->new_error(300,'更改出错,请联系客服'); } } /*换绑手机号之发送*/ public function send_code(Request $request){ try { $mobile=Auth::user()->mobile; if ($request->mobile==$mobile){ Log::error('fsdf'); return $this->new_error(300,'该手机号和原手机号一致'); } $count=User::where('mobile',$request->mobile)->where('id','<>',Auth::user()->id)->count(); if ($count>0){ return $this->new_error(300,'该手机号已被使用'); } $login=new LoginController(); $code=$login->send_code($request->mobile,0,$request->code); if ($code['code']==300){ return $this->error(300,[],$code['message']); } return $this->success([]); }catch (\Exception $exception){ Log::error('____更改手机号之发送验证码出错_____'); return $this->new_error(300,'更改出错,请联系客服'); } } /*地址管理---展示地址*/ public function show_address(){ $id=Auth::user()->id; $address=Address::where('user_id',$id)->where('is_deleted',0)->with(['get_user'])->orderByDesc('type')->orderbyDesc('updated_at')->orderbyDesc('id')->get(); $data=[]; foreach ($address as $k=>$v){ $data[$k]["id"]=$v->id; $data[$k]["type"]=$v->type; $data[$k]["con_name"]=$v->username; $data[$k]["area_code"]=$v->area_code; $data[$k]["con_mobile"]=$v->mobile; $data[$k]["provice"]=$v->province; $data[$k]["city"]=$v->city; $data[$k]["area"]=$v->town; $data[$k]["address"]=$v->address; $data[$k]["belong_id"]=$v->belong_id==null?'':$v->belong_id; $data[$k]['belong_user']=''; if ($v->belong_id){ $user=User::where('id',$v->belong_id)->select('id as belong_id','level as belong_level','nickname as belong_nickname','mobile as belong_mobile','headimgurl as avatar')->first(); $data[$k]['belong_user']=$user; } if ($v->get_user){ $data[$k]["level"]=$v->get_user->level; $data[$k]["nickname"]=$v->get_user->nickname; $data[$k]["phone"]=$v->get_user->mobile; }else{ $data[$k]["level"]=null; $data[$k]["nickname"]=null; $data[$k]["phone"]=null; } } // Log::error(json_encode($data)); return $this->success_list($data); } /*地址管理-----新增地址*/ public function add_address(Request $request,Address $address){ // Log::error('{----地址----}'.json_encode($request->all())); $id=Auth::user()->id; // $data=$request->all(); $add=Address::where('mobile',$request->con_mobile)->where('user_id',$id)->where('is_deleted',0)->where('username',$request->con_name)->where('address',$request->address)->first(); if ($add){ return $this->error(40023,'','当前地址已存在,请搜索手机号'.$request->con_mobile.'查找该地址'); } if ($request->type==1){ $count=Address::where('user_id',$id)->where('is_deleted',0)->where('type',1)->count(); if ($count>=3){ $num=$count-2; Address::where('user_id',$id)->where('is_deleted',0)->where('type',1)->orderBy('created_at')->limit($num)->update(['type'=>0]); } } $user=User::where('mobile',$request->con_mobile)->first(); if ($user){ // if ($user->id!=$id && $user->level==3){ // return $this->error(40023,'','当前手机号对应的代理-不属于自己的团队'); // } // $ids=User::where('agent_id',$id)->pluck('id')->toArray(); // $idss=User::whereIn('agent_id',$ids)->pluck('id')->toArray(); // $i=[$id]; // $ar=array_merge($ids,$i); // $ar=array_merge($ar,$idss); // if (in_array($user->id,$ar)){ // $address->belong_id=$user->id; // }else{ // return $this->error(40023,$ar,'当前手机号对应的代理不属于自己的团队'); // } $address->belong_id=$user->id; } // if (!$request->province){ // return $this->error(50021,'','选择这省市区'); // } $address->type=$request->type; $address->user_id=$id; $address->username=$request->con_name; $address->area_code=$request->input('areaCode','+86'); $address->mobile=$request->con_mobile; $address->province=$request->provice; $address->city=$request->city; $address->town=$request->area; $address->address=$request->address; $re=User::where('mobile',$request->con_mobile)->select('level','nickname')->first(); if ($re){ $address->level=$re->level; $address->nickname=$re->nickname; } $address->save(); return $this->success(['id'=>$address->id]); } /*地址管理----删除地址*/ public function del_address(Request $request){ $address=Address::find($request->id); $address->is_deleted=1; $address->save(); return $this->success([]); } /*地址管理----编辑地址*/ public function update_address(Request $request){ $address=Address::find($request->id); if ($address->con_name==$request->con_name&& $address->mobile==$request->con_mobile&& $address->province==$request->provice&&$address->city==$request->city&&$address->town==$request->area&&$address->address==$request->address){ return $this->error(50024,'','当前修改的地址已存在,请搜索手机号'.$request->con_mobile.'查找该地址'); } if ($request->type==1){ $count=Address::where('user_id',$request->id)->where('is_deleted',0)->where('type',1)->count(); if ($count>=3){ $num=$count-2; Address::where('user_id',$request->id)->where('is_deleted',0)->where('type',1)->orderBy('created_at')->limit($num)->update(['type'=>0]); } } $user=User::where('mobile',$request->con_mobile)->first(); if ($user){ // if ($user->id!=$address->user_id && $user->level==3){ // return $this->error(40023,'','当前手机号对应的代理不属于自己的团队'); // } // $ids=User::where('agent_id',$address->user_id)->pluck('id')->toArray(); // $idss=User::whereIn('agent_id',$ids)->pluck('id')->toArray(); // $ar=array_merge($ids,$address->user_id,$idss); // if (in_array($ar,$user->id)){ // $address->belong_id=$user->id; // }else{ // return $this->error(40023,'','当前手机号对应的代理不属于自己的团队'); // } $address->belong_id=$user->id; } // if (!$request->province){ // return $this->error(50021,'','选择这省市区'); // } $address->type=$request->type; $address->username=$request->con_name; $address->area_code=$request->input('areaCode','+86'); $address->mobile=$request->con_mobile; $address->province=$request->provice; $address->city=$request->city; $address->town=$request->area; $address->address=$request->address; $re=User::where('mobile',$request->con_mobile)->select('level','nickname')->first(); if ($re){ $address->level=$re->level; $address->nickname=$re->nickname; } $address->save(); return $this->success([]); } /*搜索地址**/ public function search_address(Request $request){ $where=[]; if ($request->search_name){ $search_name=$request->search_name; $where=function ($q)use ($search_name){ $q->where('username','like',"%$search_name%") ->orwhere('mobile','like',"%$search_name%"); }; } $re=Address::where('user_id',Auth::user()->id)->where($where)->with(['get_user'])->where('is_deleted',0)->orderByDesc('created_at')->get(); foreach ($re as $k=>$v){ if ($v->belong_id){ $user=User::where('id',$v->belong_id)->select('id as belong_id','level as belong_level','nickname as belong_nickname','mobile as belong_mobile','headimgurl as avatar')->first(); $re[$k]['belong_user']=$user; } if($v->get_user){ $re[$k]['nickname']=$v->get_user->nickname; $re[$k]['level']=$v->get_user->level; }else{ $re[$k]['nickname']=null; $re[$k]['level']=null; } unset($re[$k]['get_user']); } return $this->success_list($re); } /**--确认等级变动--**/ public function confirm_level(){ $id=Auth::user()->id; $user=User::find($id); $user->level_change=0; $user->save(); return $this->success([]); } public function ress(Request $request){ $add=Address::find($request->id); echo $add->user->realname; // return $add; } /*--授权书---*/ public function auth_code(Request $request){ // $users=Auth::user(); // $user=User::find($users->id); // Log::error(json_encode($request->all())); $user=User::find($request->id); if ($user->cert_status==3||$user->cert_status==6){ if ($user->auth_startime &&$user->auth_code){ if ($user->auth_img==null){ $name=$user->realname==null?$user->nickname:$user->realname; $url=$this->auth_create($name,$user->mobile,judge_level($user->level),$user->auth_code,$user->auth_startime,$user->auth_endtime,$user->id); $user->auth_img=$url; $user->save(); } $data['status']=0; }else{ $data['status']=1; } }else{ $data['status']=1; } if ($user->service_status==1){ // return $this->error(50021,'','该代理尚未通过政委审核'); return $this->error(50021,'','该代理尚未通过经销商审核'); } if ($user->service_status==2){ // return $this->error(50021,'','该代理的申请已被政委驳回'); return $this->error(50021,'','该代理的申请已被经销商驳回'); } if ($user->in_group!=1){ return $this->error(50021,'','该代理尚未通过政委审核'); } $data['auth_startime']=strtotime($user->auth_startime)*1000; $data['auth_endtime']=strtotime($user->auth_endtime)*1000; $data['code']=$user->auth_code; $data['phone']=$user->mobile; $data['level_name']=judge_level($user->level); $data['nickname']=$user->nickname; $data['realname']=$user->realname==null?$user->nickname:$user->realname; $data['url']=$user->auth_img==null?'':$user->auth_img; // Log::error('{----------}'.json_encode($data)); return $this->success($data); } public function auth_create($name,$phone,$level_name,$auth_code,$time_start,$time_end,$num){ $client=new Client(); $url='http://api.app.cliu.cc/138.jpg'; $avatarResponse = $client->get($url); $img = Image::make($avatarResponse->getBody()->getContents()); $img->text($name, 400, 565,function ($font){ $font->file(base_path().'/public/fangzheng.ttf'); $font->size(25); $font->angle(0); }); $phones=mb_substr($phone,0,3).'****'.mb_substr($phone,7,4); $img->text($phones, 400, 635,function ($font){ $font->file(base_path().'/public/fangzheng.ttf'); $font->size(25); $font->angle(0); }); $img->text($level_name, 350, 820,function ($font){ $font->file(base_path().'/public/fangzheng.ttf'); $font->size(60); $font->angle(0); }); $img->text($auth_code, 285, 965,function ($font){ $font->file(base_path().'/public/fangzheng.ttf'); $font->size(25); $font->angle(0); }); $year=mb_substr($time_start,0,4); $month=mb_substr($time_start,5,2); $day=mb_substr($time_start,8,2); $year_t=mb_substr($time_end,0,4); $month_t=mb_substr($time_end,5,2); $day_t=mb_substr($time_end,8,2); $img->text("{$year}年{$month}月{$day}日 - {$year_t}年{$month_t}月{$day_t}日", 285, 1050,function ($font){ $font->file(base_path().'/public/fangzheng.ttf'); $font->size(25); $font->angle(0); }); $name=$this->rand_code($num); $img->save(base_path().'/public/public/uploads/auth_img/'.$name.'.jpg'); return env('APP_URL').'/public/uploads/auth_img/'.$name.'.jpg'; } //0未认证 1待审核 2通过邀请人审核 3通过上级审核 4邀请人驳回 5上级驳回 6正常 public function authInfo(){ $user_id=Auth::user()->id; $user=User::where('id',$user_id) ->with(['recom_user:id,nickname,mobile,level,headimgurl,warea_id','crown_info:id,nickname,mobile,level,headimgurl']) ->with(['agent_user:id,nickname,mobile,level,headimgurl'])->first(); $users=[]; if($user->cert_status==0){ $user['status']=0; }else{ // if(in_array($user->cert_status,[1,2,3,4,5])){ $user_cert=UserCert::where('user_id',$user_id)->orderBy('id','desc')->limit(1)->get(); $users['status']=$user->cert_status; $users['service_status']=$user->service_status; if($user->crown_info && $user->crown_info->level==3){ $users['service_info']['nickname']=$user->crown_info->nickname; $users['service_info']['mobile']=hide_phone($user->crown_info->mobile); $users['service_info']['level']=$user->crown_info->level; $users['service_info']['headimgurl']=$user->crown_info->headimgurl; if(count($user_cert)>0){ $users['service_info']['company_time']=$user_cert[0]->company_updated_at==null?strtotime($user_cert[0]->company_updated_at):''; }else{ $users['service_info']['company_time']=''; } }else{ $users['service_info']['nickname']=''; $users['service_info']['mobile']=''; $users['service_info']['level']=''; $users['service_info']['headimgurl']=''; $users['service_info']['company_time']=''; // $users['service_info']=[]; } // if ($user->warea_id){ // $users['service_info']=DB::table('warea')->where('id',$user->warea_id)->select('admin_name')->first(); // } $users['nickname']=$user->nickname; $users['mobile']=hide_phone($user->mobile); $users['level']=$user->level; $users['headimgurl']=$user->headimgurl; $users['time']=strtotime($user->created_at); if($user->recom_user){ $users['warea_info']=Warea::where('id',$user->recom_user->warea_id)->select('avatar','qrcode','admin_name')->first(); $users['recom_name']=$user->recom_user->nickname; $users['recom_mobile']=hide_phone($user->recom_user->mobile); $users['recom_level']=$user->recom_user->level; $users['recom_headimgurl']=$user->recom_user->headimgurl; if(count($user_cert)>0){ $users['recom_time']=strtotime($user_cert[0]->recom_updated_at); }else{ $users['recom_time']=null; } if($user->agent_user){ $users['agent_name']=$user->agent_user->nickname; $users['agent_mobile']=hide_phone($user->agent_user->mobile); $users['agent_level']=$user->agent_user->level; $users['agent_headimgurl']=$user->agent_user->headimgurl; if(count($user_cert)>0){ $users['agent_time']=strtotime($user_cert[0]->agent_updated_at); }else{ $users['agent_time']=null; } } } // }elseif ($user->cert_status==6){ // $users['status']=6; } $users['in_group']=$user->in_group; $users['in_group_time']=$user->service_end_time; return $this->success($users); } public function rand_code($num){ $code='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $str=$num."_"; $str_1=''; for ($i=0;$i<20;$i++){ $int=rand(0,34); $str_1.=mb_substr($code,$int,1); } $str=$str.mb_substr(time(),2,3).$str_1; return $str.mb_substr(time(),7,3); } /*--上传授权书---*/ public function auth_share(Request $request,ImageUploadHandler $handler){ Log::error('{---------开始----------}'); if ($request->img){ try{ $data=$handler->save($request->img,'img',Auth::user()->id); Log::error('{---------开始-大幅度发的---------}'); if ($data){ $user=User::find(Auth::user()->id); $user->auth_img=$data['path']; $user->save(); return $this->success(['url'=>$data['path']]); }else{ return $this->error(300); } }catch (\Exception $e){ Log::error('{------这里是上传授权书-----}'.Carbon::now()->toDateTimeString()); return $this->error(300); } } } public function auth_sel(Request $request){ $user=User::where('mobile',$request->phone)->first(); if (!$user){ $status=3; $msg='未查询到授权'; }else{ if ($user->freeze_status==1 || $user->status==1){ $status=3; if ($user->status===1){ $msg='未查询到授权'; // $msg='授权已被取消'; }else{ $msg='未查询到授权'; // $msg='该代理账户已被冻结'; } }else{ if ($user->service_status==1||$user->service_status==2) { $status = 3; $msg = '该代理尚未通过审核,暂未授权'; }elseif($user->in_group != 1){ $status = 3; $msg = '该代理尚未通过审核,暂未授权'; }else{ if ($user->deleted_at){ $status=3; $re=DB::table('agent_operation_log')->where('user_id',$user->id)->where('type',4)->orderByDesc('id')->first(); if ($re){ // $cause_one=['不做','主动退货','不来了','没有进货','没货了','不在人间','单位考核','联系不上']; // $cause_two=['重复','夫妻俩都有授权','换号了','授权改为家属','更换手机号']; // $cause_three=['不思悔改','不愿意退差价','低价','淘宝','第三','窜货','长期不订货','骚扰代理','不进货','私自']; // $msg=''; // foreach ($cause_one as $k=>$v){ // $res=stripos($re->remark,$v); // if ($res===0 ||$res){ // $msg='主动退货退出'; // break; // } // } // if (!$msg){ // foreach ($cause_two as $ke=>$va){ // $res=stripos($re->remark,$va); // if ($res===0 ||$res){ // $msg='授权重复被撤销'; // break; // } // } // } // if (!$msg){ // foreach ($cause_three as $kes=>$vas){ // $res=stripos($re->remark,$vas); // if ($res===0 ||$res){ // $msg='违规被取消授权'; // } // } // } // if (!$msg){ // $msg='授权被取消'; // } $msg='未查询到授权'; }else{ $msg='未查询到授权'; } }else{ $st=[0,1,2,4,5]; if (in_array($user->cert_status,$st)){ $msg='正在审核中'; $status=3; }else{ // $now=Carbon::now()->timestamp; // $time=strtotime($user->auth_endtime); // if ($now>$time){ // $status=3; // $msg='授权已过期'; // }else{ $data['phone']=$user->mobile; $data['level']=judge_level($user->level); $data['wechat']=$user->nickname; $data['num']=$user->cre_num; $data['realname']=$user->realname; $msg='ok'; $status=1; // } } } } } } $data['status']=$status; return $this->success($data,$msg); } public function auth_show(Request $request){ $user=User::where('mobile',$request->phone)->first(); if ($user->auth_img==null){ $name=$user->realname==null?$user->nickname:$user->realname; $url=$this->auth_create($name,$user->mobile,judge_level($user->level),$user->auth_code,$user->auth_startime,$user->auth_endtime,$user->id); $user->auth_img=$url; $user->save(); } // $data['time_start']=strtotime($user->auth_startime)*1000; // $data['time_end']=strtotime($user->auth_endtime)*1000; // $data['auth_code']=$user->auth_code; // $data['phone']=$request->phone; // $data['level']=judge_level($user->level); // $data['nickname']=$user->nickname==null?$user->name:$user->nickname; // $data['realname']=$user->realname==''?$user->nickname:$user->realname; $data['url']=$user->auth_img; return $this->success($data); } public function gzh(Request $request){ // if ($request->has('from')){ // return '
//
!
//
已停止访问该网页
//
'; // } Log::error(json_encode($request->all())); // return ''; $url=$request->url(); Log::info($url); $num=mb_strlen($url); $num1=mb_strlen('http://tw.cliu.cc/api/gzh/'); if ($num>$num1){ $data=substr($url,-5); if ($data=='david'){ return ''; } $time=substr($url,-10); if (is_numeric($time)){ }else{ return ''; } } return view('yzm'); } public function gzhtest(Request $request){ // if ($request->has('from')){ // return '
//
!
//
已停止访问该网页
//
'; // } return view('yzmtest'); } public function test(Request $request){ if ($request->has('from')){ return redirect('/api/test',301); } return view('test'); } public function gzh1(){ return view('recom'); } public function auth_select(){ // return ''; // if (!Agent::isMobile()){ // return view()->file(base_path().'/public/selectstatic/header.html'); // } return view('select'); } public function logout(){ $user=Auth::user(); $row=User::where('id',$user->id)->update([ 'openid'=>null, 'unionid'=>null ]); if($row){ return $this->success([]); } return $this->error(); // return response(view('yzm')) ->withCookie(new SCookie('DWBSTOKEN', 'sid9999', time()-1,'/api')) // ->withCookie(new SCookie('DWBSTOKEN','DWBSTOKEN',time()-10,'/')); } public function login(Request $request){ $user=User::where('mobile',$request->mobile)->where('deleted_at','=',null)->first(); if (!$user){ return $this->error(600); } if ($user->status==1){ return $this->error(700); } $password = md5($request->password); if (!hash_equals($password,$user->password)) { //返回401 return $this->error(300); } $token=Auth::guard()->fromUser($user); return $this->success(['token'=>$token]); } public function update_pass(Request $request){ $id=Auth::user()->id; $user=User::find($id); $user->password=md5($request->password); $user->save(); return $this->success([]); } public function update_nickname(Request $request){ DB::beginTransaction(); try{ $user=User::find(Auth::user()->id); $user->nickname=$request->nickname; $user->save(); DB::commit(); return $this->success([],'修改昵称成功'); }catch (\Exception $exception){ Log::error('{-------用户修改昵称出错----错误信息为--}'.$exception); DB::rollBack(); return $this->error(40013,'','修改出错,请重新尝试'); } } public function CreateTokenTest(Request $request){ $phone=$request->input('phone',''); if ($phone){ $re=User::where('mobile',$phone)->first(); if ($re){ return $this->success(Auth::guard('api')->fromUser($re)); }else{ return $this->error(50214,'','没找到'); } } return $this->error(50214,'','请添加参数 phone'); } public function GetSetingTime(){ $re=System::where('keys','upgrade_status')->value('values'); if ($re==1){ $start_time=System::where('keys','upgrade_start_time')->value('values'); $end_time=System::where('keys','upgrade_end_time')->value('values'); return $this->success(['status'=>true,'start_time'=>$start_time,'end_time'=>$end_time]); } return $this->success(['status'=>false]); } //设置代理皇冠 public function setUserCrown() { // User::where('level',3)->whereIn('cert_status',[3,6])->update(['crown_id'=>null]); // $crowns = User::where('level',3)->whereIn('cert_status',[3,6])->get(); // foreach($crowns as $key=>$val){ // User::where('agent_id',$val->id)->update(['crown_id'=>$val->id]); // $tops=User::where('level',2)->whereIn('cert_status',[3,6])->where('agent_id',$val->id)->get(); // foreach($tops as $k=>$v){ // User::where('agent_id',$v->id)->update(['crown_id'=>$val->id]); // } // } } public function shouquan(Request $request){ $url='http://api.cl.jiuweiyun.cn'; return redirect($url); } /*** *author:kele *信箱授权AA */ public function xxShouQuan(Request $request){ $url='http://api.cl.jiuweiyun.cn/api/cl?status=1&code='.$request->input('code'); // $url='http://192.168.2.120:8080?status=1&code='.$request->input('code'); return redirect($url); } }