[更新]代码远程更新

This commit is contained in:
Anyon 2019-04-03 14:16:22 +08:00
parent 18f50d55d0
commit c8b39d66bd
62 changed files with 1806 additions and 1717 deletions

View File

@ -33,6 +33,32 @@ PHP 开发技术交流( QQ 群 513350915
* Gitee仓库地址https://gitee.com/zoujingli/Think.Admin * Gitee仓库地址https://gitee.com/zoujingli/Think.Admin
* GitHub仓库地址https://github.com/zoujingli/ThinkAdmin * GitHub仓库地址https://github.com/zoujingli/ThinkAdmin
框架指令
--
* 执行 `build.cmd` 可更新 `Composer` 插件,会删除并替换 `vendor` 目录
* 执行 `php think run` 启用本地开发环境,访问 `http://127.0.0.1:8000`
* 线上代码更新
>* 执行 `php think xsync:admin` 从线上服务更新 `admin` 模块的所有文件(注意文件安全)
>* 执行 `php think xsync:wechat` 从线上服务更新 `wehcat` 模块的所有文件(注意文件安全)
>* 执行 `php think xysnc:service` 从线上服务更新 `service` 模块的所有文件(注意文件安全)
>* 执行 `php think xysnc:plugs` 从线上服务更新 `plugs` 静态插件的部分文件(注意文件安全)
>* 执行 `php think xysnc:config` 从线上服务更新 `config` 项目配置的部分文件(注意文件安全)
* 微信资料管理
>* 执行 `php think xfans:all` 更新已经对接的公众号粉丝全部列表
>* 执行 `php think xfans:black` 更新已经对接的公众号黑名单列表
>* 执行 `php think xfans:list` 更新已经对接的公众号粉丝列表
>* 执行 `php think xfans:tags` 更新已经对接的公众号煯标签列表
>* 执行 `php think xclean:session` 清理无效的会话文件
>* 执行 `php think xclean:store` 清理无效的订单信息及定时任务
* 守护进程管理
>* 执行 `php think xtask:reset` 重启消息任务守护进程
>* 执行 `php think xtask:start` 启动消息任务守护进程
>* 执行 `php think xtask:state` 查询消息任务守护进程
>* 执行 `php think xtask:stop` 暂停消息任务守护进程
特别感谢 特别感谢
-- --
|名称|版本|描述|链接| |名称|版本|描述|链接|

View File

@ -1,153 +1,154 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
/** /**
* 权限管理 * 权限管理
* Class Auth * Class Auth
* @package app\admin\controller * @package app\admin\controller
*/ */
class Auth extends Controller class Auth extends Controller
{ {
/** /**
* 默认数据模型 * 默认数据模型
* @var string * @var string
*/ */
public $table = 'SystemAuth'; public $table = 'SystemAuth';
/** /**
* 权限列表 * 权限列表
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
$this->title = '系统权限管理'; $this->title = '系统权限管理';
$this->_query($this->table)->dateBetween('create_at')->like('title,desc')->equal('status')->order('sort asc,id desc')->page(); $this->_query($this->table)->dateBetween('create_at')->like('title,desc')->equal('status')->order('sort asc,id desc')->page();
} }
/** /**
* 权限授权节点 * 权限授权节点
* @return mixed * @return mixed
* @throws \think\Exception * @throws \ReflectionException
* @throws \think\exception\PDOException * @throws \think\Exception
*/ * @throws \think\exception\PDOException
public function apply() */
{ public function apply()
$this->title = '权限授权配置'; {
$auth = $this->request->post('id', '0'); $this->title = '权限授权配置';
switch (strtolower($this->request->post('action'))) { $auth = $this->request->post('id', '0');
case 'get': // 获取权限配置 switch (strtolower($this->request->post('action'))) {
$nodes = \app\admin\service\Auth::get(); case 'get': // 获取权限配置
$checked = Db::name('SystemAuthNode')->where(['auth' => $auth])->column('node'); $nodes = \app\admin\service\Auth::get();
foreach ($nodes as &$node) $node['checked'] = in_array($node['node'], $checked); $checked = Db::name('SystemAuthNode')->where(['auth' => $auth])->column('node');
$data = $this->_apply_filter(\library\tools\Data::arr2tree($nodes, 'node', 'pnode', '_sub_')); foreach ($nodes as &$node) $node['checked'] = in_array($node['node'], $checked);
return $this->success('获取权限配置成功!', $data); $data = $this->_apply_filter(\library\tools\Data::arr2tree($nodes, 'node', 'pnode', '_sub_'));
case 'save': // 保存权限配置 return $this->success('获取权限配置成功!', $data);
list($post, $data) = [$this->request->post(), []]; case 'save': // 保存权限配置
foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) $data[] = ['auth' => $auth, 'node' => $node]; list($post, $data) = [$this->request->post(), []];
Db::name('SystemAuthNode')->where(['auth' => $auth])->delete(); foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) $data[] = ['auth' => $auth, 'node' => $node];
Db::name('SystemAuthNode')->insertAll($data); Db::name('SystemAuthNode')->where(['auth' => $auth])->delete();
return $this->success('权限授权配置更新成功!'); Db::name('SystemAuthNode')->insertAll($data);
default: return $this->success('权限授权配置更新成功!');
return $this->_form($this->table, 'apply'); default:
} return $this->_form($this->table, 'apply');
} }
}
/**
* 节点数据拼装 /**
* @param array $nodes * 节点数据拼装
* @param integer $level * @param array $nodes
* @return array * @param integer $level
*/ * @return array
private function _apply_filter($nodes, $level = 1) */
{ private function _apply_filter($nodes, $level = 1)
foreach ($nodes as $key => $node) if (!empty($node['_sub_']) && is_array($node['_sub_'])) { {
$node[$key]['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1); foreach ($nodes as $key => $node) if (!empty($node['_sub_']) && is_array($node['_sub_'])) {
} $node[$key]['_sub_'] = $this->_apply_filter($node['_sub_'], $level + 1);
return $nodes; }
} return $nodes;
}
/**
* 权限添加 /**
* @return array|string * 权限添加
*/ * @return array|string
public function add() */
{ public function add()
$this->applyCsrfToken(); {
$this->_form($this->table, 'form'); $this->applyCsrfToken();
} $this->_form($this->table, 'form');
}
/**
* 权限编辑 /**
* @return array|string * 权限编辑
*/ * @return array|string
public function edit() */
{ public function edit()
$this->applyCsrfToken(); {
$this->_form($this->table, 'form'); $this->applyCsrfToken();
} $this->_form($this->table, 'form');
}
/**
* 权限禁用 /**
*/ * 权限禁用
public function forbid() */
{ public function forbid()
$this->applyCsrfToken(); {
$this->_save($this->table, ['status' => '0']); $this->applyCsrfToken();
} $this->_save($this->table, ['status' => '0']);
}
/**
* 权限恢复 /**
*/ * 权限恢复
public function resume() */
{ public function resume()
$this->applyCsrfToken(); {
$this->_save($this->table, ['status' => '1']); $this->applyCsrfToken();
} $this->_save($this->table, ['status' => '1']);
}
/**
* 权限删除 /**
*/ * 权限删除
public function del() */
{ public function del()
$this->applyCsrfToken(); {
$this->_delete($this->table); $this->applyCsrfToken();
} $this->_delete($this->table);
}
/**
* 删除结果处理 /**
* @param boolean $result * 删除结果处理
* @throws \think\Exception * @param boolean $result
* @throws \think\exception\PDOException * @throws \think\Exception
*/ * @throws \think\exception\PDOException
protected function _del_delete_result($result) */
{ protected function _del_delete_result($result)
if ($result) { {
$where = ['auth' => $this->request->post('id')]; if ($result) {
Db::name('SystemAuthNode')->where($where)->delete(); $where = ['auth' => $this->request->post('id')];
$this->success("权限删除成功!", ''); Db::name('SystemAuthNode')->where($where)->delete();
} else { $this->success("权限删除成功!", '');
$this->error("权限删除失败,请稍候再试!"); } else {
} $this->error("权限删除失败,请稍候再试!");
} }
}
} }

View File

