rabin 7 months ago
parent
commit
a02b8b8632

+ 11 - 1
api/Admin.php

@@ -27,7 +27,17 @@ class Admin extends Auth
         $module = Dever::db('system_module', 'manage')->select($where);
         $i = 0;
         foreach ($module as $k => $v) {
-            $child = Dever::db($v['data_table'])->select([]);
+            $data_where = $v['data_where'];
+            if ($data_where) {
+                if (strstr($data_where, '{uid}')) {
+                    $data_where = str_replace('{uid}', $this->user['id'], $data_where);
+                }
+                $data_where = Dever::json_decode($data_where);
+            } else {
+                $data_where = array();
+            }
+            $child = Dever::db($v['data_table'])->select($data_where);
+            
             if ($child) {
                 $data = array();
                 foreach ($child as $k1 => $v1) {

+ 6 - 0
api/Page/Data.php

@@ -203,6 +203,12 @@ class Data extends Page
                     $where[$v['key']] = array('group', $value);
                 } elseif ($v['type'] == 'selects') {
                     $where[$v['key']] = array('group', $value);
+                } elseif ($v['type'] == 'cascader') {
+                    $t = $value;
+                    if (is_array($value)) {
+                        $t = implode(',', $value);
+                    }
+                    $where[$v['key']] = array('like', $t);
                 } elseif ($v['type'] == 'like') {
                     $where[$v['key']] = array('like', $value);
                 } elseif ($v['type'] == 'in') {

+ 15 - 6
api/Page/Update.php

@@ -47,10 +47,10 @@ class Update extends Page
                 unset($data['update'][$k]['option']);
             }
         }
-        $this->column($data);
+        $active = $this->column($data);
         $data['info_id'] = false;
-        if (!$this->info && $data['column'] && $data['column']['where'] == 'id') {
-            $this->info = $this->db->find($data['column']['active']);
+        if (!$this->info && $active) {
+            $this->info = $this->db->find($active);
             if ($this->info) {
                 $data['info_id'] = $this->info['id'];
                 if (!$func) {
@@ -350,7 +350,10 @@ class Update extends Page
                         $this->checkRules($v, $input[$v['key']]);
                     }
                     if ($v['type'] == 'sku') {
-                        $sku[$v['key']] = array($v['where'], $v['content']['field'], $v['spec'], $v['spec_field'], $input[$v['key'] . '_spec'], $input[$v['key']]);
+                        if (isset($input[$v['key'] . '_spec']) && isset($input[$v['key']])) {
+                            $sku[$v['key']] = array($v['where'], $v['content']['field'], $v['spec'], $v['spec_field'], $input[$v['key'] . '_spec'], $input[$v['key']]);
+                        }
+                        
                     } elseif (strpos($v['key'], '/')) {
                         $other[$v['key']] = array($v['where'], $v['content']['field'], $v['content']['drag'], $input[$v['key']]);
                     } else {
@@ -456,7 +459,7 @@ class Update extends Page
     {
         if (isset($this->config['start']) && $this->config['start']) {
             $data['id'] = $id;
-            $data = Dever::call($this->config['start'], array($data));
+            $data = Dever::call($this->config['start'], array($this->db, $data));
         }
     }
 
@@ -464,7 +467,13 @@ class Update extends Page
     {
         if (isset($this->config['end']) && $this->config['end']) {
             $data['id'] = $id;
-            Dever::call($this->config['end'], array($data));
+            if (is_array($this->config['end'])) {
+                foreach ($this->config['end'] as $k => $v) {
+                    Dever::call($v, array($data));
+                }
+            } else {
+                Dever::call($this->config['end'], array($this->db, $data));
+            }
         }
     }
 

+ 4 - 1
lib/Auth.php

@@ -18,7 +18,7 @@ class Auth
             $info['extend']['info_id'] = 1;
             $info['extend']['module_id'] = 1;
             $info['extend']['data_id'] = 1;
-            //Dever::error('请先登录');
+            Dever::error('请先登录');
         }
         $this->system = Dever::db('system', 'manage')->find($info['extend']['system_id']);
         if (!$this->system) {
@@ -75,6 +75,9 @@ class Auth
             $key = $key . '_' . md5($param);
         }*/
 
+        if (!$this->menu) {
+            return false;
+        }
         $data['menu_id'] = $this->menu['id'];
         $data['key'] = $key;
         $info = Dever::db('menu_func', 'manage')->find($data);

+ 17 - 12
lib/Common.php

@@ -15,9 +15,12 @@ class Common
 
     public function auth()
     {
-        $auth = Env::header('authorization');
+        $auth = Dever::input('authorization');
+        if ($auth) {
+            $auth = \Dever\Helper\Str::decode($auth);
+        }
         if (!$auth) {
-            $auth = \Dever\Helper\Str::decode(Dever::input('authorization'));
+            $auth = Env::header('authorization');
         }
         if ($auth) {
             $auth = str_replace('Bearer ', '', $auth);
@@ -88,15 +91,17 @@ class Common
         $extand['info_id'] = $info_id;
         $extand['module_id'] = $module_id;
         $extand['data_id'] = $data_id;
-        $select['uid'] = $uid;
-        $select['system_id'] = $system_id;
-        $select['info_id'] = $info_id;
-        $info = Dever::db('system_user', 'manage')->find($select);
-        $select += $extand;
-        if (!$info) {
-            Dever::db('system_user', 'manage')->insert($select);
-        } else {
-            Dever::db('system_user', 'manage')->update($info['id'], $select);
+        if ($uid) {
+            $select['uid'] = $uid;
+            $select['system_id'] = $system_id;
+            $select['info_id'] = $info_id;
+            $info = Dever::db('system_user', 'manage')->find($select);
+            $select += $extand;
+            if (!$info) {
+                Dever::db('system_user', 'manage')->insert($select);
+            } else {
+                Dever::db('system_user', 'manage')->update($info['id'], $select);
+            }
         }
         return array('token' => Secure::login($uid, $extand));
     }
@@ -141,7 +146,7 @@ class Common
             }
         }
         $set = Dever::project($app);
-        $manage = $set['path'] . 'table/manage/'.$table.'.php';
+        $manage = $set['path'] . 'manage/'.$table.'.php';
         if (is_file($manage)) {
             $manage = include $manage;
             if ($source = Dever::issets($manage, 'source')) {

+ 8 - 1
lib/Menu.php

@@ -6,13 +6,17 @@ class Menu
     # 初始化菜单
     public function init($name = '')
     {
+        $config = Dever::config('manage');
+        if ($config) {
+            $this->add('manage', $config);
+        }
         if ($name) {
             $app = array($name => Project::load($name));
         } else {
             $app = Project::read();
         }
         foreach ($app as $k => $v) {
-            $base = $v['path'] . 'table/manage/core.php';
+            $base = $v['path'] . 'manage/core.php';
             if (is_file($base)) {
                 $core = include $base;
                 if ($core) {
@@ -47,6 +51,9 @@ class Menu
                 $data['sort'] = $v['sort'];
                 $data['system'] = $v['system'];
                 $data['data_table'] = $v['data_table'];
+                if (isset($v['data_where']) && $v['data_where']) {
+                    $data['data_where'] = Dever::json_encode($v['data_where']);
+                }
                 Dever::db('system_module', 'manage')->up($where, $data);
             }
         }

+ 21 - 10
lib/Page.php

@@ -120,18 +120,24 @@ class Page extends Auth
     {
         $data['column'] = false;
         if (isset($this->config['column'])) {
-            $data['column'] = $this->config['column'];
-            if (isset($this->config['column']['add'])) {
-                $data['column']['add'] = array('name' => $this->config['column']['add'], 'func' => $this->getFunc('column_add', $name . '-' . $this->config['column']['add'], 101));
-            }
-            if (isset($this->config['column']['edit'])) {
-                $data['column']['edit'] = array('name' => '编辑', 'func' => $this->getFunc('column_edit', $name . '-编辑', 102));
+            if (empty($this->config['column']['hidden'])) {
+                $data['column'] = $this->config['column'];
+                if (isset($this->config['column']['add'])) {
+                    $data['column']['add'] = array('name' => $this->config['column']['add'], 'func' => $this->getFunc('column_add', $name . '-' . $this->config['column']['add'], 101));
+                }
+                if (isset($this->config['column']['edit'])) {
+                    $data['column']['edit'] = array('name' => '编辑', 'func' => $this->getFunc('column_edit', $name . '-编辑', 102));
+                }
+                if (isset($this->config['column']['delete'])) {
+                    $data['column']['delete'] = array('name' => '删除', 'func' => $this->getFunc('column_delete', $name . '-删除', 103));
+                }
+                $data['column']['data'] = Dever::call($this->config['column']['data']);
+                $data['height'] = '100%';
             }
-            if (isset($this->config['column']['delete'])) {
-                $data['column']['delete'] = array('name' => '删除', 'func' => $this->getFunc('column_delete', $name . '-删除', 103));
+            
+            if (isset($this->config['column']['active']) && $this->config['column']['where'] == 'id') {
+                return $this->config['column']['active'];
             }
-            $data['column']['data'] = Dever::call($this->config['column']['data']);
-            $data['height'] = '100%';
         }
     }
 
@@ -391,6 +397,11 @@ class Page extends Auth
     private function setForm(&$value)
     {
         $value['value'] = Dever::input('search')[$value['key']] ?? '';
+        if (is_array($value['value'])) {
+            foreach ($value['value'] as &$v) {
+                $v = (float) $v;
+            }
+        }
         if (!$value['value']) {
             if (isset($value['default']) && !strstr($value['default'], '{')) {
                 $value['value'] = $value['default'];

+ 1 - 1
lib/Role.php

@@ -2,7 +2,7 @@
 use Dever;
 class Role extends Auth
 {
-    public function update($data)
+    public function update($db, $data)
     {
         if ($data['auth']) {
             $auth = explode(',', $data['auth']);

+ 1 - 1
lib/System.php

@@ -18,7 +18,7 @@ class System extends Auth
     }
 
     # 创建管理员
-    public function update($data)
+    public function update($db, $data)
     {
         if (isset($data['mobile']) && $data['mobile']) {
             $system = Dever::db('system', 'manage')->find(array('key' => $data['system']));

+ 0 - 0
table/manage/admin.php → manage/admin.php


+ 0 - 0
table/manage/config.php → manage/config.php


+ 0 - 0
table/manage/core.php → manage/core.php


+ 0 - 0
table/manage/cron.php → manage/cron.php


+ 0 - 0
table/manage/group_manage.php → manage/group_manage.php


+ 0 - 0
table/manage/group_org.php → manage/group_org.php


+ 0 - 0
table/manage/group_org_job.php → manage/group_org_job.php


+ 0 - 0
table/manage/group_role.php → manage/group_role.php


+ 0 - 0
table/manage/group_user.php → manage/group_user.php


+ 0 - 0
table/manage/menu.php → manage/menu.php


+ 0 - 0
table/manage/recycler.php → manage/recycler.php


+ 0 - 0
table/manage/role.php → manage/role.php


+ 0 - 0
table/manage/system.php → manage/system.php


+ 0 - 0
table/manage/system_module.php → manage/system_module.php


+ 5 - 0
table/system_module.php

@@ -25,6 +25,11 @@ return array
             'name'      => '模块下数据表名',
             'type'      => 'varchar(200)',
         ),
+        'data_where' => array
+        (
+            'name'      => '模块下数据表的获取数据方式,为空则获取所有',
+            'type'      => 'varchar(2000)',
+        ),
         'sort' => array
         (
             'name'      => '排序',