rabin 1 month ago
parent
commit
f5413c2758
7 changed files with 66 additions and 11 deletions
  1. 1 1
      api/Admin.php
  2. 2 1
      api/Login.php
  3. 30 7
      lib/Common.php
  4. 2 0
      lib/Group.php
  5. 20 1
      lib/Menu.php
  6. 10 0
      lib/System.php
  7. 1 1
      manage/core.php

+ 1 - 1
api/Admin.php

@@ -115,7 +115,7 @@ class Admin extends Auth
         if ($this->user['module_data'] && !strstr($this->user['module_data'], $module_id . '-' . $data_id)) {
             Dever::error('无模块权限');
         }
-        $result = Dever::load('common', 'manage')->token($this->user['id'], $this->user['mobile'], $this->user['select']['partition'], $this->user['select']['system_id'], $this->user['select']['info_id'], $module_id, $data_id);
+        $result = Dever::load('common', 'manage')->token($this->user['id'], $this->user['mobile'], $this->user['select']['partition'], $this->user['select']['system_key'], $this->user['select']['system_id'], $this->user['select']['info_id'], $module_id, $data_id);
         return $result;
     }
 

+ 2 - 1
api/Login.php

@@ -34,6 +34,7 @@ class Login
             # 分库
             $info['info_id'] = $info['id'];
             $info['partition'] = $system['partition'];
+            $info['system_key'] = $system['key'];
             $info['system_id'] = $system['id'];
             $partition = Dever::load('common', 'manage')->system($info);
             $db = Dever::db($system['user_table'], '', true, 'default', $partition);
@@ -105,7 +106,7 @@ class Login
         if (!$module_id || !$data_id) {
             Dever::error('登录失败,账户无效');
         }
