예제 #1
0
파일: User.php 프로젝트: bjtenao/tudu-web
 /**
  * 获取用户分页数据
  *
  * @param array $condition
  * @param mixed $sort
  * @param int   $page
  * @param int   $pageSize
  * @return Dao_User_Record_Users
  */
 public function getUserPage(array $condition, $sort = null, $page = null, $pageSize = null)
 {
     $table = 'md_user AS U LEFT JOIN md_user_info AS UI ON U.org_id = UI.org_id AND U.user_id = UI.user_id ' . 'LEFT JOIN md_department AS D ON U.org_id = D.org_id AND U.dept_id = D.dept_id ' . 'LEFT JOIN md_user_role AS R ON R.org_id = U.org_id AND R.user_id = U.user_id ' . 'LEFT JOIN md_user_group AS G ON G.org_id = U.org_id AND G.user_id = U.user_id';
     $columns = 'U.org_id AS orgid, U.user_id AS userid, U.unique_id AS uniqueid, ' . 'U.dept_id AS deptid, U.status, UI.gender, GROUP_CONCAT(DISTINCT(G.group_id)) AS groups, ' . 'D.dept_name AS deptname, UI.true_name AS truename, U.create_time AS createtime, U.unlock_time AS unlocktime, ' . 'GROUP_CONCAT(DISTINCT(R.role_id)) AS roles';
     $where = array();
     $order = array();
     $primary = 'U.user_id';
     $recordClass = 'Dao_Md_User_Record_UserPage';
     if (!empty($condition['orgid'])) {
         $where[] = 'U.org_id = ' . $this->_db->quote($condition['orgid']);
     }
     if (!empty($condition['userid'])) {
         $where[] = 'U.user_id = ' . $this->_db->quote($condition['userid']);
     }
     if (!empty($condition['domain'])) {
         $where[] = 'DM.domain_name = ' . $this->_db->quote($condition['domain']);
     }
     if (!empty($condition['domainid'])) {
         $where[] = 'U.domain_id = ' . $this->_db->quote($condition['domainid']);
     }
     if (!empty($condition['deptid'])) {
         if (is_array($condition['deptid'])) {
             $condition['deptid'] = array_map(array($this->_db, 'quote'), $condition['deptid']);
             $where[] = 'U.dept_id IN (' . implode(',', $condition['deptid']) . ')';
         } else {
             $where[] = 'U.dept_id = ' . $this->_db->quote($condition['deptid']);
         }
     }
     if (!empty($condition['groupid'])) {
         $table .= 'LEFT JOIN md_user_group AS G ON U.org_id = G.org_id AND U.user_id = G.user_id ';
         $where[] = 'G.group_id = ' . $this->_db->quote($condition['groupid']);
     }
     if (isset($condition['status']) && is_int($condition['status'])) {
         $where[] = 'U.status = ' . $condition['status'];
     }
     if (!empty($condition['keyword'])) {
         $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
         $str = "UI.true_name LIKE {$keyword} OR UI.nick LIKE {$keyword}";
         if (Oray_Function::isByte($condition['keyword'])) {
             $str .= " OR U.user_id LIKE {$keyword} OR UI.pinyin LIKE {$keyword}";
         }
         $where[] = '(' . $str . ')';
     }
     if (isset($condition['createtime'])) {
         if (is_array($condition['createtime'])) {
             $w = array();
             if (isset($condition['createtime']['start'])) {
                 $w[] = 'create_time >= ' . $condition['starttime'];
             }
             if (isset($condition['createtime']['end'])) {
                 $w[] = 'create_time <= ' . $condition['endtime'];
             }
             if ($w) {
                 $where[] = '(' . implode(' AND ', $w) . ')';
             }
         } elseif (is_int($condition['createtime'])) {
             $where[] = 'create_time >= ' . $condition['starttime'];
         }
     }
     if (!$where) {
         return new Oray_Dao_Recordset();
     }
     // WHERE
     //$where = implode(' AND ', $where);
     $where = ' WHERE ' . implode(' AND ', $where);
     // 排序
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'userid':
                 $key = 'U.user_id';
                 break;
             case 'createtime':
                 $key = 'U.create_time';
                 break;
             case 'ordernum':
                 $key = 'U.order_num';
                 break;
             case 'deptid':
                 $key = 'U.dept_id';
                 break;
             case 'status':
                 $key = 'U.status';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     if ($order) {
         $order = 'ORDER BY ' . $order;
     }
     $limit = '';
     if (null !== $page) {
         // 使用默认的分页大小
         if (null === $pageSize) {
             $pageSize = self::$_defaultPageSize;
         }
         $offset = ($page - 1) * $pageSize;
         $limit = "LIMIT {$offset}, {$pageSize}";
     }
     $sql = "SELECT {$columns} FROM {$table} {$where} GROUP BY U.org_id, U.user_id {$order} {$limit}";
     $records = $this->_db->fetchAll($sql);
     return new Oray_Dao_Recordset($records, $recordClass);
     /**
      * @see Oray_Db_Paginator
      */
     //require_once 'Oray/Db/Paginator.php';
     /*$paginator = new Oray_Db_Paginator(array(
                 Oray_Db_Paginator::ADAPTER   => $this->_db,
                 Oray_Db_Paginator::TABLE     => $table,
                 Oray_Db_Paginator::COLUMNS   => $columns,
                 Oray_Db_Paginator::ORDER     => $order,
                 Oray_Db_Paginator::PRIMARY   => $primary,
                 Oray_Db_Paginator::WHERE     => $where,
                 Oray_Db_Paginator::PAGE_SIZE => $pageSize,
     
                 Oray_Db_Paginator::RECORD_CLASS => $recordClass
             ));*/
     //return $paginator->query($page);
 }
