sql_filter = function($search,&$cond){ $cond['RoleId'] = \Zndp\User\RoleEnum::API_CLIENT; }; $list->display($this); } function sys_addedit( ){ $form = new \Jiaruan\LigerIframeForm(); $form->before_add = function(&$data){ $data['ProjectID'] = C('CC_PROJECT_ID'); $data['RoleId'] = \Zndp\User\RoleEnum::API_CLIENT; }; $form->before_save = function(&$data){ $id = I('get.id'); //取出原用户名,密码 $userinfo = M('uc_user')->field('UserName,Password')->where(array('ID'=>$id))->find(); $cond = array( 'ID' => array('neq',$id), 'UserName' => $data['UserName'], ); if( M('uc_user')->where($cond)->count() > 0 ){ json_fail('该用户名已存在,请换一个!'); } if( $data['Password'] != $userinfo['Password'] ) { $data['Password'] = (new \Zndp\User\Util)->encPwd( $data['Password'] ); }else{ unset($data['Password']); } }; $form->display($this); } public function sys_delete_api( ){ $id = I('get.id'); if(!$id){ json_fail('ID不存在!'); } $where =array('ID'=>$id); $result = M('uc_user')->where($where)->delete(); if(!$result){ json_fail('删除失败!'); } json_success('删除成功!'); } function sys_assoc_list( ){ $list = new \Jms\Gui\ClGrid(); $list->sql_filter = function($search,&$cond){ $cond['AssocId'] = I('get.id'); }; $list->row_filter = function(&$row){ $where = array('ID'=>$row['FarmId']); $row['FarmId_text'] = MM('dpyh_farm')->where($where)->getField('FarmName'); }; $list->toolbar_filter = function(&$toolbar){ if($toolbar['icon'] == 'add'){ $toolbar['url'] .= "&id=".I('get.id'); } }; $list->display($this); } function sys_addedit_assoc( ){ $form = new \Jms\Gui\ClForm(); $form->before_save = function(&$data){ $id = I('get.id'); $where = array('ID'=>$data['ID']); $res = MM('uc_user')->where($where)->setField('AssocId',$id); if(!$res){ json_fail('操作失败'); } json_success('操作成功'); }; $form->form_filter = function(&$form){ $user_list = get_user_option(); $form['fields']['ID']['editor'] = array('options'=>$user_list); }; $form->display($this); } public function sys_disassociation( ){ $id = I('get.id'); if(!$id){ json_fail('缺少ID'); } $where = array('ID'=>$id); $res = MM('uc_user')->where($where)->setField('AssocId',''); if(!$res){ json_fail('操作失败'); } json_success('操作成功'); } private function get_company_option( ){ //获取已关联的公司id $where = array('RoleId'=>\Zndp\User\RoleEnum::API_CLIENT); $assoc_ids = M('uc_user')->field('AssocId')->where($where)->select(); if($assoc_ids){//如果存在已绑定的公司id $ids = array_column($assoc_ids,'AssocId'); $where = array('ID'=>array('NOT IN',$ids),'Level'=>0);//公司查询条件 }else{ $where = array('Level'=>0); } $fields = 'ID as id,DepartName as text'; $comp_list = M('uc_organization')->field($fields)->where($where)->select(); if(empty($comp_list)){ $comp_list = array(); $first_option = array('id'=>'','text'=>'没有可选公司'); array_push($comp_list,$first_option); }else{ $first_option = array('id'=>'','text'=>'请选择关联公司'); array_unshift($comp_list,$first_option); } return $comp_list; } }