From 9a07ae1e1b0994ebf37a08d5d3ad1d992ade89c9 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 6 Jun 2020 08:58:55 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7464f8d..085c7a6 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ - [github 地址](https://github.com/yanwenwu/catch-admin) - [gitee 地址](https://gitee.com/jaguarjack/catchAdmin) - [前端 Vue 项目地址](https://github.com/yanwenwu/catch-admin-vue) - +- [文档地址](https://github.com/catch-admin/document)[个人精力实在有限,希望可以小伙伴们可以一起维护文档] ## 预览

From ac56a7b80d5746cc98e1ec1ff81d41c5165928c8 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 6 Jun 2020 09:21:24 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/library/ParseClass.php | 40 +++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/extend/catcher/library/ParseClass.php b/extend/catcher/library/ParseClass.php index c3c11f0..9848127 100644 --- a/extend/catcher/library/ParseClass.php +++ b/extend/catcher/library/ParseClass.php @@ -1,7 +1,6 @@ getClass(); @@ -28,7 +32,11 @@ class ParseClass return $methods; } - + /** + * 获取所有方法 + * + * @return array + */ public function methods() { $class = $this->getClass(); @@ -63,7 +71,12 @@ class ParseClass return $methods; } - + /** + * 获取 CLASS + * + * @return \ReflectionClass + * @throws \ReflectionException + */ public function getClass() { @@ -72,12 +85,22 @@ class ParseClass ucfirst($this->controller)); } - + /** + * @param $method + * @return bool + */ protected function isMagicMethod($method) { return strpos($method, '__') !== false; } + /** + * + * @param $module + * @return $this + * @author JaguarJack + * @date 2020/6/6 + */ public function setModule($module) { $composer = \json_decode(file_get_contents(root_path() . 'composer.json'), true); @@ -94,7 +117,14 @@ class ParseClass return $this; } - + /** + * + * @param $module + * @param $controller + * @return $this + * @author JaguarJack + * @date 2020/6/6 + */ public function setRule($module, $controller) { $this->module = $module; From ffeec69333f5ece52779615e2fd81fe5d80499f9 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 6 Jun 2020 18:57:58 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permissions/model/DataRangScopeTrait.php | 63 +++++++++++++++++++ catch/permissions/model/Roles.php | 42 +------------ catch/permissions/model/Users.php | 4 +- catch/wechat/Menus.php | 1 + catch/wechat/ReplyRule.php | 1 + catch/wechat/Users.php | 1 + 6 files changed, 70 insertions(+), 42 deletions(-) create mode 100644 catch/permissions/model/DataRangScopeTrait.php create mode 100644 catch/wechat/Menus.php create mode 100644 catch/wechat/ReplyRule.php create mode 100644 catch/wechat/Users.php diff --git a/catch/permissions/model/DataRangScopeTrait.php b/catch/permissions/model/DataRangScopeTrait.php new file mode 100644 index 0000000..4084e7c --- /dev/null +++ b/catch/permissions/model/DataRangScopeTrait.php @@ -0,0 +1,63 @@ + + * @date 2020/6/6 + */ + protected function scopeDataRange($roles) + { + return $this->whereIn($this->aliasField('creator_id'), $this->getDepartmentUserIdsBy($roles)); + } + + /** + * 获取部门IDs + * + * @param $roles + * @return array + * @author JaguarJack + * @date 2020/6/6 + */ + public function getDepartmentUserIdsBy($roles) + { + $userIds = []; + + $isAll = false; + + $user = request()->user(); + + foreach ($roles as $role) { + switch ($role->data_range) { + case Roles::ALL_DATA: + $isAll = true; + break; + case Roles::SELF_CHOOSE: + $departmentIds = array_merge(array_column($role->getDepartments()->toArray(), 'id')); + $userIds = array_merge($userIds, Users::getUserIdsByDepartmentIds($departmentIds)); + break; + case Roles::SELF_DATA: + $userIds[] = $user->id; + break; + case Roles::DEPARTMENT_DOWN_DATA: + case Roles::DEPARTMENT_DATA: + $userIds = array_merge($userIds, Users::getUserIdsByDepartmentIds([$user->department_id])); + break; + default: + break; + } + + // 如果有全部数据 直接跳出 + if ($isAll) { + break; + } + } + + return $userIds; + } +} \ No newline at end of file diff --git a/catch/permissions/model/Roles.php b/catch/permissions/model/Roles.php index e8b321b..8c59b10 100644 --- a/catch/permissions/model/Roles.php +++ b/catch/permissions/model/Roles.php @@ -18,13 +18,12 @@ class Roles extends CatchModel public const DEPARTMENT_DATA = 4; // 部门数据 public const DEPARTMENT_DOWN_DATA = 5; // 部门及以下数据 - protected $field = [ 'id', // 'role_name', // 角色名 'parent_id', // 父级ID - 'creator_id', // 创建者 - 'data_range', // 数据范围 + 'creator_id', // 创建者 + 'data_range', // 数据范围 'description', // 角色备注 'created_at', // 创建时间 'updated_at', // 更新时间 @@ -50,41 +49,4 @@ class Roles extends CatchModel return $this->belongsToMany(Users::class, 'user_has_roles', 'uid', 'role_id'); } - - public static function getDepartmentUserIdsBy($roles) - { - $uids = []; - - $isAll = false; - - $user = request()->user(); - - foreach ($roles as $role) { - switch ($role->data_range) { - case self::ALL_DATA: - $isAll = true; - break; - case self::SELF_CHOOSE: - $departmentIds = array_merge(array_column($role->getDepartments()->toArray(), 'id')); - $uids = array_merge($uids, Users::getUserIdsByDepartmentIds($departmentIds)); - break; - case self::SELF_DATA: - $uids[] = $user->id; - break; - case self::DEPARTMENT_DOWN_DATA: - case self::DEPARTMENT_DATA: - $uids = array_merge($uids, Users::getUserIdsByDepartmentIds([$user->department_id])); - break; - default: - break; - } - - // 如果有全部数据 直接跳出 - if ($isAll) { - break; - } - } - - return $uids; - } } diff --git a/catch/permissions/model/Users.php b/catch/permissions/model/Users.php index 70a4bf6..26c5074 100644 --- a/catch/permissions/model/Users.php +++ b/catch/permissions/model/Users.php @@ -18,8 +18,8 @@ class Users extends CatchModel 'username', // 用户名 'password', // 用户密码 'email', // 邮箱 登录 - 'creator_id', // 创建者ID - 'department_id', // 部门ID + 'creator_id', // 创建者ID + 'department_id', // 部门ID 'status', // 用户状态 1 正常 2 禁用 'last_login_ip', // 最后登录IP 'last_login_time', // 最后登录时间 diff --git a/catch/wechat/Menus.php b/catch/wechat/Menus.php new file mode 100644 index 0000000..6fd199e --- /dev/null +++ b/catch/wechat/Menus.php @@ -0,0 +1 @@ + Date: Sat, 6 Jun 2020 21:50:36 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 085c7a6..756592d 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,11 @@ composer create-project jaguarjack/catchadmin:dev-master ### Talking - [论坛讨论](http://bbs.catchadmin.com) - 可以提 `ISSUE`,请按照 `issue` 模板提问 -- 欢迎进入 Q 群 `302266230` 讨论以及反馈一些问题。 +- 加入 Q 群 `302266230` 讨论以及反馈一些问题。 + - 加群需要付费,所以请使用能支持群费的客户端。(不喜勿喷,过滤一部分不看文档和 TP 框架文档并且衣来伸手饭来张口的用户) + - 不建议你付费入群,认真阅读文档可以解决所有问题 + - 更愿意以 `ISSUE` 的方式提问 + - 付费入群,群里的各位也是没有义务回答各种各样的基础问题。请 GOOGLE。 ### Thanks > 排名部分先后 From e9c894073010b4910fe019cefd4a05ab28d7bd25 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sat, 6 Jun 2020 22:37:36 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/wechat.php | 100 -------------- extend/catcher/CatchAdminService.php | 2 + .../catcher/command/publish/WechatCommand.php | 130 ++++++++++++++++++ 3 files changed, 132 insertions(+), 100 deletions(-) delete mode 100644 config/wechat.php create mode 100644 extend/catcher/command/publish/WechatCommand.php diff --git a/config/wechat.php b/config/wechat.php deleted file mode 100644 index 5cddea2..0000000 --- a/config/wechat.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @copyright By CatchAdmin - * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt - */ -return [ - /** - * 公众号配置 - * - */ - 'official_account' => [ - /** - * 账号基本信息,请从微信公众平台/开放平台获取 - */ - 'app_id' => env('wechat.official_app_id'), // AppID - 'secret' => env('wechat.official_secret'), // AppSecret - 'token' => env('wechat.official_token'), // Token - 'aes_key' => env('wechat.official_aes_key'), // EncodingAESKey,兼容与安全模式下请一定要填写!!! - - /** - * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 - * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例 - */ - 'response_type' => 'array', - - /** - * 日志配置 - * - * level: 日志级别, 可选为: - * debug/info/notice/warning/error/critical/alert/emergency - * path:日志文件位置(绝对路径!!!),要求可写权限 - */ - 'log' => [ - 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod - 'channels' => [ - // 测试环境 - 'dev' => [ - 'driver' => 'single', - 'path' => '/tmp/easywechat.log', - 'level' => 'debug', - ], - // 生产环境 - 'prod' => [ - 'driver' => 'daily', - 'path' => '/tmp/easywechat.log', - 'level' => 'info', - ], - ], - ], - - /** - * 接口请求相关配置,超时时间等,具体可用参数请参考: - * http://docs.guzzlephp.org/en/stable/request-config.html - * - * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。 - * - retry_delay: 重试延迟间隔(单位:ms),默认 500 - * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php - */ - 'http' => [ - 'max_retries' => 1, - 'retry_delay' => 500, - 'timeout' => 5.0, - // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri - ], - - /** - * OAuth 配置 - * - * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login - * callback:OAuth授权完成后的回调页地址 - */ - 'oauth' => [ - 'scopes' => ['snsapi_userinfo'], - 'callback' => '/examples/oauth_callback.php', - ], - ], - - /** - * wechat pay - * - */ - 'payment' => [ - 'app_id' => 'xxxx', - 'mch_id' => 'your-mch-id', - 'key' => 'key-for-signature', // API 密钥 - - // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) - 'cert_path' => 'path/to/your/cert.pem', // XXX: 绝对路径!!!! - 'key_path' => 'path/to/your/key', // XXX: 绝对路径!!!! - - 'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它 - ], - - // 更多配置请查看 https://www.easywechat.com/docs -]; diff --git a/extend/catcher/CatchAdminService.php b/extend/catcher/CatchAdminService.php index 41af69b..43e34e0 100644 --- a/extend/catcher/CatchAdminService.php +++ b/extend/catcher/CatchAdminService.php @@ -1,6 +1,7 @@ + * @copyright By CatchAdmin + * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt + */ +namespace catcher\command\publish; + +use think\console\Command; +use think\console\Input; +use think\console\input\Argument; +use think\console\input\Option; +use think\console\Output; +use catcher\CatchAdmin; + +class WechatCommand extends Command +{ + protected function configure() + { + $this->setName('publish:wechat') + ->setDescription('publish wechat config'); + } + + protected function execute(Input $input, Output $output) + { + file_put_contents(config_path() . 'wechat.php', $this->config()); + + file_put_contents(root_path(). '.env', $this->env(), FILE_APPEND); + + $output->warning('wechat publish successfully'); + } + + protected function config() + { + return << [ + /** + * 账号基本信息,请从微信公众平台/开放平台获取 + */ + 'app_id' => env('wechat.official_app_id'), // AppID + 'secret' => env('wechat.official_secret'), // AppSecret + 'token' => env('wechat.official_token'), // Token + 'aes_key' => env('wechat.official_aes_key'), // EncodingAESKey,兼容与安全模式下请一定要填写!!! + + 'response_type' => 'array', + + /** + * OAuth 配置 + * + * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login + * callback:OAuth授权完成后的回调页地址 + */ + 'oauth' => [ + 'scopes' => ['snsapi_userinfo'], + 'callback' => '/examples/oauth_callback.php', + ], + ], + + /** + * wechat pay + * + */ + 'payment' => [ + 'app_id' => 'xxxx', + 'mch_id' => 'your-mch-id', + 'key' => 'key-for-signature', // API 密钥 + + // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书) + 'cert_path' => 'path/to/your/cert.pem', // XXX: 绝对路径!!!! + 'key_path' => 'path/to/your/key', // XXX: 绝对路径!!!! + + 'notify_url' => '默认的订单回调地址', // 你也可以在下单时单独设置来想覆盖它 + ], + + // 更多配置请查看 https://www.easywechat.com/docs +]; +CONFIG; + } + + protected function env() + { + $filename = file_exists(root_path() . '.env') ? '.env' : '.example.env'; + + + $env = \parse_ini_file(root_path() . $filename, true); + + $env['WECHAT'] = $this->envConfig(); + + $dotEnv = ''; + + foreach ($env as $key => $e) { + if (is_string($e)) { + $dotEnv .= sprintf('%s = %s', $key, $e === '1' ? 'true' : ($e === '' ? 'false' : $e)) . PHP_EOL; + $dotEnv .= PHP_EOL; + } else { + $dotEnv .= sprintf('[%s]', $key) . PHP_EOL; + foreach ($e as $k => $v) { + $dotEnv .= sprintf('%s = %s', $k, $v === '1' ? 'true' : ($v === '' ? 'false' : $v)) . PHP_EOL; + } + + $dotEnv .= PHP_EOL; + } + } + + file_put_contents(root_path() . '.env', $dotEnv); + + } + + + protected function envConfig() + { + return [ + "official_app_id" => null, + "official_secret" => null, + "official_token" => null, + "official_aes_key" => null, + ]; + } +} \ No newline at end of file From ec5a5a840222307d394e9938e114e613f2ca6525 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sun, 7 Jun 2020 14:22:41 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/wechat/Menus.php | 1 - catch/wechat/ReplyRule.php | 1 - catch/wechat/Users.php | 1 - catch/wechat/controller/Users.php | 25 +++++++++++++++++++++++++ catch/wechat/route.php | 11 +++++++++++ extend/catcher/library/WeChat.php | 10 ++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) delete mode 100644 catch/wechat/Menus.php delete mode 100644 catch/wechat/ReplyRule.php delete mode 100644 catch/wechat/Users.php create mode 100644 catch/wechat/controller/Users.php create mode 100644 catch/wechat/route.php create mode 100644 extend/catcher/library/WeChat.php diff --git a/catch/wechat/Menus.php b/catch/wechat/Menus.php deleted file mode 100644 index 6fd199e..0000000 --- a/catch/wechat/Menus.php +++ /dev/null @@ -1 +0,0 @@ - + * @copyright By CatchAdmin + * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt + */ +namespace catchAdmin\wechat\controller; + +use catcher\base\CatchController; +use catcher\CatchResponse; +use catcher\library\WeChat; + +class Users extends CatchController +{ + public function index() + { + $response = WeChat::officialAccount()->base->getValidIps(); + + return CatchResponse::success($response); + } +} \ No newline at end of file diff --git a/catch/wechat/route.php b/catch/wechat/route.php new file mode 100644 index 0000000..cdebe16 --- /dev/null +++ b/catch/wechat/route.php @@ -0,0 +1,11 @@ + + * @copyright By CatchAdmin + * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt + */ +$router->resource('official/users', '\catchAdmin\wechat\controller\Users'); \ No newline at end of file diff --git a/extend/catcher/library/WeChat.php b/extend/catcher/library/WeChat.php new file mode 100644 index 0000000..94bc16c --- /dev/null +++ b/extend/catcher/library/WeChat.php @@ -0,0 +1,10 @@ + + * @copyright By CatchAdmin + * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt + */ \ No newline at end of file From 5231770babf3213196a28cbe9ac3b2dbd556b4a5 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sun, 7 Jun 2020 14:23:07 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/library/WeChat.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/extend/catcher/library/WeChat.php b/extend/catcher/library/WeChat.php index 94bc16c..dd00106 100644 --- a/extend/catcher/library/WeChat.php +++ b/extend/catcher/library/WeChat.php @@ -7,4 +7,29 @@ * @author JaguarJack * @copyright By CatchAdmin * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt - */ \ No newline at end of file + */ +namespace catcher\library; + +use EasyWeChat\Factory; +use think\helper\Str; + +/** + * + * @method static officialAccount() + * @method static miniProgram() + * @method static openPlatform() + * @method static work() + * @method static openWork() + * @method static payment() + * + * Class WeChat + * @package catcher\library + */ +class WeChat +{ + public static function __callStatic($name, $arguments) + { + // TODO: Implement __callStatic() method. + return Factory::{$name}(\config('wechat.'. Str::snake($name))); + } +} \ No newline at end of file From 66acbeee8b3664513065c68e9bc98eb8ff800126 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Sun, 7 Jun 2020 14:23:26 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catcher/command/publish/WechatCommand.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/extend/catcher/command/publish/WechatCommand.php b/extend/catcher/command/publish/WechatCommand.php index 733200c..3716325 100644 --- a/extend/catcher/command/publish/WechatCommand.php +++ b/extend/catcher/command/publish/WechatCommand.php @@ -29,7 +29,7 @@ class WechatCommand extends Command { file_put_contents(config_path() . 'wechat.php', $this->config()); - file_put_contents(root_path(). '.env', $this->env(), FILE_APPEND); + $this->env(); $output->warning('wechat publish successfully'); } @@ -67,9 +67,43 @@ return [ ], ], + /** + * 小程序 + */ + 'mini_program' => [ + // 更多配置查看 https://www.easywechat.com/docs/master/mini-program/index + ], + + /** + * 开放平台 + */ + 'open_platform' => [ + // 更多配置查看 https://www.easywechat.com/docs/master/open-platform/index + ], + + /** + * 企业微信 + */ + 'work' => [ + // 更多配置查看 https://www.easywechat.com/docs/master/wework/index + ], + + /** + * 企业微信开放平台 + */ + 'open_work' => [ + // 配置 https://www.easywechat.com/docs/master/open-work/index + ], + + /** + * 小微商户 + */ + 'micro_merchant' => [ + // 配置 https://www.easywechat.com/docs/master/micro-merchant/index + ], + /** * wechat pay - * */ 'payment' => [ 'app_id' => 'xxxx',