From 5ff7c7bff845b10e9607e1fdccc704404958e9ec Mon Sep 17 00:00:00 2001 From: zsgwakk <1752569024@qq.com> Date: Sun, 29 Dec 2019 19:20:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=BB=84=E6=B7=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=89=E6=95=88=E6=9C=9F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/command/Install/fastadmin.sql | 11 +++---- application/admin/controller/auth/Group.php | 11 +++++++ application/admin/lang/zh-cn.php | 1 + application/admin/lang/zh-cn/auth/group.php | 1 + application/admin/view/auth/group/add.html | 11 +++++++ application/admin/view/auth/group/edit.html | 11 +++++++ extend/fast/Auth.php | 3 +- public/assets/js/backend/auth/group.js | 30 +++++++++++++++++++ 8 files changed, 73 insertions(+), 6 deletions(-) diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index cf8e91e4b..5fc0650bd 100755 --- a/application/admin/command/Install/fastadmin.sql +++ b/application/admin/command/Install/fastadmin.sql @@ -99,6 +99,7 @@ CREATE TABLE `fa_auth_group` ( `rules` text NOT NULL COMMENT '规则ID', `createtime` int(10) DEFAULT NULL COMMENT '创建时间', `updatetime` int(10) DEFAULT NULL COMMENT '更新时间', + `expiretime` int(10) DEFAULT NULL COMMENT '过期时间', `status` varchar(30) NOT NULL DEFAULT '' COMMENT '状态', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='分组表'; @@ -107,11 +108,11 @@ CREATE TABLE `fa_auth_group` ( -- Records of fa_auth_group -- ---------------------------- BEGIN; -INSERT INTO `fa_auth_group` VALUES (1, 0, 'Admin group', '*', 1490883540, 149088354, 'normal'); -INSERT INTO `fa_auth_group` VALUES (2, 1, 'Second group', '13,14,16,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,1,9,10,11,7,6,8,2,4,5', 1490883540, 1505465692, 'normal'); -INSERT INTO `fa_auth_group` VALUES (3, 2, 'Third group', '1,4,9,10,11,13,14,15,16,17,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,5', 1490883540, 1502205322, 'normal'); -INSERT INTO `fa_auth_group` VALUES (4, 1, 'Second group 2', '1,4,13,14,15,16,17,55,56,57,58,59,60,61,62,63,64,65', 1490883540, 1502205350, 'normal'); -INSERT INTO `fa_auth_group` VALUES (5, 2, 'Third group 2', '1,2,6,7,8,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34', 1490883540, 1502205344, 'normal'); +INSERT INTO `fa_auth_group` VALUES (1, 0, 'Admin group', '*', 1490883540, 149088354, 0,'normal'); +INSERT INTO `fa_auth_group` VALUES (2, 1, 'Second group', '13,14,16,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,1,9,10,11,7,6,8,2,4,5', 1490883540, 1505465692, 0, 'normal'); +INSERT INTO `fa_auth_group` VALUES (3, 2, 'Third group', '1,4,9,10,11,13,14,15,16,17,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63,64,65,5', 1490883540, 1502205322, 0, 'normal'); +INSERT INTO `fa_auth_group` VALUES (4, 1, 'Second group 2', '1,4,13,14,15,16,17,55,56,57,58,59,60,61,62,63,64,65', 1490883540, 1502205350, 0, 'normal'); +INSERT INTO `fa_auth_group` VALUES (5, 2, 'Third group 2', '1,2,6,7,8,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34', 1490883540, 1502205344, 0, 'normal'); COMMIT; -- ---------------------------- diff --git a/application/admin/controller/auth/Group.php b/application/admin/controller/auth/Group.php index 0e82c8d89..22e0080e3 100644 --- a/application/admin/controller/auth/Group.php +++ b/application/admin/controller/auth/Group.php @@ -111,6 +111,11 @@ class Group extends Backend // 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 $rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); $params['rules'] = implode(',', $rules); + //日期转时间戳 + $params['expiretime'] = empty($params['expiretime']) ? 0 : strtotime($params['expiretime']); + if (false === $params['expiretime']) { + $this->error(__('Invalid format of expire time')); + } if ($params) { $this->model->create($params); $this->success(); @@ -144,6 +149,11 @@ class Group extends Backend $this->error(__('The parent group can not be its own child or itself')); } $params['rules'] = explode(',', $params['rules']); + //日期转时间戳 + $params['expiretime'] = empty($params['expiretime']) ? 0 : strtotime($params['expiretime']); + if (false === $params['expiretime']) { + $this->error(__('Invalid format of expire time')); + } $parentmodel = model("AuthGroup")->get($params['pid']); if (!$parentmodel) { @@ -180,6 +190,7 @@ class Group extends Backend $this->error(); return; } + $row['expiretime'] = $row['expiretime'] === 0 ? 0 : date("Y-m-d H:i:s", $row['expiretime']); $this->view->assign("row", $row); return $this->view->fetch(); } diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index b18b5bf66..746c2db1b 100755 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -96,6 +96,7 @@ return [ 'End time' => '结束时间', 'Create time' => '创建时间', 'Update time' => '更新时间', + 'Expire time' => '过期时间', 'Flag' => '标志', 'Drag to sort' => '拖动进行排序', 'Redirect now' => '立即跳转', diff --git a/application/admin/lang/zh-cn/auth/group.php b/application/admin/lang/zh-cn/auth/group.php index 3a63f5860..dbf52e561 100644 --- a/application/admin/lang/zh-cn/auth/group.php +++ b/application/admin/lang/zh-cn/auth/group.php @@ -9,4 +9,5 @@ return [ 'You can not delete group that contain child group and administrators' => '你不能删除含有子组和管理员的组', 'The parent group exceeds permission limit' => '父组别超出权限范围', 'The parent group can not be its own child or itself' => '父组别不能是它的子组别及本身', + 'Invalid format of expire time' => '过期时间格式错误', ]; diff --git a/application/admin/view/auth/group/add.html b/application/admin/view/auth/group/add.html index 0eb848b54..b5bdfcf67 100644 --- a/application/admin/view/auth/group/add.html +++ b/application/admin/view/auth/group/add.html @@ -22,6 +22,17 @@
+
+ +
+ + + + +
+
diff --git a/application/admin/view/auth/group/edit.html b/application/admin/view/auth/group/edit.html index c691bd160..a853c98ad 100644 --- a/application/admin/view/auth/group/edit.html +++ b/application/admin/view/auth/group/edit.html @@ -22,6 +22,17 @@
+
+ +
+ + + + +
+
diff --git a/extend/fast/Auth.php b/extend/fast/Auth.php index 396c4cfc9..628abc2fa 100644 --- a/extend/fast/Auth.php +++ b/extend/fast/Auth.php @@ -153,11 +153,12 @@ class Auth } // 执行查询 + $nowTime = time(); $user_groups = Db::name($this->config['auth_group_access']) ->alias('aga') ->join('__' . strtoupper($this->config['auth_group']) . '__ ag', 'aga.group_id = ag.id', 'LEFT') ->field('aga.uid,aga.group_id,ag.id,ag.pid,ag.name,ag.rules') - ->where("aga.uid='{$uid}' and ag.status='normal'") + ->where("aga.uid='{$uid}' and ag.status='normal' and (ag.expiretime>={$nowTime} or ag.expiretime=0)") ->select(); $groups[$uid] = $user_groups ?: []; return $groups[$uid]; diff --git a/public/assets/js/backend/auth/group.js b/public/assets/js/backend/auth/group.js index 94a4b4b43..e076db6e6 100755 --- a/public/assets/js/backend/auth/group.js +++ b/public/assets/js/backend/auth/group.js @@ -50,6 +50,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ( {field: 'pid', title: __('Parent')}, {field: 'name', title: __('Name'), align: 'left'}, {field: 'status', title: __('Status'), formatter: Table.api.formatter.status}, + {field: 'expiretime', title: __('Expire time'), formatter: function (value,row,index) { + if (0 === value) { + return '永久'; + } else { + if (value >= parseInt(new Date().getTime()/1000)) { + var date = new Date(value * 1000); + var Y = date.getFullYear() + '-'; + var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; + var D = date.getDate() + ' '; + var h = date.getHours() + ':'; + var m = date.getMinutes() + ':'; + var s = date.getSeconds(); + return ''+(Y + M + D + h + m + s)+''; + } else { + return '已过期'; + } + } + }}, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) { if (Config.admin.group_ids.indexOf(parseInt(row.id)) > -1) { @@ -122,6 +140,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ( $(document).on("click", "#expandall", function () { $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all"); }); + //过期时间: 永久和选择时间 + $(document).on("click", "#for_ever", function () { + $("#expiretime-select").attr("style","display:none;"); + $("input[name='row[expiretime]']").val('0'); + $("#select_time").removeAttr("checked"); + }); + $(document).on("click", "#select_time", function () { + $("#expiretime-select").attr("style","display:block;"); + $("#for_ever").removeAttr("checked"); + var nowDate = new Date(); + $("input[name='row[expiretime]']").val(nowDate.getFullYear() + '-' + (nowDate.getMonth()+1) + '-' + nowDate.getDate() + ' 23:59:59'); + }); $("select[name='row[pid]']").trigger("change"); }, rendertree: function (content) { -- Gitee From 58f60776222e0baaecbc16b17cd1de5cb282e993 Mon Sep 17 00:00:00 2001 From: zsgwakk <1752569024@qq.com > Date: Sun, 29 Dec 2019 19:50:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=9E=E7=8E=B0:=E8=97=8F=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=9A=84=E8=A7=92=E8=89=B2=E5=8F=8A=E5=85=B6=E5=AD=90?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=9C=A8=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=B8=8B=E6=AD=A3=E5=B8=B8=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/library/Auth.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index 73826e454..eb0ce8e58 100644 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -282,7 +282,8 @@ class Auth extends \fast\Auth } } // 取出所有分组 - $groupList = \app\admin\model\AuthGroup::where(['status' => 'normal'])->select(); +// $groupList = \app\admin\model\AuthGroup::where(['status' => 'normal'])->select(); + $groupList = \app\admin\model\AuthGroup::all(); $objList = []; foreach ($groups as $k => $v) { if ($v['rules'] === '*') { -- Gitee