-        return Dever::load('common', 'manage')->token($admin['id'], $admin['mobile'], $system['partition'], $system['id'], $info['id'], $module_id, $data_id);
+        return Dever::load('common', 'manage')->token($admin['id'], $admin['mobile'], $system['partition'], $system['key'], $system['id'], $info['id'], $module_id, $data_id);
     }
     private function checkCode()
     {

+ 30 - 7
lib/Common.php

@@ -67,16 +67,17 @@ class Common
             $result = array();
             if (strpos($info['partition'], '.')) {
                 $temp = explode('.', $info['partition']);
-                $result = array($temp[0] => $value);
+                $result = $this->partition($result, $temp[0], $info['system_key'], $value);
                 if ($module && isset($info['data_id']) && $info['data_id']) {
                     if ($temp[0] == $temp[1]) {
-                        $result[$temp[0]] .= '/' . $info['module_id'] . '_' . $info['data_id'];
+                        $value .= '/' . $info['module_id'] . '_' . $info['data_id'];
+                        $result = $this->partition($result, $temp[0], $info['system_key'], $value);
                     } else {
-                        $result[$temp[1]] = $info['module_id'] . '_' . $info['data_id'];
+                        $result = $this->partition($result, $temp[1], $info['system_key'], $info['module_id'] . '_' . $info['data_id']);
                     }
                 }
             } else {
-                $result = array($info['partition'] => $value);
+                $result = $this->partition($result, $info['partition'], $info['system_key'], $value);
             }
             if ($field) {
                 $result['field'] = Dever::call($field);
@@ -86,6 +87,27 @@ class Common
         return false;
     }
 
+    # 设置数据隔离
+    private function partition(&$result, $type, $key, $value)
+    {
+        if ($type == 'field') {
+            $result[$type] = array
+            (
+                'type' => 'key',
+                'field' => $key,
+                'value' => $value,
+            );
+        } elseif ($type == 'where') {
+            $result[$type] = array
+            (
+                $key => $value
+            );
+        } else {
+            $result[$type] = $value;
+        }
+        return $result;
+    }
+
     # 获取token需要用到的key
     public function getToken()
     {
@@ -97,16 +119,17 @@ class Common
     }
 
     # 将token设置到route权限中,方便后续读取
-    public function setAuth($partition, $system_id, $info_id, $module_id, $data_id)
+    public function setAuth($partition, $system_key, $system_id, $info_id, $module_id, $data_id)
     {
-        $token = Dever::load('common', 'manage')->token(-1, '', $partition, $system_id, $info_id, $module_id, $data_id);
+        $token = Dever::load('common', 'manage')->token(-1, '', $partition, $system_key, $system_id, $info_id, $module_id, $data_id);
         \Dever\Route::$data['authorization'] = Secure::encode($token['token']);
     }
 
     # 生成token
-    public function token($uid, $mobile, $partition, $system_id, $info_id, $module_id, $data_id)
+    public function token($uid, $mobile, $partition, $system_key, $system_id, $info_id, $module_id, $data_id)
     {
         $extend['partition'] = $partition;
+        $extend['system_key'] = $system_key;
         $extend['system_id'] = $system_id;
         $extend['info_id'] = $info_id;
         $extend['module_id'] = $module_id;

+ 2 - 0
lib/Group.php

@@ -21,6 +21,7 @@ class Group extends Auth
     {
         if ($data['mobile']) {
             $system = Dever::db('system', 'manage')->find(2);
+            $data['system_key'] = $system['key'];
             $data['system_id'] = $system['id'];
             $data['info_id'] = $data['id'];
             $data['partition'] = $system['partition'];
@@ -43,6 +44,7 @@ class Group extends Auth
     {
         if ($mobile && $password) {
             $system = Dever::db('system', 'manage')->find(2);
+            $data['system_key'] = $system['key'];
             $data['system_id'] = $system['id'];
             $data['info_id'] = 1;
             $data['partition'] = $system['partition'];

+ 20 - 1
lib/Menu.php

@@ -86,7 +86,12 @@ class Menu
                 }
                 $data = $where;
                 $data['name'] = $v['name'];
-                $data['icon'] = $v['icon'];
+                if (isset($v['icon']) && $v['icon']) {
+                    $data['icon'] = $v['icon'];
+                } else {
+                    # 随机抽取
+                    $data['icon'] = $this->getIcon();
+                }
                 $data['sort'] = $v['sort'];
                 if (isset($v['show'])) {
                     $data['show'] = $v['show'];
@@ -111,4 +116,18 @@ class Menu
         $data = Dever::db('menu', 'manage')->select(array('parent_id' => '0'));
         return $data;
     }
+
+    public function getIcon()
+    {
+        if (empty($this->icon)) {
+            $this->icon = Dever::db('icon', 'manage')->select([]);
+        }
+        $key = array_rand($this->icon, 1);
+        $icon = $this->icon[$key]['key'];
+        $info = Dever::db('menu', 'manage')->find(array('icon' => $icon));
+        if ($info) {
+            return $this->getIcon();
+        }
+        return $icon;
+    }
 }

+ 10 - 0
lib/System.php

@@ -22,6 +22,7 @@ class System extends Auth
     {
         if (isset($data['mobile']) && $data['mobile']) {
             $system = Dever::db('system', 'manage')->find(array('key' => $system));
+            $data['system_key'] = $system['key'];
             $data['system_id'] = $system['id'];
             $data['info_id'] = $data['id'];
             $data['partition'] = $system['partition'];
@@ -35,6 +36,14 @@ class System extends Auth
                 $insert += Dever::load('common', 'manage')->createPwd($password);
                 $db->insert($insert);
             }
+
+            $db = Dever::db($system['role_table'], '', true, 'default', Dever::load('common', 'manage')->system($data));
+            $info = $db->find(array('id' => 1));
+            if (!$info) {
+                $insert = array();
+                $insert['name'] = '超级管理员';
+                $db->insert($insert);
+            }
         }
     }
 
@@ -45,6 +54,7 @@ class System extends Auth
             $info = Dever::db($data['table'])->find($data['id']);
             if ($info) {
                 $system = Dever::db('system', 'manage')->find(array('key' => $data['system']));
+                $set['system_key'] = $system['key'];
                 $set['system_id'] = $system['id'];
                 $set['info_id'] = 1;
                 $set['partition'] = $system['partition'];

+ 1 - 1
manage/core.php

@@ -48,7 +48,7 @@ return array
             # 菜单图标
             'icon' => 'flood-line',
             # 菜单排序 正序
-            'sort' => '100',
+            'sort' => '1000',
             # 所属系统模块 模块key,一般只需主菜单填写module
             'module' => 'platform',
         ),