diff --git a/README.md b/README.md index 41d15189f..009690b2a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,32 @@ PHP 开发技术交流( QQ 群 513350915) * Gitee仓库地址:https://gitee.com/zoujingli/Think.Admin * 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` 暂停消息任务守护进程 + 特别感谢 -- |名称|版本|描述|链接| diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 196261b11..bc2940362 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -1,153 +1,154 @@ -title = '系统权限管理'; - $this->_query($this->table)->dateBetween('create_at')->like('title,desc')->equal('status')->order('sort asc,id desc')->page(); - } - - /** - * 权限授权节点 - * @return mixed - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function apply() - { - $this->title = '权限授权配置'; - $auth = $this->request->post('id', '0'); - switch (strtolower($this->request->post('action'))) { - case 'get': // 获取权限配置 - $nodes = \app\admin\service\Auth::get(); - $checked = Db::name('SystemAuthNode')->where(['auth' => $auth])->column('node'); - foreach ($nodes as &$node) $node['checked'] = in_array($node['node'], $checked); - $data = $this->_apply_filter(\library\tools\Data::arr2tree($nodes, 'node', 'pnode', '_sub_')); - return $this->success('获取权限配置成功!', $data); - case 'save': // 保存权限配置 - list($post, $data) = [$this->request->post(), []]; - foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) $data[] = ['auth' => $auth, 'node' => $node]; - Db::name('SystemAuthNode')->where(['auth' => $auth])->delete(); - Db::name('SystemAuthNode')->insertAll($data); - return $this->success('权限授权配置更新成功!'); - default: - return $this->_form($this->table, 'apply'); - } - } - - /** - * 节点数据拼装 - * @param array $nodes - * @param integer $level - * @return array - */ - 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); - } - return $nodes; - } - - /** - * 权限添加 - * @return array|string - */ - public function add() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 权限编辑 - * @return array|string - */ - public function edit() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 权限禁用 - */ - public function forbid() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '0']); - } - - /** - * 权限恢复 - */ - public function resume() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '1']); - } - - /** - * 权限删除 - */ - public function del() - { - $this->applyCsrfToken(); - $this->_delete($this->table); - } - - /** - * 删除结果处理 - * @param boolean $result - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - protected function _del_delete_result($result) - { - if ($result) { - $where = ['auth' => $this->request->post('id')]; - Db::name('SystemAuthNode')->where($where)->delete(); - $this->success("权限删除成功!", ''); - } else { - $this->error("权限删除失败,请稍候再试!"); - } - } - +title = '系统权限管理'; + $this->_query($this->table)->dateBetween('create_at')->like('title,desc')->equal('status')->order('sort asc,id desc')->page(); + } + + /** + * 权限授权节点 + * @return mixed + * @throws \ReflectionException + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function apply() + { + $this->title = '权限授权配置'; + $auth = $this->request->post('id', '0'); + switch (strtolower($this->request->post('action'))) { + case 'get': // 获取权限配置 + $nodes = \app\admin\service\Auth::get(); + $checked = Db::name('SystemAuthNode')->where(['auth' => $auth])->column('node'); + foreach ($nodes as &$node) $node['checked'] = in_array($node['node'], $checked); + $data = $this->_apply_filter(\library\tools\Data::arr2tree($nodes, 'node', 'pnode', '_sub_')); + return $this->success('获取权限配置成功!', $data); + case 'save': // 保存权限配置 + list($post, $data) = [$this->request->post(), []]; + foreach (isset($post['nodes']) ? $post['nodes'] : [] as $node) $data[] = ['auth' => $auth, 'node' => $node]; + Db::name('SystemAuthNode')->where(['auth' => $auth])->delete(); + Db::name('SystemAuthNode')->insertAll($data); + return $this->success('权限授权配置更新成功!'); + default: + return $this->_form($this->table, 'apply'); + } + } + + /** + * 节点数据拼装 + * @param array $nodes + * @param integer $level + * @return array + */ + 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); + } + return $nodes; + } + + /** + * 权限添加 + * @return array|string + */ + public function add() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 权限编辑 + * @return array|string + */ + public function edit() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 权限禁用 + */ + public function forbid() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '0']); + } + + /** + * 权限恢复 + */ + public function resume() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '1']); + } + + /** + * 权限删除 + */ + public function del() + { + $this->applyCsrfToken(); + $this->_delete($this->table); + } + + /** + * 删除结果处理 + * @param boolean $result + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + protected function _del_delete_result($result) + { + if ($result) { + $where = ['auth' => $this->request->post('id')]; + Db::name('SystemAuthNode')->where($where)->delete(); + $this->success("权限删除成功!", ''); + } else { + $this->error("权限删除失败,请稍候再试!"); + } + } + } \ No newline at end of file diff --git a/application/admin/controller/Config.php b/application/admin/controller/Config.php index dcccc4831..201aa5155 100644 --- a/application/admin/controller/Config.php +++ b/application/admin/controller/Config.php @@ -1,109 +1,109 @@ -applyCsrfToken(); - $this->title = '系统参数配置'; - if ($this->request->isGet()) return $this->fetch(); - foreach ($this->request->post() as $k => $v) sysconf($k, $v); - $this->success('系统参数配置保存成功!'); - } - - /** - * 文件存储配置 - * @return string - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function file() - { - $this->applyCsrfToken(); - if ($this->request->isGet()) { - $this->fetch('file', [ - 'title' => '文件存储配置', - 'point' => [ - 'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州', - 'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海', - 'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛', - 'oss-cn-beijing.aliyuncs.com' => '华北 2 北京', - 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口', - 'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特', - 'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳', - 'oss-cn-hongkong.aliyuncs.com' => '香港 1', - 'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷', - 'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚', - 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡', - 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼', - 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡', - 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达', - 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本', - 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买', - 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福', - 'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦', - 'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜', - ], - ]); - } else { - $post = $this->request->post(); - if (isset($post['storage_type']) && $post['storage_type'] === 'local') { - $exts = array_unique(explode(',', $post['storage_local_exts'])); - if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!'); - $post['storage_local_exts'] = join(',', $exts); - } - foreach ($post as $key => $value) sysconf($key, $value); - if (isset($post['storage_type']) && $post['storage_type'] === 'oss') { - try { - $local = sysconf('storage_oss_domain'); - $bucket = $this->request->post('storage_oss_bucket'); - $domain = \library\File::instance('oss')->setBucket($bucket); - if (empty($local) || stripos($local, '.aliyuncs.com') !== false) { - sysconf('storage_oss_domain', $domain); - } - $this->success('阿里云OSS存储动态配置成功!'); - } catch (\think\exception\HttpResponseException $exception) { - throw $exception; - } catch (\Exception $e) { - $this->error("阿里云OSS存储配置失效,{$e->getMessage()}"); - } - } else { - $this->success('文件存储配置保存成功!'); - } - } - } - +applyCsrfToken(); + $this->title = '系统参数配置'; + if ($this->request->isGet()) return $this->fetch(); + foreach ($this->request->post() as $k => $v) sysconf($k, $v); + $this->success('系统参数配置保存成功!'); + } + + /** + * 文件存储配置 + * @return string + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function file() + { + $this->applyCsrfToken(); + if ($this->request->isGet()) { + $this->fetch('file', [ + 'title' => '文件存储配置', + 'point' => [ + 'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州', + 'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海', + 'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛', + 'oss-cn-beijing.aliyuncs.com' => '华北 2 北京', + 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口', + 'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特', + 'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳', + 'oss-cn-hongkong.aliyuncs.com' => '香港 1', + 'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷', + 'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚', + 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡', + 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼', + 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡', + 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达', + 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本', + 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买', + 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福', + 'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦', + 'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜', + ], + ]); + } else { + $post = $this->request->post(); + if (isset($post['storage_type']) && $post['storage_type'] === 'local') { + $exts = array_unique(explode(',', $post['storage_local_exts'])); + if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!'); + $post['storage_local_exts'] = join(',', $exts); + } + foreach ($post as $key => $value) sysconf($key, $value); + if (isset($post['storage_type']) && $post['storage_type'] === 'oss') { + try { + $local = sysconf('storage_oss_domain'); + $bucket = $this->request->post('storage_oss_bucket'); + $domain = \library\File::instance('oss')->setBucket($bucket); + if (empty($local) || stripos($local, '.aliyuncs.com') !== false) { + sysconf('storage_oss_domain', $domain); + } + $this->success('阿里云OSS存储动态配置成功!'); + } catch (\think\exception\HttpResponseException $exception) { + throw $exception; + } catch (\Exception $e) { + $this->error("阿里云OSS存储配置失效,{$e->getMessage()}"); + } + } else { + $this->success('文件存储配置保存成功!'); + } + } + } + } \ No newline at end of file diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index ea6bff2ef..974a76210 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -1,167 +1,168 @@ -title = '系统管理后台'; - $this->menus = \app\admin\service\Auth::getAuthMenu(); - if (empty($this->menus) && !session('user.id')) { - $this->redirect('@admin/login'); - } else { - $this->fetch(); - } - } - - /** - * 后台环境信息 - * @return mixed - */ - public function main() - { - $this->title = '后台首页'; - $this->think_ver = \think\App::VERSION; - $this->mysql_ver = Db::query('select version() as ver')[0]['ver']; - $this->fetch(); - } - - /** - * 清理系统运行缓存 - */ - public function clearRuntime() - { - if (!\app\admin\service\Auth::isLogin()) { - $this->error('需要登录才能操作哦!'); - } - $this->list = [ - [ - '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()), - ], - ]; - $this->fetch('admin@index/command'); - } - - /** - * 压缩发布系统 - */ - public function buildOptimize() - { - if (!\app\admin\service\Auth::isLogin()) { - $this->error('需要登录才能操作哦!'); - } - $this->list = [ - [ - 'title' => 'Build route cache', - 'message' => nl2br(Console::call('optimize:route')->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' => 'Build config and common file cache', - 'message' => nl2br(Console::call('optimize:config')->fetch()), - ], - ]; - $this->fetch('admin@index/command'); - } - - /** - * 修改密码 - * @param integer $id - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException - */ - public function pass($id) - { - $this->applyCsrfToken(); - if (intval($id) !== intval(session('user.id'))) { - $this->error('只能修改当前用户的密码!'); - } - if ($this->request->isGet()) { - $this->verify = true; - $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]); - } else { - $data = $this->_input([ - 'password' => $this->request->post('password'), - 'repassword' => $this->request->post('repassword'), - 'oldpassword' => $this->request->post('oldpassword'), - ], [ - 'oldpassword' => 'require', - 'password' => 'require|min:4', - 'repassword' => 'require|confirm:password', - ], [ - 'oldpassword.require' => '旧密码不能为空!', - 'password.require' => '登录密码不能为空!', - 'password.min' => '登录密码长度不能少于4位有效字符!', - 'repassword.require' => '重复密码不能为空!', - 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!', - ]); - $user = Db::name('SystemUser')->where(['id' => $id])->find(); - if (md5($data['oldpassword']) !== $user['password']) { - $this->error('旧密码验证失败,请重新输入!'); - } - $result = \app\admin\service\Auth::checkPassword($data['password']); - if (empty($result['code'])) $this->error($result['msg']); - if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) { - $this->success('密码修改成功,下次请使用新密码登录!', ''); - } else { - $this->error('密码修改失败,请稍候再试!'); - } - } - } - - /** - * 修改用户资料 - * @param integer $id 会员ID - */ - public function info($id = 0) - { - $this->applyCsrfToken(); - if (intval($id) === intval(session('user.id'))) { - $this->_form('SystemUser', 'user/form', 'id', [], ['id' => $id]); - } else { - $this->error('只能修改登录用户的资料!'); - } - } - +title = '系统管理后台'; + $this->menus = \app\admin\service\Auth::getAuthMenu(); + if (empty($this->menus) && !session('user.id')) { + $this->redirect('@admin/login'); + } else { + $this->fetch(); + } + } + + /** + * 后台环境信息 + * @return mixed + */ + public function main() + { + $this->title = '后台首页'; + $this->think_ver = \think\App::VERSION; + $this->mysql_ver = Db::query('select version() as ver')[0]['ver']; + $this->fetch(); + } + + /** + * 清理系统运行缓存 + */ + public function clearRuntime() + { + if (!\app\admin\service\Auth::isLogin()) { + $this->error('需要登录才能操作哦!'); + } + $this->list = [ + [ + '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()), + ], + ]; + $this->fetch('admin@index/command'); + } + + /** + * 压缩发布系统 + */ + public function buildOptimize() + { + if (!\app\admin\service\Auth::isLogin()) { + $this->error('需要登录才能操作哦!'); + } + $this->list = [ + [ + 'title' => 'Build route cache', + 'message' => nl2br(Console::call('optimize:route')->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' => 'Build config and common file cache', + 'message' => nl2br(Console::call('optimize:config')->fetch()), + ], + ]; + $this->fetch('admin@index/command'); + } + + /** + * 修改密码 + * @param integer $id + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function pass($id) + { + $this->applyCsrfToken(); + if (intval($id) !== intval(session('user.id'))) { + $this->error('只能修改当前用户的密码!'); + } + if ($this->request->isGet()) { + $this->verify = true; + $this->_form('SystemUser', 'admin@user/pass', 'id', [], ['id' => $id]); + } else { + $data = $this->_input([ + 'password' => $this->request->post('password'), + 'repassword' => $this->request->post('repassword'), + 'oldpassword' => $this->request->post('oldpassword'), + ], [ + 'oldpassword' => 'require', + 'password' => 'require|min:4', + 'repassword' => 'require|confirm:password', + ], [ + 'oldpassword.require' => '旧密码不能为空!', + 'password.require' => '登录密码不能为空!', + 'password.min' => '登录密码长度不能少于4位有效字符!', + 'repassword.require' => '重复密码不能为空!', + 'repassword.confirm' => '重复密码与登录密码不匹配,请重新输入!', + ]); + $user = Db::name('SystemUser')->where(['id' => $id])->find(); + if (md5($data['oldpassword']) !== $user['password']) { + $this->error('旧密码验证失败,请重新输入!'); + } + $result = \app\admin\service\Auth::checkPassword($data['password']); + if (empty($result['code'])) $this->error($result['msg']); + if (Data::save('SystemUser', ['id' => $user['id'], 'password' => md5($data['password'])])) { + $this->success('密码修改成功,下次请使用新密码登录!', ''); + } else { + $this->error('密码修改失败,请稍候再试!'); + } + } + } + + /** + * 修改用户资料 + * @param integer $id 会员ID + */ + public function info($id = 0) + { + $this->applyCsrfToken(); + if (intval($id) === intval(session('user.id'))) { + $this->_form('SystemUser', 'user/form', 'id', [], ['id' => $id]); + } else { + $this->error('只能修改登录用户的资料!'); + } + } + } \ No newline at end of file diff --git a/application/admin/controller/Log.php b/application/admin/controller/Log.php index f29c10d50..47b6c38ec 100644 --- a/application/admin/controller/Log.php +++ b/application/admin/controller/Log.php @@ -1,70 +1,70 @@ -title = '系统操作日志'; - $this->_query($this->table)->like('action,node,content,username,geoip')->dateBetween('create_at')->order('id desc')->page(); - } - - /** - * 列表数据处理 - * @param array $data - * @throws \Exception - */ - protected function _index_page_filter(&$data) - { - $ip = new \Ip2Region(); - foreach ($data as &$vo) { - $result = $ip->btreeSearch($vo['geoip']); - $vo['isp'] = isset($result['region']) ? $result['region'] : ''; - $vo['isp'] = str_replace(['内网IP', '0', '|'], '', $vo['isp']); - } - } - - /** - * 日志删除操作 - */ - public function del() - { - $this->applyCsrfToken(); - $this->_delete($this->table); - } - +title = '系统操作日志'; + $this->_query($this->table)->like('action,node,content,username,geoip')->dateBetween('create_at')->order('id desc')->page(); + } + + /** + * 列表数据处理 + * @param array $data + * @throws \Exception + */ + protected function _index_page_filter(&$data) + { + $ip = new \Ip2Region(); + foreach ($data as &$vo) { + $result = $ip->btreeSearch($vo['geoip']); + $vo['isp'] = isset($result['region']) ? $result['region'] : ''; + $vo['isp'] = str_replace(['内网IP', '0', '|'], '', $vo['isp']); + } + } + + /** + * 日志删除操作 + */ + public function del() + { + $this->applyCsrfToken(); + $this->_delete($this->table); + } + } \ No newline at end of file diff --git a/application/admin/controller/Login.php b/application/admin/controller/Login.php index e8565db93..da735da62 100644 --- a/application/admin/controller/Login.php +++ b/application/admin/controller/Login.php @@ -1,113 +1,113 @@ -applyCsrfToken(); - if ($this->request->isGet()) { - session('loginskey', $this->skey = session('loginskey') ? session('loginskey') : uniqid()); - $this->fetch(); - } else { - $data = $this->_input([ - 'username' => $this->request->post('username'), - 'password' => $this->request->post('password'), - ], [ - 'username' => 'require|min:4', - 'password' => 'require|min:4', - ], [ - 'username.require' => '登录账号不能为空!', - 'password.require' => '登录密码不能为空!', - 'username.min' => '登录账号长度不能少于4位有效字符!', - 'password.min' => '登录密码长度不能少于4位有效字符!', - ]); - // 用户信息验证 - $map = ['is_deleted' => '0', 'username' => $data['username']]; - $user = Db::name('SystemUser')->where($map)->find(); - if (empty($user)) $this->error('登录账号或密码错误,请重新输入!'); - if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!'); - // 账号锁定消息 - $cache = cache('user_login_' . $user['username']); - if (is_array($cache) && !empty($cache['number']) && !empty($cache['time'])) { - if ($cache['number'] >= 10 && ($diff = $cache['time'] + 3600 - time()) > 0) { - list($m, $s, $info) = [floor($diff / 60), floor($diff % 60), '']; - if ($m > 0) $info = "{$m} 分"; - $this->error("抱歉,该账号已经被锁定!

