diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index d2ba96648b5b8f1c61a45765d05af9fe0ddfdbdf..37cc99f0ed4f7152e13b74631fdacaf980e530e6 100755 --- a/application/admin/command/Install/fastadmin.sql +++ b/application/admin/command/Install/fastadmin.sql @@ -27,6 +27,7 @@ CREATE TABLE `fa_admin` ( `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', `token` varchar(59) NOT NULL DEFAULT '' COMMENT 'Session标识', `status` varchar(30) NOT NULL DEFAULT 'normal' COMMENT '状态', + `orgid` int(10) COMMENT '部门名称', PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='管理员表'; @@ -35,7 +36,7 @@ CREATE TABLE `fa_admin` ( -- Records of fa_admin -- ---------------------------- BEGIN; -INSERT INTO `fa_admin` VALUES (1, 'admin', 'Admin', '075eaec83636846f51c152f29b98a2fd', 's4f3', '/assets/img/avatar.png', 'admin@fastadmin.net', 0, 1502029281, 1492186163, 1502029281, 'd3992c3b-5ecc-4ecb-9dc2-8997780fcadc', 'normal'); +INSERT INTO `fa_admin` VALUES (1, 'admin', 'Admin', '075eaec83636846f51c152f29b98a2fd', 's4f3', '/assets/img/avatar.png', 'admin@fastadmin.net', 0, 1502029281, 1492186163, 1502029281, 'd3992c3b-5ecc-4ecb-9dc2-8997780fcadc', 'normal',0); COMMIT; -- ---------------------------- @@ -244,6 +245,12 @@ INSERT INTO `fa_auth_rule` VALUES (81, 'file', 79, 'user/rule/del', 'Del', 'fa f INSERT INTO `fa_auth_rule` VALUES (82, 'file', 79, 'user/rule/add', 'Add', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal'); INSERT INTO `fa_auth_rule` VALUES (83, 'file', 79, 'user/rule/edit', 'Edit', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal'); INSERT INTO `fa_auth_rule` VALUES (84, 'file', 79, 'user/rule/multi', 'Multi', 'fa fa-circle-o', '', '', 0, 1516374729, 1516374729, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (85, 'file', 0, 'orgnazation', '部门管理', 'fa fa-chain', '', '', 1, 1525710486, 1532965621, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (86, 'file', 85, 'orgnazation/index', '查看', 'fa fa-circle-o', '', '', 0, 1525710486, 1530111884, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (87, 'file', 85, 'orgnazation/add', '添加', 'fa fa-circle-o', '', '', 0, 1525710486, 1530111884, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (88, 'file', 85, 'orgnazation/edit', '编辑', 'fa fa-circle-o', '', '', 0, 1525710486, 1530111884, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (89, 'file', 85, 'orgnazation/del', '删除', 'fa fa-circle-o', '', '', 0, 1525710486, 1530111884, 0, 'normal'); +INSERT INTO `fa_auth_rule` VALUES (90, 'file', 85, 'orgnazation/multi', '批量更新', 'fa fa-circle-o', '', '', 0, 1525710486, 1530111884, 0, 'normal'); COMMIT; -- ---------------------------- @@ -577,3 +584,22 @@ INSERT INTO `fa_version` (`id`, `oldversion`, `newversion`, `packagesize`, `cont (1, '1.1.1,2', '1.2.1', '20M', '更新内容', 'https://www.fastadmin.net/download.html', 1, 1520425318, 0, 0, 'normal'); COMMIT; SET FOREIGN_KEY_CHECKS = 1; + +-- ---------------------------- +-- Table structure for fa_orgnazation +-- ---------------------------- +DROP TABLE IF EXISTS `fa_orgnazation`; +CREATE TABLE `fa_orgnazation` ( + `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `pid` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '父ID', + `name` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `fullname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '部门全称', + `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '描述', + `createtime` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '创建时间', + `updatetime` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '修改时间', + `weigh` int(11) NULL DEFAULT 0 COMMENT '权重', + `status` varchar(30) NOT NULL DEFAULT 'normal' COMMENT '状态', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='部门表'; + + diff --git a/application/admin/controller/Orgnazation.php b/application/admin/controller/Orgnazation.php new file mode 100644 index 0000000000000000000000000000000000000000..624681569fcfae17b6d814f676bef7799d872b67 --- /dev/null +++ b/application/admin/controller/Orgnazation.php @@ -0,0 +1,52 @@ +request->filter(['strip_tags']); + $this->model = model('Orgnazation'); + + $tree = Tree::instance(); + $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid'); + $this->orglist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + //halt($this->orglist); + $orgdata = [0 => ['type' => 'all', 'name' => __('None')]]; + foreach ($this->orglist as $k => $v) + { + $orgdata[$v['id']] = $v; + } + //$this->view->assign("flagList", $this->model->getFlagList()); + //$this->view->assign("typeList", OrgnazationModel::getTypeList()); + $this->view->assign("parentList", $orgdata); + + } + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + +} diff --git a/application/admin/controller/auth/Admin.php b/application/admin/controller/auth/Admin.php index 40c6c8018e048acd710493bb68e7e5ef1d094118..dbf07f6afeb70d00f9a184c7c66fb2748bde8c38 100644 --- a/application/admin/controller/auth/Admin.php +++ b/application/admin/controller/auth/Admin.php @@ -60,6 +60,17 @@ class Admin extends Backend } $groupdata = $result; } + + $tree = Tree::instance(); + $tree->init(collection(model('Orgnazation')->order('weigh desc,id desc')->select())->toArray(), 'pid'); + $this->orglist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + //halt($this->orglist); + $orgdata = [0 => ['type' => 'all', 'name' => __('None')]]; + foreach ($this->orglist as $k => $v) + { + $orgdata[$v['id']] = $v; + } + $this->view->assign("orgList", $orgdata); $this->view->assign('groupdata', $groupdata); $this->assignconfig("admin", ['id' => $this->auth->id]); @@ -103,6 +114,7 @@ class Admin extends Backend ->count(); $list = $this->model + ->with('orgnazation') ->where($where) ->where('id', 'in', $this->childrenAdminIds) ->field(['password', 'salt', 'token'], true) @@ -252,6 +264,92 @@ class Admin extends Backend $this->error(); } + /** + * 导入 + */ + protected function import() + { + $file = $this->request->request('file'); + if (!$file) { + $this->error(__('Parameter %s can not be empty', 'file')); + } + $filePath = ROOT_PATH . DS . 'public' . DS . $file; + if (!is_file($filePath)) { + $this->error(__('No results were found')); + } + $PHPReader = new \PHPExcel_Reader_Excel2007(); + if (!$PHPReader->canRead($filePath)) { + $PHPReader = new \PHPExcel_Reader_Excel5(); + if (!$PHPReader->canRead($filePath)) { + $PHPReader = new \PHPExcel_Reader_CSV(); + if (!$PHPReader->canRead($filePath)) { + $this->error(__('Unknown data format')); + } + } + } + + //导入文件首行类型,默认是注释,如果需要使用字段名称请使用name + $importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment'; + + $table = $this->model->getQuery()->getTable(); + $database = \think\Config::get('database.database'); + $fieldArr = []; + $list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]); + foreach ($list as $k => $v) { + if ($importHeadType == 'comment') { + $fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME']; + } else { + $fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME']; + } + } + + $PHPExcel = $PHPReader->load($filePath); //加载文件 + $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表 + $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号 + $allRow = $currentSheet->getHighestRow(); //取得一共有多少行 + $maxColumnNumber = \PHPExcel_Cell::columnIndexFromString($allColumn); + for ($currentRow = 1; $currentRow <= 1; $currentRow++) { + for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++) { + $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); + $fields[] = $val; + } + } + $insert = []; + for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) { + $values = []; + for ($currentColumn = 0; $currentColumn < $maxColumnNumber; $currentColumn++) { + $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); + $values[] = is_null($val) ? '' : $val; + } + $row = []; + $temp = array_combine($fields, $values); + halt($temp); + foreach ($temp as $k => $v) { + if (isset($fieldArr[$k]) && $k !== '') { + $row[$fieldArr[$k]] = $v; + } + + } + if ($row) { + $insert[] = $row; + } + } + if (!$insert) { + $this->error(__('No rows were updated')); + } + try { + + $this->model->saveAll($insert); + } catch (\think\exception\PDOException $exception) { + $this->error($exception->getMessage()); + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + + $this->success(); + } + + /** * 批量更新 * @internal diff --git a/application/admin/lang/zh-cn/auth/admin.php b/application/admin/lang/zh-cn/auth/admin.php index 59c7c496ca7e9a28c9e999e17166b6c5946e9ce9..77aa887c6b44479eab1039514ee65d07ca519c7f 100644 --- a/application/admin/lang/zh-cn/auth/admin.php +++ b/application/admin/lang/zh-cn/auth/admin.php @@ -4,4 +4,5 @@ return [ 'Group' => '所属组别', 'Loginfailure' => '登录失败次数', 'Login time' => '最后登录', + 'Orgnazation'=>'部门全称', ]; diff --git a/application/admin/lang/zh-cn/orgnazation.php b/application/admin/lang/zh-cn/orgnazation.php new file mode 100644 index 0000000000000000000000000000000000000000..f30617f443ca21e8ce9202e1ea1a56bde46d26b3 --- /dev/null +++ b/application/admin/lang/zh-cn/orgnazation.php @@ -0,0 +1,11 @@ + '父ID', + 'Fullname' => '部门全称', + 'Description' => '描述', + 'Createtime' => '创建时间', + 'Updatetime' => '修改时间', + 'Weigh' => '权重', + 'Status' => '状态' +]; diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index 8c47f6f7447835740c41491caaf814143c0d0b0f..489e3bfd6a766138f3e6aa7f51c1016ffc5a9d23 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -4,6 +4,7 @@ namespace app\admin\model; use think\Model; use think\Session; +use think\Validate; class Admin extends Model { @@ -31,4 +32,64 @@ class Admin extends Model return $encrypt($password . $salt); } + /** + * @param $username + * @param $password + * @return bool when user is valid return user, invalid return 0 + * @throws \think\exception\DbException + */ + public static function isValid($username, $password) + { + $rule = [ + 'username' => 'require|length:3,30', + 'password' => 'require|length:3,30', + ]; + $data = [ + 'username' => $username, + 'password' => $password, + ]; + $validate = new Validate($rule); + + if(! $validate->check($data)) return false; + + $user = self::get(['username' => $username]); + if (!$user){ + return 0; + } + if ($user->password != md5(md5($password) . $user->salt)) + { + return 0; + } + return $user; + } + + public function orgnazation() + { + return $this->belongsTo('Orgnazation','orgid'); + } + + /** + * 验证用户是否属于用户组 + * @param $username 用户名 + * @param $groupname 组名 + * @return bool + * @throws \think\exception\DbException + */ + public static function isGroup($username,$groupname) + { + $user = self::get(['username' => $username]); + if (!$user){ + return false; + } + $group = AuthGroup::get(['name'=>$groupname]); + if(!$group){ + return false; + } + else{ + $inGroup = AuthGroupAccess::get(['uid'=>$user->id,'group_id'=>$group->id]); + if(!$inGroup) return false; + else return true; + } + } + } diff --git a/application/admin/model/Orgnazation.php b/application/admin/model/Orgnazation.php new file mode 100644 index 0000000000000000000000000000000000000000..4ce5b975c10c64bcdd29efb69cf424d67afc64f0 --- /dev/null +++ b/application/admin/model/Orgnazation.php @@ -0,0 +1,25 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/auth/admin/add.html b/application/admin/view/auth/admin/add.html index 99a39996b82914182f7b399ef4eca52c5d2b3314..c637f66940b2a35fd0fdbc41823eb950ffdc9ff5 100644 --- a/application/admin/view/auth/admin/add.html +++ b/application/admin/view/auth/admin/add.html @@ -4,6 +4,16 @@
{:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+ +
+ +
+ +
diff --git a/application/admin/view/auth/admin/edit.html b/application/admin/view/auth/admin/edit.html index 428e9766dc6c8195cb3ff0ed3892facc878d2a17..84621823bed42ab84f8eda05eae04555ac58a553 100644 --- a/application/admin/view/auth/admin/edit.html +++ b/application/admin/view/auth/admin/edit.html @@ -4,11 +4,21 @@
{:build_select('group[]', $groupdata, $groupids, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+
+
+ +
+ +
- +
diff --git a/application/admin/view/orgnazation/add.html b/application/admin/view/orgnazation/add.html new file mode 100644 index 0000000000000000000000000000000000000000..d156d23122af11d913f76f1e65e4a1896119e8a0 --- /dev/null +++ b/application/admin/view/orgnazation/add.html @@ -0,0 +1,50 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')])} +
+
+ +
diff --git a/application/admin/view/orgnazation/edit.html b/application/admin/view/orgnazation/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..7f6b4973e4ca775e831d1b69fb142e3905349e04 --- /dev/null +++ b/application/admin/view/orgnazation/edit.html @@ -0,0 +1,50 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')], $row['status'])} +
+
+ +
diff --git a/application/admin/view/orgnazation/index.html b/application/admin/view/orgnazation/index.html new file mode 100644 index 0000000000000000000000000000000000000000..ab652ba7398158d5172e8c6fad6d7f3ebf61c95c --- /dev/null +++ b/application/admin/view/orgnazation/index.html @@ -0,0 +1,33 @@ +
+ {:build_heading()} + + +
diff --git a/application/config.php b/application/config.php index 823b5b6cacba32958c85e5f1585df068460cd052..7780e5c637b8d42424d178fcd338e21ce5998612 100755 --- a/application/config.php +++ b/application/config.php @@ -18,7 +18,7 @@ return [ // 应用命名空间 'app_namespace' => 'app', // 应用调试模式 - 'app_debug' => Env::get('app.debug', false), + 'app_debug' => Env::get('app.debug', true), // 应用Trace 'app_trace' => Env::get('app.trace', false), // 应用模式状态 diff --git a/application/database.php b/application/database.php index d1bbd61c81be38e29884a76e70b42bacd6f83aaf..33a9b3365909fe1c42fec5f49f4433fc978ca75d 100755 --- a/application/database.php +++ b/application/database.php @@ -24,7 +24,7 @@ return [ // 密码 'password' => Env::get('database.password', ''), // 端口 - 'hostport' => Env::get('database.hostport', ''), + 'hostport' => Env::get('database.hostport', '3307'), // 连接dsn 'dsn' => '', // 数据库连接参数 diff --git a/public/assets/js/backend/auth/admin.js b/public/assets/js/backend/auth/admin.js index 89f4ebee1c44f1b52367708170532d647a4274ef..c0a1dfc2dc85399b4eea9c2b9803de9a0c264511 100755 --- a/public/assets/js/backend/auth/admin.js +++ b/public/assets/js/backend/auth/admin.js @@ -33,6 +33,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'id', title: 'ID'}, {field: 'username', title: __('Username')}, {field: 'nickname', title: __('Nickname')}, + {field: 'orgnazation.name', title: __('Orgnazation')}, {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label}, {field: 'email', title: __('Email')}, {field: 'status', title: __("Status"), formatter: Table.api.formatter.status}, diff --git a/public/assets/js/backend/orgnazation.js b/public/assets/js/backend/orgnazation.js new file mode 100644 index 0000000000000000000000000000000000000000..54fec2f3fc58a340dd963534b9ed5543e434ace6 --- /dev/null +++ b/public/assets/js/backend/orgnazation.js @@ -0,0 +1,57 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'orgnazation/index', + add_url: 'orgnazation/add', + edit_url: 'orgnazation/edit', + del_url: 'orgnazation/del', + multi_url: 'orgnazation/multi', + table: 'orgnazation', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'pid', title: __('Pid')}, + {field: 'name', title: __('Name')}, + {field: 'fullname', title: __('Fullname')}, + {field: 'description', title: __('Description')}, + {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, + {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime}, + {field: 'weigh', title: __('Weigh')}, + {field: 'status', title: __('Status'), formatter: Table.api.formatter.status}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); \ No newline at end of file