@ -1,109 +1,109 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
/** /**
* 系统配置 * 系统配置
* Class Config * Class Config
* @package app\admin\controller * @package app\admin\controller
*/ */
class Config extends Controller class Config extends Controller
{ {
/** /**
* 默认数据模型 * 默认数据模型
* @var string * @var string
*/ */
protected $table = 'SystemConfig'; protected $table = 'SystemConfig';
/** /**
* 系统参数配置 * 系统参数配置
* @return mixed * @return mixed
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function info() public function info()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '系统参数配置'; $this->title = '系统参数配置';
if ($this->request->isGet()) return $this->fetch(); if ($this->request->isGet()) return $this->fetch();
foreach ($this->request->post() as $k => $v) sysconf($k, $v); foreach ($this->request->post() as $k => $v) sysconf($k, $v);
$this->success('系统参数配置保存成功!'); $this->success('系统参数配置保存成功!');
} }
/** /**
* 文件存储配置 * 文件存储配置
* @return string * @return string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function file() public function file()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->fetch('file', [ $this->fetch('file', [
'title' => '文件存储配置', 'title' => '文件存储配置',
'point' => [ 'point' => [
'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州', 'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州',
'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海', 'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海',
'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛', 'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛',
'oss-cn-beijing.aliyuncs.com' => '华北 2 北京', 'oss-cn-beijing.aliyuncs.com' => '华北 2 北京',
'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口', 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口',
'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特', 'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特',
'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳', 'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳',
'oss-cn-hongkong.aliyuncs.com' => '香港 1', 'oss-cn-hongkong.aliyuncs.com' => '香港 1',
'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷', 'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷',
'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚', 'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚',
'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡', 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡',
'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼', 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼',
'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡', 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡',
'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达', 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达',
'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本', 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本',
'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买', 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买',
'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福', 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福',
'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦', 'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦',
'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜', 'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜',
], ],
]); ]);
} else { } else {
$post = $this->request->post(); $post = $this->request->post();
if (isset($post['storage_type']) && $post['storage_type'] === 'local') { if (isset($post['storage_type']) && $post['storage_type'] === 'local') {
$exts = array_unique(explode(',', $post['storage_local_exts'])); $exts = array_unique(explode(',', $post['storage_local_exts']));
if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!'); if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!');
$post['storage_local_exts'] = join(',', $exts); $post['storage_local_exts'] = join(',', $exts);
} }
foreach ($post as $key => $value) sysconf($key, $value); foreach ($post as $key => $value) sysconf($key, $value);
if (isset($post['storage_type']) && $post['storage_type'] === 'oss') { if (isset($post['storage_type']) && $post['storage_type'] === 'oss') {
try { try {
$local = sysconf('storage_oss_domain'); $local = sysconf('storage_oss_domain');
$bucket = $this->request->post('storage_oss_bucket'); $bucket = $this->request->post('storage_oss_bucket');
$domain = \library\File::instance('oss')->setBucket($bucket); $domain = \library\File::instance('oss')->setBucket($bucket);
if (empty($local) || stripos($local, '.aliyuncs.com') !== false) { if (empty($local) || stripos($local, '.aliyuncs.com') !== false) {
sysconf('storage_oss_domain', $domain); sysconf('storage_oss_domain', $domain);
} }
$this->success('阿里云OSS存储动态配置成功'); $this->success('阿里云OSS存储动态配置成功');
} catch (\think\exception\HttpResponseException $exception) { } catch (\think\exception\HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("阿里云OSS存储配置失效{$e->getMessage()}"); $this->error("阿里云OSS存储配置失效{$e->getMessage()}");
} }
} else { } else {
$this->success('文件存储配置保存成功!'); $this->success('文件存储配置保存成功!');
} }
} }
} }
} }

View File

@ -1,167 +1,168 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
use library\tools\Data; use library\tools\Data;
use think\Console; use think\Console;
use think\Db; use think\Db;
/** /**
* 后台入口管理 * 后台入口管理
* Class Index * Class Index
* @package app\admin\controller * @package app\admin\controller
*/ */
class Index extends Controller class Index extends Controller
{ {
/** /**
* 显示后台首页 * 显示后台首页
* @throws \think\db\exception\DataNotFoundException * @throws \ReflectionException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\exception\DbException * @throws \think\db\exception\ModelNotFoundException
*/ * @throws \think\exception\DbException
public function index() */
{ public function index()
$this->title = '系统管理后台'; {
$this->menus = \app\admin\service\Auth::getAuthMenu(); $this->title = '系统管理后台';
if (empty($this->menus) && !session('user.id')) { $this->menus = \app\admin\service\Auth::getAuthMenu();
$this->redirect('@admin/login'); if (empty($this->menus) && !session('user.id')) {
} else { $this->redirect('@admin/login');
$this->fetch(); } else {
} $this->fetch();
} }
}
/**
* 后台环境信息 /**
* @return mixed * 后台环境信息
*/ * @return mixed
public function main() */
{ public function main()
$this->title = '后台首页'; {
$this->think_ver = \think\App::VERSION; $this->title = '后台首页';
$this->mysql_ver = Db::query('select version() as ver')[0]['ver']; $this->think_ver = \think\App::VERSION;
$this->fetch(); $this->mysql_ver = Db::query('select version() as ver')[0]['ver'];
} $this->fetch();
}
/**
* 清理系统运行缓存 /**
*/ * 清理系统运行缓存
public function clearRuntime() */
{ public function clearRuntime()
if (!\app\admin\service\Auth::isLogin()) { {
$this->error('需要登录才能操作哦!'); if (!\app\admin\service\Auth::isLogin()) {
} $this->error('需要登录才能操作哦!');
$this->list = [ }
[ $this->list = [
'title' => 'Clean up running cached files', [
'message' => nl2br(Console::call('clear')->fetch()), 'title' => 'Clean up running cached files',
], [ 'message' => nl2br(Console::call('clear')->fetch()),
'title' => 'Clean up invalid session files', ], [
'message' => nl2br(Console::call('xclean:session')->fetch()), 'title' => 'Clean up invalid session files',
], 'message' => nl2br(Console::call('xclean:session')->fetch()),
]; ],
$this->fetch('admin@index/command'); ];
} $this->fetch('admin@index/command');
}
/**
* 压缩发布系统 /**
*/ * 压缩发布系统
public function buildOptimize() */
{ public function buildOptimize()
if (!\app\admin\service\Auth::isLogin()) { {
$this->error('需要登录才能操作哦!'); if (!\app\admin\service\Auth::isLogin()) {
} $this->error('需要登录才能操作哦!');
$this->list = [ }
[ $this->list = [
'title' => 'Build route cache', [
'message' => nl2br(Console::call('optimize:route')->fetch()), 'title' => 'Build route cache',
], [ 'message' => nl2br(Console::call('optimize:route')->fetch()),
'title' => 'Build database schema cache', ], [
'message' => nl2br(Console::call('optimize:schema')->fetch()), 'title' => 'Build database schema cache',
], [ 'message' => nl2br(Console::call('optimize:schema')->fetch()),
'title' => 'Optimizes PSR0 and PSR4 packages', ], [
'message' => nl2br(Console::call('optimize:autoload')->fetch()), 'title' => 'Optimizes PSR0 and PSR4 packages',
], [ 'message' => nl2br(Console::call('optimize:autoload')->fetch()),
'title' => 'Build config and common file cache', ], [
'message' => nl2br(Console::call('optimize:config')->fetch()), 'title' => 'Build config and common file cache',
], 'message' => nl2br(Console::call('optimize:config')->fetch()),
]; ],
$this->fetch('admin@index/command'); ];
} $this->fetch('admin@index/command');
}
/**
* 修改密码 /**
* @param integer $id * 修改密码
* @throws \think\Exception * @param integer $id
* @throws \think\db\exception\DataNotFoundException * @throws \think\Exception
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\exception\DbException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\PDOException * @throws \think\exception\DbException
*/ * @throws \think\exception\PDOException
public function pass($id) */
{ public function pass($id)
$this->applyCsrfToken(); {
if (intval($id) !== intval(session('user.id'))) { $this->applyCsrfToken();
$this->error('只能修改当前用户的密码!'); if (intval($id) !== intval(session('user.id'))) {
} $this->error('只能修改当前用户的密码!');
if ($this->request->isGet()) { }
$this->verify = true; if ($this->request->isGet()) {
$this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]); $this->verify = true;
} else { $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]);
$data = $this->_input([ } else {
'password' => $this->request->post('password'), $data = $this->_input([
'repassword' => $this->request->post('repassword'), 'password' => $this->request->post('password'),
'oldpassword' => $this->request->post('oldpassword'), 'repassword' => $this->request->post('repassword'),
], [ 'oldpassword' => $this->request->post('oldpassword'),
'oldpassword' => 'require', ], [
'password' => 'require|min:4', 'oldpassword' => 'require',
'repassword' => 'require|confirm:password', 'password' => 'require|min:4',
], [ 'repassword' => 'require|confirm:password',
'oldpassword.require' => '旧密码不能为空!', ], [
'password.require' => '登录密码不能为空!', 'oldpassword.require' => '旧密码不能为空!',
'password.min' => '登录密码长度不能少于4位有效字符', 'password.require' => '登录密码不能为空!',
'repassword.require' => '重复密码不能为空!', 'password.min' => '登录密码长度不能少于4位有效字符',
'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!', 'repassword.require' => '重复密码不能为空!',
]); 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!',
$user = Db::name('SystemUser')->where(['id' => $id])->find(); ]);
if (md5($data['oldpassword']) !== $user['password']) { $user = Db::name('SystemUser')->where(['id' => $id])->find();
$this->error('旧密码验证失败,请重新输入!'); if (md5($data['oldpassword']) !== $user['password']) {
} $this->error('旧密码验证失败,请重新输入!');
$result = \app\admin\service\Auth::checkPassword($data['password']); }
if (empty($result['code'])) $this->error($result['msg']); $result = \app\admin\service\Auth::checkPassword($data['password']);
if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) { if (empty($result['code'])) $this->error($result['msg']);
$this->success('密码修改成功,下次请使用新密码登录!', ''); if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) {
} else { $this->success('密码修改成功,下次请使用新密码登录!', '');
$this->error('密码修改失败,请稍候再试!'); } else {
} $this->error('密码修改失败,请稍候再试!');
} }
} }
}
/**
* 修改用户资料 /**
* @param integer $id 会员ID * 修改用户资料
*/ * @param integer $id 会员ID
public function info($id = 0) */
{ public function info($id = 0)
$this->applyCsrfToken(); {
if (intval($id) === intval(session('user.id'))) { $this->applyCsrfToken();
$this->_form('SystemUser', 'user/form', 'id', [], ['id' => $id]); if (intval($id) === intval(session('user.id'))) {
} else { $this->_form('SystemUser', 'user/form', 'id', [], ['id' => $id]);
$this->error('只能修改登录用户的资料!'); } else {
} $this->error('只能修改登录用户的资料!');
} }
}
} }

View File

@ -1,70 +1,70 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
/** /**
* 系统日志管理 * 系统日志管理
* Class Log * Class Log
* @package app\admin\controller * @package app\admin\controller
*/ */
class Log extends Controller class Log extends Controller
{ {
/** /**
* 指定当前数据表 * 指定当前数据表
* @var string * @var string
*/ */
public $table = 'SystemLog'; public $table = 'SystemLog';
/** /**
* 日志列表 * 日志列表
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function index() public function index()
{ {
$this->title = '系统操作日志'; $this->title = '系统操作日志';
$this->_query($this->table)->like('action,node,content,username,geoip')->dateBetween('create_at')->order('id desc')->page(); $this->_query($this->table)->like('action,node,content,username,geoip')->dateBetween('create_at')->order('id desc')->page();
} }
/** /**
* 列表数据处理 * 列表数据处理
* @param array $data * @param array $data
* @throws \Exception * @throws \Exception
*/ */
protected function _index_page_filter(&$data) protected function _index_page_filter(&$data)
{ {
$ip = new \Ip2Region(); $ip = new \Ip2Region();
foreach ($data as &$vo) { foreach ($data as &$vo) {
$result = $ip->btreeSearch($vo['geoip']); $result = $ip->btreeSearch($vo['geoip']);
$vo['isp'] = isset($result['region']) ? $result['region'] : ''; $vo['isp'] = isset($result['region']) ? $result['region'] : '';
$vo['isp'] = str_replace(['内网IP', '0', '|'], '', $vo['isp']); $vo['isp'] = str_replace(['内网IP', '0', '|'], '', $vo['isp']);
} }
} }
/** /**
* 日志删除操作 * 日志删除操作
*/ */
public function del() public function del()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_delete($this->table); $this->_delete($this->table);
} }
} }

