public function login() { $validator = \Validator::make($this->request->all(), ['mobile' => 'required', 'password' => 'required']); $account = $this->request->get('mobile'); //查询用户是否被删除 $del_user_user_name = Customer::onlyTrashed()->where('user_name', $account)->first(); $del_user_mobile = Customer::onlyTrashed()->where('mobile', $account)->first(); if ($del_user_user_name || $del_user_mobile) { return return_rest('0', array('token' => '', 'customer' => array('id' => '', 'avatar' => '', 'type' => '', 'nickname' => '', 'name' => '', 'user_name' => '', 'mobile' => '')), '您已被移出!'); } $password = $this->request->get('password'); $credentials_mobile = array('mobile' => $account, 'password' => $password); $credentials_user_name = array('user_name' => $account, 'password' => $password); $token = \JWTAuth::attempt($credentials_mobile) ? \JWTAuth::attempt($credentials_mobile) : \JWTAuth::attempt($credentials_user_name); if (!$token) { // $validator->after(function ($validator) { // //$validator->errors()->add('error_msg', '用户名或密码错误'); // return $this->errorBadRequest(return_rest('0','','用户名或密码错误','10021')); // }); return return_rest('0', array('token' => '', 'customer' => array('id' => '', 'avatar' => '', 'type' => '', 'nickname' => '', 'name' => '', 'user_name' => '', 'mobile' => '')), '用户名或密码错误'); } if ($validator->fails()) { //return $this->errorBadRequest($validator->messages()); $messages = $validator->messages(); $mobiles = $messages->get('mobile'); foreach ($mobiles as $mobile) { if ($mobile == 'The selected mobile is invalid.') { return $this->errorBadRequest(return_rest('0', '', '手机号码未注册')); } } return return_rest('0', array('token' => '', 'customer' => array('id' => '', 'avatar' => '', 'type' => '', 'nickname' => '', 'name' => '')), '请按照规则输入手机号码'); } //登录成功 获取用户信息 $customer = Customer::select('id', 'type', 'name', 'nickname', 'avatar', 'user_name', 'mobile')->where('user_name', $this->request->get('mobile'))->orWhere('mobile', $this->request->get('mobile'))->first(); return return_rest('1', compact('token', 'customer'), '登陆成功'); }