DpyhBaseManagerAction.class.php 4.0 KB

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