View File

@ -1,113 +1,113 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
/** /**
* 用户登录管理 * 用户登录管理
* Class Login * Class Login
* @package app\admin\controller * @package app\admin\controller
*/ */
class Login extends Controller class Login extends Controller
{ {
/** /**
* 设置页面标题 * 设置页面标题
* @var string * @var string
*/ */
public $title = '管理登录'; public $title = '管理登录';
/** /**
* 用户登录 * 用户登录
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
if ($this->request->isGet()) { if ($this->request->isGet()) {
session('loginskey', $this->skey = session('loginskey') ? session('loginskey') : uniqid()); session('loginskey', $this->skey = session('loginskey') ? session('loginskey') : uniqid());
$this->fetch(); $this->fetch();
} else { } else {
$data = $this->_input([ $data = $this->_input([
'username' => $this->request->post('username'), 'username' => $this->request->post('username'),
'password' => $this->request->post('password'), 'password' => $this->request->post('password'),
], [ ], [
'username' => 'require|min:4', 'username' => 'require|min:4',
'password' => 'require|min:4', 'password' => 'require|min:4',
], [ ], [
'username.require' => '登录账号不能为空!', 'username.require' => '登录账号不能为空!',
'password.require' => '登录密码不能为空!', 'password.require' => '登录密码不能为空!',
'username.min' => '登录账号长度不能少于4位有效字符', 'username.min' => '登录账号长度不能少于4位有效字符',
'password.min' => '登录密码长度不能少于4位有效字符', 'password.min' => '登录密码长度不能少于4位有效字符',
]); ]);
// 用户信息验证 // 用户信息验证
$map = ['is_deleted' => '0', 'username' => $data['username']]; $map = ['is_deleted' => '0', 'username' => $data['username']];
$user = Db::name('SystemUser')->where($map)->find(); $user = Db::name('SystemUser')->where($map)->find();
if (empty($user)) $this->error('登录账号或密码错误,请重新输入!'); if (empty($user)) $this->error('登录账号或密码错误,请重新输入!');
if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!'); if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!');
// 账号锁定消息 // 账号锁定消息
$cache = cache('user_login_' . $user['username']); $cache = cache('user_login_' . $user['username']);
if (is_array($cache) && !empty($cache['number']) && !empty($cache['time'])) { if (is_array($cache) && !empty($cache['number']) && !empty($cache['time'])) {
if ($cache['number'] >= 10 && ($diff = $cache['time'] + 3600 - time()) > 0) { if ($cache['number'] >= 10 && ($diff = $cache['time'] + 3600 - time()) > 0) {
list($m, $s, $info) = [floor($diff / 60), floor($diff % 60), '']; list($m, $s, $info) = [floor($diff / 60), floor($diff % 60), ''];
if ($m > 0) $info = "{$m}"; if ($m > 0) $info = "{$m}";
$this->error("<strong class='color-red'>抱歉,该账号已经被锁定!</strong><p class='nowrap'>连续 10 次登录错误,请 {$info} {$s} 秒后再登录!</p>"); $this->error("<strong class='color-red'>抱歉,该账号已经被锁定!</strong><p class='nowrap'>连续 10 次登录错误,请 {$info} {$s} 秒后再登录!</p>");
} }
} }
if (md5($user['password'] . session('loginskey')) !== $data['password']) { if (md5($user['password'] . session('loginskey')) !== $data['password']) {
if (empty($cache) || empty($cache['time']) || empty($cache['number']) || $cache['time'] + 3600 < time()) { if (empty($cache) || empty($cache['time']) || empty($cache['number']) || $cache['time'] + 3600 < time()) {
$cache = ['time' => time(), 'number' => 1, 'geoip' => $this->request->ip()]; $cache = ['time' => time(), 'number' => 1, 'geoip' => $this->request->ip()];
} elseif ($cache['number'] + 1 <= 10) { } elseif ($cache['number'] + 1 <= 10) {
$cache = ['time' => time(), 'number' => $cache['number'] + 1, 'geoip' => $this->request->ip()]; $cache = ['time' => time(), 'number' => $cache['number'] + 1, 'geoip' => $this->request->ip()];
} }
cache('user_login_' . $user['username'], $cache); cache('user_login_' . $user['username'], $cache);
if (($diff = 10 - $cache['number']) > 0) { if (($diff = 10 - $cache['number']) > 0) {
$this->error("<strong class='color-red'>登录账号或密码错误!</strong><p class='nowrap'>还有 {$diff} 次尝试机会,将锁定一小时内禁止登录!</p>"); $this->error("<strong class='color-red'>登录账号或密码错误!</strong><p class='nowrap'>还有 {$diff} 次尝试机会,将锁定一小时内禁止登录!</p>");
} else { } else {
_syslog('系统管理', "账号{$user['username']}连续10次登录密码错误请注意账号安全"); _syslog('系统管理', "账号{$user['username']}连续10次登录密码错误请注意账号安全");
$this->error("<strong class='color-red'>登录账号或密码错误!</strong><p class='nowrap'>尝试次数达到上限,锁定一小时内禁止登录!</p>"); $this->error("<strong class='color-red'>登录账号或密码错误!</strong><p class='nowrap'>尝试次数达到上限,锁定一小时内禁止登录!</p>");
} }
} }
// 登录成功并更新账号 // 登录成功并更新账号
cache('user_login_' . $user['username'], null); cache('user_login_' . $user['username'], null);
Db::name('SystemUser')->where(['id' => $user['id']])->update([ Db::name('SystemUser')->where(['id' => $user['id']])->update([
'login_at' => Db::raw('now()'), 'login_at' => Db::raw('now()'),
'login_ip' => $this->request->ip(), 'login_ip' => $this->request->ip(),
'login_num' => Db::raw('login_num+1'), 'login_num' => Db::raw('login_num+1'),
]); ]);
session('user', $user); session('user', $user);
session('loginskey', null); session('loginskey', null);
empty($user['authorize']) || \app\admin\service\Auth::applyNode(); empty($user['authorize']) || \app\admin\service\Auth::applyNode();
_syslog('系统管理', '用户登录系统成功'); _syslog('系统管理', '用户登录系统成功');
$this->success('登录成功,正在进入系统...', url('@admin')); $this->success('登录成功,正在进入系统...', url('@admin'));
} }
} }
/** /**
* 退出登录 * 退出登录
*/ */
public function out() public function out()
{ {
if ($_SESSION) $_SESSION = []; if ($_SESSION) $_SESSION = [];
[session_unset(), session_destroy()]; [session_unset(), session_destroy()];
$this->success('退出登录成功!', url('@admin/login')); $this->success('退出登录成功!', url('@admin/login'));
} }
} }

View File

@ -1,133 +1,134 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
use library\tools\Data; use library\tools\Data;
use think\Db; use think\Db;
/** /**
* 系统菜单管理 * 系统菜单管理
* Class Menu * Class Menu
* @package app\admin\controller * @package app\admin\controller
*/ */
class Menu extends Controller class Menu extends Controller
{ {
/** /**
* 当前操作数据库 * 当前操作数据库
* @var string * @var string
*/ */
protected $table = 'SystemMenu'; protected $table = 'SystemMenu';
/** /**
* 系统菜单显示 * 系统菜单显示
*/ */
public function index() public function index()
{ {
$this->title = '系统菜单管理'; $this->title = '系统菜单管理';
$this->_page($this->table, false); $this->_page($this->table, false);
} }
/** /**
* 列表数据处理 * 列表数据处理
* @param array $data * @param array $data
*/ */
protected function _index_page_filter(&$data) protected function _index_page_filter(&$data)
{ {
foreach ($data as &$vo) { foreach ($data as &$vo) {
if ($vo['url'] !== '#') { if ($vo['url'] !== '#') {
$vo['url'] = url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}"); $vo['url'] = url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}");
} }
$vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id'])); $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
} }
$data = Data::arr2table($data); $data = Data::arr2table($data);
} }
/** /**
* 编辑菜单 * 编辑菜单
*/ */
public function edit() public function edit()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_form($this->table, 'form'); $this->_form($this->table, 'form');
} }
/** /**
* 添加菜单 * 添加菜单
*/ */
public function add() public function add()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_form($this->table, 'form'); $this->_form($this->table, 'form');
} }
/** /**
* 表单数据 * 表单数据处理
* @param array $vo * @param array $vo
* @throws \think\db\exception\DataNotFoundException * @throws \ReflectionException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\exception\DbException * @throws \think\db\exception\ModelNotFoundException
*/ * @throws \think\exception\DbException
protected function _form_filter(&$vo) */
{ protected function _form_filter(&$vo)
if ($this->request->isGet()) { {
// 上级菜单处理 if ($this->request->isGet()) {
$_menus = Db::name($this->table)->where(['status' => '1'])->order('sort asc,id asc')->select(); // 上级菜单处理
$_menus[] = ['title' => '顶级菜单', 'id' => '0', 'pid' => '-1']; $_menus = Db::name($this->table)->where(['status' => '1'])->order('sort asc,id asc')->select();
$menus = Data::arr2table($_menus); $_menus[] = ['title' => '顶级菜单', 'id' => '0', 'pid' => '-1'];
foreach ($menus as $key => &$menu) if (substr_count($menu['path'], '-') > 3) unset($menus[$key]); # 移除三级以下的菜单 $menus = Data::arr2table($_menus);
elseif (isset($vo['pid']) && $vo['pid'] !== '' && $cur = "-{$vo['pid']}-{$vo['id']}") foreach ($menus as $key => &$menu) if (substr_count($menu['path'], '-') > 3) unset($menus[$key]); # 移除三级以下的菜单
if (stripos("{$menu['path']}-", "{$cur}-") !== false || $menu['path'] === $cur) unset($menus[$key]); # 移除与自己相关联的菜单 elseif (isset($vo['pid']) && $vo['pid'] !== '' && $cur = "-{$vo['pid']}-{$vo['id']}")
// 选择自己的上级菜单 if (stripos("{$menu['path']}-", "{$cur}-") !== false || $menu['path'] === $cur) unset($menus[$key]); # 移除与自己相关联的菜单
if (!isset($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0'); // 选择自己的上级菜单
// 读取系统功能节点 if (!isset($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0');
$nodes = \app\admin\service\Auth::get(); // 读取系统功能节点
foreach ($nodes as $key => $node) { $nodes = \app\admin\service\Auth::get();
if (empty($node['is_menu'])) unset($nodes[$key]); foreach ($nodes as $key => $node) {
unset($nodes[$key]['pnode'], $nodes[$key]['is_login'], $nodes[$key]['is_menu'], $nodes[$key]['is_auth']); if (empty($node['is_menu'])) unset($nodes[$key]);
} unset($nodes[$key]['pnode'], $nodes[$key]['is_login'], $nodes[$key]['is_menu'], $nodes[$key]['is_auth']);
list($this->menus, $this->nodes) = [$menus, array_values($nodes)]; }
} list($this->menus, $this->nodes) = [$menus, array_values($nodes)];
} }
}
/**
* 启用菜单 /**
*/ * 启用菜单
public function resume() */
{ public function resume()
$this->applyCsrfToken(); {
$this->_save($this->table, ['status' => '1']); $this->applyCsrfToken();
} $this->_save($this->table, ['status' => '1']);
}
/**
* 禁用菜单 /**
*/ * 禁用菜单
public function forbid() */
{ public function forbid()
$this->applyCsrfToken(); {
$this->_save($this->table, ['status' => '0']); $this->applyCsrfToken();
} $this->_save($this->table, ['status' => '0']);
}
/**
* 删除菜单 /**
*/ * 删除菜单
public function del() */
{ public function del()
$this->applyCsrfToken(); {
$this->_delete($this->table); $this->applyCsrfToken();
} $this->_delete($this->table);
}
} }

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
@ -33,7 +33,7 @@ class Node extends Controller
/** /**
* 显示节点列表 * 显示节点列表
* @return mixed * @throws \ReflectionException
*/ */
public function index() public function index()
{ {
@ -51,6 +51,7 @@ class Node extends Controller
/** /**
* 清理无效的节点数据 * 清理无效的节点数据
* @throws \ReflectionException
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;

View File

@ -1,163 +1,163 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller; namespace app\admin\controller;
use library\Controller; use library\Controller;
use library\tools\Data; use library\tools\Data;
use think\Db; use think\Db;
/** /**
* 系统用户管理控制器 * 系统用户管理控制器
* Class User * Class User
* @package app\admin\controller * @package app\admin\controller
* @author Anyon <zoujingli@qq.com> * @author Anyon <zoujingli@qq.com>
* @date 2017/02/15 18:12 * @date 2017/02/15 18:12
*/ */
class User extends Controller class User extends Controller
{ {
/** /**
* 指定当前数据表 * 指定当前数据表
* @var string * @var string
*/ */
public $table = 'SystemUser'; public $table = 'SystemUser';
/** /**
* 用户列表 * 用户列表
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
$this->title = '系统用户管理'; $this->title = '系统用户管理';
$this->_query($this->table)->where(['is_deleted' => '0'])->like('username,phone,mail')->dateBetween('login_at')->equal('status')->page(); $this->_query($this->table)->where(['is_deleted' => '0'])->like('username,phone,mail')->dateBetween('login_at')->equal('status')->page();
} }
/** /**
* 授权管理 * 授权管理
* @return mixed * @return mixed
*/ */
public function auth() public function auth()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_form($this->table, 'auth'); $this->_form($this->table, 'auth');
} }
/** /**
* 用户添加 * 用户添加
* @return mixed * @return mixed
*/ */
public function add() public function add()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_form($this->table, 'form'); $this->_form($this->table, 'form');
} }
/** /**
* 用户编辑 * 用户编辑
* @return mixed * @return mixed
*/ */
public function edit() public function edit()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_form($this->table, 'form'); $this->_form($this->table, 'form');
} }
/** /**
* 用户密码修改 * 用户密码修改
* @return mixed * @return mixed
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function pass() public function pass()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->verify = false; $this->verify = false;
$this->_form($this->table, 'pass'); $this->_form($this->table, 'pass');
} else { } else {
$post = $this->request->post(); $post = $this->request->post();
if ($post['password'] !== $post['repassword']) { if ($post['password'] !== $post['repassword']) {
$this->error('两次输入的密码不一致!'); $this->error('两次输入的密码不一致!');
} }
$result = \app\admin\service\Auth::checkPassword($post['password']); $result = \app\admin\service\Auth::checkPassword($post['password']);
if (empty($result['code'])) $this->error($result['msg']); if (empty($result['code'])) $this->error($result['msg']);
$data = ['id' => $post['id'], 'password' => md5($post['password'])]; $data = ['id' => $post['id'], 'password' => md5($post['password'])];
if (Data::save($this->table, $data, 'id')) { if (Data::save($this->table, $data, 'id')) {
$this->success('密码修改成功,下次请使用新密码登录!', ''); $this->success('密码修改成功,下次请使用新密码登录!', '');
} else { } else {
$this->error('密码修改失败,请稍候再试!'); $this->error('密码修改失败,请稍候再试!');
} }
} }
} }
/** /**
* 表单数据默认处理 * 表单数据默认处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function _form_filter(&$data) public function _form_filter(&$data)
{ {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data['authorize'] = (isset($data['authorize']) && is_array($data['authorize'])) ? join(',', $data['authorize']) : ''; $data['authorize'] = (isset($data['authorize']) && is_array($data['authorize'])) ? join(',', $data['authorize']) : '';
if (isset($data['id'])) unset($data['username']); if (isset($data['id'])) unset($data['username']);
elseif (Db::name($this->table)->where(['username' => $data['username']])->count() > 0) { elseif (Db::name($this->table)->where(['username' => $data['username']])->count() > 0) {
$this->error('用户账号已经存在,请使用其它账号!'); $this->error('用户账号已经存在,请使用其它账号!');
} }
} else { } else {
$data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : ''); $data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : '');
$this->assign('authorizes', Db::name('SystemAuth')->where(['status' => '1'])->select()); $this->assign('authorizes', Db::name('SystemAuth')->where(['status' => '1'])->select());
} }
} }
/** /**
* 删除用户 * 删除用户
*/ */
public function del() public function del()
{ {
if (in_array('10000', explode(',', $this->request->post('id')))) { if (in_array('10000', explode(',', $this->request->post('id')))) {
$this->error('系统超级账号禁止删除!'); $this->error('系统超级账号禁止删除!');
} }
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_delete($this->table); $this->_delete($this->table);
} }
/** /**
* 用户禁用 * 用户禁用
*/ */
public function forbid() public function forbid()
{ {
if (in_array('10000', explode(',', $this->request->post('id')))) { if (in_array('10000', explode(',', $this->request->post('id')))) {
$this->error('系统超级账号禁止操作!'); $this->error('系统超级账号禁止操作!');
} }
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_save($this->table, ['status' => '0']); $this->_save($this->table, ['status' => '0']);
} }
/** /**
* 用户禁用 * 用户禁用
*/ */
public function resume() public function resume()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_save($this->table, ['status' => '1']); $this->_save($this->table, ['status' => '1']);
} }
} }

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller\api; namespace app\admin\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller\api; namespace app\admin\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\controller\api; namespace app\admin\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\queue; namespace app\admin\queue;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\service; namespace app\admin\service;
@ -30,7 +30,7 @@ class Auth
* 权限检查中间件入口 * 权限检查中间件入口
* @param \think\Request $request * @param \think\Request $request
* @param \Closure $next * @param \Closure $next
* @return mixed|\think\response\Json|\think\response\Redirect * @return mixed
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
@ -72,18 +72,19 @@ class Auth
* 获取系统代码节点 * 获取系统代码节点
* @param array $nodes * @param array $nodes
* @return array * @return array
* @throws \ReflectionException
*/ */
public static function get($nodes = []) public static function get($nodes = [])
{ {
$ignore = self::getIgnore(); list($ignore, $map) = [self::getIgnore(), Node::getClassTreeNode(env('app_path'))];
$alias = Db::name('SystemNode')->column('node,is_menu,is_auth,is_login,title'); $alias = Db::name('SystemNode')->column('node,is_menu,is_auth,is_login,title');
foreach (Node::getTree(env('app_path')) as $thr) { foreach (Node::getMethodTreeNode(env('app_path')) as $thr => $title) {
foreach ($ignore as $str) if (stripos($thr, $str) === 0) continue 2; foreach ($ignore as $str) if (stripos($thr, $str) === 0) continue 2;
$tmp = explode('/', $thr); $tmp = explode('/', $thr);
list($one, $two) = ["{$tmp[0]}", "{$tmp[0]}/{$tmp[1]}"]; list($one, $two) = ["{$tmp[0]}", "{$tmp[0]}/{$tmp[1]}"];
$nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => '', 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => '']); $nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => '', 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => '']);
$nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => '', 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => $one]); $nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => isset($map[$two]) ? $map[$two] : '', 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => $one]);
$nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => '', 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => $two]); $nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => $title, 'is_menu' => 0, 'is_auth' => 0, 'is_login' => 0], ['pnode' => $two]);
} }
foreach ($nodes as &$node) list($node['is_auth'], $node['is_menu'], $node['is_login']) = [intval($node['is_auth']), intval($node['is_menu']), empty($node['is_auth']) ? intval($node['is_login']) : 1]; foreach ($nodes as &$node) list($node['is_auth'], $node['is_menu'], $node['is_login']) = [intval($node['is_auth']), intval($node['is_menu']), empty($node['is_auth']) ? intval($node['is_login']) : 1];
return $nodes; return $nodes;
@ -124,7 +125,7 @@ class Auth
/** /**
* 应用用户权限节点 * 应用用户权限节点
* @return bool * @return boolean
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
@ -153,6 +154,7 @@ class Auth
/** /**
* 获取授权后的菜单 * 获取授权后的菜单
* @return array * @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\service; namespace app\admin\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\service; namespace app\admin\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\admin\service; namespace app\admin\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
if (!function_exists('auth')) { if (!function_exists('auth')) {

View File

@ -16,13 +16,13 @@
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td style="max-width:200px">framework 版本</td> <td style="max-width:200px">应用组件版本</td>
<td>{:sysconf('app_version')}</td> <td>{:sysconf('app_version')}</td>
<td style="max-width:200px">产品名称</td> <td style="max-width:200px">产品名称</td>
<td>framework</td> <td>framework</td>
</tr> </tr>
<tr> <tr>
<td>ThinkPHP 版本</td> <td>ThinkAdmin 版本</td>
<td>{$think_ver}</td> <td>{$think_ver}</td>
<td>在线体验</td> <td>在线体验</td>
<td> <td>
@ -44,8 +44,8 @@
<td>{:php_sapi_name()}</td> <td>{:php_sapi_name()}</td>
<td>项目地址</td> <td>项目地址</td>
<td> <td>
<a target="_blank" href="https://github.com/zoujingli/ThinkAdmin"> <a target="_blank" href="https://github.com/zoujingli/framework">
https://github.com/zoujingli/ThinkAdmin https://github.com/zoujingli/framework
</a> </a>
</td> </td>
</tr> </tr>
@ -54,8 +54,8 @@
<td>{$mysql_ver}</td> <td>{$mysql_ver}</td>
<td>BUG反馈</td> <td>BUG反馈</td>
<td> <td>
<a target="_blank" href="https://github.com/zoujingli/ThinkAdmin/issues"> <a target="_blank" href="https://github.com/zoujingli/framework/issues">
https://github.com/zoujingli/ThinkAdmin/issues https://github.com/zoujingli/framework/issues
</a> </a>
</td> </td>
</tr> </tr>
@ -75,7 +75,7 @@
<td>POST大小限制</td> <td>POST大小限制</td>
<td>{:ini_get('post_max_size')}</td> <td>{:ini_get('post_max_size')}</td>
<td>办公地址</td> <td>办公地址</td>
<td>广州市天河区东圃一横路东泷商贸中心C座316</td> <td>广州市天河区东圃一横路东泷商贸中心G02</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\controller; namespace app\service\controller;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\controller; namespace app\service\controller;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\controller\api; namespace app\service\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\controller\api; namespace app\service\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\handler; namespace app\service\handler;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\handler; namespace app\service\handler;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\handler; namespace app\service\handler;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\logic; namespace app\service\logic;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\service\logic; namespace app\service\logic;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\command; namespace app\wechat\command;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\command\fans; namespace app\wechat\command\fans;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\command\fans; namespace app\wechat\command\fans;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\command\fans; namespace app\wechat\command\fans;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\command\fans; namespace app\wechat\command\fans;

View File

@ -1,98 +1,98 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\service\Wechat; use app\wechat\service\Wechat;
use library\Controller; use library\Controller;
use library\File; use library\File;
/** /**
* 模板配置 * 模板配置
* Class Config * Class Config
* @package app\wechat\controller * @package app\wechat\controller
*/ */
class Config extends Controller class Config extends Controller
{ {
/** /**
* 公众号授权绑定 * 公众号授权绑定
* @return mixed * @return mixed
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function options() public function options()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->thrNotify = url('@wechat/api.push', '', false, true); $this->thrNotify = url('@wechat/api.push', '', false, true);
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->title = '公众号授权绑定'; $this->title = '公众号授权绑定';
if (!($this->geoip = cache('mygeoip'))) { if (!($this->geoip = cache('mygeoip'))) {
cache('mygeoip', $this->geoip = gethostbyname($this->request->host()), 360); cache('mygeoip', $this->geoip = gethostbyname($this->request->host()), 360);
} }
$code = encode(url('@admin', '', true, true) . '#' . $this->request->url()); $code = encode(url('@admin', '', true, true) . '#' . $this->request->url());
$this->authurl = config('wechat.service_url') . "/service/api.push/auth/{$code}"; $this->authurl = config('wechat.service_url') . "/service/api.push/auth/{$code}";
if ($this->request->has('appid', 'get', true) && $this->request->has('appkey', 'get', true)) { if ($this->request->has('appid', 'get', true) && $this->request->has('appkey', 'get', true)) {
sysconf('wechat_type', 'thr'); sysconf('wechat_type', 'thr');
sysconf('wechat_thr_appid', input('appid')); sysconf('wechat_thr_appid', input('appid'));
sysconf('wechat_thr_appkey', input('appkey')); sysconf('wechat_thr_appkey', input('appkey'));
Wechat::wechat()->setApiNotifyUri($this->thrNotify); Wechat::wechat()->setApiNotifyUri($this->thrNotify);
} }
try { try {
$this->wechat = Wechat::wechat()->getConfig(); $this->wechat = Wechat::wechat()->getConfig();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->wechat = []; $this->wechat = [];
} }
return $this->fetch(); return $this->fetch();
} }
foreach ($this->request->post() as $k => $v) sysconf($k, $v); foreach ($this->request->post() as $k => $v) sysconf($k, $v);
if ($this->request->post('wechat_type') === 'thr') { if ($this->request->post('wechat_type') === 'thr') {
Wechat::wechat()->setApiNotifyUri($this->thrNotify); Wechat::wechat()->setApiNotifyUri($this->thrNotify);
} }
$this->success('公众号参数获取成功!', url('@admin') . '#' . url('wechat/config/options')); $this->success('公众号参数获取成功!', url('@admin') . '#' . url('wechat/config/options'));
} }
/** /**
* 公众号支付配置 * 公众号支付配置
* @return mixed * @return mixed
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function payment() public function payment()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '公众号支付配置'; $this->title = '公众号支付配置';
if ($this->request->isGet()) { if ($this->request->isGet()) {
$file = File::instance('local'); $file = File::instance('local');
$this->wechat_mch_ssl_cer = sysconf('wechat_mch_ssl_cer'); $this->wechat_mch_ssl_cer = sysconf('wechat_mch_ssl_cer');
$this->wechat_mch_ssl_key = sysconf('wechat_mch_ssl_key'); $this->wechat_mch_ssl_key = sysconf('wechat_mch_ssl_key');
$this->wechat_mch_ssl_p12 = sysconf('wechat_mch_ssl_p12'); $this->wechat_mch_ssl_p12 = sysconf('wechat_mch_ssl_p12');
if (!$file->has($this->wechat_mch_ssl_cer, true)) $this->wechat_mch_ssl_cer = ''; if (!$file->has($this->wechat_mch_ssl_cer, true)) $this->wechat_mch_ssl_cer = '';
if (!$file->has($this->wechat_mch_ssl_key, true)) $this->wechat_mch_ssl_key = ''; if (!$file->has($this->wechat_mch_ssl_key, true)) $this->wechat_mch_ssl_key = '';
if (!$file->has($this->wechat_mch_ssl_p12, true)) $this->wechat_mch_ssl_p12 = ''; if (!$file->has($this->wechat_mch_ssl_p12, true)) $this->wechat_mch_ssl_p12 = '';
return $this->fetch(); return $this->fetch();
} }
if ($this->request->post('wechat_mch_ssl_type') === 'p12') { if ($this->request->post('wechat_mch_ssl_type') === 'p12') {
if (!($sslp12 = $this->request->post('wechat_mch_ssl_p12'))) { if (!($sslp12 = $this->request->post('wechat_mch_ssl_p12'))) {
$mchid = $this->request->post('wechat_mch_id'); $mchid = $this->request->post('wechat_mch_id');
$content = File::instance('local')->get($sslp12, true); $content = File::instance('local')->get($sslp12, true);
if (!openssl_pkcs12_read($content, $certs, $mchid)) { if (!openssl_pkcs12_read($content, $certs, $mchid)) {
$this->error('商户MCH_ID与支付P12证书不匹配'); $this->error('商户MCH_ID与支付P12证书不匹配');
} }
} }
} }
foreach ($this->request->post() as $k => $v) sysconf($k, $v); foreach ($this->request->post() as $k => $v) sysconf($k, $v);
$this->success('公众号支付配置成功!'); $this->success('公众号支付配置成功!');
} }
} }

View File

@ -1,132 +1,132 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller; namespace app\wechat\controller;
use app\admin\service\Queue; use app\admin\service\Queue;
use app\wechat\queue\Jobs; use app\wechat\queue\Jobs;
use app\wechat\service\Wechat; use app\wechat\service\Wechat;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
/** /**
* 微信粉丝管理 * 微信粉丝管理
* Class Fans * Class Fans
* @package app\wechat\controller * @package app\wechat\controller
*/ */
class Fans extends Controller class Fans extends Controller
{ {
/** /**
* 绑定数据表 * 绑定数据表
* @var string * @var string
*/ */
protected $table = 'WechatFans'; protected $table = 'WechatFans';
/** /**
* 微信粉丝管理 * 微信粉丝管理
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
$this->title = '微信粉丝管理'; $this->title = '微信粉丝管理';
$this->_query($this->table)->like('nickname')->equal('subscribe,is_black') $this->_query($this->table)->like('nickname')->equal('subscribe,is_black')
->dateBetween('subscribe_at')->order('subscribe_time desc')->page(); ->dateBetween('subscribe_at')->order('subscribe_time desc')->page();
} }
/** /**
* 微信粉丝列表处理 * 微信粉丝列表处理
* @param array $data * @param array $data
*/ */
protected function _index_page_filter(array &$data) protected function _index_page_filter(array &$data)
{ {
$tags = Db::name('WechatFansTags')->column('id,name'); $tags = Db::name('WechatFansTags')->column('id,name');
foreach ($data as &$user) { foreach ($data as &$user) {
$user['tags'] = []; $user['tags'] = [];
foreach (explode(',', $user['tagid_list']) as $tagid) { foreach (explode(',', $user['tagid_list']) as $tagid) {
if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid]; if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid];
} }
foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) { foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) {
if (isset($user[$k])) $user[$k] = emoji_decode($user[$k]); if (isset($user[$k])) $user[$k] = emoji_decode($user[$k]);
} }
} }
} }
/** /**
* 批量拉黑粉丝 * 批量拉黑粉丝
*/ */
public function setBlack() public function setBlack()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
try { try {
foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
Wechat::WeChatUser()->batchBlackList($openids); Wechat::WeChatUser()->batchBlackList($openids);
Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '1']); Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '1']);
} }
$this->success('拉黑粉丝信息成功!'); $this->success('拉黑粉丝信息成功!');
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); $this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}");
} }
} }
/** /**
*批量取消拉黑粉丝 *批量取消拉黑粉丝
*/ */
public function delBlack() public function delBlack()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
try { try {
foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
Wechat::WeChatUser()->batchUnblackList($openids); Wechat::WeChatUser()->batchUnblackList($openids);
Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '0']); Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '0']);
} }
$this->success('取消拉黑粉丝信息成功!'); $this->success('取消拉黑粉丝信息成功!');
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("取消拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); $this->error("取消拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}");
} }
} }
/** /**
* 同步粉丝列表 * 同步粉丝列表
*/ */
public function sync() public function sync()
{ {
try { try {
Queue::add('同步粉丝列表', Jobs::URI, 0, [], 0); Queue::add('同步粉丝列表', Jobs::URI, 0, [], 0);
$this->success('创建同步粉丝任务成功,需要时间来完成。<br>请到系统任务管理查看进度!'); $this->success('创建同步粉丝任务成功,需要时间来完成。<br>请到系统任务管理查看进度!');
} catch (HttpResponseException $exception) { } catch (HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("创建同步粉丝任务失败,请稍候再试!<br> {$e->getMessage()}"); $this->error("创建同步粉丝任务失败,请稍候再试!<br> {$e->getMessage()}");
} }
} }
/** /**
* 删除粉丝 * 删除粉丝
*/ */
public function del() public function del()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_delete($this->table); $this->_delete($this->table);
} }
} }