예제 #2
0
파일: Oplog.php 프로젝트: bjtenao/tudu-web
 /**
  * Get record page
  *
  * @param array $condition
  * @param mixed $sort
  * @param int $page
  * @param int $pageSize
  * @return Oray_Dao_Recordset
  */
 public function getAdminLogPage(array $condition = null, $sort = null, $page = null, $pageSize = null)
 {
     $table = 'md_op_log';
     $columns = 'org_id AS orgid, user_id AS userid, module, action, sub_action AS subaction, ' . 'target, ip, local, create_time AS createtime, detail';
     $primary = 'create_time';
     $recordClass = "Dao_Md_Log_Record_Oplog";
     $where = array();
     $order = array();
     if (!empty($condition['userid'])) {
         $where[] = 'user_id = ' . $this->_db->quote($condition['userid']);
     }
     if (!empty($condition['orgid'])) {
         $where[] = 'org_id = ' . $this->_db->quote($condition['orgid']);
     }
     if (!empty($condition['module'])) {
         $where[] = 'module = ' . $this->_db->quote($condition['module']);
     }
     /*if (!empty($condition['starttime']) && !empty($condition['endtime'])) {
                 $where[] = 'create_time >= UNIX_TIMESTAMP(' . $this->_db->quote($condition['starttime']) . ') AND create_time <= UNIX_TIMESTAMP(' . $this->_db->quote($condition['endtime']) . ')';
             }
     
             if (!empty($condition['starttime']) && empty($condition['endtime'])) {
                 $where[] = 'create_time >= UNIX_TIMESTAMP(' . $this->_db->quote($condition['starttime']) . ')';
             }
     
             if (empty($condition['starttime']) && !empty($condition['endtime'])) {
                 $where[] = 'create_time <= UNIX_TIMESTAMP(' . $this->_db->quote($condition['endtime']) . ')';
             }*/
     if (isset($condition['createtime'])) {
         if (is_int($condition['createtime'])) {
             $where[] = 'create_time = ' . $condition['createtime'];
         } elseif (is_array($condition['createtime'])) {
             $arr = $condition['createtime'];
             if (isset($arr[0]) && is_int($arr[0])) {
                 $where[] = 'create_time >= ' . $arr[0];
             }
             if (isset($arr[1]) && is_int($arr[1])) {
                 $where[] = 'create_time <=' . $arr[1];
             }
         }
     }
     if (!empty($condition['keywords']) && Oray_Function::isByte($condition['keywords'])) {
         $keyword = $this->_db->quote('%' . $condition['keywords'] . '%');
         $where[] = "(user_id LIKE {$keyword} OR ip LIKE {$keyword})";
     }
     // WHERE
     $where = implode(' AND ', $where);
     // 格式化排序参数
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'createtime':
                 $key = 'create_time';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     // 使用默认的分页大小
     if (null === $pageSize) {
         $pageSize = self::$_defaultPageSize;
     }
     /**
      * @see Oray_Db_Paginator
      */
     require_once 'Oray/Db/Paginator.php';
     // 初始化分页器
     $paginator = new Oray_Db_Paginator(array(Oray_Db_Paginator::ADAPTER => $this->_db, Oray_Db_Paginator::RECORD_CLASS => $recordClass, Oray_Db_Paginator::PAGE_SIZE => $pageSize, Oray_Db_Paginator::TABLE => $table, Oray_Db_Paginator::PRIMARY => $primary, Oray_Db_Paginator::COLUMNS => $columns, Oray_Db_Paginator::WHERE => $where, Oray_Db_Paginator::ORDER => $order));
     // 返回查询结果
     return $paginator->query($page);
 }
