[更新] 改 NodeModel 为 NodeService

This commit is contained in:
Anyon 2017-05-08 11:33:23 +08:00
parent 2ad0a1037d
commit b492289b8b
8 changed files with 21 additions and 22 deletions

View File

@ -14,9 +14,9 @@
namespace app\admin\controller;
use app\admin\model\NodeModel;
use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\Db;
@ -51,7 +51,7 @@ class Auth extends BasicAdmin {
$auth_id = $this->request->get('id', '0');
switch (strtolower($this->request->get('action', '0'))) {
case 'getnode':
$nodes = NodeModel::get();
$nodes = NodeService::get();
$checked = Db::name('SystemAuthNode')->where('auth', $auth_id)->column('node');
foreach ($nodes as $key => &$node) {
$node['checked'] = in_array($node['node'], $checked);

View File

@ -14,9 +14,9 @@
namespace app\admin\controller;
use app\admin\model\NodeModel;
use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\Db;
use think\View;
@ -35,7 +35,7 @@ class Index extends BasicAdmin {
* @return View
*/
public function index() {
NodeModel::applyAuthNode();
NodeService::applyAuthNode();
$list = Db::name('SystemMenu')->where('status', '1')->order('sort asc,id asc')->select();
$menus = $this->_filterMenu(ToolsService::arr2tree($list));
$this->assign('title', '系统管理');

View File

@ -46,7 +46,6 @@ class Log extends BasicAdmin {
$db->where($key, 'like', "%{$get[$key]}%");
}
}
parent::_list($db);
}

View File

@ -14,9 +14,9 @@
namespace app\admin\controller;
use app\admin\model\NodeModel;
use controller\BasicAdmin;
use service\LogService;
use service\NodeService;
use think\Db;
/**
@ -55,7 +55,7 @@ class Login extends BasicAdmin {
($user['password'] !== md5($password)) && $this->error('登录密码与账号不匹配,请重新输入!');
Db::name('SystemUser')->where('id', $user['id'])->update(['login_at' => ['exp', 'now()'], 'login_num' => ['exp', 'login_num+1']]);
session('user', $user);
!empty($user['authorize']) && NodeModel::applyAuthNode();
!empty($user['authorize']) && NodeService::applyAuthNode();
LogService::write('系统管理', '用户登录系统成功');
$this->success('登录成功,正在进入系统...', '@admin');
}

View File

@ -14,9 +14,9 @@
namespace app\admin\controller;
use app\admin\model\NodeModel;
use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
use think\Db;
@ -93,7 +93,7 @@ class Menu extends BasicAdmin {
}
}
// 读取系统功能节点
$nodes = NodeModel::get(APP_PATH);
$nodes = NodeService::get(APP_PATH);
foreach ($nodes as $key => $_vo) {
if (empty($_vo['is_menu'])) {
unset($nodes[$key]);

View File

@ -14,9 +14,9 @@
namespace app\admin\controller;
use app\admin\model\NodeModel;
use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use service\ToolsService;
/**
@ -45,7 +45,7 @@ class Node extends BasicAdmin {
];
$this->assign('alert', $alert);
$this->assign('title', '系统节点管理');
$this->assign('nodes', ToolsService::arr2table(NodeModel::get(), 'node', 'pnode'));
$this->assign('nodes', ToolsService::arr2table(NodeService::get(), 'node', 'pnode'));
return view();
}

View File

@ -13,8 +13,8 @@
// +----------------------------------------------------------------------
use app\admin\model\NodeModel;
use service\DataService;
use service\NodeService;
use Wechat\Loader;
use think\Db;
@ -82,7 +82,7 @@ function decode($string) {
* @return bool
*/
function auth($node) {
return NodeModel::checkAuthNode($node);
return NodeService::checkAuthNode($node);
}
/**

View File

@ -12,18 +12,18 @@
// | github开源项目https://github.com/zoujingli/Think.Admin
// +----------------------------------------------------------------------
namespace app\admin\model;
namespace service;
use think\Db;
/**
* 系统权限节点读取器
* Class Node
* @package app\admin\model
* Class NodeService
* @package extend
* @author Anyon <zoujingli@qq.com>
* @date 2017/03/14 18:12
* @date 2017/05/08 11:28
*/
class NodeModel {
class NodeService {
/**
* 应用用户权限节点
@ -64,7 +64,7 @@ class NodeModel {
* @param string $node 节点
* @return bool
*/
public static function checkAuthNode($node) {
static public function checkAuthNode($node) {
$auth_node = strtolower($node);
if (session('user.username') === 'admin' || stripos($node, 'admin/index') === 0) {
return true;
@ -79,7 +79,7 @@ class NodeModel {
* 获取系统代码节点
* @return array
*/
static public function get() {
public static function get() {
$alias = [];
foreach (Db::name('SystemNode')->select() as $vo) {
$alias["{$vo['node']}"] = $vo;
@ -112,7 +112,7 @@ class NodeModel {
* @param array $nodes 额外数据
* @return array
*/
static public function getNodeTree($path, $nodes = []) {
public static function getNodeTree($path, $nodes = []) {
foreach (self::_getFilePaths($path) as $vo) {
if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) {
continue;
@ -137,7 +137,7 @@ class NodeModel {
* @param string $ext 文件后缀
* @return array
*/
static private function _getFilePaths($path, $data = [], $ext = 'php') {
private static function _getFilePaths($path, $data = [], $ext = 'php') {
foreach (scandir($path) as $dir) {
if ($dir[0] === '.') {
continue;