From 856cba0466d1f33ab0f8bf1cbb0d013145a04d9e Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Tue, 1 Apr 2025 16:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BB=E5=BC=8F=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/auth/Admin.php | 80 +++ .../admin/controller/auth/api/Adminlog.php | 149 +++++ .../admin/controller/auth/api/Group.php | 319 +++++++++ .../admin/controller/auth/api/Rule.php | 162 +++++ .../admin/controller/manystore/Index.php | 44 +- .../admin/controller/manystore/ShopApply.php | 73 ++ .../admin/lang/zh-cn/auth/api/group.php | 12 + .../admin/lang/zh-cn/auth/api/rule.php | 29 + .../admin/lang/zh-cn/manystore/shop_apply.php | 20 + application/admin/library/Auth.php | 76 +++ application/admin/model/Admin.php | 19 + application/admin/model/api/AdminLog.php | 119 ++++ application/admin/model/api/AuthGroup.php | 22 + .../admin/model/api/AuthGroupAccess.php | 11 + application/admin/model/api/AuthRule.php | 63 ++ .../admin/model/manystore/ShopApply.php | 83 +++ application/admin/validate/ApiAuthRule.php | 52 ++ .../admin/validate/manystore/ShopApply.php | 27 + application/admin/view/auth/admin/add.html | 9 + application/admin/view/auth/admin/edit.html | 10 + .../admin/view/auth/api/adminlog/detail.html | 27 + .../admin/view/auth/api/adminlog/index.html | 21 + .../admin/view/auth/api/group/add.html | 38 ++ .../admin/view/auth/api/group/edit.html | 38 ++ .../admin/view/auth/api/group/index.html | 21 + application/admin/view/auth/api/rule/add.html | 96 +++ .../admin/view/auth/api/rule/edit.html | 99 +++ .../admin/view/auth/api/rule/index.html | 35 + application/admin/view/auth/api/rule/tpl.html | 43 ++ application/admin/view/command/add.html | 1 + .../admin/view/manystore/index/add.html | 13 +- .../admin/view/manystore/shop_apply/add.html | 75 +++ .../admin/view/manystore/shop_apply/edit.html | 76 +++ .../view/manystore/shop_apply/index.html | 29 + application/adminapi/behavior/AdminLog.php | 14 + application/adminapi/common.php | 1 + application/adminapi/config.php | 6 + application/adminapi/controller/Admin.php | 149 +++++ application/adminapi/controller/Rule.php | 80 +++ application/adminapi/lang/zh-cn.php | 102 +++ application/adminapi/lang/zh-cn/common.php | 3 + .../lang/zh-cn/csmtable/xc_clogin_api.php | 7 + application/adminapi/lang/zh-cn/user.php | 39 ++ .../lang/zh-cn/xilufitness/xilufitess.php | 21 + application/adminapi/library/Auth.php | 622 ++++++++++++++++++ .../adminapi/library/ExceptionHandle.php | 37 ++ application/adminapi/model/Admin.php | 118 ++++ application/adminapi/model/AdminLog.php | 119 ++++ application/adminapi/model/AuthGroup.php | 22 + .../adminapi/model/AuthGroupAccess.php | 11 + application/adminapi/model/AuthRule.php | 210 ++++++ application/adminapi/tags.php | 18 + application/api/controller/school/Shop.php | 52 +- application/common/controller/AdminApi.php | 366 +++++++++++ application/common/controller/Backend.php | 2 +- .../common/controller/ManystoreBase.php | 2 +- application/common/model/BaseModel.php | 223 +++++++ .../common/model/dyqc/ManystoreShop.php | 31 +- .../common/model/manystore/ShopApply.php | 174 +++++ application/database.php | 6 +- public/assets/js/backend/auth/api/adminlog.js | 64 ++ public/assets/js/backend/auth/api/group.js | 160 +++++ public/assets/js/backend/auth/api/rule.js | 221 +++++++ .../assets/js/backend/manystore/shop_apply.js | 127 ++++ .../js/backend/school/classes/classes_lib.js | 2 +- .../manystore/school/classes/classes_lib.js | 2 +- 66 files changed, 4980 insertions(+), 22 deletions(-) create mode 100644 application/admin/controller/auth/api/Adminlog.php create mode 100644 application/admin/controller/auth/api/Group.php create mode 100644 application/admin/controller/auth/api/Rule.php create mode 100644 application/admin/controller/manystore/ShopApply.php create mode 100644 application/admin/lang/zh-cn/auth/api/group.php create mode 100644 application/admin/lang/zh-cn/auth/api/rule.php create mode 100644 application/admin/lang/zh-cn/manystore/shop_apply.php create mode 100644 application/admin/model/api/AdminLog.php create mode 100644 application/admin/model/api/AuthGroup.php create mode 100644 application/admin/model/api/AuthGroupAccess.php create mode 100644 application/admin/model/api/AuthRule.php create mode 100644 application/admin/model/manystore/ShopApply.php create mode 100644 application/admin/validate/ApiAuthRule.php create mode 100644 application/admin/validate/manystore/ShopApply.php create mode 100644 application/admin/view/auth/api/adminlog/detail.html create mode 100644 application/admin/view/auth/api/adminlog/index.html create mode 100644 application/admin/view/auth/api/group/add.html create mode 100644 application/admin/view/auth/api/group/edit.html create mode 100644 application/admin/view/auth/api/group/index.html create mode 100644 application/admin/view/auth/api/rule/add.html create mode 100644 application/admin/view/auth/api/rule/edit.html create mode 100644 application/admin/view/auth/api/rule/index.html create mode 100644 application/admin/view/auth/api/rule/tpl.html create mode 100644 application/admin/view/manystore/shop_apply/add.html create mode 100644 application/admin/view/manystore/shop_apply/edit.html create mode 100644 application/admin/view/manystore/shop_apply/index.html create mode 100644 application/adminapi/behavior/AdminLog.php create mode 100644 application/adminapi/common.php create mode 100644 application/adminapi/config.php create mode 100644 application/adminapi/controller/Admin.php create mode 100644 application/adminapi/controller/Rule.php create mode 100644 application/adminapi/lang/zh-cn.php create mode 100644 application/adminapi/lang/zh-cn/common.php create mode 100644 application/adminapi/lang/zh-cn/csmtable/xc_clogin_api.php create mode 100644 application/adminapi/lang/zh-cn/user.php create mode 100644 application/adminapi/lang/zh-cn/xilufitness/xilufitess.php create mode 100644 application/adminapi/library/Auth.php create mode 100644 application/adminapi/library/ExceptionHandle.php create mode 100644 application/adminapi/model/Admin.php create mode 100644 application/adminapi/model/AdminLog.php create mode 100644 application/adminapi/model/AuthGroup.php create mode 100644 application/adminapi/model/AuthGroupAccess.php create mode 100644 application/adminapi/model/AuthRule.php create mode 100644 application/adminapi/tags.php create mode 100644 application/common/controller/AdminApi.php create mode 100644 application/common/model/manystore/ShopApply.php create mode 100644 public/assets/js/backend/auth/api/adminlog.js create mode 100644 public/assets/js/backend/auth/api/group.js create mode 100644 public/assets/js/backend/auth/api/rule.js create mode 100644 public/assets/js/backend/manystore/shop_apply.js diff --git a/application/admin/controller/auth/Admin.php b/application/admin/controller/auth/Admin.php index 065108e..1d32fba 100644 --- a/application/admin/controller/auth/Admin.php +++ b/application/admin/controller/auth/Admin.php @@ -27,6 +27,7 @@ class Admin extends Backend protected $selectpageFields = 'id,username,nickname,avatar'; protected $searchFields = 'id,username,nickname'; protected $childrenGroupIds = []; + protected $childrenApiGroupIds = []; protected $childrenAdminIds = []; public function _initialize() @@ -36,6 +37,9 @@ class Admin extends Backend $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin()); $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin()); +// var_dump($this->childrenGroupIds); + + $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); @@ -61,6 +65,39 @@ class Admin extends Backend } $this->view->assign('groupdata', $groupdata); + + $this->childrenApiGroupIds = $this->auth->getChildrenApiGroupIds($this->auth->isSuperAdmin()); +// var_dump($this->childrenApiGroupIds); + + $groupList = collection(\app\admin\model\api\AuthGroup::where('id', 'in', $this->childrenApiGroupIds)->select())->toArray(); + + Tree::instance()->init($groupList); + $groupdata = []; + if ($this->auth->isSuperAdmin()) { + $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); + foreach ($result as $k => $v) { + $groupdata[$v['id']] = $v['name']; + } + } else { + $result = []; + $groups = $this->auth->getGroups(); + foreach ($groups as $m => $n) { + $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id'])); + $temp = []; + foreach ($childlist as $k => $v) { + $temp[$v['id']] = $v['name']; + } + $result[__($n['name'])] = $temp; + } + $groupdata = $result; + } + + $this->view->assign('apigroupdata', $groupdata); + + + + + $this->assignconfig("admin", ['id' => $this->auth->id]); $this->getCity(); @@ -141,6 +178,7 @@ class Admin extends Backend exception($this->model->getError()); } $group = $this->request->post("group/a"); + $apigroup = $this->request->post("apigroup/a"); //过滤不允许的组别,避免越权 $group = array_intersect($this->childrenGroupIds, $group); @@ -148,11 +186,27 @@ class Admin extends Backend exception(__('The parent group exceeds permission limit')); } + + $apigroup = array_intersect($this->childrenApiGroupIds, $apigroup); + if (!$apigroup) { + exception(__('The parent group exceeds permission limit')); + } + + + $dataset = []; foreach ($group as $value) { $dataset[] = ['uid' => $this->model->id, 'group_id' => $value]; } model('AuthGroupAccess')->saveAll($dataset); + + + $dataset = []; + foreach ($apigroup as $value) { + $dataset[] = ['uid' => $this->model->id, 'group_id' => $value]; + } + (new \app\admin\model\api\AuthGroupAccess())->saveAll($dataset); + Db::commit(); } catch (\Exception $e) { Db::rollback(); @@ -207,8 +261,10 @@ class Admin extends Backend // 先移除所有权限 model('AuthGroupAccess')->where('uid', $row->id)->delete(); + \app\admin\model\api\AuthGroupAccess::where('uid', $row->id)->delete(); $group = $this->request->post("group/a"); + $apigroup = $this->request->post("apigroup/a"); // 过滤不允许的组别,避免越权 $group = array_intersect($this->childrenGroupIds, $group); @@ -216,11 +272,25 @@ class Admin extends Backend exception(__('The parent group exceeds permission limit')); } + $apigroup = array_intersect($this->childrenApiGroupIds, $apigroup); + if (!$apigroup) { + exception(__('The parent group exceeds permission limit')); + } + + $dataset = []; foreach ($group as $value) { $dataset[] = ['uid' => $row->id, 'group_id' => $value]; } model('AuthGroupAccess')->saveAll($dataset); + + + $dataset = []; + foreach ($apigroup as $value) { + $dataset[] = ['uid' => $row->id, 'group_id' => $value]; + } + (new \app\admin\model\api\AuthGroupAccess())->saveAll($dataset); + Db::commit(); } catch (\Exception $e) { Db::rollback(); @@ -237,6 +307,16 @@ class Admin extends Backend } $this->view->assign("row", $row); $this->view->assign("groupids", $groupids); + + + $grouplist = $this->auth->getApiGroups($row['id']); + $groupids = []; + foreach ($grouplist as $k => $v) { + $groupids[] = $v['id']; + } +// $this->view->assign("row", $row); + $this->view->assign("apigroupids", $groupids); + return $this->view->fetch(); } diff --git a/application/admin/controller/auth/api/Adminlog.php b/application/admin/controller/auth/api/Adminlog.php new file mode 100644 index 0000000..5f292e0 --- /dev/null +++ b/application/admin/controller/auth/api/Adminlog.php @@ -0,0 +1,149 @@ +model = new \app\admin\model\api\AdminLog; + + $this->childrenAdminIds = $this->auth->getChildrenAdminIds(true); + $this->childrenGroupIds = $this->auth->getChildrenGroupIds(true); + + $groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds) + ->column('id,name'); + + $this->view->assign('groupdata', $groupName); + +// var_dump(XcAdminSessionUtils::getManystoreToken());die; + } + + /** + * 查看 + */ + public function index() + { + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + $isSuperAdmin = $this->auth->isSuperAdmin(); + $childrenAdminIds = $this->childrenAdminIds; + $list = $this->model + ->where($where) + ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) { + if (!$isSuperAdmin) { + $query->where('admin_id', 'in', $childrenAdminIds); + } + }) + ->field('content,useragent', true) + ->order($sort, $order) + ->paginate($limit); + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 详情 + */ + public function detail($ids) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + if (!$this->auth->isSuperAdmin()) { + if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) { + $this->error(__('You have no permission')); + } + } + $this->view->assign("row", $row->toArray()); + return $this->view->fetch(); + } + + /** + * 添加 + * @internal + */ + public function add() + { + $this->error(); + } + + /** + * 编辑 + * @internal + */ + public function edit($ids = null) + { + $this->error(); + } + + /** + * 删除 + */ + public function del($ids = "") + { + if (!$this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids) { + $isSuperAdmin = $this->auth->isSuperAdmin(); + $childrenAdminIds = $this->childrenAdminIds; + $adminList = $this->model->where('id', 'in', $ids) + ->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) { + if (!$isSuperAdmin) { + $query->where('admin_id', 'in', $childrenAdminIds); + } + }) + ->select(); + if ($adminList) { + $deleteIds = []; + foreach ($adminList as $k => $v) { + $deleteIds[] = $v->id; + } + if ($deleteIds) { + $this->model->destroy($deleteIds); + $this->success(); + } + } + } + $this->error(); + } + + /** + * 批量更新 + * @internal + */ + public function multi($ids = "") + { + // 管理员禁止批量操作 + $this->error(); + } + +} diff --git a/application/admin/controller/auth/api/Group.php b/application/admin/controller/auth/api/Group.php new file mode 100644 index 0000000..5bedb09 --- /dev/null +++ b/application/admin/controller/auth/api/Group.php @@ -0,0 +1,319 @@ +model = new AuthGroup; + + $this->childrenGroupIds = $this->auth->getChildrenApiGroupIds(true); + + $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray(); + + Tree::instance()->init($groupList); + $groupList = []; + if ($this->auth->isSuperAdmin()) { + $groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); + } else { + $groups = $this->auth->getApiGroups(); + $groupIds = []; + foreach ($groups as $m => $n) { + if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) { + continue; + } + $groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid']))); + foreach ($groupList as $index => $item) { + $groupIds[] = $item['id']; + } + } + } + $groupName = []; + foreach ($groupList as $k => $v) { + $groupName[$v['id']] = $v['name']; + } + + $this->grouplist = $groupList; + $this->groupdata = $groupName; + $this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getApiGroupIds()]); + + $this->view->assign('groupdata', $this->groupdata); + } + + /** + * 查看 + */ + public function index() + { + if ($this->request->isAjax()) { + $list = $this->grouplist; + $total = count($list); + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + $params['rules'] = explode(',', $params['rules']); + if (!in_array($params['pid'], $this->childrenGroupIds)) { + $this->error(__('The parent group exceeds permission limit')); + } + $parentmodel = (new AuthGroup)->get($params['pid']); + if (!$parentmodel) { + $this->error(__('The parent group can not found')); + } + // 父级别的规则节点 + $parentrules = explode(',', $parentmodel->rules); + // 当前组别的规则节点 + $currentrules = $this->auth->getRuleIds(); + $rules = $params['rules']; + // 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 + $rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); + // 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 + $rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); + $params['rules'] = implode(',', $rules); + if ($params) { + $this->model->create($params); + $this->success(); + } + $this->error(); + } + return $this->view->fetch(); + } + + /** + * 编辑 + */ + public function edit($ids = null) + { + if (!in_array($ids, $this->childrenGroupIds)) { + $this->error(__('You have no permission')); + } + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + //父节点不能是非权限内节点 + if (!in_array($params['pid'], $this->childrenGroupIds)) { + $this->error(__('The parent group exceeds permission limit')); + } + // 父节点不能是它自身的子节点或自己本身 + if (in_array($params['pid'], Tree::instance()->getChildrenIds($row->id, true))) { + $this->error(__('The parent group can not be its own child or itself')); + } + $params['rules'] = explode(',', $params['rules']); + + $parentmodel = (new AuthGroup)->get($params['pid']); + if (!$parentmodel) { + $this->error(__('The parent group can not found')); + } + // 父级别的规则节点 + $parentrules = explode(',', $parentmodel->rules); + // 当前组别的规则节点 + $currentrules = $this->auth->getRuleIds(); + $rules = $params['rules']; + // 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限 + $rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules); + // 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限 + $rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules); + $params['rules'] = implode(',', $rules); + if ($params) { + Db::startTrans(); + try { + $row->save($params); + $children_auth_groups = (new AuthGroup)->all(['id' => ['in', implode(',', (Tree::instance()->getChildrenIds($row->id)))]]); + $childparams = []; + foreach ($children_auth_groups as $key => $children_auth_group) { + $childparams[$key]['id'] = $children_auth_group->id; + $childparams[$key]['rules'] = implode(',', array_intersect(explode(',', $children_auth_group->rules), $rules)); + } + (new AuthGroup)->saveAll($childparams); + Db::commit(); + $this->success(); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + } + $this->error(); + return; + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } + + /** + * 删除 + */ + public function del($ids = "") + { + if (!$this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids) { + $ids = explode(',', $ids); + $grouplist = $this->auth->getGroups(); + $group_ids = array_map(function ($group) { + return $group['id']; + }, $grouplist); + // 移除掉当前管理员所在组别 + $ids = array_diff($ids, $group_ids); + + // 循环判断每一个组别是否可删除 + $grouplist = $this->model->where('id', 'in', $ids)->select(); + $groupaccessmodel = new AuthGroupAccess(); + foreach ($grouplist as $k => $v) { + // 当前组别下有管理员 + $groupone = $groupaccessmodel->get(['group_id' => $v['id']]); + if ($groupone) { + $ids = array_diff($ids, [$v['id']]); + continue; + } + // 当前组别下有子组别 + $groupone = $this->model->get(['pid' => $v['id']]); + if ($groupone) { + $ids = array_diff($ids, [$v['id']]); + continue; + } + } + if (!$ids) { + $this->error(__('You can not delete group that contain child group and administrators')); + } + $count = $this->model->where('id', 'in', $ids)->delete(); + if ($count) { + $this->success(); + } + } + $this->error(); + } + + /** + * 批量更新 + * @internal + */ + public function multi($ids = "") + { + // 组别禁止批量操作 + $this->error(); + } + + /** + * 读取角色权限树 + * + * @internal + */ + public function roletree() + { + $this->loadlang('auth/group'); + + $model = (new AuthGroup); + $id = $this->request->post("id"); + $pid = $this->request->post("pid"); + $parentGroupModel = $model->get($pid); + $currentGroupModel = null; + if ($id) { + $currentGroupModel = $model->get($id); + } + if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) { + $id = $id ? $id : null; + $ruleList = collection((new AuthRule())->order('weigh', 'desc')->order('id', 'asc')->select())->toArray(); + //读取父类角色所有节点列表 + $parentRuleList = []; + if (in_array('*', explode(',', $parentGroupModel->rules))) { + $parentRuleList = $ruleList; + } else { + $parentRuleIds = explode(',', $parentGroupModel->rules); + foreach ($ruleList as $k => $v) { + if (in_array($v['id'], $parentRuleIds)) { + $parentRuleList[] = $v; + } + } + } + + $ruleTree = new Tree(); + $groupTree = new Tree(); + //当前所有正常规则列表 + $ruleTree->init($parentRuleList); + //角色组列表 + $groupTree->init(collection((new AuthGroup)->where('id', 'in', $this->childrenGroupIds)->select())->toArray()); + + //读取当前角色下规则ID集合 + $adminRuleIds = $this->auth->getRuleIds(); + //是否是超级管理员 + $superadmin = $this->auth->isSuperAdmin(); + //当前拥有的规则ID集合 + $currentRuleIds = $id ? explode(',', $currentGroupModel->rules) : []; + + if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) { + $parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name'); + $hasChildrens = []; + foreach ($parentRuleList as $k => $v) { + if ($v['haschild']) { + $hasChildrens[] = $v['id']; + } + } + $parentRuleIds = array_map(function ($item) { + return $item['id']; + }, $parentRuleList); + $nodeList = []; + foreach ($parentRuleList as $k => $v) { + if (!$superadmin && !in_array($v['id'], $adminRuleIds)) { + continue; + } + if ($v['pid'] && !in_array($v['pid'], $parentRuleIds)) { + continue; + } + $state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens)); + $nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state); + } + $this->success('', null, $nodeList); + } else { + $this->error(__('Can not change the parent to child')); + } + } else { + $this->error(__('Group not found')); + } + } +} diff --git a/application/admin/controller/auth/api/Rule.php b/application/admin/controller/auth/api/Rule.php new file mode 100644 index 0000000..f0c8cb6 --- /dev/null +++ b/application/admin/controller/auth/api/Rule.php @@ -0,0 +1,162 @@ +auth->isSuperAdmin()) { + $this->error(__('Access is allowed only to the super management group')); + } + $this->model = new AuthRule; + // 必须将结果集转换为数组 + $ruleList = \think\Db::name("api_auth_rule")->field('type,condition,remark,createtime,updatetime', true)->order('weigh DESC,id ASC')->select(); + foreach ($ruleList as $k => &$v) { + $v['title'] = __($v['title']); + } + unset($v); + Tree::instance()->init($ruleList)->icon = [' ', ' ', ' ']; + $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); + $ruledata = [0 => __('None')]; + foreach ($this->rulelist as $k => &$v) { + if (!$v['ismenu']) { + continue; + } + $ruledata[$v['id']] = $v['title']; + unset($v['spacer']); + } + unset($v); + $this->view->assign('ruledata', $ruledata); + $this->view->assign("menutypeList", $this->model->getMenutypeList()); + } + + /** + * 查看 + */ + public function index() + { + if ($this->request->isAjax()) { + $list = $this->rulelist; + $total = count($this->rulelist); + $result = array("total" => $total, "rows" => $list); + + return json($result); + } + return $this->view->fetch(); + } + + /** + * 添加 + */ + public function add() + { + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + if ($params) { + if (!$params['ismenu'] && !$params['pid']) { + $this->error(__('The non-menu rule must have parent')); + } + $result = $this->model->validate()->save($params); + if ($result === false) { + $this->error($this->model->getError()); + } + Cache::rm('__menu__'); + $this->success(); + } + $this->error(); + } + return $this->view->fetch(); + } + + /** + * 编辑 + */ + public function edit($ids = null) + { + $row = $this->model->get(['id' => $ids]); + if (!$row) { + $this->error(__('No Results were found')); + } + if ($this->request->isPost()) { + $this->token(); + $params = $this->request->post("row/a", [], 'strip_tags'); + if ($params) { + if (!$params['ismenu'] && !$params['pid']) { + $this->error(__('The non-menu rule must have parent')); + } + if ($params['pid'] == $row['id']) { + $this->error(__('Can not change the parent to self')); + } + if ($params['pid'] != $row['pid']) { + $childrenIds = Tree::instance()->init(collection(AuthRule::select())->toArray())->getChildrenIds($row['id']); + if (in_array($params['pid'], $childrenIds)) { + $this->error(__('Can not change the parent to child')); + } + } + //这里需要针对name做唯一验证 +// $ruleValidate = \think\Loader::validate(ApiAuthRule::class); +// $ruleValidate->rule([ +// 'name' => 'require|unique:ApiAuthRule,name,' . $row->id, +// ]); +// $result = $row->validate($ruleValidate)->save($params); + $result = $row->save($params); + + if ($result === false) { + $this->error($row->getError()); + } + Cache::rm('__menu__'); + $this->success(); + } + $this->error(); + } + $this->view->assign("row", $row); + return $this->view->fetch(); + } + + /** + * 删除 + */ + public function del($ids = "") + { + if (!$this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids) { + $delIds = []; + foreach (explode(',', $ids) as $k => $v) { + $delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true)); + } + $delIds = array_unique($delIds); + $count = $this->model->where('id', 'in', $delIds)->delete(); + if ($count) { + Cache::rm('__menu__'); + $this->success(); + } + } + $this->error(); + } +} diff --git a/application/admin/controller/manystore/Index.php b/application/admin/controller/manystore/Index.php index d37f8fc..58f3b56 100644 --- a/application/admin/controller/manystore/Index.php +++ b/application/admin/controller/manystore/Index.php @@ -62,7 +62,48 @@ class Index extends Backend protected $error_auth = false; protected $qSwitch = true; - protected $qFields = ["user_id"]; + protected $qFields = ["user_id","name","address_detail","type","tel","legal_entity","shop_apply_id"]; + + + protected function checkAssemblyParameters(){ + if(!$this->qSwitch)return false; + //得到所有get参数 + $get = $this->request->get(); + //得到当前model所有字段 + + + $fields = $this->shopModel->getTableFields(); + +// $commonFields = (new Field())->getCommonFields(); +// var_dump($commonFields); + $fieldLists = $fields; +// foreach ($commonFields as $commonField) { +// if (!in_array($commonField['column_name'], $fields)) { +// $fieldLists[] = $commonField; +// } +// } + $q_fields = []; + + foreach ($get as $kay=>$getField) { + if (in_array($kay, $fieldLists) || in_array($kay, $this->qFields)) { + $q_fields[$kay] = $getField; + } + } + + + //将q_fields塞入模板中 + foreach ($q_fields as $k=>$v) { + //渲染站点配置 + $this->assign('q_'.$k, $v); + } + + foreach ($this->qFields as $k) { + //渲染站点配置 + if(!isset($q_fields[$k]))$this->assign('q_'.$k, ""); + } + + + } public function _initialize() @@ -740,6 +781,7 @@ class Index extends Backend Admin::where(array('admin_shop_id'=>$row['shop_id']))->update(['admin_shop_id'=>0]); Evaluate::where(array('shop_id'=>$row['shop_id']))->delete(); + \app\common\model\manystore\ShopApply::where(array('shop_id'=>$row['shop_id']))->update(['shop_id'=>0,'store_id'=>0]); if(!$result){ exception('商家信息删除失败'); } diff --git a/application/admin/controller/manystore/ShopApply.php b/application/admin/controller/manystore/ShopApply.php new file mode 100644 index 0000000..5eba6db --- /dev/null +++ b/application/admin/controller/manystore/ShopApply.php @@ -0,0 +1,73 @@ +model = new \app\admin\model\manystore\ShopApply; + $this->view->assign("typeList", $this->model->getTypeList()); + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + /** + * 查看 + */ + public function index() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->model + ->with(['user','shop']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + foreach ($list as $row) { + + $row->getRelation('user')->visible(['nickname','mobile','avatar']); + $row->getRelation('shop')->visible(['name','logo']); + } + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + +} diff --git a/application/admin/lang/zh-cn/auth/api/group.php b/application/admin/lang/zh-cn/auth/api/group.php new file mode 100644 index 0000000..9deec57 --- /dev/null +++ b/application/admin/lang/zh-cn/auth/api/group.php @@ -0,0 +1,12 @@ + '父组别不能是自身的子组别', + 'The parent group can not found' => '父组别未找到', + 'Group not found' => '组别未找到', + 'Can not change the parent to child' => '父组别不能是它的子组别', + 'Can not change the parent to self' => '父组别不能是它自己', + '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' => '父组别不能是它的子组别及本身', +]; diff --git a/application/admin/lang/zh-cn/auth/api/rule.php b/application/admin/lang/zh-cn/auth/api/rule.php new file mode 100644 index 0000000..6f8f9da --- /dev/null +++ b/application/admin/lang/zh-cn/auth/api/rule.php @@ -0,0 +1,29 @@ + '显示全部', + 'Condition' => '规则条件', + 'Remark' => '备注', + 'Icon' => '图标', + 'Alert' => '警告', + 'Name' => '规则', + 'Controller/Action' => '控制器名/方法名', + 'Ismenu' => '菜单', + 'Menutype' => '菜单类型', + 'Addtabs' => '选项卡(默认)', + 'Dialog' => '弹窗', + 'Ajax' => 'Ajax请求', + 'Blank' => '链接', + 'Extend' => '扩展属性', + 'Search icon' => '搜索图标', + 'Toggle menu visible' => '点击切换菜单显示', + 'Toggle sub menu' => '点击切换子菜单', + 'Menu tips' => '父级菜单无需匹配控制器和方法,子级菜单请使用控制器名', + 'Node tips' => '控制器/方法名,如果有目录请使用 目录名/控制器名/方法名', + 'Url tips' => '一般情况下留空即可,如果是外部链接或相对链接请输入', + 'The non-menu rule must have parent' => '非菜单规则节点必须有父级', + 'Can not change the parent to child' => '父级不能是它的子级', + 'Can not change the parent to self' => '父级不能是它自己', + 'Name only supports letters, numbers, underscore and slash' => 'URL规则只能是小写字母、数字、下划线和/组成', + 'Rule_name' => '权限标识(菜单需要)', +]; diff --git a/application/admin/lang/zh-cn/manystore/shop_apply.php b/application/admin/lang/zh-cn/manystore/shop_apply.php new file mode 100644 index 0000000..f12fc91 --- /dev/null +++ b/application/admin/lang/zh-cn/manystore/shop_apply.php @@ -0,0 +1,20 @@ + '申请用户', + 'Type' => '类型', + 'Type 1' => '个人', + 'Type 2' => '机构', + 'Name' => '机构名称', + 'Realname' => '联系人姓名', + 'Mobile' => '联系电话', + 'Address' => '机构|授课地址', + 'Shop_id' => '申请的机构id', + 'Create_time' => '创建时间', + 'Update_time' => '修改时间', + 'User.nickname' => '昵称', + 'User.mobile' => '手机号', + 'User.avatar' => '头像', + 'Shop.name' => '店铺名称', + 'Shop.logo' => '品牌LOGO' +]; diff --git a/application/admin/library/Auth.php b/application/admin/library/Auth.php index 6e1c61f..3a01b38 100644 --- a/application/admin/library/Auth.php +++ b/application/admin/library/Auth.php @@ -279,6 +279,13 @@ class Auth extends \fast\Auth return parent::getGroups($uid); } + public function getApiGroups($uid = null) + { + $uid = is_null($uid) ? $this->id : $uid; +// var_dump($uid); + return parent::getApiGroups($uid); + } + public function getRuleList($uid = null) { $uid = is_null($uid) ? $this->id : $uid; @@ -580,4 +587,73 @@ class Auth extends \fast\Auth { return $this->_error ? __($this->_error) : ''; } + + + + + /** + * 取出当前管理员所拥有api权限的分组 + * @param boolean $withself 是否包含当前所在的分组 + * @return array + */ + public function getChildrenApiGroupIds($withself = false) + { + //取出当前管理员所有的分组 + $groups = $this->getApiGroups(); +// var_dump($groups); + + $groupIds = []; + foreach ($groups as $k => $v) { + $groupIds[] = $v['id']; + } + $originGroupIds = $groupIds; + foreach ($groups as $k => $v) { + if (in_array($v['pid'], $originGroupIds)) { + $groupIds = array_diff($groupIds, [$v['id']]); + unset($groups[$k]); + } + } + // 取出所有分组 + $groupList = \app\admin\model\api\AuthGroup::where($this->isSuperAdmin() ? '1=1' : ['status' => 'normal'])->select(); + $objList = []; + foreach ($groups as $k => $v) { + if ($v['rules'] === '*') { + $objList = $groupList; + break; + } + // 取出包含自己的所有子节点 + $childrenList = Tree::instance()->init($groupList, 'pid')->getChildren($v['id'], true); + $obj = Tree::instance()->init($childrenList, 'pid')->getTreeArray($v['pid']); + $objList = array_merge($objList, Tree::instance()->getTreeList($obj)); + } + $childrenGroupIds = []; + foreach ($objList as $k => $v) { + $childrenGroupIds[] = $v['id']; + } + if (!$withself) { + $childrenGroupIds = array_diff($childrenGroupIds, $groupIds); + } + return $childrenGroupIds; + } + + + + /** + * 获取管理员所属于的分组ID + * @param int $uid + * @return array + */ + public function getApiGroupIds($uid = null) + { + $groups = $this->getApiGroups($uid); + $groupIds = []; + foreach ($groups as $K => $v) { + $groupIds[] = (int)$v['group_id']; + } + return $groupIds; + } + + + + } diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index 79975f5..6c778a1 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -20,6 +20,25 @@ class Admin extends Model 'salt' ]; + + + /** + * 获取会员的组别 + */ + public function getGroupsAttr($value, $data) + { + $group_ids = \app\admin\model\api\AuthGroupAccess::where("uid", $data['id'])->column("group_id"); + if(!$group_ids)return []; + + $groups = \app\admin\model\api\AuthGroup::where("id","in",$group_ids)->select(); + return $groups; + } + + + + + + public static function init() { self::beforeWrite(function ($row) { diff --git a/application/admin/model/api/AdminLog.php b/application/admin/model/api/AdminLog.php new file mode 100644 index 0000000..3e8df1e --- /dev/null +++ b/application/admin/model/api/AdminLog.php @@ -0,0 +1,119 @@ +isLogin() ? $auth->id : 0; + $username = $auth->isLogin() ? $auth->username : __('Unknown'); + + // 设置过滤函数 + request()->filter('trim,strip_tags,htmlspecialchars'); + + $controllername = Loader::parseName(request()->controller()); + $actionname = strtolower(request()->action()); + $path = str_replace('.', '/', $controllername) . '/' . $actionname; + if (self::$ignoreRegex) { + foreach (self::$ignoreRegex as $index => $item) { + if (preg_match($item, $path)) { + return; + } + } + } + $content = $content ?: self::$content; + if (!$content) { + $content = request()->param('') ?: file_get_contents("php://input"); + $content = self::getPureContent($content); + } + $title = $title ?: self::$title; + if (!$title) { + $title = []; + $breadcrumb = Auth::instance()->getBreadcrumb($path); + foreach ($breadcrumb as $k => $v) { + $title[] = $v['title']; + } + $title = implode(' / ', $title); + } + self::create([ + 'title' => $title, + 'content' => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content, + 'url' => substr(xss_clean(strip_tags(request()->url())), 0, 1500), + 'admin_id' => $admin_id, + 'username' => $username, + 'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255), + 'ip' => xss_clean(strip_tags(request()->ip())) + ]); + } + + /** + * 获取已屏蔽关键信息的数据 + * @param $content + * @return array + */ + protected static function getPureContent($content) + { + if (!is_array($content)) { + return $content; + } + foreach ($content as $index => &$item) { + if (preg_match("/(password|salt|token)/i", $index)) { + $item = "***"; + } else { + if (is_array($item)) { + $item = self::getPureContent($item); + } + } + } + return $content; + } + + public function admin() + { + return $this->belongsTo('Admin', 'admin_id')->setEagerlyType(0); + } +} diff --git a/application/admin/model/api/AuthGroup.php b/application/admin/model/api/AuthGroup.php new file mode 100644 index 0000000..4a8e396 --- /dev/null +++ b/application/admin/model/api/AuthGroup.php @@ -0,0 +1,22 @@ + __('Addtabs'), 'dialog' => __('Dialog'), 'ajax' => __('Ajax'), 'blank' => __('Blank')]; + } + + public function setPyAttr($value, $data) + { + if (isset($data['title']) && $data['title']) { + return self::$pinyin->abbr(__($data['title'])); + } + return ''; + } + + public function setPinyinAttr($value, $data) + { + if (isset($data['title']) && $data['title']) { + return self::$pinyin->permalink(__($data['title']), ''); + } + return ''; + } +} diff --git a/application/admin/model/manystore/ShopApply.php b/application/admin/model/manystore/ShopApply.php new file mode 100644 index 0000000..e9283cd --- /dev/null +++ b/application/admin/model/manystore/ShopApply.php @@ -0,0 +1,83 @@ + __('Type 1'), '2' => __('Type 2')]; + } + + + public function getTypeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['type']) ? $data['type'] : ''); + $list = $this->getTypeList(); + return isset($list[$value]) ? $list[$value] : ''; + } + + + public function getCreateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + + public function getUpdateTimeTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : ''); + return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; + } + + protected function setCreateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + protected function setUpdateTimeAttr($value) + { + return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); + } + + + public function user() + { + return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + + + public function shop() + { + return $this->belongsTo(Shop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0); + } +} diff --git a/application/admin/validate/ApiAuthRule.php b/application/admin/validate/ApiAuthRule.php new file mode 100644 index 0000000..b249804 --- /dev/null +++ b/application/admin/validate/ApiAuthRule.php @@ -0,0 +1,52 @@ + '[a-z0-9_\/]+']; + + /** + * 验证规则 + */ + protected $rule = [ + 'name' => 'require|unique:ApiAuthRule', + 'title' => 'require', + ]; + + /** + * 提示消息 + */ + protected $message = [ + 'name.format' => 'URL规则只能是小写字母、数字、下划线和/组成' + ]; + + /** + * 字段描述 + */ + protected $field = [ + ]; + + /** + * 验证场景 + */ + protected $scene = [ + ]; + + public function __construct(array $rules = [], $message = [], $field = []) + { + $this->field = [ + 'name' => __('Name'), + 'title' => __('Title'), + ]; + $this->message['name.format'] = __('Name only supports letters, numbers, underscore and slash'); + parent::__construct($rules, $message, $field); + } + +} diff --git a/application/admin/validate/manystore/ShopApply.php b/application/admin/validate/manystore/ShopApply.php new file mode 100644 index 0000000..b607da9 --- /dev/null +++ b/application/admin/validate/manystore/ShopApply.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/auth/admin/add.html b/application/admin/view/auth/admin/add.html index 53865f3..c6d24d8 100644 --- a/application/admin/view/auth/admin/add.html +++ b/application/admin/view/auth/admin/add.html @@ -6,6 +6,15 @@ {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])} + + +
{:__('Title')} | +{:__('Content')} | +
---|---|
{:__($key)} | +{if $key=='createtime'}{$vo|datetime}{else/}{$vo|htmlentities}{/if} | +