View File

@ -1,194 +1,194 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\service\Wechat; use app\wechat\service\Wechat;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
/** /**
* 回复规则管理 * 回复规则管理
* Class Keys * Class Keys
* @package app\wechat\controller * @package app\wechat\controller
*/ */
class Keys extends Controller class Keys extends Controller
{ {
/** /**
* 绑定数据表 * 绑定数据表
* @var string * @var string
*/ */
protected $table = 'WechatKeys'; protected $table = 'WechatKeys';
/** /**
* 消息类型 * 消息类型
* @var array * @var array
*/ */
public $types = [ public $types = [
'text' => '文字', 'news' => '图文', 'image' => '图片', 'music' => '音乐', 'text' => '文字', 'news' => '图文', 'image' => '图片', 'music' => '音乐',
'video' => '视频', 'voice' => '语音', 'customservice' => '转客服', 'video' => '视频', 'voice' => '语音', 'customservice' => '转客服',
]; ];
/** /**
* 显示关键字列表 * 显示关键字列表
* @return array|string * @return array|string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
// 关键字二维码生成 // 关键字二维码生成
if ($this->request->get('action') === 'qrc') { if ($this->request->get('action') === 'qrc') {
try { try {
$wechat = Wechat::WeChatQrcode(); $wechat = Wechat::WeChatQrcode();
$result = $wechat->create($this->request->get('keys', '')); $result = $wechat->create($this->request->get('keys', ''));
$this->success('生成二维码成功!', "javascript:$.previewImage('{$wechat->url($result['ticket'])}')"); $this->success('生成二维码成功!', "javascript:$.previewImage('{$wechat->url($result['ticket'])}')");
} catch (\think\exception\HttpResponseException $exception) { } catch (\think\exception\HttpResponseException $exception) {
throw $exception; throw $exception;
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("生成二维码失败,请稍候再试!<br> {$e->getMessage()}"); $this->error("生成二维码失败,请稍候再试!<br> {$e->getMessage()}");
} }
} }
// 关键字列表显示 // 关键字列表显示
$this->title = '回复规则管理'; $this->title = '回复规则管理';
return $this->_query($this->table)->like('keys,type')->equal('status')->dateBetween('create_at')->whereNotIn('keys', ['subscribe', 'default'])->order('sort asc,id desc')->page(); return $this->_query($this->table)->like('keys,type')->equal('status')->dateBetween('create_at')->whereNotIn('keys', ['subscribe', 'default'])->order('sort asc,id desc')->page();
} }
/** /**
* 列表数据处理 * 列表数据处理
* @param array $data * @param array $data
*/ */
protected function _index_page_filter(&$data) protected function _index_page_filter(&$data)
{ {
try { try {
foreach ($data as &$vo) { foreach ($data as &$vo) {
$vo['qrc'] = url('@wechat/keys/index') . "?action=qrc&keys={$vo['keys']}"; $vo['qrc'] = url('@wechat/keys/index') . "?action=qrc&keys={$vo['keys']}";
$vo['type'] = isset($this->types[$vo['type']]) ? $this->types[$vo['type']] : $vo['type']; $vo['type'] = isset($this->types[$vo['type']]) ? $this->types[$vo['type']] : $vo['type'];
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error($e->getMessage()); $this->error($e->getMessage());
} }
} }
/** /**
* 添加关键字 * 添加关键字
* @return string * @return string
*/ */
public function add() public function add()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '添加关键字规则'; $this->title = '添加关键字规则';
return $this->_form($this->table, 'form'); return $this->_form($this->table, 'form');
} }
/** /**
* 编辑关键字 * 编辑关键字
* @return string * @return string
*/ */
public function edit() public function edit()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '编辑关键字规则'; $this->title = '编辑关键字规则';
return $this->_form($this->table, 'form'); return $this->_form($this->table, 'form');
} }
/** /**
* 删除关键字 * 删除关键字
*/ */
public function del() public function del()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_delete($this->table); $this->_delete($this->table);
} }
/** /**
* 禁用关键字 * 禁用关键字
*/ */
public function forbid() public function forbid()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_save($this->table, ['status' => '0']); $this->_save($this->table, ['status' => '0']);
} }
/** /**
* 启用关键字 * 启用关键字
*/ */
public function resume() public function resume()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->_save($this->table, ['status' => '1']); $this->_save($this->table, ['status' => '1']);
} }
/** /**
* 关注默认回复 * 关注默认回复
* @return array|string * @return array|string
*/ */
public function subscribe() public function subscribe()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '编辑关注回复规则'; $this->title = '编辑关注回复规则';
return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'subscribe']); return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'subscribe']);
} }
/** /**
* 无配置默认回复 * 无配置默认回复
* @return array|string * @return array|string
*/ */
public function defaults() public function defaults()
{ {
$this->applyCsrfToken(); $this->applyCsrfToken();
$this->title = '编辑默认回复规则'; $this->title = '编辑默认回复规则';
return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'default']); return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'default']);
} }
/** /**
* 添加数据处理 * 添加数据处理
* @param array $data * @param array $data
*/ */
protected function _form_filter(array &$data) protected function _form_filter(array &$data)
{ {
if ($this->request->isPost() && isset($data['keys'])) { if ($this->request->isPost() && isset($data['keys'])) {
$db = Db::name($this->table)->where('keys', $data['keys']); $db = Db::name($this->table)->where('keys', $data['keys']);
empty($data['id']) || $db->where('id', 'neq', $data['id']); empty($data['id']) || $db->where('id', 'neq', $data['id']);
if ($db->count() > 0) $this->error('关键字已经存在,请使用其它关键字!'); if ($db->count() > 0) $this->error('关键字已经存在,请使用其它关键字!');
} }
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->msgTypes = $this->types; $this->msgTypes = $this->types;
$root = rtrim(dirname(request()->basefile(true)), '\\/'); $root = rtrim(dirname(request()->basefile(true)), '\\/');
$this->defaultImage = "{$root}/static/theme/img/image.png"; $this->defaultImage = "{$root}/static/theme/img/image.png";
} }
} }
/** /**
* 编辑结果处理 * 编辑结果处理
* @param $result * @param $result
*/ */
protected function _form_result($result) protected function _form_result($result)
{ {
if ($result !== false) { if ($result !== false) {
list($url, $keys) = ['', $this->request->post('keys')]; list($url, $keys) = ['', $this->request->post('keys')];
if (!in_array($keys, ['subscribe', 'default'])) { if (!in_array($keys, ['subscribe', 'default'])) {
$url = url('@admin') . '#' . url('wechat/keys/index') . '?spm=' . $this->request->get('spm'); $url = url('@admin') . '#' . url('wechat/keys/index') . '?spm=' . $this->request->get('spm');
} }
$this->success('恭喜, 关键字保存成功!', $url); $this->success('恭喜, 关键字保存成功!', $url);
} }
$this->error('关键字保存失败, 请稍候再试!'); $this->error('关键字保存失败, 请稍候再试!');
} }
} }

