fixed conflict

This commit is contained in:
JaguarJack 2020-06-08 08:56:05 +08:00
commit 3b063ac1fd
11 changed files with 345 additions and 151 deletions

View File

@ -32,7 +32,7 @@
- [github 地址](https://github.com/yanwenwu/catch-admin) - [github 地址](https://github.com/yanwenwu/catch-admin)
- [gitee 地址](https://gitee.com/jaguarjack/catchAdmin) - [gitee 地址](https://gitee.com/jaguarjack/catchAdmin)
- [前端 Vue 项目地址](https://github.com/yanwenwu/catch-admin-vue) - [前端 Vue 项目地址](https://github.com/yanwenwu/catch-admin-vue)
- [文档地址](https://github.com/catch-admin/document)[个人精力实在有限,希望可以小伙伴们可以一起维护文档]
## 预览 ## 预览
<p align="center"> <p align="center">
<img src="https://cdn.learnku.com/uploads/images/202005/17/18206/0ECPy72zUZ.png!large"> <img src="https://cdn.learnku.com/uploads/images/202005/17/18206/0ECPy72zUZ.png!large">
@ -103,7 +103,11 @@ composer create-project jaguarjack/catchadmin:dev-master
### Talking ### Talking
- [论坛讨论](http://bbs.catchadmin.com) - [论坛讨论](http://bbs.catchadmin.com)
- 可以提 `ISSUE`,请按照 `issue` 模板提问 - 可以提 `ISSUE`,请按照 `issue` 模板提问
- 欢迎进入 Q 群 `302266230` 讨论以及反馈一些问题。 - 加入 Q 群 `302266230` 讨论以及反馈一些问题。
- 加群需要付费,所以请使用能支持群费的客户端。(不喜勿喷,过滤一部分不看文档和 TP 框架文档并且衣来伸手饭来张口的用户)
- 不建议你付费入群,认真阅读文档可以解决所有问题
- 更愿意以 `ISSUE` 的方式提问
- 付费入群,群里的各位也是没有义务回答各种各样的基础问题。请 GOOGLE。
### Thanks ### Thanks
> 排名部分先后 > 排名部分先后

View File

@ -0,0 +1,63 @@
<?php
namespace catchAdmin\permissions\model;
trait DataRangScopeTrait
{
/**
* 数据范围查询
*
* @param $roles
* @return mixed
* @author JaguarJack <njphper@gmail.com>
* @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 <njphper@gmail.com>
* @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;
}
}

View File

@ -18,7 +18,6 @@ class Roles extends CatchModel
public const DEPARTMENT_DATA = 4; // 部门数据 public const DEPARTMENT_DATA = 4; // 部门数据
public const DEPARTMENT_DOWN_DATA = 5; // 部门及以下数据 public const DEPARTMENT_DOWN_DATA = 5; // 部门及以下数据
protected $field = [ protected $field = [
'id', // 'id', //
'role_name', // 角色名 'role_name', // 角色名
@ -50,41 +49,4 @@ class Roles extends CatchModel
return $this->belongsToMany(Users::class, 'user_has_roles', 'uid', 'role_id'); 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;
}
} }

View File

@ -0,0 +1,25 @@
<?php
/**
* @filename Users.php
* @date 2020/6/7
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @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);
}
}

11
catch/wechat/route.php Normal file
View File

@ -0,0 +1,11 @@
<?php
/**
* @filename route.php
* @date 2020/6/7
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @copyright By CatchAdmin
* @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
*/
$router->resource('official/users', '\catchAdmin\wechat\controller\Users');

View File

@ -1,100 +0,0 @@
<?php
/**
* @filename wechat.php
* @createdAt 2020/2/13
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @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
* callbackOAuth授权完成后的回调页地址
*/
'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
];

View File

@ -1,7 +1,7 @@
<?php <?php
namespace catcher; namespace catcher;
use catcher\command\TestCommand; use catcher\command\publish\WechatCommand;
use catcher\command\Tools\BackupCommand; use catcher\command\Tools\BackupCommand;
use catcher\command\Tools\CompressPackageCommand; use catcher\command\Tools\CompressPackageCommand;
use catcher\command\CreateModuleCommand; use catcher\command\CreateModuleCommand;
@ -70,8 +70,8 @@ class CatchAdminService extends Service
WsWorkerCommand::class, WsWorkerCommand::class,
ExportDataCommand::class, ExportDataCommand::class,
MakeMenuCommand::class, MakeMenuCommand::class,
TestCommand::class,
ExcelTaskCommand::class, ExcelTaskCommand::class,
WechatCommand::class
]); ]);
} }
/** /**

View File

@ -0,0 +1,164 @@
<?php
/**
* @filename WechatCommand.php
* @date 2020/6/6
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @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 <<<CONFIG
<?php
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兼容与安全模式下请一定要填写
'response_type' => 'array',
/**
* OAuth 配置
*
* scopes公众平台snsapi_userinfo / snsapi_base开放平台snsapi_login
* callbackOAuth授权完成后的回调页地址
*/
'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,
];
}
}

View File

@ -1,7 +1,6 @@
<?php <?php
namespace catcher\library; namespace catcher\library;
use think\helper\Str;
class ParseClass class ParseClass
{ {
@ -11,6 +10,11 @@ class ParseClass
protected $controller; protected $controller;
/**
* 获取父类方法
*
* @return array
*/
public function parentMethods() public function parentMethods()
{ {
$class = $this->getClass(); $class = $this->getClass();
@ -28,7 +32,11 @@ class ParseClass
return $methods; return $methods;
} }
/**
* 获取所有方法
*
* @return array
*/
public function methods() public function methods()
{ {
$class = $this->getClass(); $class = $this->getClass();
@ -63,7 +71,12 @@ class ParseClass
return $methods; return $methods;
} }
/**
* 获取 CLASS
*
* @return \ReflectionClass
* @throws \ReflectionException
*/
public function getClass() public function getClass()
{ {
@ -72,12 +85,22 @@ class ParseClass
ucfirst($this->controller)); ucfirst($this->controller));
} }
/**
* @param $method
* @return bool
*/
protected function isMagicMethod($method) protected function isMagicMethod($method)
{ {
return strpos($method, '__') !== false; return strpos($method, '__') !== false;
} }
/**
*
* @param $module
* @return $this
* @author JaguarJack <njphper@gmail.com>
* @date 2020/6/6
*/
public function setModule($module) public function setModule($module)
{ {
$composer = \json_decode(file_get_contents(root_path() . 'composer.json'), true); $composer = \json_decode(file_get_contents(root_path() . 'composer.json'), true);
@ -94,7 +117,14 @@ class ParseClass
return $this; return $this;
} }
/**
*
* @param $module
* @param $controller
* @return $this
* @author JaguarJack <njphper@gmail.com>
* @date 2020/6/6
*/
public function setRule($module, $controller) public function setRule($module, $controller)
{ {
$this->module = $module; $this->module = $module;

View File

@ -0,0 +1,35 @@
<?php
/**
* @filename WeChat.php
* @date 2020/6/7
* @project https://github.com/yanwenwu/catch-admin
* @document http://doc.catchadmin.com
* @author JaguarJack <njphper@gmail.com>
* @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)));
}
}