DpyhCompManagerAction.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. class DpyhCompManagerAction extends CommonAction {
  3. const tableName = 'dpyh_comp_manager';
  4. const pkName = 'ID';
  5. function sys_add( ){
  6. $form = new \Jms\Gui\ClForm();
  7. $form->before_add = function(&$data){
  8. //检查用户名是否重复
  9. $where = array('UserName'=>$data['UserName']);
  10. if( M('uc_user')->where($where)->count() > 0 ){
  11. json_fail('用户名已存在');
  12. }
  13. //检查密码格式
  14. if(strlen($data['Password']) < 4 ){
  15. json_fail('密码长度必须大于4位');
  16. }
  17. //检查手机号是否重复(可通过手机号码登录)
  18. $where = array('Mobile'=>$data['Mobile']);
  19. if( $data['Mobile'] !== '' && M('uc_user')->where($where)->count() > 0 ){
  20. json_fail('手机号码已被使用');
  21. }
  22. $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) );
  23. $data['RoleId'] = \Zndp\User\RoleEnum::COMPANY_ADMINISTRATOR; //公司管理员
  24. $data['OrganizationId'] = I('get.depart_id');
  25. };
  26. $form->display($this);
  27. }
  28. function sys_list( ){
  29. $list = new \Jms\Gui\ClGrid();
  30. $list->sql_sort = 'OrganizationId asc';
  31. $list->sql_filter = function($search,&$cond){
  32. $cond['RoleId'] = \Zndp\User\RoleEnum::COMPANY_ADMINISTRATOR;
  33. $cond['OrganizationId'] = I('get.id');
  34. };
  35. $list->toolbar_filter = function(&$button){
  36. if($button['icon'] == 'add'){
  37. $button['url'] .= '&depart_id=' .I('get.id');
  38. }
  39. };
  40. $list->display($this);
  41. }
  42. function sys_edit( ){
  43. $form = new \Jms\Gui\ClForm();
  44. $form->before_display = function(&$data){
  45. $data['Password'] = '';
  46. };
  47. $form->before_modify = function(&$data){
  48. $id = I('get.id');
  49. // 检查用户名是否重复
  50. $where = array('UserName'=>$data['UserName'],'ID'=>array('neq',$id));
  51. if( M('uc_user')->where($where)->count() > 0 ){
  52. json_fail('用户名已存在');
  53. }
  54. // 检查密码
  55. if(!$data['Password']){
  56. unset($data['Password']);
  57. }elseif($data['Password'] && strlen($data['Password']) < 4 ){
  58. json_fail('密码长度必须大于4位');
  59. }else{
  60. $data['Password'] = \Zndp\User\Util::encPwd( trim($data['Password']) );
  61. }
  62. //检查手机号是否重复(可通过手机号码登录)
  63. $where = array('Mobile'=>$data['Mobile'],'ID'=>array('neq',$id));
  64. if( $data['Mobile'] !== '' && M('uc_user')->where($where)->count() > 0 ){
  65. json_fail('手机号码已被使用');
  66. }
  67. };
  68. $form->display($this);
  69. }
  70. function sys_change_depart( ){
  71. $form = new \Jms\Gui\ClForm();
  72. $form->before_modify = function(&$data){
  73. var_dump($data);exit;
  74. };
  75. //字段联动
  76. $form->onchange_filter = function($field,$data){
  77. $result = array();
  78. if($field == 'OrganizationId'){
  79. if($data[$field]){
  80. // 根据选择的部门等级,显示对应等级角色
  81. $cond = array('ID'=>$data[$field]);
  82. $level = M('uc_organization')->where($cond)->getField('Level');
  83. $result['DepartRole'] = get_role_option($level);
  84. }
  85. }
  86. return $result;
  87. };
  88. $form->form_filter = function(&$form){
  89. // 初始化部门下拉选项
  90. $depart_list = get_depart_option();
  91. $form['fields']['OrganizationId']['editor'] = array('options'=>$depart_list);
  92. // 初始化角色下拉选项
  93. $cond = array('ID'=>$this->userinfo['OrganizationId']);
  94. $level = M('uc_organization')->where($cond)->getField('Level');
  95. if($level === null){ //平台管理员
  96. $role_list = get_role_option();
  97. }else{
  98. $role_list = get_role_option($level);
  99. }
  100. $form['fields']['DepartRole']['editor'] = array('options'=>$role_list);
  101. };
  102. $form->display($this);
  103. }
  104. }