diff --git a/README.md b/README.md
index 7464f8d..756592d 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)[个人精力实在有限,希望可以小伙伴们可以一起维护文档]
## 预览
@@ -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
> 排名部分先后
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/controller/Users.php b/catch/wechat/controller/Users.php
new file mode 100644
index 0000000..1d2349a
--- /dev/null
+++ b/catch/wechat/controller/Users.php
@@ -0,0 +1,25 @@
+
+ * @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/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 d2aea28..b04e73b 100644
--- a/extend/catcher/CatchAdminService.php
+++ b/extend/catcher/CatchAdminService.php
@@ -1,7 +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());
+
+ $this->env();
+
+ $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',
+ ],
+ ],
+
+ /**
+ * 小程序
+ */
+ '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',
+ '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
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;
diff --git a/extend/catcher/library/WeChat.php b/extend/catcher/library/WeChat.php
new file mode 100644
index 0000000..dd00106
--- /dev/null
+++ b/extend/catcher/library/WeChat.php
@@ -0,0 +1,35 @@
+
+ * @copyright By CatchAdmin
+ * @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
+ */
+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