예제 #3
0
파일: Login.php 프로젝트: bjtenao/tudu-web
 /**
  * Get record page 前台登录日志列表
  *
  * @param array $condition
  * @param mixed $sort
  * @param int $page
  * @param int $pageSize
  * @return Oray_Dao_Recordset
  */
 public function getLoginLogPage(array $condition = null, $sort = null, $page = null, $pageSize = null)
 {
     $table = 'md_login_log';
     $columns = 'login_log_id AS loginlogid, org_id AS orgid, unique_id AS uniqueid, address, ' . 'truename, ip, local, isp, `clientkey`, client_info AS clientinfo, create_time AS createtime';
     $primary = 'create_time';
     $recordClass = "Dao_Md_Log_Record_Login";
     $where = array();
     $order = array();
     if (!empty($condition['orgid'])) {
         $where[] = 'org_id = ' . $this->_db->quote($condition['orgid']);
     }
     if (!empty($condition['uniqueid'])) {
         $where[] = 'unique_id = ' . $this->_db->quote($condition['uniqueid']);
     }
     if (!empty($condition['address'])) {
         $where[] = 'address = ' . $this->_db->quote($condition['address']);
     }
     if (!empty($condition['truename'])) {
         $where[] = 'truename = ' . $this->_db->quote($condition['truename']);
     }
     if (isset($condition['createtime'])) {
         if (is_int($condition['createtime'])) {
             $where[] = 'create_time = ' . $condition['createtime'];
         } elseif (is_array($condition['createtime'])) {
             $arr = $condition['createtime'];
             if (isset($arr[0]) && is_int($arr[0])) {
                 $where[] = 'create_time >= ' . $arr[0];
             }
             if (isset($arr[1]) && is_int($arr[1])) {
                 $where[] = 'create_time <=' . $arr[1];
             }
         }
     }
     if (!empty($condition['keywords'])) {
         $keyword = $this->_db->quote('%' . $condition['keywords'] . '%');
         $like[] = "truename LIKE {$keyword}";
         if (Oray_Function::isByte($condition['keywords'])) {
             $like[] = "address LIKE {$keyword}";
             $like[] = "ip LIKE {$keyword}";
         }
         $where[] = '(' . implode(' OR ', $like) . ')';
     }
     // WHERE
     $where = implode(' AND ', $where);
     // 格式化排序参数
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'createtime':
                 $key = 'create_time';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     // 使用默认的分页大小
     if (null === $pageSize) {
         $pageSize = self::$_defaultPageSize;
     }
     /**
      * @see Oray_Db_Paginator
      */
     require_once 'Oray/Db/Paginator.php';
     // 初始化分页器
     $paginator = new Oray_Db_Paginator(array(Oray_Db_Paginator::ADAPTER => $this->_db, Oray_Db_Paginator::RECORD_CLASS => $recordClass, Oray_Db_Paginator::PAGE_SIZE => $pageSize, Oray_Db_Paginator::TABLE => $table, Oray_Db_Paginator::PRIMARY => $primary, Oray_Db_Paginator::COLUMNS => $columns, Oray_Db_Paginator::WHERE => $where, Oray_Db_Paginator::ORDER => $order));
     // 返回查询结果
     return $paginator->query($page);
 }