连续 10 次登录错误,请 {$info} {$s} 秒后再登录!

"); - } - } - if (md5($user['password'] . session('loginskey')) !== $data['password']) { - if (empty($cache) || empty($cache['time']) || empty($cache['number']) || $cache['time'] + 3600 < time()) { - $cache = ['time' => time(), 'number' => 1, 'geoip' => $this->request->ip()]; - } elseif ($cache['number'] + 1 <= 10) { - $cache = ['time' => time(), 'number' => $cache['number'] + 1, 'geoip' => $this->request->ip()]; - } - cache('user_login_' . $user['username'], $cache); - if (($diff = 10 - $cache['number']) > 0) { - $this->error("登录账号或密码错误!

还有 {$diff} 次尝试机会,将锁定一小时内禁止登录!

"); - } else { - _syslog('系统管理', "账号{$user['username']}连续10次登录密码错误,请注意账号安全!"); - $this->error("登录账号或密码错误!

尝试次数达到上限,锁定一小时内禁止登录!

"); - } - } - // 登录成功并更新账号 - cache('user_login_' . $user['username'], null); - Db::name('SystemUser')->where(['id' => $user['id']])->update([ - 'login_at' => Db::raw('now()'), - 'login_ip' => $this->request->ip(), - 'login_num' => Db::raw('login_num+1'), - ]); - session('user', $user); - session('loginskey', null); - empty($user['authorize']) || \app\admin\service\Auth::applyNode(); - _syslog('系统管理', '用户登录系统成功'); - $this->success('登录成功,正在进入系统...', url('@admin')); - } - } - - /** - * 退出登录 - */ - public function out() - { - if ($_SESSION) $_SESSION = []; - [session_unset(), session_destroy()]; - $this->success('退出登录成功!', url('@admin/login')); - } - +applyCsrfToken(); + if ($this->request->isGet()) { + session('loginskey', $this->skey = session('loginskey') ? session('loginskey') : uniqid()); + $this->fetch(); + } else { + $data = $this->_input([ + 'username' => $this->request->post('username'), + 'password' => $this->request->post('password'), + ], [ + 'username' => 'require|min:4', + 'password' => 'require|min:4', + ], [ + 'username.require' => '登录账号不能为空!', + 'password.require' => '登录密码不能为空!', + 'username.min' => '登录账号长度不能少于4位有效字符!', + 'password.min' => '登录密码长度不能少于4位有效字符!', + ]); + // 用户信息验证 + $map = ['is_deleted' => '0', 'username' => $data['username']]; + $user = Db::name('SystemUser')->where($map)->find(); + if (empty($user)) $this->error('登录账号或密码错误,请重新输入!'); + if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!'); + // 账号锁定消息 + $cache = cache('user_login_' . $user['username']); + if (is_array($cache) && !empty($cache['number']) && !empty($cache['time'])) { + if ($cache['number'] >= 10 && ($diff = $cache['time'] + 3600 - time()) > 0) { + list($m, $s, $info) = [floor($diff / 60), floor($diff % 60), '']; + if ($m > 0) $info = "{$m} 分"; + $this->error("抱歉,该账号已经被锁定!

