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 @@