예제 #4
0
파일: User.php 프로젝트: bjtenao/tudu-web
 /**
  * 更新用户
  */
 public function update(array $params)
 {
     // 组织ID必须有
     if (empty($params['orgid'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "orgid"', self::CODE_INVALID_ORGID);
     }
     $orgId = $params['orgid'];
     $edit = array('truename' => true, 'password' => true, 'dept' => true, 'status' => true, 'role' => true, 'group' => true, 'cast' => true, 'netdisk' => true, 'email' => true);
     if (!empty($params['edit'])) {
         $edit = $params['edit'];
     }
     /* @var $daoUser Dao_Md_User_User */
     $daoUser = Tudu_Dao_Manager::getDao('Dao_Md_User_User', Tudu_Dao_Manager::DB_MD);
     // 用户名
     if (empty($params['userid'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing the value of parameter "userid"', self::CODE_MISSING_UID);
     }
     $userId = $params['userid'];
     $user = $daoUser->getUser(array('orgid' => $orgId, 'userid' => $userId));
     $userIf = $daoUser->getUserInfo(array('orgid' => $orgId, 'userid' => $userId));
     // 用户不存在
     if (null === $user) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing the value of parameter "userid"', self::CODE_USER_NOTEXISTS);
     }
     // 用户真实姓名
     if ($edit['truename'] && empty($params['truename'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Missing or invalid value of parameter "truename"', self::CODE_INVALID_USERNAME);
     }
     // 邮箱格式有误
     if ($edit['email'] && !empty($params['email']) && !Oray_Function::isEmail($params['email'])) {
         require_once 'Model/User/Exception.php';
         throw new Model_User_Exception('Invalid value of parameter "email"', self::CODE_INVALID_EMAIL);
     }
     $userParam = array();
     $userInfo = array();
     if ($edit['status']) {
         $userParam['status'] = isset($params['status']) ? (int) $params['status'] : 1;
     }
     if ($edit['dept']) {
         $userParam['deptid'] = isset($params['deptid']) ? $params['deptid'] : null;
     }
     if (isset($params['ordernum'])) {
         $userParam['ordernum'] = (int) $params['ordernum'];
     }
     $userParam['lastupdatetime'] = time();
     if (isset($params['isshow'])) {
         $userParam['isshow'] = $params['isshow'];
     }
     if (isset($params['truename'])) {
         $userInfo['truename'] = $params['truename'];
     }
     if (isset($params['position'])) {
         $userInfo['position'] = $params['position'];
     }
     if (isset($params['gender'])) {
         $userInfo['gender'] = (int) $params['gender'];
     }
     if (isset($params['tel'])) {
         $userInfo['tel'] = $params['tel'];
     }
     if (isset($params['mobile'])) {
         $userInfo['mobile'] = $params['mobile'];
     }
     if (isset($params['email'])) {
         $userInfo['email'] = $params['email'];
     }
     /* @var $daoOrg Dao_Md_Org_Org */
     $daoOrg = Tudu_Dao_Manager::getDao('Dao_Md_Org_Org', Tudu_Dao_Manager::DB_MD);
     // 读取组织信息
     $org = $daoOrg->getOrg(array('orgid' => $orgId));
     // 网盘空间
     if ($edit['netdisk'] && !empty($params['maxndquota'])) {
         $ndQuota = (double) $params['maxndquota'] * 1000000;
         if ($ndQuota != $user->maxNdQuota) {
             if ($params['maxndquota'] > 1000) {
                 require_once 'Model/User/Exception.php';
                 throw new Model_User_Exception('You can not set exceed 1000MB netdisk space', self::CODE_EXCEED_MAX_NDSPACE);
             }
             /* @var $daoFolder Dao_Td_Netdisk_Folder */
             $daoFolder = Tudu_Dao_Manager::getDao('Dao_Td_Netdisk_Folder', Tudu_Dao_Manager::DB_TS);
             $folderRoot = $daoFolder->getFolder(array('uniqueid' => $user->uniqueId, 'folderid' => '^root'));
             if (null !== $folderRoot && $ndQuota < $folderRoot->folderSize) {
                 require_once 'Model/User/Exception.php';
                 throw new Model_User_Exception('This netdisk space can not less than the used netdisk space', self::CODE_LESS_NDSPACE);
             }
             // 更新用户网盘跟文件夹空间
             if (null !== $folderRoot) {
                 $daoFolder->updateFolder($user->uniqueId, '^root', array('maxquota' => $ndQuota));
             }
             $userParam['maxndquota'] = $ndQuota;
         }
     }
     // 无效的出生日期
     if (!empty($params['birthday'])) {
         if (false === $params['birthday']) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Missing or invalid value of parameter "birthday"', self::CODE_INVALID_BIRTHDAY);
         }
         $userInfo['birthday'] = $params['birthday'];
     }
     if ($edit['truename'] && !Oray_Function::isByte($params['truename'])) {
         require_once 'Tudu/Pinyin.php';
         $userInfo['pinyin'] = Tudu_Pinyin::parse($params['truename'], true);
     }
     if (!empty($params['nick'])) {
         $userInfo['nick'] = $params['nick'];
     }
     if (!empty($params['idnumber'])) {
         $userInfo['idnumber'] = $params['idnumber'];
     }
     if ($edit['password'] && !empty($params['password'])) {
         if ($daoUser->isAdmin($orgId, $userId)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Can not modify the administrator password', self::CODE_NOT_MODIFY_PWD);
         }
         $userParam['initpassword'] = 1;
         $userInfo['password'] = $params['password'];
     }
     // 用户头像
     if (!empty($params['avatars'])) {
         $userInfo['avatartype'] = $params['avatartype'];
         $userInfo['avatars'] = $params['avatars'];
         /* @var $daoImContact Dao_Im_Contact_Contact */
         //$daoImContact = Tudu_Dao_Manager::getDao('Dao_Im_Contact_Contact', Tudu_Dao_Manager::DB_IM);
         // 需要更新im自定义联系人表的updatetime
         // im通过更新时间判断是否需要获取用户头像
         //$daoImContact->updateUser($userId . '@' . $orgId, array('updatetime' => time()));
     }
     // 更新用户数据
     if (!empty($userParam)) {
         if (!$daoUser->updateUser($orgId, $user->userId, $userParam)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Update user failed', self::CODE_SAVE_FAILED);
         }
     }
     if (!empty($userInfo)) {
         if (!$daoUser->updateUserInfo($orgId, $user->userId, $userInfo)) {
             require_once 'Model/User/Exception.php';
             throw new Model_User_Exception('Update user info failed', self::CODE_SAVE_FAILED);
         }
     }
     // 群组
     /* @var $daoGroup Dao_Md_User_Group */
     $daoGroup = Tudu_Dao_Manager::getDao('Dao_Md_User_Group', Tudu_Dao_Manager::DB_MD);
     if ($edit['group']) {
         $groups = !empty($params['groupid']) ? $params['groupid'] : array();
         $daoUser->removeGroups($user->orgId, $user->userId);
         foreach ($groups as $groupId) {
             $daoGroup->addUser($orgId, $groupId, $userId);
         }
     }
     // 权限组
     /* @var $daoRole Dao_Md_User_Role */
     $daoRole = Tudu_Dao_Manager::getDao('Dao_Md_User_Role', Tudu_Dao_Manager::DB_MD);
     if ($edit['role']) {
         $roles = !empty($params['roleid']) ? $params['roleid'] : array();
         $daoUser->removeRoles($user->orgId, $user->userId);
         foreach ($roles as $roleId) {
             $daoRole->addUsers($orgId, $roleId, $userId);
         }
     }
     // 组织架构
     /* @var $daoCast Dao_Md_User_Cast */
     $daoCast = Tudu_Dao_Manager::getDao('Dao_Md_User_Cast', Tudu_Dao_Manager::DB_MD);
     if ($edit['cast']) {
         $castDepts = !empty($params['castdept']) ? $params['castdept'] : array();
         $castUsers = !empty($params['castuser']) ? $params['castuser'] : array();
         // 清除组织架构
         $daoCast->clear($orgId, $userId);
         // 隐藏部门
         foreach ($castDepts as $dept) {
             if (!trim($dept) || $dept == '^root' || $dept == $userParam['deptid']) {
                 continue;
             }
             $daoCast->hideDepartment($orgId, $userId, $dept);
         }
         // 隐藏用户
         foreach ($castUsers as $uId) {
             if (!$uId || $uId == $userId) {
                 continue;
             }
             $daoCast->hideUser($orgId, $userId, $uId);
         }
         // 更换部门
         if ($user->deptId != $userParam['deptid']) {
             $daoCast->updateDepartment($orgId, $userId, $userParam['deptid']);
         }
     }
     // 修改企业默认密码
     if ($edit['password'] && !empty($params['password']) && $org->defaultPassword != $params['password']) {
         $daoOrg->updateOrg($orgId, array('defaultpassword' => $params['password']));
     }
     // 发送通知,插入消息队列
     if (Tudu_Model::hasResource(Tudu_Model::RESOURCE_CONFIG)) {
         $config = Tudu_Model::getResource(Tudu_Model::RESOURCE_CONFIG);
         if ($config['httpsqs']) {
             $options = $config['httpsqs'];
             $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']);
             $data = implode(' ', array(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_UPDATE, null, implode(':', array($orgId, $user->userName, $user->uniqueId, ''))));
             $httpsqs->put($data);
         }
     }
     // 添加后台操作日志
     if (!empty($params['operator']) && !empty($params['clientip'])) {
         $params['local'] = empty($params['local']) ? null : $params['local'];
         $trueName = $edit['truename'] ? $params['truename'] : $userIf->trueName;
         $this->_createLog(Dao_Md_Log_Oplog::MODULE_USER, Dao_Md_Log_Oplog::OPERATION_UPDATE, null, array('orgid' => $orgId, 'operator' => $params['operator'], 'clientip' => $params['clientip'], 'local' => $params['local']), implode(':', array($orgId, $user->userName, $user->uniqueId)), array('truename' => $trueName, 'account' => $user->userName));
     }
 }
예제 #5
0
파일: Cast.php 프로젝트: bjtenao/tudu-web
 /**
  *
  * @param $condition
  * @param $filter
  * @param $sort
  * @param $maxCount
  */
 public function getCastUserPage(array $condition, $sort = null, $page = null, $pageSize = null)
 {
     if (empty($condition['orgid']) || empty($condition['userid'])) {
         return new Oray_Dao_Recordset();
     }
     $orgId = $this->_db->quote($condition['orgid']);
     $userId = $this->_db->quote($condition['userid']);
     $table = 'md_user AS U ' . "LEFT JOIN md_cast_disable_user AS CU ON CU.org_id = U.org_id AND CU.user_id = U.user_id AND CU.owner_id = {$userId} " . 'LEFT JOIN md_user_info AS UI ON U.org_id = UI.org_id AND U.user_id = UI.user_id ' . 'LEFT JOIN md_department DE ON U.org_id = DE.org_id AND U.dept_id = DE.dept_id';
     $columns = 'U.org_id AS orgid, UI.true_name AS truename, U.user_id AS userid, mobile, ' . 'U.dept_id AS deptid, DE.dept_name AS deptname, UI.pinyin, U.unique_id AS uniqueid, ' . 'UI.position, UI.tel';
     $where = array();
     $order = array();
     $recordClass = 'Dao_Md_User_Record_Users';
     $primary = 'U.org_id';
     //$where[] = 'CU.org_id =' . $orgId;
     //$where[] = 'CU.owner_id =' . $userId;
     $where[] = 'U.org_id =' . $orgId;
     $where[] = 'CU.user_id IS NULL';
     $where[] = 'U.status <> 0 AND U.is_show = 1';
     if (!empty($condition['keyword'])) {
         $keyword = $this->_db->quote('%' . $condition['keyword'] . '%');
         $like[] = "UI.true_name LIKE {$keyword}";
         if (Oray_Function::isByte($keyword)) {
             $like[] = "UI.pinyin LIKE {$keyword}";
             $like[] = "U.user_id LIKE {$keyword}";
         }
         $where[] = '(' . implode(' OR ', $like) . ')';
     }
     if (!empty($condition['pinyin'])) {
         $keyword = $this->_db->quote($condition['pinyin'] . '%');
         $where[] = "(U.true_name LIKE {$keyword} OR UI.pinyin LIKE {$keyword})";
     }
     if (!empty($condition['deptid']) && is_array($condition['deptid'])) {
         foreach ($condition['deptid'] as $deptId) {
             $dept[] = 'U.dept_id = ' . $this->_db->quote($deptId);
         }
         $where[] = '(' . implode(' OR ', $dept) . ')';
     }
     // WHERE
     $where = implode(' AND ', $where);
     // 排序
     $sort = $this->_formatSort($sort);
     foreach ($sort as $key => $val) {
         switch ($key) {
             case 'ordernum':
                 $key = 'U.order_num';
                 break;
             case 'userid':
                 $key = 'U.user_id';
                 break;
             case 'deptid':
                 $key = 'U.dept_id';
                 break;
             default:
                 continue 2;
                 break;
         }
         $order[] = $key . ' ' . $val;
     }
     // ORDER
     $order = implode(', ', $order);
     // 使用默认的分页大小
     if (null === $pageSize) {
         $pageSize = self::$_defaultPageSize;
     }
     /**
      * @see Oray_Db_Paginator
      */
     require_once 'Oray/Db/Paginator.php';
     $paginator = new Oray_Db_Paginator(array(Oray_Db_Paginator::ADAPTER => $this->_db, Oray_Db_Paginator::TABLE => $table, Oray_Db_Paginator::COLUMNS => $columns, Oray_Db_Paginator::ORDER => $order, Oray_Db_Paginator::PRIMARY => $primary, Oray_Db_Paginator::WHERE => $where, Oray_Db_Paginator::PAGE_SIZE => $pageSize, Oray_Db_Paginator::RECORD_CLASS => $recordClass));
     return $paginator->query($page);
 }