View File

@ -1,155 +1,155 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller; namespace app\wechat\controller;
use app\admin\service\Log; use app\admin\service\Log;
use app\wechat\service\Wechat; use app\wechat\service\Wechat;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
/** /**
* 微信菜单管理 * 微信菜单管理
* Class Menu * Class Menu
* @package app\wechat\controller * @package app\wechat\controller
*/ */
class Menu extends Controller class Menu extends Controller
{ {
/** /**
* 微信菜单的类型 * 微信菜单的类型
* @var array * @var array
*/ */
protected $menuType = [ protected $menuType = [
'click' => '匹配规则', 'click' => '匹配规则',
'view' => '跳转网页', 'view' => '跳转网页',
'miniprogram' => '打开小程序', 'miniprogram' => '打开小程序',
// 'customservice' => '转多客服', // 'customservice' => '转多客服',
'scancode_push' => '扫码推事件', 'scancode_push' => '扫码推事件',
'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框', 'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框',
'pic_sysphoto' => '弹出系统拍照发图', 'pic_sysphoto' => '弹出系统拍照发图',
'pic_photo_or_album' => '弹出拍照或者相册发图', 'pic_photo_or_album' => '弹出拍照或者相册发图',
'pic_weixin' => '弹出微信相册发图器', 'pic_weixin' => '弹出微信相册发图器',
'location_select' => '弹出地理位置选择器', 'location_select' => '弹出地理位置选择器',
]; ];
/** /**
* 显示菜单列表 * 显示菜单列表
* @return array * @return array
* @throws \think\Exception * @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function index() public function index()
{ {
if ($this->request->get('output') === 'json') { if ($this->request->get('output') === 'json') {
$where = [['keys', 'notin', ['subscribe', 'default']], ['status', 'eq', '1']]; $where = [['keys', 'notin', ['subscribe', 'default']], ['status', 'eq', '1']];
$keys = Db::name('WechatKeys')->where($where)->order('sort asc,id desc')->select(); $keys = Db::name('WechatKeys')->where($where)->order('sort asc,id desc')->select();
$this->success('获取数据成功!', ['menudata' => sysdata('menudata'), 'keysdata' => $keys]); $this->success('获取数据成功!', ['menudata' => sysdata('menudata'), 'keysdata' => $keys]);
} }
$this->title = '微信菜单定制'; $this->title = '微信菜单定制';
$this->menuTypes = $this->menuType; $this->menuTypes = $this->menuType;
return $this->fetch(); return $this->fetch();
} }
/** /**
* 微信菜单编辑 * 微信菜单编辑
*/ */
public function edit() public function edit()
{ {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data = $this->request->post('data'); $data = $this->request->post('data');
if (empty($data)) { // 删除菜单 if (empty($data)) { // 删除菜单
try { try {
Wechat::WeChatMenu()->delete(); Wechat::WeChatMenu()->delete();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error('删除取消微信菜单失败,请稍候再试!' . $e->getMessage()); $this->error('删除取消微信菜单失败,请稍候再试!' . $e->getMessage());
} }
$this->success('删除并取消微信菜单成功!', ''); $this->success('删除并取消微信菜单成功!', '');
} }
try { try {
sysdata('menudata', $this->buildMenu($menudata = json_decode($data, true))); sysdata('menudata', $this->buildMenu($menudata = json_decode($data, true)));
Wechat::WeChatMenu()->create(['button' => sysdata('menudata')]); Wechat::WeChatMenu()->create(['button' => sysdata('menudata')]);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("微信菜单发布失败,请稍候再试!<br> {$e->getMessage()}"); $this->error("微信菜单发布失败,请稍候再试!<br> {$e->getMessage()}");
} }
_syslog('微信管理', '发布微信菜单成功'); _syslog('微信管理', '发布微信菜单成功');
$this->success('保存发布菜单成功!', ''); $this->success('保存发布菜单成功!', '');
} }
} }
/** /**
* @param array $list * @param array $list
* @return mixed * @return mixed
*/ */
private function buildMenu(array $list) private function buildMenu(array $list)
{ {
foreach ($list as &$vo) { foreach ($list as &$vo) {
unset($vo['active'], $vo['show']); unset($vo['active'], $vo['show']);
if (empty($vo['sub_button'])) { if (empty($vo['sub_button'])) {
$vo = $this->build_menu_item($vo); $vo = $this->build_menu_item($vo);
} else { } else {
$item = ['name' => $vo['name'], 'sub_button' => []]; $item = ['name' => $vo['name'], 'sub_button' => []];
foreach ($vo['sub_button'] as &$sub) { foreach ($vo['sub_button'] as &$sub) {
unset($sub['active'], $sub['show']); unset($sub['active'], $sub['show']);
array_push($item['sub_button'], $this->build_menu_item($sub)); array_push($item['sub_button'], $this->build_menu_item($sub));
} }
$vo = $item; $vo = $item;
} }
} }
return $list; return $list;
} }
/** /**
* 单个微信菜单数据过滤处理 * 单个微信菜单数据过滤处理
* @param array $item * @param array $item
* @return array * @return array
*/ */
private function build_menu_item(array $item) private function build_menu_item(array $item)
{ {
switch (strtolower($item['type'])) { switch (strtolower($item['type'])) {
case 'pic_weixin': case 'pic_weixin':
case 'pic_sysphoto': case 'pic_sysphoto':
case 'scancode_push': case 'scancode_push':
case 'location_select': case 'location_select':
case 'scancode_waitmsg': case 'scancode_waitmsg':
case 'pic_photo_or_album': case 'pic_photo_or_album':
return ['name' => $item['name'], 'type' => $item['type'], 'key' => isset($item['key']) ? $item['key'] : $item['type']]; return ['name' => $item['name'], 'type' => $item['type'], 'key' => isset($item['key']) ? $item['key'] : $item['type']];
case 'click': case 'click':
return ['name' => $item['name'], 'type' => $item['type'], 'key' => $item['key']]; return ['name' => $item['name'], 'type' => $item['type'], 'key' => $item['key']];
case 'view': case 'view':
return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url']]; return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url']];
case 'miniprogram': case 'miniprogram':
return [ return [
'name' => $item['name'], 'type' => $item['type'], 'url' => $item['url'], 'name' => $item['name'], 'type' => $item['type'], 'url' => $item['url'],
'appid' => $item['appid'], 'pagepath' => $item['pagepath'], 'appid' => $item['appid'], 'pagepath' => $item['pagepath'],
]; ];
} }
} }
/** /**
* 取消菜单 * 取消菜单
*/ */
public function cancel() public function cancel()
{ {
try { try {
Wechat::WeChatMenu()->delete(); Wechat::WeChatMenu()->delete();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->error("菜单取消失败,请稍候再试!<br> {$e->getMessage()}"); $this->error("菜单取消失败,请稍候再试!<br> {$e->getMessage()}");
} }
$this->success('菜单取消成功,重新关注可立即生效!', ''); $this->success('菜单取消成功,重新关注可立即生效!', '');
} }
} }

