before_add = function(&$data){ $uc_user = M('uc_user'); $depart_id = I('get.depart_id'); // 部门负责人唯一 if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人 $where = array('OrganizationId'=>$depart_id,'RoleId'=>$data['RoleId']); $count = $uc_user->where($where)->count(); if($count > 0){ json_fail('部门已有负责人'); } } //检查用户名是否重复 $where = array('UserName'=>$data['UserName']); if( $uc_user->where($where)->count() > 0 ){ json_fail('用户名已存在'); } //检查密码格式 if(strlen($data['Password']) < 4 ){ json_fail('密码长度必须大于4位'); } //检查手机号格式及是否重复(可通过手机号码登录) $rule = array('pattern'=>'mobile'); $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule); if(!$result){ json_fail(\Jiaruan\FieldValidator::getLastError()); } $where = array('Mobile'=>$data['Mobile']); if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){ json_fail('手机号码已被使用'); } $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) ); //$data['RoleId'] = json_encode($data['RoleId']); //拥有角色 $data['OrganizationId'] = $depart_id; }; $form->form_filter = function(&$form){ // 根据部门id获取部门等级,根据获取同等级角色 $cond = array('ID'=>I('get.depart_id')); $level= M('uc_organization')->where($cond)->getField('Level'); $role_list = get_role_option($level); $form['fields']['RoleId']['editor'] = array('options'=>$role_list); }; $form->display($this); } function sys_list( ){ $list = new \Jms\Gui\ClGrid(); $list->sql_sort = 'OrganizationId asc'; $list->sql_filter = function($search,&$cond){ $super_manage = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR); $cond['RoleId'] = array('not in',$super_manage);//平台管理员账号不显示 $id = I('get.id'); if($id){ $cond['OrganizationId'] = $id; }elseif( ! in_array($this->userinfo['RoleId'],$super_manage) ){ //非平台管理员查看 $cond['OrganizationId'] = $this->userinfo['OrganizationId']; }else{ } //搜索条件 if($search['UserName']){ //按用户名搜索 $cond['UserName'] = $search['UserName']; } if($search['RealName']){ //按姓名搜索 $cond['RealName'] = $search['RealName']; } if($search['Mobile']){ //按电话搜索 $cond['Mobile'] = $search['Mobile']; } }; $list->row_filter = function(&$row){ $where = array('ID'=>$row['RoleId']); $row['RoleId'] = M('uc_role')->where($where)->getField('RoleName'); }; $list->toolbar_filter = function(&$button){ if($button['icon'] == 'add'){ $button['url'] .= '&depart_id=' .I('get.id'); } }; $list->display($this); } function sys_edit( ){ $form = new \Jms\Gui\ClForm(); //字段联动 $form->onchange_filter = function($field,$data){ $result = array(); if($field == 'OrganizationId'){ if($data[$field]){ // 根据选择的部门等级,显示对应等级角色 $cond = array('ID'=>$data[$field]); $level = M('uc_organization')->where($cond)->getField('Level'); $result['RoleId'] = get_role_option($level); } } return $result; }; $form->form_filter = function(&$form){ // 初始化部门下拉选项 $zndp_util = new \Zndp\User\Util(); $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']); $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list); // 初始化角色下拉选项 $id = I('get.id'); $cond = array('ID'=>$id); $depart_id = M('uc_user')->where($cond)->getField('OrganizationId'); $cond = array('ID'=>$depart_id); $level = M('uc_organization')->where($cond)->getField('Level'); $role_list = get_role_option($level); $form['fields']['RoleId']['editor'] = array('options'=>$role_list); }; $form->before_display = function(&$data){ $data['Password'] = ''; }; $form->before_modify = function(&$data){ $id = I('get.id'); $uc_user = M('uc_user'); // 部门负责人唯一 if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人 $where = array('OrganizationId'=>$data['OrganizationId'],'RoleId'=>$data['RoleId'],'ID'=>array('NEQ',$id)); $count = $uc_user->where($where)->count(); if($count > 0){ json_fail('该部门已有负责人'); } } // 检查用户名是否重复 $where = array('UserName'=>$data['UserName'],'ID'=>array('neq',$id)); if( $uc_user->where($where)->count() > 0 ){ json_fail('用户名已存在'); } //检查手机号格式及是否重复(可通过手机号码登录) $rule = array('pattern'=>'mobile'); $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule); if(!$result){ json_fail(\Jiaruan\FieldValidator::getLastError()); } $where = array('Mobile'=>$data['Mobile'],'ID'=>array('neq',$id)); if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){ json_fail('手机号码已被使用'); } // 检查密码 if(!$data['Password']){ unset($data['Password']); }elseif($data['Password'] && strlen($data['Password']) < 4 ){ json_fail('密码长度必须大于4位'); }else{ $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) ); } }; $form->display($this); } function sys_change_depart( ){ $form = new \Jms\Gui\ClForm(); $form->before_modify = function(&$data){ }; //字段联动 $form->onchange_filter = function($field,$data){ $result = array(); if($field == 'OrganizationId'){ if($data[$field]){ // 根据选择的部门等级,显示对应等级角色 $cond = array('ID'=>$data[$field]); $level = M('uc_organization')->where($cond)->getField('Level'); $result['RoleId'] = get_role_option($level); } } return $result; }; $form->form_filter = function(&$form){ // 初始化部门下拉选项 $zndp_util = new \Zndp\User\Util(); $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']); $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list); // 初始化角色下拉选项 $id = I('get.id'); $cond = array('ID'=>$id); $depart_id = M('uc_user')->where($cond)->getField('OrganizationId'); $cond = array('ID'=>$depart_id); $level = M('uc_organization')->where($cond)->getField('Level'); $role_list = get_role_option($level); $form['fields']['RoleId']['editor'] = array('options'=>$role_list); }; $form->display($this); } function sys_nav_tree( ){ //获取导航树数据 $fields = 'ID as id,ParentID as pId,DepartName as name,Level as level'; $zndp_util = new \Zndp\User\Util(); $depart_list = $zndp_util->get_depart_option('',$fields,'name',false); if(empty($depart_list)){ //没有数据,显示该 $depart_list[0] = array('id'=>'','pid'=>'','name'=>'没有组织','direct_url'=>''); }else{ for($i=0; $iuserinfo['RoleId'], $admin_arr) ){ $all_list = array('id'=>'0','pId'=>'','name'=>'所有用户','direct_url'=>'?s=dpyh_manager/sys_list','open'=>true); array_unshift($depart_list,$all_list); } $this->assign('title','用户管理'); $this->assign('tree_data',$depart_list); $this->display(); } function sys_list_search( ){ } public function sys_del( ){ $grid = new \Jiaruan\GridData(); $grid->deleteByPk($this); } function sys_all_list( ){ $list = new \Jms\Gui\ClGrid(); $list->sql_sort = 'OrganizationId asc'; $list->sql_filter = function($search,&$cond){ // 部门管理员不显示部门负责人账号信息 $super_manage = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR); $leader_list = \Zndp\User\RoleEnum::get_leader_list(); if( in_array($this->userinfo['RoleId'],$super_manage) || in_array($this->userinfo['RoleId'],$leader_list) ){ //平台管理员或部门负责人 $cond['RoleId'] = array('not in',$super_manage); }else{ //否则不能看负责人账号信息 $hide_list = array_merge($super_manage,$leader_list); $cond['RoleId'] = array('NOT IN',$hide_list); } //查看部门下所有账号 $zndp_util = new \Zndp\User\Util(); $depart_list = $zndp_util->get_depart_ids($this->userinfo['OrganizationId']); $cond['OrganizationId'] = array('in',$depart_list); //搜索条件 if($search['UserName']){ //按用户名搜索 $cond['UserName'] = $search['UserName']; } if($search['RealName']){ //按姓名搜索 $cond['RealName'] = $search['RealName']; } if($search['Mobile']){ //按电话搜索 $cond['Mobile'] = $search['Mobile']; } }; $list->row_filter = function(&$row){ $where = array('ID'=>$row['RoleId']); $row['RoleId_text'] = M('uc_role')->where($where)->getField('RoleName'); $where = array('ID'=>$row['OrganizationId']); $row['OrganizationId_text'] = M('uc_organization')->where($where)->getField('DepartName'); }; $list->toolbar_filter = function(&$button){ if($button['icon'] == 'add'){ $button['url'] .= '&depart_id=' .I('get.id'); } }; $list->display($this); } function sys_all_add( ){ $form = new \Jms\Gui\ClForm(); $form->before_add = function(&$data){ $uc_user = M('uc_user'); $depart_id = I('get.depart_id'); // 部门负责人唯一 if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人 $where = array('OrganizationId'=>$depart_id,'RoleId'=>$data['RoleId']); $count = $uc_user->where($where)->count(); if($count > 0){ json_fail('部门已有负责人'); } } //检查用户名是否重复 $where = array('UserName'=>$data['UserName']); if( $uc_user->where($where)->count() > 0 ){ json_fail('用户名已存在'); } //检查密码格式 if(strlen($data['Password']) < 4 ){ json_fail('密码长度必须大于4位'); } //检查手机号格式及是否重复(可通过手机号码登录) $rule = array('pattern'=>'mobile'); $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule); if(!$result){ json_fail(\Jiaruan\FieldValidator::getLastError()); } $where = array('Mobile'=>$data['Mobile']); if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){ json_fail('手机号码已被使用'); } $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) ); }; //字段联动 $form->onchange_filter = function($field,$data){ $result = array(); if($field == 'OrganizationId'){ if($data[$field]){ // 根据选择的部门等级,显示对应等级角色 $cond = array('ID'=>$data[$field]); $level = M('uc_organization')->where($cond)->getField('Level'); $result['RoleId'] = get_role_option($level); } } return $result; }; $form->form_filter = function(&$form){ // 初始化部门下拉选项 $zndp_util = new \Zndp\User\Util(); $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']); $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list); // 根据部门id获取部门等级,根据获取同等级角色 $cond = array('ID'=>$depart_list[0]['id']); $level= M('uc_organization')->where($cond)->getField('Level'); $role_list = get_role_option($level); $form['fields']['RoleId']['editor'] = array('options'=>$role_list); }; $form->display($this); } }