model = new AdminModel(); $this->groupModel = new AuthGroupModel(); $this->storeModel = new StoreModel(); $this->groupAccessModel = new AuthGroupAccessModel(); } public function loadByLogin($username, $password) { $admin = $this->model->loadByLogin($username,$password); if (!$admin) return $this->fail(lang('The account password is incorrect')); $access = $this->groupAccessModel->findByAdminId($admin->id); if (!$access) return $this->fail(lang('Background permission is not set')); $group = $this->groupModel->findById($access->group_id); if (!$group) return $this->fail(lang('The role group does not exist')); $stores = $this->storeModel->findByIds($admin->store_ids ? explode(',', $admin->store_ids) : []); if(count($stores) == 0) return $this->fail("该员工未绑定门店信息"); unset($admin['password']); $admin['group'] = $group; $admin['stores'] = $stores; $token = \Jwt::getToken([ 'iss'=>'jwt_user', //该JWT的签发者 'iat'=>time(), //签发时间 'exp'=>time()+7200*7, //过期时间 'nbf'=>time(), //该时间之前不接收处理该Token 'jti'=>md5(uniqid('JWT').time()), //该Token唯一标识 'admin_id' => $admin->id, 'account' => $admin->account, 'nickname' => $admin->nickname, 'group_id' => $group->id, 'group_name' => $group->name, ]); if($token === false) return $this->fail(lang('Failed to obtain token')); $admin->token = $token; // $redis = Cache::store('redis')->handler(); //返回句柄对象,可执行其它高级方法 // $sadd = $redis->sadd('user:infos', $token); $refreshToken = $this->model->refreshToken($admin->id, $token); return $refreshToken ? $this->ok($admin) : $this->fail("Fail"); } }