[优化]代码整合优化

This commit is contained in:
邹景立 2017-03-22 11:09:04 +08:00
parent 01defc5d6f
commit 290fe74069
16 changed files with 67 additions and 59 deletions

View File

@ -19,7 +19,7 @@ use controller\BasicAdmin;
use library\Data; use library\Data;
use library\Tools; use library\Tools;
use think\Db; use think\Db;
use think\response\View; use think\View;
/** /**
* 后台入口 * 后台入口

View File

@ -40,6 +40,8 @@ class Plugs extends BasicAdmin {
/** /**
* 文件上传 * 文件上传
* @param string $mode
* @return \think\response\View
*/ */
public function upfile($mode = 'one') { public function upfile($mode = 'one') {
$types = $this->request->get('type', 'jpg,png'); $types = $this->request->get('type', 'jpg,png');

View File

@ -44,7 +44,7 @@ class User extends BasicAdmin {
/** /**
* 授权管理 * 授权管理
* @return type * @return array|string
*/ */
public function auth() { public function auth() {
return $this->_form($this->table, 'auth'); return $this->_form($this->table, 'auth');
@ -88,7 +88,7 @@ class User extends BasicAdmin {
/** /**
* 表单数据默认处理 * 表单数据默认处理
* @param type $data * @param array $data
*/ */
public function _form_filter(&$data) { public function _form_filter(&$data) {
if ($this->request->isPost()) { if ($this->request->isPost()) {

View File

@ -27,13 +27,12 @@ class Node {
/** /**
* 应用用户权限节点 * 应用用户权限节点
* @param type $authid
* @return bool * @return bool
*/ */
public static function applyAuthNode() { public static function applyAuthNode() {
cache('need_access_node', null); cache('need_access_node', null);
if (($authorize = session('user.authorize'))) { if (($authorize = session('user.authorize'))) {
$nodes = (array) Db::name('SystemAuthNode')->where('auth', 'in', explode(',', $authorize))->column('node'); $nodes = (array)Db::name('SystemAuthNode')->where('auth', 'in', explode(',', $authorize))->column('node');
return session('user.nodes', $nodes); return session('user.nodes', $nodes);
} }
return false; return false;
@ -58,7 +57,7 @@ class Node {
/** /**
* 检查用户节点权限 * 检查用户节点权限
* @param string $node * @param string $node 节点
* @return bool * @return bool
*/ */
public static function checkAuthNode($node) { public static function checkAuthNode($node) {
@ -69,7 +68,7 @@ class Node {
if (!in_array($auth_node, self::getAuthNode())) { if (!in_array($auth_node, self::getAuthNode())) {
return true; return true;
} }
return in_array($auth_node, (array) session('user.nodes')); return in_array($auth_node, (array)session('user.nodes'));
} }
/** /**
@ -77,15 +76,16 @@ class Node {
* @return array * @return array
*/ */
static public function get() { static public function get() {
$data = Db::name('SystemNode')->select();
$nodes = [];
$alias = []; $alias = [];
foreach ($data as $vo) { foreach (Db::name('SystemNode')->select() as $vo) {
$alias["{$vo['node']}"] = $vo; $alias["{$vo['node']}"] = $vo;
} }
$nodes = [];
foreach (self::getNodeTree(APP_PATH) as $thr) { foreach (self::getNodeTree(APP_PATH) as $thr) {
if (stripos($thr, 'admin/plugs') === 0 || stripos($thr, 'admin/login') === 0 || stripos($thr, 'admin/index') === 0 || stripos($thr, 'index') === 0 || stripos($thr, 'store/api') === 0) { foreach (['admin/plugs', 'admin/login', 'admin/index', 'store/api', 'index'] as $str) {
continue; if (stripos($thr, $str) === 0) {
continue 2;
}
} }
$tmp = explode('/', $thr); $tmp = explode('/', $thr);
$one = $tmp[0]; $one = $tmp[0];
@ -99,26 +99,22 @@ class Node {
/** /**
* 获取节点列表 * 获取节点列表
* @param string $path * @param string $path 路径
* @param array $nodes * @param array $nodes 额外数据
* @return array * @return array
*/ */
static public function getNodeTree($path, $nodes = []) { static public function getNodeTree($path, $nodes = []) {
foreach (self::getFilePaths($path) as $vo) { foreach (self::_getFilePaths($path) as $vo) {
if (stripos($vo, DS . 'controller' . DS) === false) { if (!preg_match('|/(\w+)/controller/(\w+)|', str_replace(DS, '/', $vo), $matches) || count($matches) !== 3) {
continue; continue;
} }
$_tmp = explode(DS, $vo); $className = config('app_namespace') . str_replace('/', '\\', $matches[0]);
$controllerName = preg_replace('|\.php$|', '', array_pop($_tmp));
array_pop($_tmp);
$moduleName = array_pop($_tmp);
$className = config('app_namespace') . "\\{$moduleName}\\controller\\{$controllerName}";
if (!class_exists($className)) { if (!class_exists($className)) {
continue; continue;
} }
foreach (get_class_methods($className) as $actionName) { foreach (get_class_methods($className) as $actionName) {
if ($actionName[0] !== '_') { if ($actionName[0] !== '_') {
$nodes[] = strtolower("{$moduleName}/{$controllerName}/{$actionName}"); $nodes[] = strtolower("{$matches[1]}/{$matches[2]}/{$actionName}");
} }
} }
} }
@ -127,19 +123,18 @@ class Node {
/** /**
* 获取所有PHP文件 * 获取所有PHP文件
* @param string $path * @param string $path 目录
* @param array $data * @param array $data 额外数据
* @param string $ext * @param string $ext 文件后缀
* @return array * @return array
*/ */
static private function getFilePaths($path, $data = [], $ext = 'php') { static private function _getFilePaths($path, $data = [], $ext = 'php') {
foreach (scandir($path) as $dir) { foreach (scandir($path) as $dir) {
if ($dir[0] === '.') { if ($dir[0] === '.') {
continue; continue;
} }
$tmp = realpath($path . DS . $dir); if (($tmp = realpath($path . DS . $dir)) && (is_dir($tmp) || pathinfo($tmp, PATHINFO_EXTENSION) === $ext)) {
if ($tmp && (is_dir($tmp) || pathinfo($tmp, PATHINFO_EXTENSION) === $ext)) { is_dir($tmp) ? $data = array_merge($data, self::_getFilePaths($tmp)) : $data[] = $tmp;
is_dir($tmp) ? $data = array_merge($data, self::getFilePaths($tmp)) : $data[] = $tmp;
} }
} }
return $data; return $data;

View File

@ -14,7 +14,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">联系手机</label> <label class="layui-form-label">联系手机</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="tel" name="phone" value='{$vo.phone|default=""}' pattern="^1[3-9][0-9]{9}$" title="请输入联系手机" placeholder="请输入联系手机" class="layui-input"> <input type="tel" autofocus name="phone" value='{$vo.phone|default=""}' pattern="^1[3-9][0-9]{9}$" title="请输入联系手机" placeholder="请输入联系手机" class="layui-input">
</div> </div>
</div> </div>

View File

@ -15,7 +15,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">旧的密码</label> <label class="layui-form-label">旧的密码</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="password" name="oldpassword" value='' pattern="^\S{1,}$" required="" title="请输入旧的密码" placeholder="请输入旧的密码" class="layui-input"> <input type="password" autofocus name="oldpassword" value='' pattern="^\S{1,}$" required="" title="请输入旧的密码" placeholder="请输入旧的密码" class="layui-input">
</div> </div>
</div> </div>
{/if} {/if}

View File

@ -85,8 +85,7 @@ function auth($node) {
function sysconf($name) { function sysconf($name) {
static $config = []; static $config = [];
if (empty($config)) { if (empty($config)) {
$list = Db::name('SystemConfig')->select(); foreach (Db::name('SystemConfig')->select() as $vo) {
foreach ($list as $vo) {
$config[$vo['name']] = $vo['value']; $config[$vo['name']] = $vo['value'];
} }
} }

View File

@ -25,6 +25,15 @@
style='width:50px;'> style='width:50px;'>
<span class='glyphicon glyphicon-refresh'></span> <span class='glyphicon glyphicon-refresh'></span>
</a> </a>
<script>
require(['jquery'],function(){
$('[data-reload]').hover(function(){
$(this).find('.glyphicon').addClass('fa-spin');
},function(){
$(this).find('.glyphicon').removeClass('fa-spin');
});
});
</script>
<div class="topbar-left topbar-user"> <div class="topbar-left topbar-user">
<div class="dropdown topbar-info-item"> <div class="dropdown topbar-info-item">
<a href="#" class="dropdown-toggle topbar-btn text-center" data-toggle="dropdown"> <a href="#" class="dropdown-toggle topbar-btn text-center" data-toggle="dropdown">

View File

@ -57,15 +57,12 @@ class BasicAdmin extends Controller {
*/ */
public function _initialize() { public function _initialize() {
# 用户登录状态检查 # 用户登录状态检查
if ($this->checkLogin || $this->checkAuth) { if (($this->checkLogin || $this->checkAuth) && !$this->_isLogin()) {
if (!$this->_isLogin()) {
$this->redirect('@admin/login'); $this->redirect('@admin/login');
} }
}
# 节点访问权限检查 # 节点访问权限检查
if ($this->checkLogin && $this->checkAuth) { if ($this->checkLogin && $this->checkAuth) {
$node = strtolower($this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action()); if (!auth(join('/', [$this->request->module(), $this->request->controller(), $this->request->action()]))) {
if (!auth($node)) {
$this->error('抱歉,您没有访问该模块的权限!'); $this->error('抱歉,您没有访问该模块的权限!');
} }
} }
@ -123,7 +120,7 @@ class BasicAdmin extends Controller {
} }
if ($is_page) { if ($is_page) {
$row_page = $this->request->get('rows', cookie('rows'), 'intval'); $row_page = $this->request->get('rows', cookie('rows'), 'intval');
cookie('rows', $row_page >= 10 ? $row_page : 10); cookie('rows', $row_page >= 10 ? $row_page : 20);
$page = $db->paginate($row_page, $total, ['query' => $this->request->get()]); $page = $db->paginate($row_page, $total, ['query' => $this->request->get()]);
$result['list'] = $page->all(); $result['list'] = $page->all();
$result['page'] = preg_replace(['|href="(.*?)"|', '|pagination|'], ['data-open="$1" href="javascript:void(0);"', 'pagination pull-right'], $page->render()); $result['page'] = preg_replace(['|href="(.*?)"|', '|pagination|'], ['data-open="$1" href="javascript:void(0);"', 'pagination pull-right'], $page->render());
@ -185,7 +182,7 @@ class BasicAdmin extends Controller {
* @return bool * @return bool
*/ */
protected function _callback($method, &$data) { protected function _callback($method, &$data) {
foreach (array($method, "_" . $this->request->action() . "{$method}") as $method) { foreach ([$method, "_" . $this->request->action() . "{$method}"] as $method) {
if (method_exists($this, $method) && false === $this->$method($data)) { if (method_exists($this, $method) && false === $this->$method($data)) {
return false; return false;
} }

View File

@ -39,7 +39,7 @@ class BasicApi {
exit($this->response('禁止访问接口安全方法!', 'ACCESS_NOT_ALLOWED')->send()); exit($this->response('禁止访问接口安全方法!', 'ACCESS_NOT_ALLOWED')->send());
} }
// 访问 Token 检测处理 // 访问 Token 检测处理
$this->token = $this->request->request('token', $this->request->header('token', false)); $this->token = $this->request->param('token', $this->request->header('token', false));
// if ((empty($this->token) || !$this->getCache($this->token)) && ($this->request->action() !== 'auth')) { // if ((empty($this->token) || !$this->getCache($this->token)) && ($this->request->action() !== 'auth')) {
if (empty($this->token) && $this->request->action() !== 'auth') { if (empty($this->token) && $this->request->action() !== 'auth') {
exit($this->response('访问TOKEN失效请重新授权', 'ACCESS_TOKEN_FAILD')->send()); exit($this->response('访问TOKEN失效请重新授权', 'ACCESS_TOKEN_FAILD')->send());
@ -48,10 +48,10 @@ class BasicApi {
/** /**
* 输出返回数据 * 输出返回数据
* @access protected * @param string $msg 提示消息内容
* @param string $code 业务状态码
* @param mixed $data 要返回的数据 * @param mixed $data 要返回的数据
* @param String $type 返回类型 JSON XML * @param string $type 返回类型 JSON XML
* @param integer $code HTTP状态码
* @return Response * @return Response
*/ */
public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') { public function response($msg, $code = 'SUCCESS', $data = [], $type = 'json') {

View File

@ -123,6 +123,7 @@ class FileService {
$auth = new Auth(sysconf('storage_qiniu_access_key'), sysconf('storage_qiniu_secret_key')); $auth = new Auth(sysconf('storage_qiniu_access_key'), sysconf('storage_qiniu_secret_key'));
return file_get_contents($auth->privateDownloadUrl(self::getBaseUriQiniu() . $filename)); return file_get_contents($auth->privateDownloadUrl(self::getBaseUriQiniu() . $filename));
} }
Log::error("通过{$storage}读取文件{$filename}的不存在!");
return null; return null;
} }

View File

@ -15,6 +15,7 @@
namespace service; namespace service;
use library\Data; use library\Data;
use library\QRcode;
use think\Db; use think\Db;
use think\Log; use think\Log;
use Wechat\WechatPay; use Wechat\WechatPay;
@ -50,6 +51,10 @@ class PayService {
if ($prepayid === false) { if ($prepayid === false) {
return false; return false;
} }
$filename = join('/', str_split(md5($prepayid), 16)) . '.png';
if (!FileService::hasFile($filename)) {
FileService::save($filename, QRcode::png($prepayid, $filename, Constants::QR_ECLEVEL_L, 8));
}
$filename = ROOT_PATH . "public/upload/{$pay->appid}/payqrc/" . join('/', str_split(md5($prepayid), 16)) . '.png'; $filename = ROOT_PATH . "public/upload/{$pay->appid}/payqrc/" . join('/', str_split(md5($prepayid), 16)) . '.png';
!is_dir(dirname($filename)) && mkdir(dirname($filename), 0755, true); !is_dir(dirname($filename)) && mkdir(dirname($filename), 0755, true);
!file_exists($filename) && QRcode::png($prepayid, $filename, Constants::QR_ECLEVEL_L, 8); !file_exists($filename) && QRcode::png($prepayid, $filename, Constants::QR_ECLEVEL_L, 8);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d::getLoader(); return ComposerAutoloaderInit92a5fe0bb87f97baabea0fdabbc00865::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d class ComposerAutoloaderInit92a5fe0bb87f97baabea0fdabbc00865
{ {
private static $loader; private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit92a5fe0bb87f97baabea0fdabbc00865', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit92a5fe0bb87f97baabea0fdabbc00865', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) { if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php'; require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit1d73f902df261cf5d17436029a67d17d::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865::getInitializer($loader));
} else { } else {
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInit1d73f902df261cf5d17436029a67d17d
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit1d73f902df261cf5d17436029a67d17d::$files; $includeFiles = Composer\Autoload\ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865::$files;
} else { } else {
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
} }
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire1d73f902df261cf5d17436029a67d17d($fileIdentifier, $file); composerRequire92a5fe0bb87f97baabea0fdabbc00865($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequire1d73f902df261cf5d17436029a67d17d($fileIdentifier, $file) function composerRequire92a5fe0bb87f97baabea0fdabbc00865($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file; require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit1d73f902df261cf5d17436029a67d17d class ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865
{ {
public static $files = array ( public static $files = array (
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php', '9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
@ -273,9 +273,9 @@ class ComposerStaticInit1d73f902df261cf5d17436029a67d17d
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit1d73f902df261cf5d17436029a67d17d::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1d73f902df261cf5d17436029a67d17d::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1d73f902df261cf5d17436029a67d17d::$classMap; $loader->classMap = ComposerStaticInit92a5fe0bb87f97baabea0fdabbc00865::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }