dever 5 years ago
parent
commit
aa88a3265d
4 changed files with 73 additions and 2 deletions
  1. 3 0
      config/base.php
  2. 20 1
      database/role.php
  3. 43 0
      src/Auth.php
  4. 7 1
      src/Database.php

+ 3 - 0
config/base.php

@@ -24,6 +24,9 @@ $config['base'] = array
 	(
 		'url' => 'https://webapi.amap.com/maps?v=1.4.8&key=b51a0d5f8f977726eeaa070a30bcf3cd',
 	),
+
+	# 后台管理的数据执行权限的设置
+	'manageAuthData' => '',
 );
 
 # 模板配置

+ 20 - 1
database/role.php

@@ -94,7 +94,12 @@ $role = function() use($cur)
 	return $array;
 };
 
-
+# 获取权限list 建议这里使用匿名函数
+$auth_data = function()
+{
+	$auth_data = Dever::load('manage/auth.getByData');
+	return $auth_data;
+};
 
 //print_r($auth);die;
 
@@ -283,6 +288,20 @@ $config = array
 			'update'	=> 'checkbox',
 			'option'	=> $top,
 		),
+
+		'auth_data'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '数据权限',
+			'default' 	=> '',
+			'desc' 		=> '数据权限',
+			'match' 	=> 'option',
+			'update'	=> 'checkbox',
+			//每个项对应的一个input以及父级更新的类型
+			//'update_input' => '数量',
+			//'update_parent' => 'radio',
+			'option'	=> $auth_data,
+		),
 	),
 
 	# 更新表结构 请注意,新增字段已经无需在此增加add了,直接在struct中新增即可。如果是更新字段和删除字段,还需在此加相应配置,并且修改最新的版本号。

+ 43 - 0
src/Auth.php

@@ -105,6 +105,22 @@ class Auth
         return $this->real($this->data(), $state);
     }
 
+    /**
+     * 获取当前登录的管理员信息
+     *
+     * @return mixed
+     */
+    public function authData($state = true)
+    {
+        $data = $this->info($state);
+
+        if (isset($data['role_info']['auth_data'])) {
+            return $data['role_info']['auth_data'];
+        }
+
+        return '';
+    }
+
     /**
      * 实时读取信息
      *
@@ -294,6 +310,7 @@ class Auth
         if ($user['id'] == 1) {
             $user['oper'] = 'all';
             $user['auth'] = 'all';
+            $user['auth_data'] = 'all';
             $user['top'] = 'all';
         } else {
             $role = Dever::db('manage/role')->get(array('where_id' => $user['role']));
@@ -301,6 +318,7 @@ class Auth
             if ($role) {
                 $user['oper'] = array();
                 $user['auth'] = array();
+                $user['auth_data'] = array();
                 $user['self'] = 2;
                 $top = array();
                 foreach ($role as $k => $v) {
@@ -314,6 +332,9 @@ class Auth
                     if ($v['auth']) {
                         $user['auth'][] = $v['auth'];
                     }
+                    if ($v['auth_data']) {
+                        $user['auth_data'][] = $v['auth_data'];
+                    }
                     if (!$user['top'] && $v['top']) {
                         $top[] = $v['top'];
                     }
@@ -324,6 +345,7 @@ class Auth
 
                 $user['oper'] = implode(',', $user['oper']);
                 $user['auth'] = implode(',', $user['auth']);
+                $user['auth_data'] = implode(',', $user['auth_data']);
 
                 if (!$user['top'] && $top) {
                     $user['top'] = implode(',', $top);
@@ -337,6 +359,10 @@ class Auth
                     $user['auth'] = 'all';
                 }
 
+                if (strpos($user['auth_data'], 'all') !== false) {
+                    $user['auth_data'] = 'all';
+                }
+
                 if (strpos($user['top'], 'all') !== false) {
                     $user['top'] = 'all';
                 } elseif ($user['top']) {
@@ -612,6 +638,23 @@ class Auth
         return $result;
     }
 
+    /**
+     * 获取所有数据权限列表,并进行统计处理
+     *
+     * @return mixed
+     */
+    public function getByData()
+    {
+        $key = Dever::config('base')->manageAuthData;
+        $result = array();
+        if ($key) {
+            $result = Dever::load($key);
+            $result['state'] = 1;
+        }
+
+        return $result;
+    }
+
     /**
      * 修改当前管理员的密码
      *

+ 7 - 1
src/Database.php

@@ -1846,7 +1846,13 @@ class Database
         $result = $return = array();
 
         if (isset($config['top_option']) && $config['top_option']) {
-            $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
+            if (isset($config['top_option'][0])) {
+                foreach ($config['top_option'] as $k => $v) {
+                    $param['option'][$v['col']] = array($v['value'], 'in');
+                }
+            } else {
+                $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
+            }
         }
 
         if ($excel == true) {