lizhen_gitee 8 mēneši atpakaļ
vecāks
revīzija
dfb2b4453b

+ 1 - 1
application/admin/view/auth/admin/add.html

@@ -3,7 +3,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker',  'data-rule'=>'required'])}
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/auth/admin/edit.html

@@ -3,7 +3,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, $groupids, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, $groupids, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
         </div>
     </div>
     <div class="form-group">

+ 8 - 3
application/common/library/Authcompany.php

@@ -410,9 +410,11 @@ class Authcompany extends \fast\Authpc
         return parent::getRuleIds($uid);
     }
 
+    //绝对不允许*管理员
     public function isSuperAdmin()
     {
-        return in_array('*', $this->getRuleIds()) ? true : false;
+        return false;
+//        return in_array('*', $this->getRuleIds()) ? true : false;
     }
 
     /**
@@ -451,7 +453,7 @@ class Authcompany extends \fast\Authpc
             }
         }
         // 取出所有分组
-        $groupList = \app\company\model\AuthGroup::where($this->isSuperAdmin() ? '1=1' : ['status' => 'normal'])->select();
+        $groupList = \app\company\model\AuthGroup::where($this->isSuperAdmin() ? '1=1' : ['status' => 'normal'])->where('company_id',$this->company_id)->select();
         $objList = [];
         foreach ($groups as $k => $v) {
             if ($v['rules'] === '*') {
@@ -491,7 +493,8 @@ class Authcompany extends \fast\Authpc
             }
         } else {
             //超级管理员拥有所有人的权限
-            $childrenAdminIds = User::column('id');
+//            $childrenAdminIds = User::column('id');
+            $childrenAdminIds = User::where('company_id',$this->company_id)->column('id');
         }
         if ($withself) {
             if (!in_array($this->id, $childrenAdminIds)) {
@@ -586,6 +589,7 @@ class Authcompany extends \fast\Authpc
 
         return array_column($ruleList,'permission');
     }
+    /*
     public function getSidebar($params = [], $fixedPage = 'dashboard')
     {
         // 边栏开始
@@ -715,6 +719,7 @@ class Authcompany extends \fast\Authpc
 
         return [$menu, $nav, $selected, $referer];
     }
+    */
 
     /**
      * 获取允许输出的字段

+ 75 - 53
application/company/controller/auth/Admin.php

@@ -33,8 +33,12 @@ class Admin extends Apic
         parent::_initialize();
         $this->model = model('Admin');
 
-        $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
-        $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
+        $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());//下级管理员
+        $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());//下级角色组
+
+        /*dump($this->childrenAdminIds);
+        dump($this->childrenGroupIds);
+        exit;*/
 
         $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
 
@@ -88,12 +92,11 @@ class Admin extends Apic
             }
 
             $list = Db::name('pc_admin')
-                ->where('company_id',$this->auth->company_id)
+                ->where('company_id',$this->auth->company_id) //多此一举
                 ->where('id', 'in', $this->childrenAdminIds)
                 ->field(['password', 'salt', 'token'], true)
                 ->order('id', 'asc')
-                ->autopage()
-                ->select();
+                ->paginate();
 
             foreach ($list as $k => &$v) {
                 $v['avatar'] = localpath_to_netpath($v['avatar']);
@@ -103,7 +106,8 @@ class Admin extends Apic
             }
             unset($v);
 
-            $this->success(1,$list);
+            $result = array("total" => $list->total(), "list" => $list->items());
+            $this->success(1,$result);
 
     }
 
@@ -176,6 +180,10 @@ class Admin extends Apic
         }
 
         $row['groupids'] = $groupids;
+
+        unset($row['password']);
+        unset($row['salt']);
+
         $this->success(1,$row);
     }
 