View File

@ -1,160 +1,160 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | framework // | framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ] // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top // | 官方网站: http://framework.thinkadmin.top
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller; namespace app\wechat\controller;
use app\wechat\service\Media; use app\wechat\service\Media;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
/** /**
* 微信图文管理 * 微信图文管理
* Class News * Class News
* @package app\wechat\controller * @package app\wechat\controller
*/ */
class News extends Controller class News extends Controller
{ {
/** /**
* 设置默认操作表 * 设置默认操作表
* @var string * @var string
*/ */
protected $table = 'WechatNews'; protected $table = 'WechatNews';
/** /**
* 图文列表 * 图文列表
* @return array|string * @return array|string
*/ */
public function index() public function index()
{ {
$this->title = '微信图文列表'; $this->title = '微信图文列表';
$db = Db::name($this->table)->where(['is_deleted' => '0']); $db = Db::name($this->table)->where(['is_deleted' => '0']);
return parent::_page($db->order('id desc')); return parent::_page($db->order('id desc'));
} }
/** /**
* 图文列表数据处理 * 图文列表数据处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
protected function _index_page_filter(&$data) protected function _index_page_filter(&$data)
{ {
foreach ($data as &$vo) $vo = Media::news($vo['id']); foreach ($data as &$vo) $vo = Media::news($vo['id']);
} }
/** /**
* 图文选择器 * 图文选择器
* @return string * @return string
*/ */
public function select() public function select()
{ {
return $this->index(); return $this->index();
} }
/** /**
* 图文列表数据处理 * 图文列表数据处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
protected function _select_page_filter(&$data) protected function _select_page_filter(&$data)
{ {
foreach ($data as &$vo) $vo = Media::news($vo['id']); foreach ($data as &$vo) $vo = Media::news($vo['id']);
} }
/** /**
* 添加图文 * 添加图文
* @return string * @return string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function add() public function add()
{ {
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->title = '新建图文'; $this->title = '新建图文';
return $this->fetch('form'); return $this->fetch('form');
} }
$data = $this->request->post(); $data = $this->request->post();
if (($ids = $this->_apply_news_article($data['data'])) && !empty($ids)) { if (($ids = $this->_apply_news_article($data['data'])) && !empty($ids)) {
if (data_save($this->table, ['article_id' => $ids, 'create_by' => session('user.id')], 'id') !== false) { if (data_save($this->table, ['article_id' => $ids, 'create_by' => session('user.id')], 'id') !== false) {
$url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm'); $url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm');
$this->success('图文添加成功!', $url); $this->success('图文添加成功!', $url);
} }
} }
$this->error('图文添加失败,请稍候再试!'); $this->error('图文添加失败,请稍候再试!');
} }
/** /**
* 编辑图文 * 编辑图文
* @return string * @return string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function edit() public function edit()
{ {
$id = $this->request->get('id', ''); $id = $this->request->get('id', '');
if ($this->request->isGet()) { if ($this->request->isGet()) {
empty($id) && $this->error('参数错误,请稍候再试!'); empty($id) && $this->error('参数错误,请稍候再试!');
if ($this->request->get('output') === 'json') { if ($this->request->get('output') === 'json') {
$this->success('获取数据成功!', Media::news($id)); $this->success('获取数据成功!', Media::news($id));
} }
return $this->fetch('form', ['title' => '编辑图文']); return $this->fetch('form', ['title' => '编辑图文']);
} }
$post = $this->request->post(); $post = $this->request->post();
if (isset($post['data']) && ($ids = $this->_apply_news_article($post['data']))) { if (isset($post['data']) && ($ids = $this->_apply_news_article($post['data']))) {
if (data_save('wechat_news', ['id' => $id, 'article_id' => $ids], 'id')) { if (data_save('wechat_news', ['id' => $id, 'article_id' => $ids], 'id')) {
$this->success('图文更新成功!', url('@admin') . '#' . url('@wechat/news/index')); $this->success('图文更新成功!', url('@admin') . '#' . url('@wechat/news/index'));
} }
} }
$this->error('图文更新失败,请稍候再试!'); $this->error('图文更新失败,请稍候再试!');
} }
/** /**
* 图文更新操作 * 图文更新操作
* @param array $data * @param array $data
* @param array $ids * @param array $ids
* @return string * @return string
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
private function _apply_news_article($data, $ids = []) private function _apply_news_article($data, $ids = [])
{ {
foreach ($data as &$vo) { foreach ($data as &$vo) {
$vo['create_at'] = date('Y-m-d H:i:s'); $vo['create_at'] = date('Y-m-d H:i:s');
if (empty($vo['digest'])) { if (empty($vo['digest'])) {
$vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120); $vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120);
} }
if (empty($vo['id'])) { if (empty($vo['id'])) {
$result = $id = Db::name('WechatNewsArticle')->insertGetId($vo); $result = $id = Db::name('WechatNewsArticle')->insertGetId($vo);
} else { } else {
$id = intval($vo['id']); $id = intval($vo['id']);
$result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo); $result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo);
} }
if ($result !== false) array_push($ids, $id); if ($result !== false) array_push($ids, $id);
} }
return join(',', $ids); return join(',', $ids);
} }
/** /**
* 删除用户 * 删除用户
*/ */
public function del() public function del()
{ {
$this->_delete($this->table); $this->_delete($this->table);
} }
} }

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller\api; namespace app\wechat\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller\api; namespace app\wechat\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\controller\api; namespace app\wechat\controller\api;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\queue; namespace app\wechat\queue;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\service; namespace app\wechat\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\service; namespace app\wechat\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\wechat\service; namespace app\wechat\service;

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// 注册系统指令 // 注册系统指令

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
return [ return [

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
return [ return [

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
return [ return [

View File

@ -7,7 +7,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// IE兼容提示 // IE兼容提示

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +--------------------------------------------------------------------*/ // +--------------------------------------------------------------------*/
::-webkit-input-placeholder{color:#aaa} ::-webkit-input-placeholder{color:#aaa}

View File

@ -9,7 +9,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +--------------------------------------------------------------------*/ // +--------------------------------------------------------------------*/
body,html{height:100%} body,html{height:100%}

2
think
View File

@ -10,7 +10,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/ThinkAdmin // | github开源项目https://github.com/zoujingli/framework
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think; namespace think;

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 ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35::getLoader(); return ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35 class ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a
{ {
private static $loader; private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) { if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php'; require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::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 ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$files; $includeFiles = Composer\Autoload\ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$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) {
composerRequire407a0fe5b8b66687453d756daf4a3b35($fileIdentifier, $file); composerRequirea2a5ca7b097a9d41d2230b028e215f7a($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequire407a0fe5b8b66687453d756daf4a3b35($fileIdentifier, $file) function composerRequirea2a5ca7b097a9d41d2230b028e215f7a($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 ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35 class ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a
{ {
public static $files = array ( public static $files = array (
'841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php', '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php',
@ -346,9 +346,9 @@ class ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35
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 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$classMap; $loader->classMap = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -177,8 +177,8 @@
}, },
{ {
"name": "symfony/options-resolver", "name": "symfony/options-resolver",
"version": "v3.4.23", "version": "v3.4.24",
"version_normalized": "3.4.23.0", "version_normalized": "3.4.24.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/options-resolver.git", "url": "https://github.com/symfony/options-resolver.git",
@ -499,12 +499,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5" "reference": "ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5d8dbc0707782c5b68ea5600f19001e128ee39c5", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd",
"reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5", "reference": "ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -523,7 +523,7 @@
"qiniu/php-sdk": "^7.2", "qiniu/php-sdk": "^7.2",
"topthink/framework": "5.1.*" "topthink/framework": "5.1.*"
}, },
"time": "2019-04-02T08:17:16+00:00", "time": "2019-04-03T05:55:15+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {

View File

@ -96,7 +96,7 @@ class Sync extends Command
private static function removeEmptyDir($dir) private static function removeEmptyDir($dir)
{ {
if (is_dir($dir) && count(scandir($dir)) === 2) { if (is_dir($dir) && count(scandir($dir)) === 2) {
rmdir($dir); if (rmdir($dir)) self::removeEmptyDir(dirname($dir));
} }
} }

View File

@ -35,7 +35,7 @@ class Cors
header('Access-Control-Allow-Methods:GET,POST,OPTIONS'); header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
header('Access-Control-Allow-Origin:' . self::getOrigin($request)); header('Access-Control-Allow-Origin:' . self::getOrigin($request));
header('Access-Control-Allow-Headers:' . self::getAllows($request)); header('Access-Control-Allow-Headers:' . self::getAllows($request));
header('Access-Control-Expose-Headers: User-Token-Csrf'); header('Access-Control-Expose-Headers:User-Token-Csrf');
header('Content-Type:text/plain charset=UTF-8'); header('Content-Type:text/plain charset=UTF-8');
header('Access-Control-Max-Age:1728000'); header('Access-Control-Max-Age:1728000');
header('HTTP/1.0 204 No Content'); header('HTTP/1.0 204 No Content');

View File

@ -21,6 +21,13 @@ namespace library\tools;
*/ */
class Node class Node
{ {
/**
* 控制器忽略函数
* @var array
*/
protected static $ignore = ['initialize', 'success', 'error', 'redirect', 'fetch', 'assign', 'callback'];
/** /**
* 获取当前访问节点 * 获取当前访问节点
* @return string * @return string
@ -32,6 +39,57 @@ class Node
return self::parseString("{$module}/{$controller}") . '/' . strtolower($action); return self::parseString("{$module}/{$controller}") . '/' . strtolower($action);
} }
/**
* 获取方法节点列表
* @param string $dir 控制器根路径
* @param array $nodes 额外数据
* @return array
* @throws \ReflectionException
*/
public static function getMethodTreeNode($dir, $nodes = [])
{
foreach (self::scanDir($dir) as $file) {
list($matches, $filename) = [[], str_replace(DIRECTORY_SEPARATOR, '/', $file)];
if (!preg_match('|/(\w+)/controller/(.+)|', $filename, $matches)) continue;
if (class_exists($classname = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4)))) {
foreach ((new \ReflectionClass($classname))->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
list($function, $comment) = [$method->getName(), $method->getDocComment()];
if (stripos($function, '_') === 0 || in_array($function, self::$ignore)) continue;
$controller = str_replace('/', '.', substr($matches[2], 0, -4));
if (stripos($controller, 'api.') !== false || stripos($controller, 'wap.') !== false) continue;
$node = self::parseString("{$matches[1]}/{$controller}") . '/' . strtolower($function);
$nodes[$node] = preg_replace('/^\/\*\*\*(.*?)\*.*?$/', '$1', preg_replace("/\s/", '', $comment));
if (stripos($nodes[$node], '@') !== false) $nodes[$node] = '';
}
}
}
return $nodes;
}
/**
* 获取控制器节点列表
* @param string $dir 控制器根路径
* @param array $nodes 额外数据
* @return array
* @throws \ReflectionException
*/
public static function getClassTreeNode($dir, $nodes = [])
{
foreach (self::scanDir($dir) as $file) {
list($matches, $filename) = [[], str_replace(DIRECTORY_SEPARATOR, '/', $file)];
if (!preg_match('|/(\w+)/controller/(.+)|', $filename, $matches)) continue;
if (class_exists($classname = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4)))) {
$controller = str_replace('/', '.', substr($matches[2], 0, -4));
if (stripos($controller, 'api.') !== false || stripos($controller, 'wap.') !== false) continue;
$node = self::parseString("{$matches[1]}/{$controller}");
$comment = (new \ReflectionClass($classname))->getDocComment();
$nodes[$node] = preg_replace('/^\/\*\*\*(.*?)\*.*?$/', '$1', preg_replace("/\s/", '', $comment));
if (stripos($nodes[$node], '@') !== false) $nodes[$node] = '';
}
}
return $nodes;
}
/** /**
* 获取节点列表 * 获取节点列表
* @param string $dir 控制器根路径 * @param string $dir 控制器根路径
@ -40,16 +98,15 @@ class Node
*/ */
public static function getTree($dir, $nodes = []) public static function getTree($dir, $nodes = [])
{ {
$ignore = ['initialize', 'success', 'error', 'redirect', 'fetch', 'assign', 'callback'];
foreach (self::scanDir($dir) as $file) { foreach (self::scanDir($dir) as $file) {
list($matches, $filename) = [[], str_replace(DIRECTORY_SEPARATOR, '/', $file)]; list($matches, $filename) = [[], str_replace(DIRECTORY_SEPARATOR, '/', $file)];
if (!preg_match('|/(\w+)/controller/(.+)|', $filename, $matches)) continue; if (!preg_match('|/(\w+)/controller/(.+)|', $filename, $matches)) continue;
$className = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4)); $classname = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4));
if (class_exists($className)) foreach (get_class_methods($className) as $funcName) { if (class_exists($classname)) foreach (get_class_methods($classname) as $function) {
if (stripos($funcName, '_') === 0 || in_array($funcName, $ignore)) continue; if (stripos($function, '_') === 0 || in_array($function, self::$ignore)) continue;
$controller = str_replace('/', '.', substr($matches[2], 0, -4)); $controller = str_replace('/', '.', substr($matches[2], 0, -4));
if (stripos($controller, 'api.') !== false || stripos($controller, 'wap.') !== false) continue; if (stripos($controller, 'api.') !== false || stripos($controller, 'wap.') !== false) continue;
$nodes[] = self::parseString("{$matches[1]}/{$controller}") . '/' . strtolower($funcName); $nodes[] = self::parseString("{$matches[1]}/{$controller}") . '/' . strtolower($function);
} }
} }
return $nodes; return $nodes;