where('username', $username) ->find(); if (!$user || !password_verify($password, $user['password'])) { throw new \Exception('用户名或密码错误'); } if ($user['status'] != 1) { throw new \Exception('账户已禁用,请联系管理员'); } $userInfo = [ 'id' => $user['id'], // 用户ID 'company_id' => $user['company_id'], // 所属公司ID 'company_name' => $user['company']['company_name'], // 所属公司名称 'username' => $user['username'], 'role' => $user['role'], ]; Session::set('user_info', $userInfo); return $userInfo; } }