@@ -185,59 +193,73 @@ class Admin extends Apic
     public function edit()
     {
         $ids = input('id',0);
-        if ($this->request->isPost()) {
-            $this->token();
-            $params = $this->request->post("row/a");
-            if ($params) {
-                Db::startTrans();
-                try {
-                    if ($params['password']) {
-                        if (!Validate::is($params['password'], '\S{6,30}')) {
-                            exception(__("Please input correct password"));
-                        }
-                        $params['salt'] = Random::alnum();
-                        $params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
-                    } else {
-                        unset($params['password'], $params['salt']);
-                    }
-                    //这里需要针对username和email做唯一验证
-                    $adminValidate = \think\Loader::validate('Admin');
-                    $adminValidate->rule([
-                        'username' => 'require|regex:\w{3,30}|unique:PcAdmin,username,' . $row->id,
-                        'email'    => 'require|email|unique:PcAdmin,email,' . $row->id,
-                        'mobile'   => 'regex:1[3-9]\d{9}|unique:PcAdmin,mobile,' . $row->id,
-                        'password' => 'regex:\S{32}',
-                    ]);
-                    $result = $row->validate('Admin.edit')->save($params);
-                    if ($result === false) {
-                        exception($row->getError());
-                    }
+        $row = $this->model->get(['id' => $ids]);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        if (!in_array($row->id, $this->childrenAdminIds)) {
+            $this->error(__('You have no permission'));
+        }
+
+        $params = [
+            'username' => input('username',''),//手机号
+            'nickname' => input('nickname',''),//姓名
+            'password' => input('password',''),//密码
+            'gonghao'  => input('gonghao',''), //工号
+        ];
+        $group_id = input('group_id',0);
+        if(empty($group_id)){
+            $this->error();
+        }
+
+        Db::startTrans();
+        try {
+            if ($params['password']) {
+                if (!Validate::is($params['password'], '\S{6,30}')) {
+                    exception(__("Please input correct password"));
+                }
+                $params['salt'] = Random::alnum();
+                $params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
+            } else {
+                unset($params['password'], $params['salt']);
+            }
+            $params['mobile'] = $params['username'];
+            //这里需要针对username和email做唯一验证
+            $adminValidate = \think\Loader::validate('Admin');
+            $adminValidate->rule([
+                'mobile'   => 'require|regex:1\d{10}|unique:PcAdmin,mobile,' . $row->id,
+                'username' => 'require|regex:1\d{10}|unique:PcAdmin,username,' . $row->id,
+                'password' => 'regex:\S{32}',
+            ]);
+            $result = $row->validate('Admin.edit')->save($params);
+            if ($result === false) {
+                exception($row->getError());
+            }
 
-                    // 先移除所有权限
-                    model('AuthGroupAccess')->where('uid', $row->id)->delete();
+            // 先移除所有权限
+            model('AuthGroupAccess')->where('uid', $row->id)->delete();
 
-                    $group = $this->request->post("group/a");
+            $group = [$group_id];
 
-                    // 过滤不允许的组别,避免越权
-                    $group = array_intersect($this->childrenGroupIds, $group);
-                    if (!$group) {
-                        exception(__('The parent group exceeds permission limit'));
-                    }
+            // 过滤不允许的组别,避免越权
+            $group = array_intersect($this->childrenGroupIds, $group);
+            if (!$group) {
+                exception(__('The parent group exceeds permission limit'));
+            }
 
-                    $dataset = [];
-                    foreach ($group as $value) {
-                        $dataset[] = ['uid' => $row->id, 'group_id' => $value];
-                    }
-                    model('AuthGroupAccess')->saveAll($dataset);
-                    Db::commit();
-                } catch (\Exception $e) {
-                    Db::rollback();
-                    $this->error($e->getMessage());
-                }
-                $this->success();
+            $dataset = [];
+            foreach ($group as $value) {
+                $dataset[] = ['uid' => $row->id, 'group_id' => $value];
             }
-            $this->error(__('Parameter %s can not be empty', ''));
+            model('AuthGroupAccess')->saveAll($dataset);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
         }
+        $this->success();
+
+
 
     }
 

+ 2 - 2
application/company/validate/Admin.php

@@ -11,11 +11,11 @@ class Admin extends Validate
      * 验证规则
      */
     protected $rule = [
-        'username' => 'require|regex:\w{3,30}|unique:PcAdmin',
+        'mobile'   => 'require|regex:1\d{10}|unique:PcAdmin,mobile',
+        'username' => 'require|regex:1\d{10}|unique:PcAdmin,username',
         'nickname' => 'require',
         'password' => 'require|regex:\S{32}',
 //        'email'    => 'require|email|unique:PcAdmin,email',
-        'mobile'   => 'regex:1[3-9]\d{9}|unique:PcAdmin,mobile',
     ];
 
     /**