DpyhManagerAction.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. class DpyhManagerAction extends CommonAction {
  3. const tableName = 'dpyh_manager';
  4. const pkName = 'ID';
  5. function sys_add( ){
  6. $form = new \Jms\Gui\ClForm();
  7. $form->before_add = function(&$data){
  8. $uc_user = M('uc_user');
  9. $depart_id = I('get.depart_id');
  10. // 部门负责人唯一
  11. if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人
  12. $where = array('OrganizationId'=>$depart_id,'RoleId'=>$data['RoleId']);
  13. $count = $uc_user->where($where)->count();
  14. if($count > 0){
  15. json_fail('部门已有负责人');
  16. }
  17. }
  18. //检查用户名是否重复
  19. $where = array('UserName'=>$data['UserName']);
  20. if( $uc_user->where($where)->count() > 0 ){
  21. json_fail('用户名已存在');
  22. }
  23. //检查密码格式
  24. if(strlen($data['Password']) < 4 ){
  25. json_fail('密码长度必须大于4位');
  26. }
  27. //检查手机号格式及是否重复(可通过手机号码登录)
  28. $rule = array('pattern'=>'mobile');
  29. $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule);
  30. if(!$result){
  31. json_fail(\Jiaruan\FieldValidator::getLastError());
  32. }
  33. $where = array('Mobile'=>$data['Mobile']);
  34. if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){
  35. json_fail('手机号码已被使用');
  36. }
  37. $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) );
  38. //$data['RoleId'] = json_encode($data['RoleId']); //拥有角色
  39. $data['OrganizationId'] = $depart_id;
  40. };
  41. $form->form_filter = function(&$form){
  42. // 根据部门id获取部门等级,根据获取同等级角色
  43. $cond = array('ID'=>I('get.depart_id'));
  44. $level= M('uc_organization')->where($cond)->getField('Level');
  45. $role_list = get_role_option($level);
  46. $form['fields']['RoleId']['editor'] = array('options'=>$role_list);
  47. };
  48. $form->display($this);
  49. }
  50. function sys_list( ){
  51. $list = new \Jms\Gui\ClGrid();
  52. $list->sql_sort = 'OrganizationId asc';
  53. $list->sql_filter = function($search,&$cond){
  54. $super_manage = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR);
  55. $cond['RoleId'] = array('not in',$super_manage);//平台管理员账号不显示
  56. $id = I('get.id');
  57. if($id){
  58. $cond['OrganizationId'] = $id;
  59. }elseif( ! in_array($this->userinfo['RoleId'],$super_manage) ){ //非平台管理员查看
  60. $cond['OrganizationId'] = $this->userinfo['OrganizationId'];
  61. }else{
  62. }
  63. //搜索条件
  64. if($search['UserName']){ //按用户名搜索
  65. $cond['UserName'] = $search['UserName'];
  66. }
  67. if($search['RealName']){ //按姓名搜索
  68. $cond['RealName'] = $search['RealName'];
  69. }
  70. if($search['Mobile']){ //按电话搜索
  71. $cond['Mobile'] = $search['Mobile'];
  72. }
  73. };
  74. $list->row_filter = function(&$row){
  75. $where = array('ID'=>$row['RoleId']);
  76. $row['RoleId'] = M('uc_role')->where($where)->getField('RoleName');
  77. };
  78. $list->toolbar_filter = function(&$button){
  79. if($button['icon'] == 'add'){
  80. $button['url'] .= '&depart_id=' .I('get.id');
  81. }
  82. };
  83. $list->display($this);
  84. }
  85. function sys_edit( ){
  86. $form = new \Jms\Gui\ClForm();
  87. //字段联动
  88. $form->onchange_filter = function($field,$data){
  89. $result = array();
  90. if($field == 'OrganizationId'){
  91. if($data[$field]){
  92. // 根据选择的部门等级,显示对应等级角色
  93. $cond = array('ID'=>$data[$field]);
  94. $level = M('uc_organization')->where($cond)->getField('Level');
  95. $result['RoleId'] = get_role_option($level);
  96. }
  97. }
  98. return $result;
  99. };
  100. $form->form_filter = function(&$form){
  101. // 初始化部门下拉选项
  102. $zndp_util = new \Zndp\User\Util();
  103. $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']);
  104. $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list);
  105. // 初始化角色下拉选项
  106. $id = I('get.id');
  107. $cond = array('ID'=>$id);
  108. $depart_id = M('uc_user')->where($cond)->getField('OrganizationId');
  109. $cond = array('ID'=>$depart_id);
  110. $level = M('uc_organization')->where($cond)->getField('Level');
  111. $role_list = get_role_option($level);
  112. $form['fields']['RoleId']['editor'] = array('options'=>$role_list);
  113. };
  114. $form->before_display = function(&$data){
  115. $data['Password'] = '';
  116. };
  117. $form->before_modify = function(&$data){
  118. $id = I('get.id');
  119. $uc_user = M('uc_user');
  120. // 部门负责人唯一
  121. if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人
  122. $where = array('OrganizationId'=>$data['OrganizationId'],'RoleId'=>$data['RoleId'],'ID'=>array('NEQ',$id));
  123. $count = $uc_user->where($where)->count();
  124. if($count > 0){
  125. json_fail('该部门已有负责人');
  126. }
  127. }
  128. // 检查用户名是否重复
  129. $where = array('UserName'=>$data['UserName'],'ID'=>array('neq',$id));
  130. if( $uc_user->where($where)->count() > 0 ){
  131. json_fail('用户名已存在');
  132. }
  133. //检查手机号格式及是否重复(可通过手机号码登录)
  134. $rule = array('pattern'=>'mobile');
  135. $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule);
  136. if(!$result){
  137. json_fail(\Jiaruan\FieldValidator::getLastError());
  138. }
  139. $where = array('Mobile'=>$data['Mobile'],'ID'=>array('neq',$id));
  140. if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){
  141. json_fail('手机号码已被使用');
  142. }
  143. // 检查密码
  144. if(!$data['Password']){
  145. unset($data['Password']);
  146. }elseif($data['Password'] && strlen($data['Password']) < 4 ){
  147. json_fail('密码长度必须大于4位');
  148. }else{
  149. $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) );
  150. }
  151. };
  152. $form->display($this);
  153. }
  154. function sys_change_depart( ){
  155. $form = new \Jms\Gui\ClForm();
  156. $form->before_modify = function(&$data){
  157. };
  158. //字段联动
  159. $form->onchange_filter = function($field,$data){
  160. $result = array();
  161. if($field == 'OrganizationId'){
  162. if($data[$field]){
  163. // 根据选择的部门等级,显示对应等级角色
  164. $cond = array('ID'=>$data[$field]);
  165. $level = M('uc_organization')->where($cond)->getField('Level');
  166. $result['RoleId'] = get_role_option($level);
  167. }
  168. }
  169. return $result;
  170. };
  171. $form->form_filter = function(&$form){
  172. // 初始化部门下拉选项
  173. $zndp_util = new \Zndp\User\Util();
  174. $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']);
  175. $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list);
  176. // 初始化角色下拉选项
  177. $id = I('get.id');
  178. $cond = array('ID'=>$id);
  179. $depart_id = M('uc_user')->where($cond)->getField('OrganizationId');
  180. $cond = array('ID'=>$depart_id);
  181. $level = M('uc_organization')->where($cond)->getField('Level');
  182. $role_list = get_role_option($level);
  183. $form['fields']['RoleId']['editor'] = array('options'=>$role_list);
  184. };
  185. $form->display($this);
  186. }
  187. function sys_nav_tree( ){
  188. //获取导航树数据
  189. $fields = 'ID as id,ParentID as pId,DepartName as name,Level as level';
  190. $zndp_util = new \Zndp\User\Util();
  191. $depart_list = $zndp_util->get_depart_option('',$fields,'name',false);
  192. if(empty($depart_list)){
  193. //没有数据,显示该
  194. $depart_list[0] = array('id'=>'','pid'=>'','name'=>'没有组织','direct_url'=>'');
  195. }else{
  196. for($i=0; $i<count($depart_list); $i++){// 放入链接
  197. if($depart_list[$i]['level'] <= \Zndp\User\DepartEnum::WORK_STATION){
  198. $depart_list[$i]['open']= true;
  199. }
  200. $depart_list[$i]['direct_url'] = '?s=dpyh_manager/sys_list';
  201. }
  202. }
  203. //平台,超级管理员,插入所有用户列表
  204. $admin_arr = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR);
  205. if( in_array($this->userinfo['RoleId'], $admin_arr) ){
  206. $all_list = array('id'=>'0','pId'=>'','name'=>'所有用户','direct_url'=>'?s=dpyh_manager/sys_list','open'=>true);
  207. array_unshift($depart_list,$all_list);
  208. }
  209. $this->assign('title','用户管理');
  210. $this->assign('tree_data',$depart_list);
  211. $this->display();
  212. }
  213. function sys_list_search( ){
  214. }
  215. public function sys_del( ){
  216. $grid = new \Jiaruan\GridData();
  217. $grid->deleteByPk($this);
  218. }
  219. function sys_all_list( ){
  220. $list = new \Jms\Gui\ClGrid();
  221. $list->sql_sort = 'OrganizationId asc';
  222. $list->sql_filter = function($search,&$cond){
  223. // 部门管理员不显示部门负责人账号信息
  224. $super_manage = array(\Zndp\User\RoleEnum::GENERAL_ADMINISTRATOR,\Zndp\User\RoleEnum::SUPER_ADMINISTRATOR);
  225. $leader_list = \Zndp\User\RoleEnum::get_leader_list();
  226. if( in_array($this->userinfo['RoleId'],$super_manage) || in_array($this->userinfo['RoleId'],$leader_list) ){ //平台管理员或部门负责人
  227. $cond['RoleId'] = array('not in',$super_manage);
  228. }else{ //否则不能看负责人账号信息
  229. $hide_list = array_merge($super_manage,$leader_list);
  230. $cond['RoleId'] = array('NOT IN',$hide_list);
  231. }
  232. //查看部门下所有账号
  233. $zndp_util = new \Zndp\User\Util();
  234. $depart_list = $zndp_util->get_depart_ids($this->userinfo['OrganizationId']);
  235. $cond['OrganizationId'] = array('in',$depart_list);
  236. //搜索条件
  237. if($search['UserName']){ //按用户名搜索
  238. $cond['UserName'] = $search['UserName'];
  239. }
  240. if($search['RealName']){ //按姓名搜索
  241. $cond['RealName'] = $search['RealName'];
  242. }
  243. if($search['Mobile']){ //按电话搜索
  244. $cond['Mobile'] = $search['Mobile'];
  245. }
  246. };
  247. $list->row_filter = function(&$row){
  248. $where = array('ID'=>$row['RoleId']);
  249. $row['RoleId_text'] = M('uc_role')->where($where)->getField('RoleName');
  250. $where = array('ID'=>$row['OrganizationId']);
  251. $row['OrganizationId_text'] = M('uc_organization')->where($where)->getField('DepartName');
  252. };
  253. $list->toolbar_filter = function(&$button){
  254. if($button['icon'] == 'add'){
  255. $button['url'] .= '&depart_id=' .I('get.id');
  256. }
  257. };
  258. $list->display($this);
  259. }
  260. function sys_all_add( ){
  261. $form = new \Jms\Gui\ClForm();
  262. $form->before_add = function(&$data){
  263. $uc_user = M('uc_user');
  264. $depart_id = I('get.depart_id');
  265. // 部门负责人唯一
  266. if( in_array($data['RoleId'],\Zndp\User\RoleEnum::get_leader_list()) ){//角色是负责人
  267. $where = array('OrganizationId'=>$depart_id,'RoleId'=>$data['RoleId']);
  268. $count = $uc_user->where($where)->count();
  269. if($count > 0){
  270. json_fail('部门已有负责人');
  271. }
  272. }
  273. //检查用户名是否重复
  274. $where = array('UserName'=>$data['UserName']);
  275. if( $uc_user->where($where)->count() > 0 ){
  276. json_fail('用户名已存在');
  277. }
  278. //检查密码格式
  279. if(strlen($data['Password']) < 4 ){
  280. json_fail('密码长度必须大于4位');
  281. }
  282. //检查手机号格式及是否重复(可通过手机号码登录)
  283. $rule = array('pattern'=>'mobile');
  284. $result = \Jiaruan\FieldValidator::validate($data['Mobile'], $rule);
  285. if(!$result){
  286. json_fail(\Jiaruan\FieldValidator::getLastError());
  287. }
  288. $where = array('Mobile'=>$data['Mobile']);
  289. if( $data['Mobile'] !== '' && $uc_user->where($where)->count() > 0 ){
  290. json_fail('手机号码已被使用');
  291. }
  292. $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) );
  293. };
  294. //字段联动
  295. $form->onchange_filter = function($field,$data){
  296. $result = array();
  297. if($field == 'OrganizationId'){
  298. if($data[$field]){
  299. // 根据选择的部门等级,显示对应等级角色
  300. $cond = array('ID'=>$data[$field]);
  301. $level = M('uc_organization')->where($cond)->getField('Level');
  302. $result['RoleId'] = get_role_option($level);
  303. }
  304. }
  305. return $result;
  306. };
  307. $form->form_filter = function(&$form){
  308. // 初始化部门下拉选项
  309. $zndp_util = new \Zndp\User\Util();
  310. $depart_list = $zndp_util->get_depart_option($this->userinfo['OrganizationId']);
  311. $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list);
  312. // 根据部门id获取部门等级,根据获取同等级角色
  313. $cond = array('ID'=>$depart_list[0]['id']);
  314. $level= M('uc_organization')->where($cond)->getField('Level');
  315. $role_list = get_role_option($level);
  316. $form['fields']['RoleId']['editor'] = array('options'=>$role_list);
  317. };
  318. $form->display($this);
  319. }
  320. }