连续 10 次登录错误,请 {$info} {$s} 秒后再登录!

"); + } + } + if (md5($user['password'] . session('loginskey')) !== $data['password']) { + if (empty($cache) || empty($cache['time']) || empty($cache['number']) || $cache['time'] + 3600 < time()) { + $cache = ['time' => time(), 'number' => 1, 'geoip' => $this->request->ip()]; + } elseif ($cache['number'] + 1 <= 10) { + $cache = ['time' => time(), 'number' => $cache['number'] + 1, 'geoip' => $this->request->ip()]; + } + cache('user_login_' . $user['username'], $cache); + if (($diff = 10 - $cache['number']) > 0) { + $this->error("登录账号或密码错误!

还有 {$diff} 次尝试机会,将锁定一小时内禁止登录!

"); + } else { + _syslog('系统管理', "账号{$user['username']}连续10次登录密码错误,请注意账号安全!"); + $this->error("登录账号或密码错误!

尝试次数达到上限,锁定一小时内禁止登录!

"); + } + } + // 登录成功并更新账号 + cache('user_login_' . $user['username'], null); + Db::name('SystemUser')->where(['id' => $user['id']])->update([ + 'login_at' => Db::raw('now()'), + 'login_ip' => $this->request->ip(), + 'login_num' => Db::raw('login_num+1'), + ]); + session('user', $user); + session('loginskey', null); + empty($user['authorize']) || \app\admin\service\Auth::applyNode(); + _syslog('系统管理', '用户登录系统成功'); + $this->success('登录成功,正在进入系统...', url('@admin')); + } + } + + /** + * 退出登录 + */ + public function out() + { + if ($_SESSION) $_SESSION = []; + [session_unset(), session_destroy()]; + $this->success('退出登录成功!', url('@admin/login')); + } + } \ No newline at end of file diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index e928cd66a..4309db22e 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -1,133 +1,134 @@ -title = '系统菜单管理'; - $this->_page($this->table, false); - } - - /** - * 列表数据处理 - * @param array $data - */ - protected function _index_page_filter(&$data) - { - foreach ($data as &$vo) { - if ($vo['url'] !== '#') { - $vo['url'] = url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}"); - } - $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id'])); - } - $data = Data::arr2table($data); - } - - /** - * 编辑菜单 - */ - public function edit() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 添加菜单 - */ - public function add() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 表单数据 - * @param array $vo - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - */ - protected function _form_filter(&$vo) - { - 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 = Data::arr2table($_menus); - foreach ($menus as $key => &$menu) if (substr_count($menu['path'], '-') > 3) 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'); - // 读取系统功能节点 - $nodes = \app\admin\service\Auth::get(); - foreach ($nodes as $key => $node) { - 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)]; - } - } - - /** - * 启用菜单 - */ - public function resume() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '1']); - } - - /** - * 禁用菜单 - */ - public function forbid() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '0']); - } - - /** - * 删除菜单 - */ - public function del() - { - $this->applyCsrfToken(); - $this->_delete($this->table); - } - +title = '系统菜单管理'; + $this->_page($this->table, false); + } + + /** + * 列表数据处理 + * @param array $data + */ + protected function _index_page_filter(&$data) + { + foreach ($data as &$vo) { + if ($vo['url'] !== '#') { + $vo['url'] = url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}"); + } + $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id'])); + } + $data = Data::arr2table($data); + } + + /** + * 编辑菜单 + */ + public function edit() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 添加菜单 + */ + public function add() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 表单数据处理 + * @param array $vo + * @throws \ReflectionException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + protected function _form_filter(&$vo) + { + 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 = Data::arr2table($_menus); + foreach ($menus as $key => &$menu) if (substr_count($menu['path'], '-') > 3) 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'); + // 读取系统功能节点 + $nodes = \app\admin\service\Auth::get(); + foreach ($nodes as $key => $node) { + 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)]; + } + } + + /** + * 启用菜单 + */ + public function resume() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '1']); + } + + /** + * 禁用菜单 + */ + public function forbid() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '0']); + } + + /** + * 删除菜单 + */ + public function del() + { + $this->applyCsrfToken(); + $this->_delete($this->table); + } + } \ No newline at end of file diff --git a/application/admin/controller/Message.php b/application/admin/controller/Message.php index 97b1bb531..608eca3d3 100644 --- a/application/admin/controller/Message.php +++ b/application/admin/controller/Message.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller; diff --git a/application/admin/controller/Node.php b/application/admin/controller/Node.php index f44951989..781827037 100644 --- a/application/admin/controller/Node.php +++ b/application/admin/controller/Node.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller; @@ -33,7 +33,7 @@ class Node extends Controller /** * 显示节点列表 - * @return mixed + * @throws \ReflectionException */ public function index() { @@ -51,6 +51,7 @@ class Node extends Controller /** * 清理无效的节点数据 + * @throws \ReflectionException * @throws \think\Exception * @throws \think\exception\PDOException */ diff --git a/application/admin/controller/Queue.php b/application/admin/controller/Queue.php index cb8034aea..413d56e2c 100644 --- a/application/admin/controller/Queue.php +++ b/application/admin/controller/Queue.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller; diff --git a/application/admin/controller/User.php b/application/admin/controller/User.php index 11be336c6..9fb41e2e7 100644 --- a/application/admin/controller/User.php +++ b/application/admin/controller/User.php @@ -1,163 +1,163 @@ - - * @date 2017/02/15 18:12 - */ -class User extends Controller -{ - - /** - * 指定当前数据表 - * @var string - */ - public $table = 'SystemUser'; - - /** - * 用户列表 - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException - */ - public function index() - { - $this->title = '系统用户管理'; - $this->_query($this->table)->where(['is_deleted' => '0'])->like('username,phone,mail')->dateBetween('login_at')->equal('status')->page(); - } - - /** - * 授权管理 - * @return mixed - */ - public function auth() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'auth'); - } - - /** - * 用户添加 - * @return mixed - */ - public function add() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 用户编辑 - * @return mixed - */ - public function edit() - { - $this->applyCsrfToken(); - $this->_form($this->table, 'form'); - } - - /** - * 用户密码修改 - * @return mixed - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function pass() - { - $this->applyCsrfToken(); - if ($this->request->isGet()) { - $this->verify = false; - $this->_form($this->table, 'pass'); - } else { - $post = $this->request->post(); - if ($post['password'] !== $post['repassword']) { - $this->error('两次输入的密码不一致!'); - } - $result = \app\admin\service\Auth::checkPassword($post['password']); - if (empty($result['code'])) $this->error($result['msg']); - $data = ['id' => $post['id'], 'password' => md5($post['password'])]; - if (Data::save($this->table, $data, 'id')) { - $this->success('密码修改成功,下次请使用新密码登录!', ''); - } else { - $this->error('密码修改失败,请稍候再试!'); - } - } - } - - /** - * 表单数据默认处理 - * @param array $data - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - */ - public function _form_filter(&$data) - { - if ($this->request->isPost()) { - $data['authorize'] = (isset($data['authorize']) && is_array($data['authorize'])) ? join(',', $data['authorize']) : ''; - if (isset($data['id'])) unset($data['username']); - elseif (Db::name($this->table)->where(['username' => $data['username']])->count() > 0) { - $this->error('用户账号已经存在,请使用其它账号!'); - } - } else { - $data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : ''); - $this->assign('authorizes', Db::name('SystemAuth')->where(['status' => '1'])->select()); - } - } - - /** - * 删除用户 - */ - public function del() - { - if (in_array('10000', explode(',', $this->request->post('id')))) { - $this->error('系统超级账号禁止删除!'); - } - $this->applyCsrfToken(); - $this->_delete($this->table); - } - - /** - * 用户禁用 - */ - public function forbid() - { - if (in_array('10000', explode(',', $this->request->post('id')))) { - $this->error('系统超级账号禁止操作!'); - } - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '0']); - } - - /** - * 用户禁用 - */ - public function resume() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '1']); - } - -} + + * @date 2017/02/15 18:12 + */ +class User extends Controller +{ + + /** + * 指定当前数据表 + * @var string + */ + public $table = 'SystemUser'; + + /** + * 用户列表 + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function index() + { + $this->title = '系统用户管理'; + $this->_query($this->table)->where(['is_deleted' => '0'])->like('username,phone,mail')->dateBetween('login_at')->equal('status')->page(); + } + + /** + * 授权管理 + * @return mixed + */ + public function auth() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'auth'); + } + + /** + * 用户添加 + * @return mixed + */ + public function add() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 用户编辑 + * @return mixed + */ + public function edit() + { + $this->applyCsrfToken(); + $this->_form($this->table, 'form'); + } + + /** + * 用户密码修改 + * @return mixed + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function pass() + { + $this->applyCsrfToken(); + if ($this->request->isGet()) { + $this->verify = false; + $this->_form($this->table, 'pass'); + } else { + $post = $this->request->post(); + if ($post['password'] !== $post['repassword']) { + $this->error('两次输入的密码不一致!'); + } + $result = \app\admin\service\Auth::checkPassword($post['password']); + if (empty($result['code'])) $this->error($result['msg']); + $data = ['id' => $post['id'], 'password' => md5($post['password'])]; + if (Data::save($this->table, $data, 'id')) { + $this->success('密码修改成功,下次请使用新密码登录!', ''); + } else { + $this->error('密码修改失败,请稍候再试!'); + } + } + } + + /** + * 表单数据默认处理 + * @param array $data + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function _form_filter(&$data) + { + if ($this->request->isPost()) { + $data['authorize'] = (isset($data['authorize']) && is_array($data['authorize'])) ? join(',', $data['authorize']) : ''; + if (isset($data['id'])) unset($data['username']); + elseif (Db::name($this->table)->where(['username' => $data['username']])->count() > 0) { + $this->error('用户账号已经存在,请使用其它账号!'); + } + } else { + $data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : ''); + $this->assign('authorizes', Db::name('SystemAuth')->where(['status' => '1'])->select()); + } + } + + /** + * 删除用户 + */ + public function del() + { + if (in_array('10000', explode(',', $this->request->post('id')))) { + $this->error('系统超级账号禁止删除!'); + } + $this->applyCsrfToken(); + $this->_delete($this->table); + } + + /** + * 用户禁用 + */ + public function forbid() + { + if (in_array('10000', explode(',', $this->request->post('id')))) { + $this->error('系统超级账号禁止操作!'); + } + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '0']); + } + + /** + * 用户禁用 + */ + public function resume() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '1']); + } + +} diff --git a/application/admin/controller/api/Message.php b/application/admin/controller/api/Message.php index 6541539cf..81282b875 100644 --- a/application/admin/controller/api/Message.php +++ b/application/admin/controller/api/Message.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller\api; diff --git a/application/admin/controller/api/Plugs.php b/application/admin/controller/api/Plugs.php index 7dda37fd3..f61a600b8 100644 --- a/application/admin/controller/api/Plugs.php +++ b/application/admin/controller/api/Plugs.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller\api; diff --git a/application/admin/controller/api/Update.php b/application/admin/controller/api/Update.php index 45868bc7a..7de7557b7 100644 --- a/application/admin/controller/api/Update.php +++ b/application/admin/controller/api/Update.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\controller\api; diff --git a/application/admin/queue/JobsBase.php b/application/admin/queue/JobsBase.php index 658eb53cd..5045c2caf 100644 --- a/application/admin/queue/JobsBase.php +++ b/application/admin/queue/JobsBase.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\queue; diff --git a/application/admin/service/Auth.php b/application/admin/service/Auth.php index 94ecbab11..e103b4465 100644 --- a/application/admin/service/Auth.php +++ b/application/admin/service/Auth.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\service; @@ -30,7 +30,7 @@ class Auth * 权限检查中间件入口 * @param \think\Request $request * @param \Closure $next - * @return mixed|\think\response\Json|\think\response\Redirect + * @return mixed * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException @@ -72,18 +72,19 @@ class Auth * 获取系统代码节点 * @param array $nodes * @return array + * @throws \ReflectionException */ 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'); - 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; $tmp = explode('/', $thr); 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[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => '', '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[$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' => $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]; return $nodes; @@ -124,7 +125,7 @@ class Auth /** * 应用用户权限节点 - * @return bool + * @return boolean * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException @@ -153,6 +154,7 @@ class Auth /** * 获取授权后的菜单 * @return array + * @throws \ReflectionException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException diff --git a/application/admin/service/Log.php b/application/admin/service/Log.php index 66785be4e..2dbdbea90 100644 --- a/application/admin/service/Log.php +++ b/application/admin/service/Log.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\service; diff --git a/application/admin/service/Message.php b/application/admin/service/Message.php index 9a0d41eef..2bb5a64b8 100644 --- a/application/admin/service/Message.php +++ b/application/admin/service/Message.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\service; diff --git a/application/admin/service/Queue.php b/application/admin/service/Queue.php index 4dd5466a0..1ebd7b1b4 100644 --- a/application/admin/service/Queue.php +++ b/application/admin/service/Queue.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\admin\service; diff --git a/application/admin/sys.php b/application/admin/sys.php index 9d8656b3c..9425bddef 100644 --- a/application/admin/sys.php +++ b/application/admin/sys.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- if (!function_exists('auth')) { diff --git a/application/admin/view/index/main.html b/application/admin/view/index/main.html index aa6e6c171..c2c258b69 100644 --- a/application/admin/view/index/main.html +++ b/application/admin/view/index/main.html @@ -16,13 +16,13 @@ - framework 版本 + 应用组件版本 {:sysconf('app_version')} 产品名称 framework - ThinkPHP 版本 + ThinkAdmin 版本 {$think_ver} 在线体验 @@ -44,8 +44,8 @@ {:php_sapi_name()} 项目地址 - - https://github.com/zoujingli/ThinkAdmin + + https://github.com/zoujingli/framework @@ -54,8 +54,8 @@ {$mysql_ver} BUG反馈 - - https://github.com/zoujingli/ThinkAdmin/issues + + https://github.com/zoujingli/framework/issues @@ -75,7 +75,7 @@ POST大小限制 {:ini_get('post_max_size')} 办公地址 - 广州市天河区东圃一横路东泷商贸中心C座316 + 广州市天河区东圃一横路东泷商贸中心G02 diff --git a/application/service/controller/Config.php b/application/service/controller/Config.php index c895605c1..c56942b18 100644 --- a/application/service/controller/Config.php +++ b/application/service/controller/Config.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\controller; diff --git a/application/service/controller/Index.php b/application/service/controller/Index.php index 4d77f0efb..10e95c082 100644 --- a/application/service/controller/Index.php +++ b/application/service/controller/Index.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\controller; diff --git a/application/service/controller/api/Client.php b/application/service/controller/api/Client.php index fc7e317c0..483f6d363 100644 --- a/application/service/controller/api/Client.php +++ b/application/service/controller/api/Client.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\controller\api; diff --git a/application/service/controller/api/Push.php b/application/service/controller/api/Push.php index 9151fed0e..7fdbd9efc 100644 --- a/application/service/controller/api/Push.php +++ b/application/service/controller/api/Push.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\controller\api; diff --git a/application/service/handler/Publish.php b/application/service/handler/Publish.php index 2925518e0..88bc5460c 100644 --- a/application/service/handler/Publish.php +++ b/application/service/handler/Publish.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\handler; diff --git a/application/service/handler/Receive.php b/application/service/handler/Receive.php index 3079f5896..77f6fe979 100644 --- a/application/service/handler/Receive.php +++ b/application/service/handler/Receive.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\handler; diff --git a/application/service/handler/Wechat.php b/application/service/handler/Wechat.php index 796f0c34c..da4875fbb 100644 --- a/application/service/handler/Wechat.php +++ b/application/service/handler/Wechat.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\handler; diff --git a/application/service/logic/Build.php b/application/service/logic/Build.php index 6e095fa61..578d5f40a 100644 --- a/application/service/logic/Build.php +++ b/application/service/logic/Build.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\logic; diff --git a/application/service/logic/Wechat.php b/application/service/logic/Wechat.php index 4f595a416..b4df49d82 100644 --- a/application/service/logic/Wechat.php +++ b/application/service/logic/Wechat.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\service\logic; diff --git a/application/wechat/command/Fans.php b/application/wechat/command/Fans.php index 4fa5b1317..cb72554c4 100644 --- a/application/wechat/command/Fans.php +++ b/application/wechat/command/Fans.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\command; diff --git a/application/wechat/command/fans/FansAll.php b/application/wechat/command/fans/FansAll.php index 08e1d376d..0e79cf31d 100644 --- a/application/wechat/command/fans/FansAll.php +++ b/application/wechat/command/fans/FansAll.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\command\fans; diff --git a/application/wechat/command/fans/FansBlack.php b/application/wechat/command/fans/FansBlack.php index a92a76946..f5ffc0ba5 100644 --- a/application/wechat/command/fans/FansBlack.php +++ b/application/wechat/command/fans/FansBlack.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\command\fans; diff --git a/application/wechat/command/fans/FansList.php b/application/wechat/command/fans/FansList.php index fdc2f3e24..c404b4d9b 100644 --- a/application/wechat/command/fans/FansList.php +++ b/application/wechat/command/fans/FansList.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\command\fans; diff --git a/application/wechat/command/fans/FansTags.php b/application/wechat/command/fans/FansTags.php index 9f6130548..c0664642b 100644 --- a/application/wechat/command/fans/FansTags.php +++ b/application/wechat/command/fans/FansTags.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\command\fans; diff --git a/application/wechat/controller/Config.php b/application/wechat/controller/Config.php index 548f09e29..7225d8edd 100644 --- a/application/wechat/controller/Config.php +++ b/application/wechat/controller/Config.php @@ -1,98 +1,98 @@ -applyCsrfToken(); - $this->thrNotify = url('@wechat/api.push', '', false, true); - if ($this->request->isGet()) { - $this->title = '公众号授权绑定'; - if (!($this->geoip = cache('mygeoip'))) { - cache('mygeoip', $this->geoip = gethostbyname($this->request->host()), 360); - } - $code = encode(url('@admin', '', true, true) . '#' . $this->request->url()); - $this->authurl = config('wechat.service_url') . "/service/api.push/auth/{$code}"; - if ($this->request->has('appid', 'get', true) && $this->request->has('appkey', 'get', true)) { - sysconf('wechat_type', 'thr'); - sysconf('wechat_thr_appid', input('appid')); - sysconf('wechat_thr_appkey', input('appkey')); - Wechat::wechat()->setApiNotifyUri($this->thrNotify); - } - try { - $this->wechat = Wechat::wechat()->getConfig(); - } catch (\Exception $e) { - $this->wechat = []; - } - return $this->fetch(); - } - foreach ($this->request->post() as $k => $v) sysconf($k, $v); - if ($this->request->post('wechat_type') === 'thr') { - Wechat::wechat()->setApiNotifyUri($this->thrNotify); - } - $this->success('公众号参数获取成功!', url('@admin') . '#' . url('wechat/config/options')); - } - - /** - * 公众号支付配置 - * @return mixed - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function payment() - { - $this->applyCsrfToken(); - $this->title = '公众号支付配置'; - if ($this->request->isGet()) { - $file = File::instance('local'); - $this->wechat_mch_ssl_cer = sysconf('wechat_mch_ssl_cer'); - $this->wechat_mch_ssl_key = sysconf('wechat_mch_ssl_key'); - $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_key, true)) $this->wechat_mch_ssl_key = ''; - if (!$file->has($this->wechat_mch_ssl_p12, true)) $this->wechat_mch_ssl_p12 = ''; - return $this->fetch(); - } - if ($this->request->post('wechat_mch_ssl_type') === 'p12') { - if (!($sslp12 = $this->request->post('wechat_mch_ssl_p12'))) { - $mchid = $this->request->post('wechat_mch_id'); - $content = File::instance('local')->get($sslp12, true); - if (!openssl_pkcs12_read($content, $certs, $mchid)) { - $this->error('商户MCH_ID与支付P12证书不匹配!'); - } - } - } - foreach ($this->request->post() as $k => $v) sysconf($k, $v); - $this->success('公众号支付配置成功!'); - } - -} +applyCsrfToken(); + $this->thrNotify = url('@wechat/api.push', '', false, true); + if ($this->request->isGet()) { + $this->title = '公众号授权绑定'; + if (!($this->geoip = cache('mygeoip'))) { + cache('mygeoip', $this->geoip = gethostbyname($this->request->host()), 360); + } + $code = encode(url('@admin', '', true, true) . '#' . $this->request->url()); + $this->authurl = config('wechat.service_url') . "/service/api.push/auth/{$code}"; + if ($this->request->has('appid', 'get', true) && $this->request->has('appkey', 'get', true)) { + sysconf('wechat_type', 'thr'); + sysconf('wechat_thr_appid', input('appid')); + sysconf('wechat_thr_appkey', input('appkey')); + Wechat::wechat()->setApiNotifyUri($this->thrNotify); + } + try { + $this->wechat = Wechat::wechat()->getConfig(); + } catch (\Exception $e) { + $this->wechat = []; + } + return $this->fetch(); + } + foreach ($this->request->post() as $k => $v) sysconf($k, $v); + if ($this->request->post('wechat_type') === 'thr') { + Wechat::wechat()->setApiNotifyUri($this->thrNotify); + } + $this->success('公众号参数获取成功!', url('@admin') . '#' . url('wechat/config/options')); + } + + /** + * 公众号支付配置 + * @return mixed + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function payment() + { + $this->applyCsrfToken(); + $this->title = '公众号支付配置'; + if ($this->request->isGet()) { + $file = File::instance('local'); + $this->wechat_mch_ssl_cer = sysconf('wechat_mch_ssl_cer'); + $this->wechat_mch_ssl_key = sysconf('wechat_mch_ssl_key'); + $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_key, true)) $this->wechat_mch_ssl_key = ''; + if (!$file->has($this->wechat_mch_ssl_p12, true)) $this->wechat_mch_ssl_p12 = ''; + return $this->fetch(); + } + if ($this->request->post('wechat_mch_ssl_type') === 'p12') { + if (!($sslp12 = $this->request->post('wechat_mch_ssl_p12'))) { + $mchid = $this->request->post('wechat_mch_id'); + $content = File::instance('local')->get($sslp12, true); + if (!openssl_pkcs12_read($content, $certs, $mchid)) { + $this->error('商户MCH_ID与支付P12证书不匹配!'); + } + } + } + foreach ($this->request->post() as $k => $v) sysconf($k, $v); + $this->success('公众号支付配置成功!'); + } + +} diff --git a/application/wechat/controller/Fans.php b/application/wechat/controller/Fans.php index f1cd2fbba..953d6694e 100644 --- a/application/wechat/controller/Fans.php +++ b/application/wechat/controller/Fans.php @@ -1,132 +1,132 @@ -title = '微信粉丝管理'; - $this->_query($this->table)->like('nickname')->equal('subscribe,is_black') - ->dateBetween('subscribe_at')->order('subscribe_time desc')->page(); - } - - /** - * 微信粉丝列表处理 - * @param array $data - */ - protected function _index_page_filter(array &$data) - { - $tags = Db::name('WechatFansTags')->column('id,name'); - foreach ($data as &$user) { - $user['tags'] = []; - foreach (explode(',', $user['tagid_list']) as $tagid) { - if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid]; - } - foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) { - if (isset($user[$k])) $user[$k] = emoji_decode($user[$k]); - } - } - } - - /** - * 批量拉黑粉丝 - */ - public function setBlack() - { - $this->applyCsrfToken(); - try { - foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { - Wechat::WeChatUser()->batchBlackList($openids); - Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '1']); - } - $this->success('拉黑粉丝信息成功!'); - } catch (HttpResponseException $exception) { - throw $exception; - } catch (\Exception $e) { - $this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); - } - } - - /** - *批量取消拉黑粉丝 - */ - public function delBlack() - { - $this->applyCsrfToken(); - try { - foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { - Wechat::WeChatUser()->batchUnblackList($openids); - Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '0']); - } - $this->success('取消拉黑粉丝信息成功!'); - } catch (HttpResponseException $exception) { - throw $exception; - } catch (\Exception $e) { - $this->error("取消拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); - } - } - - /** - * 同步粉丝列表 - */ - public function sync() - { - try { - Queue::add('同步粉丝列表', Jobs::URI, 0, [], 0); - $this->success('创建同步粉丝任务成功,需要时间来完成。
请到系统任务管理查看进度!'); - } catch (HttpResponseException $exception) { - throw $exception; - } catch (\Exception $e) { - $this->error("创建同步粉丝任务失败,请稍候再试!
{$e->getMessage()}"); - } - } - - /** - * 删除粉丝 - */ - public function del() - { - $this->applyCsrfToken(); - $this->_delete($this->table); - } - +title = '微信粉丝管理'; + $this->_query($this->table)->like('nickname')->equal('subscribe,is_black') + ->dateBetween('subscribe_at')->order('subscribe_time desc')->page(); + } + + /** + * 微信粉丝列表处理 + * @param array $data + */ + protected function _index_page_filter(array &$data) + { + $tags = Db::name('WechatFansTags')->column('id,name'); + foreach ($data as &$user) { + $user['tags'] = []; + foreach (explode(',', $user['tagid_list']) as $tagid) { + if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid]; + } + foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) { + if (isset($user[$k])) $user[$k] = emoji_decode($user[$k]); + } + } + } + + /** + * 批量拉黑粉丝 + */ + public function setBlack() + { + $this->applyCsrfToken(); + try { + foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { + Wechat::WeChatUser()->batchBlackList($openids); + Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '1']); + } + $this->success('拉黑粉丝信息成功!'); + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $e) { + $this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); + } + } + + /** + *批量取消拉黑粉丝 + */ + public function delBlack() + { + $this->applyCsrfToken(); + try { + foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) { + Wechat::WeChatUser()->batchUnblackList($openids); + Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '0']); + } + $this->success('取消拉黑粉丝信息成功!'); + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $e) { + $this->error("取消拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}"); + } + } + + /** + * 同步粉丝列表 + */ + public function sync() + { + try { + Queue::add('同步粉丝列表', Jobs::URI, 0, [], 0); + $this->success('创建同步粉丝任务成功,需要时间来完成。
请到系统任务管理查看进度!'); + } catch (HttpResponseException $exception) { + throw $exception; + } catch (\Exception $e) { + $this->error("创建同步粉丝任务失败,请稍候再试!
{$e->getMessage()}"); + } + } + + /** + * 删除粉丝 + */ + public function del() + { + $this->applyCsrfToken(); + $this->_delete($this->table); + } + } \ No newline at end of file diff --git a/application/wechat/controller/Keys.php b/application/wechat/controller/Keys.php index ce8e9b58e..fcc6e9b4b 100644 --- a/application/wechat/controller/Keys.php +++ b/application/wechat/controller/Keys.php @@ -1,194 +1,194 @@ - '文字', 'news' => '图文', 'image' => '图片', 'music' => '音乐', - 'video' => '视频', 'voice' => '语音', 'customservice' => '转客服', - ]; - - /** - * 显示关键字列表 - * @return array|string - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException - */ - public function index() - { - // 关键字二维码生成 - if ($this->request->get('action') === 'qrc') { - try { - $wechat = Wechat::WeChatQrcode(); - $result = $wechat->create($this->request->get('keys', '')); - $this->success('生成二维码成功!', "javascript:$.previewImage('{$wechat->url($result['ticket'])}')"); - } catch (\think\exception\HttpResponseException $exception) { - throw $exception; - } catch (\Exception $e) { - $this->error("生成二维码失败,请稍候再试!
{$e->getMessage()}"); - } - } - // 关键字列表显示 - $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(); - } - - /** - * 列表数据处理 - * @param array $data - */ - protected function _index_page_filter(&$data) - { - try { - foreach ($data as &$vo) { - $vo['qrc'] = url('@wechat/keys/index') . "?action=qrc&keys={$vo['keys']}"; - $vo['type'] = isset($this->types[$vo['type']]) ? $this->types[$vo['type']] : $vo['type']; - } - } catch (\Exception $e) { - $this->error($e->getMessage()); - } - } - - /** - * 添加关键字 - * @return string - */ - public function add() - { - $this->applyCsrfToken(); - $this->title = '添加关键字规则'; - return $this->_form($this->table, 'form'); - } - - /** - * 编辑关键字 - * @return string - */ - public function edit() - { - $this->applyCsrfToken(); - $this->title = '编辑关键字规则'; - return $this->_form($this->table, 'form'); - } - - /** - * 删除关键字 - */ - public function del() - { - $this->applyCsrfToken(); - $this->_delete($this->table); - } - - /** - * 禁用关键字 - */ - public function forbid() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '0']); - } - - /** - * 启用关键字 - */ - public function resume() - { - $this->applyCsrfToken(); - $this->_save($this->table, ['status' => '1']); - } - - /** - * 关注默认回复 - * @return array|string - */ - public function subscribe() - { - $this->applyCsrfToken(); - $this->title = '编辑关注回复规则'; - return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'subscribe']); - } - - - /** - * 无配置默认回复 - * @return array|string - */ - public function defaults() - { - $this->applyCsrfToken(); - $this->title = '编辑默认回复规则'; - return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'default']); - } - - /** - * 添加数据处理 - * @param array $data - */ - protected function _form_filter(array &$data) - { - if ($this->request->isPost() && isset($data['keys'])) { - $db = Db::name($this->table)->where('keys', $data['keys']); - empty($data['id']) || $db->where('id', 'neq', $data['id']); - if ($db->count() > 0) $this->error('关键字已经存在,请使用其它关键字!'); - } - if ($this->request->isGet()) { - $this->msgTypes = $this->types; - $root = rtrim(dirname(request()->basefile(true)), '\\/'); - $this->defaultImage = "{$root}/static/theme/img/image.png"; - } - } - - /** - * 编辑结果处理 - * @param $result - */ - protected function _form_result($result) - { - if ($result !== false) { - list($url, $keys) = ['', $this->request->post('keys')]; - if (!in_array($keys, ['subscribe', 'default'])) { - $url = url('@admin') . '#' . url('wechat/keys/index') . '?spm=' . $this->request->get('spm'); - } - $this->success('恭喜, 关键字保存成功!', $url); - } - $this->error('关键字保存失败, 请稍候再试!'); - } - + '文字', 'news' => '图文', 'image' => '图片', 'music' => '音乐', + 'video' => '视频', 'voice' => '语音', 'customservice' => '转客服', + ]; + + /** + * 显示关键字列表 + * @return array|string + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function index() + { + // 关键字二维码生成 + if ($this->request->get('action') === 'qrc') { + try { + $wechat = Wechat::WeChatQrcode(); + $result = $wechat->create($this->request->get('keys', '')); + $this->success('生成二维码成功!', "javascript:$.previewImage('{$wechat->url($result['ticket'])}')"); + } catch (\think\exception\HttpResponseException $exception) { + throw $exception; + } catch (\Exception $e) { + $this->error("生成二维码失败,请稍候再试!
{$e->getMessage()}"); + } + } + // 关键字列表显示 + $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(); + } + + /** + * 列表数据处理 + * @param array $data + */ + protected function _index_page_filter(&$data) + { + try { + foreach ($data as &$vo) { + $vo['qrc'] = url('@wechat/keys/index') . "?action=qrc&keys={$vo['keys']}"; + $vo['type'] = isset($this->types[$vo['type']]) ? $this->types[$vo['type']] : $vo['type']; + } + } catch (\Exception $e) { + $this->error($e->getMessage()); + } + } + + /** + * 添加关键字 + * @return string + */ + public function add() + { + $this->applyCsrfToken(); + $this->title = '添加关键字规则'; + return $this->_form($this->table, 'form'); + } + + /** + * 编辑关键字 + * @return string + */ + public function edit() + { + $this->applyCsrfToken(); + $this->title = '编辑关键字规则'; + return $this->_form($this->table, 'form'); + } + + /** + * 删除关键字 + */ + public function del() + { + $this->applyCsrfToken(); + $this->_delete($this->table); + } + + /** + * 禁用关键字 + */ + public function forbid() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '0']); + } + + /** + * 启用关键字 + */ + public function resume() + { + $this->applyCsrfToken(); + $this->_save($this->table, ['status' => '1']); + } + + /** + * 关注默认回复 + * @return array|string + */ + public function subscribe() + { + $this->applyCsrfToken(); + $this->title = '编辑关注回复规则'; + return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'subscribe']); + } + + + /** + * 无配置默认回复 + * @return array|string + */ + public function defaults() + { + $this->applyCsrfToken(); + $this->title = '编辑默认回复规则'; + return $this->_form($this->table, 'form', 'keys', [], ['keys' => 'default']); + } + + /** + * 添加数据处理 + * @param array $data + */ + protected function _form_filter(array &$data) + { + if ($this->request->isPost() && isset($data['keys'])) { + $db = Db::name($this->table)->where('keys', $data['keys']); + empty($data['id']) || $db->where('id', 'neq', $data['id']); + if ($db->count() > 0) $this->error('关键字已经存在,请使用其它关键字!'); + } + if ($this->request->isGet()) { + $this->msgTypes = $this->types; + $root = rtrim(dirname(request()->basefile(true)), '\\/'); + $this->defaultImage = "{$root}/static/theme/img/image.png"; + } + } + + /** + * 编辑结果处理 + * @param $result + */ + protected function _form_result($result) + { + if ($result !== false) { + list($url, $keys) = ['', $this->request->post('keys')]; + if (!in_array($keys, ['subscribe', 'default'])) { + $url = url('@admin') . '#' . url('wechat/keys/index') . '?spm=' . $this->request->get('spm'); + } + $this->success('恭喜, 关键字保存成功!', $url); + } + $this->error('关键字保存失败, 请稍候再试!'); + } + } \ No newline at end of file diff --git a/application/wechat/controller/Menu.php b/application/wechat/controller/Menu.php index 3999ebc37..4eb766811 100644 --- a/application/wechat/controller/Menu.php +++ b/application/wechat/controller/Menu.php @@ -1,155 +1,155 @@ - '匹配规则', - 'view' => '跳转网页', - 'miniprogram' => '打开小程序', - // 'customservice' => '转多客服', - 'scancode_push' => '扫码推事件', - 'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框', - 'pic_sysphoto' => '弹出系统拍照发图', - 'pic_photo_or_album' => '弹出拍照或者相册发图', - 'pic_weixin' => '弹出微信相册发图器', - 'location_select' => '弹出地理位置选择器', - ]; - - /** - * 显示菜单列表 - * @return array - * @throws \think\Exception - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - * @throws \think\exception\PDOException - */ - public function index() - { - if ($this->request->get('output') === 'json') { - $where = [['keys', 'notin', ['subscribe', 'default']], ['status', 'eq', '1']]; - $keys = Db::name('WechatKeys')->where($where)->order('sort asc,id desc')->select(); - $this->success('获取数据成功!', ['menudata' => sysdata('menudata'), 'keysdata' => $keys]); - } - $this->title = '微信菜单定制'; - $this->menuTypes = $this->menuType; - return $this->fetch(); - } - - /** - * 微信菜单编辑 - */ - public function edit() - { - if ($this->request->isPost()) { - $data = $this->request->post('data'); - if (empty($data)) { // 删除菜单 - try { - Wechat::WeChatMenu()->delete(); - } catch (\Exception $e) { - $this->error('删除取消微信菜单失败,请稍候再试!' . $e->getMessage()); - } - $this->success('删除并取消微信菜单成功!', ''); - } - try { - sysdata('menudata', $this->buildMenu($menudata = json_decode($data, true))); - Wechat::WeChatMenu()->create(['button' => sysdata('menudata')]); - } catch (\Exception $e) { - $this->error("微信菜单发布失败,请稍候再试!
{$e->getMessage()}"); - } - _syslog('微信管理', '发布微信菜单成功'); - $this->success('保存发布菜单成功!', ''); - } - } - - /** - * @param array $list - * @return mixed - */ - private function buildMenu(array $list) - { - foreach ($list as &$vo) { - unset($vo['active'], $vo['show']); - if (empty($vo['sub_button'])) { - $vo = $this->build_menu_item($vo); - } else { - $item = ['name' => $vo['name'], 'sub_button' => []]; - foreach ($vo['sub_button'] as &$sub) { - unset($sub['active'], $sub['show']); - array_push($item['sub_button'], $this->build_menu_item($sub)); - } - $vo = $item; - } - } - return $list; - } - - /** - * 单个微信菜单数据过滤处理 - * @param array $item - * @return array - */ - private function build_menu_item(array $item) - { - switch (strtolower($item['type'])) { - case 'pic_weixin': - case 'pic_sysphoto': - case 'scancode_push': - case 'location_select': - case 'scancode_waitmsg': - case 'pic_photo_or_album': - return ['name' => $item['name'], 'type' => $item['type'], 'key' => isset($item['key']) ? $item['key'] : $item['type']]; - case 'click': - return ['name' => $item['name'], 'type' => $item['type'], 'key' => $item['key']]; - case 'view': - return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url']]; - case 'miniprogram': - return [ - 'name' => $item['name'], 'type' => $item['type'], 'url' => $item['url'], - 'appid' => $item['appid'], 'pagepath' => $item['pagepath'], - ]; - } - } - - /** - * 取消菜单 - */ - public function cancel() - { - try { - Wechat::WeChatMenu()->delete(); - } catch (\Exception $e) { - $this->error("菜单取消失败,请稍候再试!
{$e->getMessage()}"); - } - $this->success('菜单取消成功,重新关注可立即生效!', ''); - } - + '匹配规则', + 'view' => '跳转网页', + 'miniprogram' => '打开小程序', + // 'customservice' => '转多客服', + 'scancode_push' => '扫码推事件', + 'scancode_waitmsg' => '扫码推事件且弹出“消息接收中”提示框', + 'pic_sysphoto' => '弹出系统拍照发图', + 'pic_photo_or_album' => '弹出拍照或者相册发图', + 'pic_weixin' => '弹出微信相册发图器', + 'location_select' => '弹出地理位置选择器', + ]; + + /** + * 显示菜单列表 + * @return array + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function index() + { + if ($this->request->get('output') === 'json') { + $where = [['keys', 'notin', ['subscribe', 'default']], ['status', 'eq', '1']]; + $keys = Db::name('WechatKeys')->where($where)->order('sort asc,id desc')->select(); + $this->success('获取数据成功!', ['menudata' => sysdata('menudata'), 'keysdata' => $keys]); + } + $this->title = '微信菜单定制'; + $this->menuTypes = $this->menuType; + return $this->fetch(); + } + + /** + * 微信菜单编辑 + */ + public function edit() + { + if ($this->request->isPost()) { + $data = $this->request->post('data'); + if (empty($data)) { // 删除菜单 + try { + Wechat::WeChatMenu()->delete(); + } catch (\Exception $e) { + $this->error('删除取消微信菜单失败,请稍候再试!' . $e->getMessage()); + } + $this->success('删除并取消微信菜单成功!', ''); + } + try { + sysdata('menudata', $this->buildMenu($menudata = json_decode($data, true))); + Wechat::WeChatMenu()->create(['button' => sysdata('menudata')]); + } catch (\Exception $e) { + $this->error("微信菜单发布失败,请稍候再试!
{$e->getMessage()}"); + } + _syslog('微信管理', '发布微信菜单成功'); + $this->success('保存发布菜单成功!', ''); + } + } + + /** + * @param array $list + * @return mixed + */ + private function buildMenu(array $list) + { + foreach ($list as &$vo) { + unset($vo['active'], $vo['show']); + if (empty($vo['sub_button'])) { + $vo = $this->build_menu_item($vo); + } else { + $item = ['name' => $vo['name'], 'sub_button' => []]; + foreach ($vo['sub_button'] as &$sub) { + unset($sub['active'], $sub['show']); + array_push($item['sub_button'], $this->build_menu_item($sub)); + } + $vo = $item; + } + } + return $list; + } + + /** + * 单个微信菜单数据过滤处理 + * @param array $item + * @return array + */ + private function build_menu_item(array $item) + { + switch (strtolower($item['type'])) { + case 'pic_weixin': + case 'pic_sysphoto': + case 'scancode_push': + case 'location_select': + case 'scancode_waitmsg': + case 'pic_photo_or_album': + return ['name' => $item['name'], 'type' => $item['type'], 'key' => isset($item['key']) ? $item['key'] : $item['type']]; + case 'click': + return ['name' => $item['name'], 'type' => $item['type'], 'key' => $item['key']]; + case 'view': + return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url']]; + case 'miniprogram': + return [ + 'name' => $item['name'], 'type' => $item['type'], 'url' => $item['url'], + 'appid' => $item['appid'], 'pagepath' => $item['pagepath'], + ]; + } + } + + /** + * 取消菜单 + */ + public function cancel() + { + try { + Wechat::WeChatMenu()->delete(); + } catch (\Exception $e) { + $this->error("菜单取消失败,请稍候再试!
{$e->getMessage()}"); + } + $this->success('菜单取消成功,重新关注可立即生效!', ''); + } + } \ No newline at end of file diff --git a/application/wechat/controller/News.php b/application/wechat/controller/News.php index 124ef88f0..450a8a846 100644 --- a/application/wechat/controller/News.php +++ b/application/wechat/controller/News.php @@ -1,160 +1,160 @@ -title = '微信图文列表'; - $db = Db::name($this->table)->where(['is_deleted' => '0']); - return parent::_page($db->order('id desc')); - } - - /** - * 图文列表数据处理 - * @param array $data - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - */ - protected function _index_page_filter(&$data) - { - foreach ($data as &$vo) $vo = Media::news($vo['id']); - } - - /** - * 图文选择器 - * @return string - */ - public function select() - { - return $this->index(); - } - - /** - * 图文列表数据处理 - * @param array $data - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\ModelNotFoundException - * @throws \think\exception\DbException - */ - protected function _select_page_filter(&$data) - { - foreach ($data as &$vo) $vo = Media::news($vo['id']); - } - - /** - * 添加图文 - * @return string - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function add() - { - if ($this->request->isGet()) { - $this->title = '新建图文'; - return $this->fetch('form'); - } - $data = $this->request->post(); - 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) { - $url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm'); - $this->success('图文添加成功!', $url); - } - } - $this->error('图文添加失败,请稍候再试!'); - } - - /** - * 编辑图文 - * @return string - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - public function edit() - { - $id = $this->request->get('id', ''); - if ($this->request->isGet()) { - empty($id) && $this->error('参数错误,请稍候再试!'); - if ($this->request->get('output') === 'json') { - $this->success('获取数据成功!', Media::news($id)); - } - return $this->fetch('form', ['title' => '编辑图文']); - } - $post = $this->request->post(); - if (isset($post['data']) && ($ids = $this->_apply_news_article($post['data']))) { - if (data_save('wechat_news', ['id' => $id, 'article_id' => $ids], 'id')) { - $this->success('图文更新成功!', url('@admin') . '#' . url('@wechat/news/index')); - } - } - $this->error('图文更新失败,请稍候再试!'); - } - - /** - * 图文更新操作 - * @param array $data - * @param array $ids - * @return string - * @throws \think\Exception - * @throws \think\exception\PDOException - */ - private function _apply_news_article($data, $ids = []) - { - foreach ($data as &$vo) { - $vo['create_at'] = date('Y-m-d H:i:s'); - if (empty($vo['digest'])) { - $vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120); - } - if (empty($vo['id'])) { - $result = $id = Db::name('WechatNewsArticle')->insertGetId($vo); - } else { - $id = intval($vo['id']); - $result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo); - } - if ($result !== false) array_push($ids, $id); - } - return join(',', $ids); - } - - /** - * 删除用户 - */ - public function del() - { - $this->_delete($this->table); - } - +title = '微信图文列表'; + $db = Db::name($this->table)->where(['is_deleted' => '0']); + return parent::_page($db->order('id desc')); + } + + /** + * 图文列表数据处理 + * @param array $data + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + protected function _index_page_filter(&$data) + { + foreach ($data as &$vo) $vo = Media::news($vo['id']); + } + + /** + * 图文选择器 + * @return string + */ + public function select() + { + return $this->index(); + } + + /** + * 图文列表数据处理 + * @param array $data + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + protected function _select_page_filter(&$data) + { + foreach ($data as &$vo) $vo = Media::news($vo['id']); + } + + /** + * 添加图文 + * @return string + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function add() + { + if ($this->request->isGet()) { + $this->title = '新建图文'; + return $this->fetch('form'); + } + $data = $this->request->post(); + 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) { + $url = url('@admin') . '#' . url('@wechat/news/index') . '?spm=' . $this->request->get('spm'); + $this->success('图文添加成功!', $url); + } + } + $this->error('图文添加失败,请稍候再试!'); + } + + /** + * 编辑图文 + * @return string + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function edit() + { + $id = $this->request->get('id', ''); + if ($this->request->isGet()) { + empty($id) && $this->error('参数错误,请稍候再试!'); + if ($this->request->get('output') === 'json') { + $this->success('获取数据成功!', Media::news($id)); + } + return $this->fetch('form', ['title' => '编辑图文']); + } + $post = $this->request->post(); + if (isset($post['data']) && ($ids = $this->_apply_news_article($post['data']))) { + if (data_save('wechat_news', ['id' => $id, 'article_id' => $ids], 'id')) { + $this->success('图文更新成功!', url('@admin') . '#' . url('@wechat/news/index')); + } + } + $this->error('图文更新失败,请稍候再试!'); + } + + /** + * 图文更新操作 + * @param array $data + * @param array $ids + * @return string + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + private function _apply_news_article($data, $ids = []) + { + foreach ($data as &$vo) { + $vo['create_at'] = date('Y-m-d H:i:s'); + if (empty($vo['digest'])) { + $vo['digest'] = mb_substr(strip_tags(str_replace(["\s", ' '], '', $vo['content'])), 0, 120); + } + if (empty($vo['id'])) { + $result = $id = Db::name('WechatNewsArticle')->insertGetId($vo); + } else { + $id = intval($vo['id']); + $result = Db::name('WechatNewsArticle')->where('id', $id)->update($vo); + } + if ($result !== false) array_push($ids, $id); + } + return join(',', $ids); + } + + /** + * 删除用户 + */ + public function del() + { + $this->_delete($this->table); + } + } \ No newline at end of file diff --git a/application/wechat/controller/api/Push.php b/application/wechat/controller/api/Push.php index 075e2ab66..0fee24ec3 100644 --- a/application/wechat/controller/api/Push.php +++ b/application/wechat/controller/api/Push.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\controller\api; diff --git a/application/wechat/controller/api/Review.php b/application/wechat/controller/api/Review.php index 2cbf1de8c..c5ff0a579 100644 --- a/application/wechat/controller/api/Review.php +++ b/application/wechat/controller/api/Review.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\controller\api; diff --git a/application/wechat/controller/api/Tools.php b/application/wechat/controller/api/Tools.php index 8f2b7aa16..302db53f6 100644 --- a/application/wechat/controller/api/Tools.php +++ b/application/wechat/controller/api/Tools.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\controller\api; diff --git a/application/wechat/queue/Jobs.php b/application/wechat/queue/Jobs.php index ac91009ac..ed5c55548 100644 --- a/application/wechat/queue/Jobs.php +++ b/application/wechat/queue/Jobs.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\queue; diff --git a/application/wechat/service/Fans.php b/application/wechat/service/Fans.php index d8b9eaef2..3e70b1b5a 100644 --- a/application/wechat/service/Fans.php +++ b/application/wechat/service/Fans.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\service; diff --git a/application/wechat/service/Media.php b/application/wechat/service/Media.php index 9c6f97c4d..fc93f5431 100644 --- a/application/wechat/service/Media.php +++ b/application/wechat/service/Media.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\service; diff --git a/application/wechat/service/Wechat.php b/application/wechat/service/Wechat.php index 191e8da19..915a935b7 100644 --- a/application/wechat/service/Wechat.php +++ b/application/wechat/service/Wechat.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace app\wechat\service; diff --git a/application/wechat/sys.php b/application/wechat/sys.php index 17d5a3737..8a280794f 100644 --- a/application/wechat/sys.php +++ b/application/wechat/sys.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- // 注册系统指令 diff --git a/config/cookie.php b/config/cookie.php index 62e9c7fa8..fb4e8d962 100644 --- a/config/cookie.php +++ b/config/cookie.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- return [ diff --git a/config/log.php b/config/log.php index 9a10e89d6..6db386449 100644 --- a/config/log.php +++ b/config/log.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- return [ diff --git a/config/template.php b/config/template.php index d42c04ef1..74a61c719 100644 --- a/config/template.php +++ b/config/template.php @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- return [ diff --git a/public/static/admin.js b/public/static/admin.js index 9ee1a5a54..b01b47c95 100644 --- a/public/static/admin.js +++ b/public/static/admin.js @@ -7,7 +7,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- // IE兼容提示 diff --git a/public/static/theme/css/console.css b/public/static/theme/css/console.css index a69255814..8c29fe350 100644 --- a/public/static/theme/css/console.css +++ b/public/static/theme/css/console.css @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +--------------------------------------------------------------------*/ ::-webkit-input-placeholder{color:#aaa} diff --git a/public/static/theme/css/login.css b/public/static/theme/css/login.css index 5d850478b..4462ccbd8 100644 --- a/public/static/theme/css/login.css +++ b/public/static/theme/css/login.css @@ -9,7 +9,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +--------------------------------------------------------------------*/ body,html{height:100%} diff --git a/think b/think index 9db75dba2..e5f177807 100644 --- a/think +++ b/think @@ -10,7 +10,7 @@ // +---------------------------------------------------------------------- // | 开源协议 ( https://mit-license.org ) // +---------------------------------------------------------------------- -// | github开源项目:https://github.com/zoujingli/ThinkAdmin +// | github开源项目:https://github.com/zoujingli/framework // +---------------------------------------------------------------------- namespace think; diff --git a/vendor/autoload.php b/vendor/autoload.php index 8583ae84a..16d2becae 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35::getLoader(); +return ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 56cb5ebfe..dca7e4c12 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35 +class ComposerAutoloaderInita2a5ca7b097a9d41d2230b028e215f7a { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35 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(); - 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()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInit407a0fe5b8b66687453d756daf4a3b35 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$files; + $includeFiles = Composer\Autoload\ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire407a0fe5b8b66687453d756daf4a3b35($fileIdentifier, $file); + composerRequirea2a5ca7b097a9d41d2230b028e215f7a($fileIdentifier, $file); } return $loader; } } -function composerRequire407a0fe5b8b66687453d756daf4a3b35($fileIdentifier, $file) +function composerRequirea2a5ca7b097a9d41d2230b028e215f7a($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 65da3279a..33009c809 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35 +class ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a { public static $files = array ( '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php', @@ -346,9 +346,9 @@ class ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit407a0fe5b8b66687453d756daf4a3b35::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInita2a5ca7b097a9d41d2230b028e215f7a::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index d18b540be..198c2b3bd 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -177,8 +177,8 @@ }, { "name": "symfony/options-resolver", - "version": "v3.4.23", - "version_normalized": "3.4.23.0", + "version": "v3.4.24", + "version_normalized": "3.4.24.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", @@ -499,12 +499,12 @@ "source": { "type": "git", "url": "https://github.com/zoujingli/ThinkLibrary.git", - "reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5" + "reference": "ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5d8dbc0707782c5b68ea5600f19001e128ee39c5", - "reference": "5d8dbc0707782c5b68ea5600f19001e128ee39c5", + "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd", + "reference": "ee43486ce1f064a0702f229b0ce3a52a8f9bb5dd", "shasum": "", "mirrors": [ { @@ -523,7 +523,7 @@ "qiniu/php-sdk": "^7.2", "topthink/framework": "5.1.*" }, - "time": "2019-04-02T08:17:16+00:00", + "time": "2019-04-03T05:55:15+00:00", "type": "library", "installation-source": "dist", "autoload": { diff --git a/vendor/zoujingli/think-library/src/command/Sync.php b/vendor/zoujingli/think-library/src/command/Sync.php index 03db71326..bc9d3dda1 100644 --- a/vendor/zoujingli/think-library/src/command/Sync.php +++ b/vendor/zoujingli/think-library/src/command/Sync.php @@ -96,7 +96,7 @@ class Sync extends Command private static function removeEmptyDir($dir) { if (is_dir($dir) && count(scandir($dir)) === 2) { - rmdir($dir); + if (rmdir($dir)) self::removeEmptyDir(dirname($dir)); } } diff --git a/vendor/zoujingli/think-library/src/tools/Cors.php b/vendor/zoujingli/think-library/src/tools/Cors.php index aa2b63cb9..53b665e9a 100644 --- a/vendor/zoujingli/think-library/src/tools/Cors.php +++ b/vendor/zoujingli/think-library/src/tools/Cors.php @@ -35,7 +35,7 @@ class Cors header('Access-Control-Allow-Methods:GET,POST,OPTIONS'); header('Access-Control-Allow-Origin:' . self::getOrigin($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('Access-Control-Max-Age:1728000'); header('HTTP/1.0 204 No Content'); diff --git a/vendor/zoujingli/think-library/src/tools/Node.php b/vendor/zoujingli/think-library/src/tools/Node.php index 42dd116b7..668e88ecc 100644 --- a/vendor/zoujingli/think-library/src/tools/Node.php +++ b/vendor/zoujingli/think-library/src/tools/Node.php @@ -21,6 +21,13 @@ namespace library\tools; */ class Node { + + /** + * 控制器忽略函数 + * @var array + */ + protected static $ignore = ['initialize', 'success', 'error', 'redirect', 'fetch', 'assign', 'callback']; + /** * 获取当前访问节点 * @return string @@ -32,6 +39,57 @@ class Node 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 控制器根路径 @@ -40,16 +98,15 @@ class Node */ public static function getTree($dir, $nodes = []) { - $ignore = ['initialize', 'success', 'error', 'redirect', 'fetch', 'assign', 'callback']; foreach (self::scanDir($dir) as $file) { list($matches, $filename) = [[], str_replace(DIRECTORY_SEPARATOR, '/', $file)]; if (!preg_match('|/(\w+)/controller/(.+)|', $filename, $matches)) continue; - $className = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4)); - if (class_exists($className)) foreach (get_class_methods($className) as $funcName) { - if (stripos($funcName, '_') === 0 || in_array($funcName, $ignore)) continue; + $classname = env('app_namespace') . str_replace('/', '\\', substr($matches[0], 0, -4)); + if (class_exists($classname)) foreach (get_class_methods($classname) as $function) { + 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; - $nodes[] = self::parseString("{$matches[1]}/{$controller}") . '/' . strtolower($funcName); + $nodes[] = self::parseString("{$matches[1]}/{$controller}") . '/' . strtolower($function); } } return $nodes;