Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
068234b57c | ||
![]() |
dc1ce92194 | ||
![]() |
937e1745d2 | ||
![]() |
9f6f02ad24 | ||
![]() |
340e8c356b | ||
![]() |
65d3111e65 | ||
![]() |
22a8574824 | ||
![]() |
584477f711 | ||
![]() |
2ae7efce04 | ||
![]() |
b12edc9439 | ||
![]() |
c02297ab91 | ||
![]() |
b2b6dbd5ed | ||
![]() |
3f154e5fb5 | ||
![]() |
cff7b38058 | ||
![]() |
849493eea2 | ||
![]() |
8cace712ae | ||
![]() |
b44c8838c4 | ||
![]() |
901c7f6cd7 | ||
![]() |
870e81ab9d | ||
![]() |
d4ec2d104f | ||
![]() |
614448d07a | ||
![]() |
dcbe82f398 | ||
![]() |
afe70d39b9 | ||
![]() |
9118e07d7b | ||
![]() |
c0f05fcf8f | ||
![]() |
35445f37e1 | ||
![]() |
94c430f491 | ||
![]() |
97efb82971 | ||
![]() |
5f49a22a5e | ||
![]() |
85f4fc0df8 | ||
![]() |
04a7818608 |
@@ -146,9 +146,10 @@ composer create-project jaguarjack/catchadmin:dev-master
|
||||
### Talking
|
||||
- [论坛讨论](http://bbs.catchadmin.com)
|
||||
- 可以提 `ISSUE`,请按照 `issue` 模板提问
|
||||
- 加入 Q 群 `302266230` 暗号 `catchadmin`。
|
||||
- 加入 Q 群 `302266230` 前请先 star 项目支持一下, 备注填写用户名 + 平台。例如: JaguarJack Github
|
||||
|
||||
### Thanks
|
||||
- 感谢 [JetBrains](https://www.jetbrains.com) 提供生产力巨高的 `PHPStorm`和`WebStorm`
|
||||
> 排名部分先后
|
||||
|
||||
- [top-think/think](https://github.com/top-think/think)
|
||||
|
@@ -29,7 +29,7 @@ class Index extends CatchController
|
||||
|
||||
$user = $auth->user();
|
||||
|
||||
$this->afterLoginSuccess($user);
|
||||
$this->afterLoginSuccess($user, $token);
|
||||
// 登录事件
|
||||
$this->loginEvent($user->username);
|
||||
|
||||
@@ -70,12 +70,16 @@ class Index extends CatchController
|
||||
*
|
||||
* @time 2020年09月09日
|
||||
* @param $user
|
||||
* @param $token
|
||||
* @return void
|
||||
*/
|
||||
protected function afterLoginSuccess($user)
|
||||
protected function afterLoginSuccess($user, $token)
|
||||
{
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->last_login_time = time();
|
||||
if ($user->hasField('remember_token')) {
|
||||
$user->remember_token = $token;
|
||||
}
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ class CatchCrontabCommand extends Command
|
||||
->addOption('pid', '-p', Option::VALUE_REQUIRED, 'you can send signal to the process of pid')
|
||||
->addOption('static', '-s', Option::VALUE_REQUIRED, 'default static process number', 1)
|
||||
->addOption('dynamic', '-dy', Option::VALUE_REQUIRED, 'default dynamic process number', 10)
|
||||
->addOption('interval', '-i', Option::VALUE_REQUIRED, 'interval/seconds', 60)
|
||||
->addOption('interval', '-i', Option::VALUE_REQUIRED, 'interval/seconds', 5)
|
||||
->setDescription('start catch crontab schedule');
|
||||
}
|
||||
|
||||
|
127
catch/monitor/command/ScheduleCommand.php
Normal file
127
catch/monitor/command/ScheduleCommand.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace catchAdmin\monitor\command;
|
||||
|
||||
use catchAdmin\monitor\command\process\Process;
|
||||
use catchAdmin\monitor\model\Crontab;
|
||||
use catchAdmin\monitor\model\CrontabLog;
|
||||
use Cron\CronExpression;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class ScheduleCommand extends Command
|
||||
{
|
||||
protected $pid;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('catch:schedule')
|
||||
->setDescription('catch schedule');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
foreach ($this->getExecuteAbleCommands() as $command) {
|
||||
|
||||
$process = new Process(function (Process $process) use ($command) {
|
||||
$this->executeCommand($command);
|
||||
$process->exit();
|
||||
});
|
||||
|
||||
$process->start();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('CatchSchedule Error:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行 command
|
||||
*
|
||||
* @time 2021年01月18日
|
||||
* @param $command
|
||||
* @return void
|
||||
*/
|
||||
protected function executeCommand($command)
|
||||
{
|
||||
$start = time();
|
||||
|
||||
$errorMessage = '';
|
||||
|
||||
try {
|
||||
$this->getConsole()->call($command->task);
|
||||
} catch (\Exception $e) {
|
||||
$errorMessage = $e->getMessage();
|
||||
}
|
||||
|
||||
$end = time();
|
||||
|
||||
// 插入 crontab 执行日志
|
||||
CrontabLog::insert([
|
||||
'crontab_id' => $command->id,
|
||||
'used_time' => $end - $start,
|
||||
'status' => $errorMessage ? CrontabLog::FAILED : CrontabLog::SUCCESS,
|
||||
'error_message' => $errorMessage,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可执行任务
|
||||
*
|
||||
* @time 2021年01月17日
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array
|
||||
*/
|
||||
protected function getExecuteAbleCommands()
|
||||
{
|
||||
$executeAbleCommands = [];
|
||||
|
||||
Crontab::where('status', Crontab::ENABLE)
|
||||
->where('tactics', '<>', Crontab::EXECUTE_FORBIDDEN)
|
||||
->select()
|
||||
->each(function ($command) use (&$executeAbleCommands){
|
||||
if ($command->tactics == Crontab::EXECUTE_IMMEDIATELY) {
|
||||
$executeAbleCommands[] = $command;
|
||||
return true;
|
||||
}
|
||||
|
||||
$can = date('Y-m-d H:i', CronExpression::factory(trim($command->cron))
|
||||
->getNextRunDate(date('Y-m-d H:i:s'), 0, true)
|
||||
->getTimestamp()) == date('Y-m-d H:i', time());
|
||||
|
||||
if ($can) {
|
||||
// 如果任务只执行一次 之后禁用该任务
|
||||
if ($command->tactics === Crontab::EXECUTE_ONCE) {
|
||||
Crontab::where('id', $command->id)->update([
|
||||
'status' => Crontab::DISABLE,
|
||||
]);
|
||||
}
|
||||
|
||||
$executeAbleCommands[] = $command;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return $executeAbleCommands;
|
||||
}
|
||||
}
|
@@ -116,7 +116,7 @@ trait RegisterSignal
|
||||
$process->exit();
|
||||
});
|
||||
|
||||
$process->start();
|
||||
$process->start();
|
||||
|
||||
Process::alarm($this->interval);
|
||||
});
|
||||
|
@@ -121,7 +121,7 @@ trait Store
|
||||
{
|
||||
$pidFile = config('catch.crontab.master_pid_file');
|
||||
|
||||
if (!file_exists($pidFile)) {
|
||||
if (!FileSystem::exists($pidFile)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ trait Store
|
||||
*/
|
||||
public function renderStatus()
|
||||
{
|
||||
return file_get_contents(self::statusPath());
|
||||
return FileSystem::sharedGet(self::statusPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -19,6 +19,6 @@ trait CrontabSearch
|
||||
|
||||
public function searchStatusAttr($query, $value, $data)
|
||||
{
|
||||
return $query->whereLike('status', $value);
|
||||
return $query->where('status', $value);
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ $router->group('monitor', function () use ($router){
|
||||
$router->put('crontab/enable/<id>', '\catchAdmin\monitor\controller\Crontab@disOrEnable');
|
||||
|
||||
// crontab 日志
|
||||
$router->get('crontab/log', '\catchAdmin\monitor\controller\CrontabLog@index');
|
||||
$router->delete('crontab/log/<id>', '\catchAdmin\monitor\controller\CrontabLog@delete');
|
||||
$router->get('crontab/log/list', '\catchAdmin\monitor\controller\CrontabLog@index');
|
||||
$router->delete('crontab/log/list/<id>', '\catchAdmin\monitor\controller\CrontabLog@delete');
|
||||
|
||||
})->middleware('auth');
|
@@ -8,6 +8,7 @@ use catchAdmin\permissions\model\Roles;
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catchAdmin\permissions\request\CreateRequest;
|
||||
use catchAdmin\permissions\request\UpdateRequest;
|
||||
use catchAdmin\permissions\request\ProfileRequest;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchCacheKeys;
|
||||
@@ -67,15 +68,6 @@ class User extends CatchController
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月06日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function create()
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param CreateRequest $request
|
||||
@@ -109,12 +101,6 @@ class User extends CatchController
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function edit($id){}
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月04日
|
||||
@@ -124,7 +110,7 @@ class User extends CatchController
|
||||
*/
|
||||
public function update($id, UpdateRequest $request)
|
||||
{
|
||||
$this->user->updateBy($id, $request->param());
|
||||
$this->user->updateBy($id, $request->filterEmptyField()->param());
|
||||
|
||||
$user = $this->user->findBy($id);
|
||||
|
||||
@@ -248,10 +234,10 @@ class User extends CatchController
|
||||
* 更新个人信息
|
||||
*
|
||||
* @time 2020年09月20日
|
||||
* @param Request $request
|
||||
* @param ProfileRequest $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function profile(Request $request)
|
||||
public function profile(ProfileRequest $request)
|
||||
{
|
||||
return CatchResponse::success($this->user->updateBy($request->user()->id, $request->param()));
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
||||
class AddUserRememberToken extends Migrator
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
if ($this->hasTable('users')) {
|
||||
$table = $this->table('users');
|
||||
|
||||
$table->addColumn('remember_token', 'string', [
|
||||
'limit' => 512,
|
||||
'default' => '',
|
||||
'comment' => '用户token',
|
||||
'after' => 'avatar'])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ class Users extends CatchModel
|
||||
'password', // 用户密码
|
||||
'email', // 邮箱 登录
|
||||
'avatar', // 头像
|
||||
'remember_token',
|
||||
'creator_id', // 创建者ID
|
||||
'department_id', // 部门ID
|
||||
'status', // 用户状态 1 正常 2 禁用
|
||||
@@ -28,7 +29,6 @@ class Users extends CatchModel
|
||||
'created_at', // 创建时间
|
||||
'updated_at', // 更新时间
|
||||
'deleted_at', // 删除状态,0未删除 >0 已删除
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
|
17
catch/permissions/request/ProfileRequest.php
Normal file
17
catch/permissions/request/ProfileRequest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\request;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\base\CatchRequest;
|
||||
|
||||
class ProfileRequest extends CatchRequest
|
||||
{
|
||||
protected function rules(): array
|
||||
{
|
||||
// TODO: Implement rules() method.
|
||||
return [
|
||||
'username|用户名' => 'require|max:20',
|
||||
'email|邮箱' => 'require|email|unique:'.Users::class . ',email,' . $this->user()->id,
|
||||
];
|
||||
}
|
||||
}
|
@@ -15,9 +15,4 @@ class UpdateRequest extends CatchRequest
|
||||
'email|邮箱' => 'require|email|unique:'.Users::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function message()
|
||||
{
|
||||
// TODO: Implement message() method.
|
||||
}
|
||||
}
|
||||
|
@@ -66,15 +66,13 @@ class Config extends CatchModel
|
||||
$config = [];
|
||||
foreach ($data as $key => $item) {
|
||||
foreach ($item as $k => $value) {
|
||||
if ($value) {
|
||||
$config[$key . '.' .$k] = [
|
||||
'pid' => $parentConfig['id'],
|
||||
'key' => $key . '.' . $k,
|
||||
'value' => $value,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
];
|
||||
}
|
||||
$config[$key . '.' .$k] = [
|
||||
'pid' => $parentConfig['id'],
|
||||
'key' => $key . '.' . $k,
|
||||
'value' => $value,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,8 +15,10 @@ $router->group(function () use ($router) {
|
||||
$router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@backup');
|
||||
|
||||
// 上传
|
||||
$router->post('upload/image', '\catchAdmin\system\controller\Upload@image');
|
||||
$router->post('upload/file', '\catchAdmin\system\controller\Upload@file');
|
||||
$router->group('upload', function () use ($router){
|
||||
$router->post('image', '\catchAdmin\system\controller\Upload@image');
|
||||
$router->post('file', '\catchAdmin\system\controller\Upload@file');
|
||||
})->middleware(\catcher\middlewares\JsonResponseMiddleware::class);
|
||||
|
||||
// 附件
|
||||
$router->resource('attachments', '\catchAdmin\system\controller\Attachments');
|
||||
|
@@ -18,18 +18,19 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"topthink/framework": "6.0.5",
|
||||
"topthink/framework": "6.0.6",
|
||||
"topthink/think-orm": "2.0.33",
|
||||
"topthink/think-migration": "^3.0",
|
||||
"thans/tp-jwt-auth": "1.1",
|
||||
"jaguarjack/think-filesystem-cloud": "dev-master",
|
||||
"overtrue/wechat": "^4.2",
|
||||
"phpoffice/phpspreadsheet": "^1.12",
|
||||
"dragonmantank/cron-expression": "^3.0",
|
||||
"symfony/finder": "^4.4",
|
||||
"ext-json": "*",
|
||||
"overtrue/easy-sms": "^1.1",
|
||||
"jaguarjack/migration-generator": "dev-master"
|
||||
"jaguarjack/migration-generator": "dev-master",
|
||||
"lcobucci/jwt": "3.3",
|
||||
"jaguarjack/think-filesystem-cloud": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"topthink/think-trace": "^1.0",
|
||||
|
@@ -49,7 +49,7 @@ return [
|
||||
// 是否严格检查字段是否存在
|
||||
'fields_strict' => true,
|
||||
// 是否需要断线重连
|
||||
'break_reconnect' => false,
|
||||
'break_reconnect' => true,
|
||||
// 监听SQL
|
||||
'trigger_sql' => true,
|
||||
// 开启字段缓存
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use think\helper\Arr;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\event\LoadModuleRoutes;
|
||||
@@ -48,7 +50,7 @@ class CatchAdminService extends Service
|
||||
|
||||
$this->app->bind('catch\console', $catchConsole);
|
||||
|
||||
$this->commands($catchConsole->commands());
|
||||
$this->commands($catchConsole->defaultCommands());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
@@ -10,18 +12,30 @@ use think\helper\Str;
|
||||
|
||||
class CatchAuth
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $guard;
|
||||
|
||||
// 默认获取
|
||||
protected $username = 'email';
|
||||
|
||||
// 校验字段
|
||||
protected $password = 'password';
|
||||
|
||||
// 保存用户信息
|
||||
protected $user = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $checkPassword = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->auth = config('catch.auth');
|
||||
@@ -52,7 +66,9 @@ class CatchAuth
|
||||
public function attempt($condition)
|
||||
{
|
||||
try {
|
||||
|
||||
$user = $this->authenticate($condition);
|
||||
|
||||
if (!$user) {
|
||||
throw new LoginFailedException();
|
||||
}
|
||||
@@ -60,7 +76,7 @@ class CatchAuth
|
||||
throw new LoginFailedException('该用户已被禁用|' . $user->username, Code::USER_FORBIDDEN);
|
||||
}
|
||||
|
||||
if (!password_verify($condition['password'], $user->password)) {
|
||||
if ($this->checkPassword && !password_verify($condition['password'], $user->password)) {
|
||||
throw new LoginFailedException('登录失败|' . $user->username);
|
||||
}
|
||||
|
||||
@@ -268,4 +284,17 @@ class CatchAuth
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略密码认证
|
||||
*
|
||||
* @time 2021年01月27日
|
||||
* @return $this
|
||||
*/
|
||||
public function ignorePasswordVerify(): CatchAuth
|
||||
{
|
||||
$this->checkPassword = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename CacheKeys.php
|
||||
* @createdAt 2020/1/17
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -13,7 +15,6 @@ namespace catcher;
|
||||
use catcher\library\Composer;
|
||||
use catcher\facade\FileSystem;
|
||||
use think\App;
|
||||
use think\console\Command;
|
||||
|
||||
class CatchConsole
|
||||
{
|
||||
@@ -34,18 +35,18 @@ class CatchConsole
|
||||
* @time 2020年07月02日
|
||||
* @return array
|
||||
*/
|
||||
public function commands()
|
||||
public function commands(): array
|
||||
{
|
||||
$commandFiles = FileSystem::allFiles($this->path);
|
||||
|
||||
$commands = [];
|
||||
|
||||
/* \Symfony\Component\Finder\SplFileInfo $command */
|
||||
/* \Symfony\Component\Finder\SplFileInfo $command */
|
||||
foreach ($commandFiles as $command) {
|
||||
if ($command->getExtension() === 'php') {
|
||||
$lastPath = str_replace($this->parseNamespace(), '',pathinfo($command, PATHINFO_DIRNAME));
|
||||
$lastPath = str_replace($this->parseNamespace(), '', pathinfo($command->getPathname(), PATHINFO_DIRNAME));
|
||||
$namespace = $this->namespace . str_replace(DIRECTORY_SEPARATOR, '\\', $lastPath) . '\\';
|
||||
$commandClass = $namespace . pathinfo($command, PATHINFO_FILENAME);
|
||||
$commandClass = $namespace . pathinfo($command->getPathname(), PATHINFO_FILENAME);
|
||||
$commands[] = $commandClass;
|
||||
}
|
||||
}
|
||||
@@ -59,20 +60,23 @@ class CatchConsole
|
||||
* @time 2020年07月19日
|
||||
* @return string
|
||||
*/
|
||||
protected function parseNamespace()
|
||||
protected function parseNamespace(): string
|
||||
{
|
||||
// 没有设置 namespace 默认使用 extend 目录
|
||||
if (!$this->namespace) {
|
||||
return root_path(). 'extend';
|
||||
$psr4 = (new Composer)->psr4Autoload();
|
||||
|
||||
if (strpos($this->namespace, '\\') === false) {
|
||||
$rootNamespace = $this->namespace . '\\';
|
||||
} else {
|
||||
$rootNamespace = substr($this->namespace, 0, strpos($this->namespace, '\\') + 1);
|
||||
}
|
||||
|
||||
$psr4 = (new Composer())->psr4Autoload();
|
||||
$path = root_path(). $psr4[$rootNamespace] . DIRECTORY_SEPARATOR;
|
||||
|
||||
$rootNamespace = substr($this->namespace, 0, strpos($this->namespace, '\\') + 1);
|
||||
if (strpos($this->namespace, '\\') !== false) {
|
||||
$path .= str_replace('\\', DIRECTORY_SEPARATOR, substr($this->namespace, strpos($this->namespace, '\\') + 1));
|
||||
}
|
||||
|
||||
return root_path(). $psr4[$rootNamespace] . DIRECTORY_SEPARATOR .
|
||||
|
||||
str_replace('\\', DIRECTORY_SEPARATOR, substr($this->namespace, strpos($this->namespace, '\\') + 1));
|
||||
return rtrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +86,7 @@ class CatchConsole
|
||||
* @param $path
|
||||
* @return $this
|
||||
*/
|
||||
public function path($path)
|
||||
public function path($path): CatchConsole
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
@@ -96,11 +100,40 @@ class CatchConsole
|
||||
* @param $namespace
|
||||
* @return $this
|
||||
*/
|
||||
public function setNamespace($namespace)
|
||||
public function setNamespace($namespace): CatchConsole
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认 commands
|
||||
*
|
||||
* @time 2021年01月24日
|
||||
* @return array
|
||||
*/
|
||||
public function defaultCommands(): array
|
||||
{
|
||||
$defaultCommands = FileSystem::allFiles(__DIR__ . DIRECTORY_SEPARATOR . 'command');
|
||||
|
||||
$commands = [];
|
||||
|
||||
/* \Symfony\Component\Finder\SplFileInfo $command */
|
||||
foreach ($defaultCommands as $command) {
|
||||
if ($command->getExtension() === 'php') {
|
||||
|
||||
$filename = str_replace('.php', '', str_replace(__DIR__, '', $command->getPathname()));
|
||||
|
||||
$class = 'catcher' . str_replace(DIRECTORY_SEPARATOR, '\\', $filename);
|
||||
|
||||
if (class_exists($class)) {
|
||||
$commands[] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $commands;
|
||||
}
|
||||
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use app\ExceptionHandle;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\library\excel\Excel;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catcher\base\CatchModel;
|
||||
@@ -11,7 +13,7 @@ class CatchQuery extends Query
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
@@ -19,29 +21,38 @@ class CatchQuery extends Query
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchJoin(string $model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
|
||||
public function catchJoin($model, string $joinField, string $currentJoinField, array $field = [], string $type = 'INNER', array $bind = []): CatchQuery
|
||||
{
|
||||
$table = app($model)->getTable();
|
||||
$tableAlias = null;
|
||||
|
||||
if (is_string($model)) {
|
||||
$table = app($model)->getTable();
|
||||
} else {
|
||||
list($model, $tableAlias) = $model;
|
||||
$table = app($model)->getTable();
|
||||
}
|
||||
|
||||
// 合并字段
|
||||
$this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($table) {
|
||||
return $table . '.' . $value;
|
||||
$this->options['field'] = array_merge($this->options['field'] ?? [], array_map(function ($value) use ($table, $tableAlias) {
|
||||
return ($tableAlias ? : $table) . '.' . $value;
|
||||
}, $field));
|
||||
|
||||
return $this->join($table, sprintf('%s.%s=%s.%s', $table, $joinField, $this->getAlias(), $currentJoinField), $type, $bind);
|
||||
return $this->join($tableAlias ? sprintf('%s %s', $table, $tableAlias) : $table
|
||||
|
||||
, sprintf('%s.%s=%s.%s', $tableAlias ? $tableAlias : $table, $joinField, $this->getAlias(), $currentJoinField), $type, $bind);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchLeftJoin(string $model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
public function catchLeftJoin($model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
{
|
||||
return $this->catchJoin($model, $joinField, $currentJoinField, $field,'LEFT', $bind);
|
||||
}
|
||||
@@ -49,14 +60,14 @@ class CatchQuery extends Query
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
* @param string $model
|
||||
* @param mixed $model
|
||||
* @param string $joinField
|
||||
* @param string $currentJoinField
|
||||
* @param array $field
|
||||
* @param array $bind
|
||||
* @return CatchQuery
|
||||
*/
|
||||
public function catchRightJoin(string $model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
public function catchRightJoin($model, string $joinField, string $currentJoinField, array $field = [], array $bind = []): CatchQuery
|
||||
{
|
||||
return $this->catchJoin($model, $joinField, $currentJoinField, $field,'RIGHT', $bind);
|
||||
}
|
||||
@@ -118,7 +129,8 @@ class CatchQuery extends Query
|
||||
|
||||
foreach ($params as $field => $value) {
|
||||
$method = 'search' . Str::studly($field) . 'Attr';
|
||||
if ($value !== null && method_exists($this->model, $method)) {
|
||||
// value in [null, '']
|
||||
if ($value !== null && $value !== '' && method_exists($this->model, $method)) {
|
||||
$this->model->$method($this, $value, $params);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +138,57 @@ class CatchQuery extends Query
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速搜索
|
||||
*
|
||||
* @param array $params
|
||||
* @return Query
|
||||
*/
|
||||
public function quickSearch($params = []): Query
|
||||
{
|
||||
$requestParams = \request()->param();
|
||||
|
||||
if (empty($params) && empty($requestParams)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
foreach ($requestParams as $field => $value) {
|
||||
if (isset($params[$field])) {
|
||||
// ['>', value] || value
|
||||
if (is_array($params[$field])) {
|
||||
$this->where($field, $params[$field][0], $params[$field][1]);
|
||||
} else {
|
||||
$this->where($field, $value);
|
||||
}
|
||||
} else {
|
||||
// 区间范围 start_数据库字段 & end_数据库字段
|
||||
$startPos = strpos($field, 'start_');
|
||||
if ($startPos === 0) {
|
||||
$this->where(str_replace('start_','', $field), '>=', strtotime($value));
|
||||
}
|
||||
$endPos = strpos($field, 'end_');
|
||||
if ($endPos === 0) {
|
||||
$this->where(str_replace('end_', '', $field), '>=', strtotime($value));
|
||||
}
|
||||
// 模糊搜索
|
||||
if (Str::contains($field, 'like')) {
|
||||
[$operate, $field] = explode('_', $field);
|
||||
if ($operate === 'like') {
|
||||
$this->whereLike($field, $value);
|
||||
} else if ($operate === '%like') {
|
||||
$this->whereLeftLike($field, $value);
|
||||
} else {
|
||||
$this->whereRightLike($field, $value);
|
||||
}
|
||||
}
|
||||
// = 值搜索
|
||||
$this->where($field, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月13日
|
||||
@@ -166,6 +229,28 @@ class CatchQuery extends Query
|
||||
return parent::whereLike($field, $condition, $logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $condition
|
||||
* @param string $logic
|
||||
* @return Query
|
||||
*/
|
||||
public function whereLeftLike(string $field, $condition, string $logic = 'AND'): Query
|
||||
{
|
||||
return $this->where($field, $condition, $logic, 'left');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param $condition
|
||||
* @param string $logic
|
||||
* @return Query
|
||||
*/
|
||||
public function whereRightLike(string $field, $condition, string $logic = 'AND'): Query
|
||||
{
|
||||
return $this->where($field, $condition, $logic, 'right');
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外的字段
|
||||
*
|
||||
|
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use think\Paginator;
|
||||
use think\Response;
|
||||
use think\response\Json;
|
||||
|
||||
class CatchResponse
|
||||
@@ -19,11 +19,11 @@ class CatchResponse
|
||||
*/
|
||||
public static function success($data = [], $msg = 'success', $code = Code::SUCCESS): Json
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'data' => $data,
|
||||
]);
|
||||
return json([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,14 +35,14 @@ class CatchResponse
|
||||
*/
|
||||
public static function paginate(Paginator $list)
|
||||
{
|
||||
return json([
|
||||
'code' => Code::SUCCESS,
|
||||
'message' => 'success',
|
||||
'count' => $list->total(),
|
||||
'current' => $list->currentPage(),
|
||||
'limit' => $list->listRows(),
|
||||
'data' => $list->getCollection(),
|
||||
]);
|
||||
return json([
|
||||
'code' => Code::SUCCESS,
|
||||
'message' => 'success',
|
||||
'count' => $list->total(),
|
||||
'current' => $list->currentPage(),
|
||||
'limit' => $list->listRows(),
|
||||
'data' => $list->getCollection(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,9 +55,9 @@ class CatchResponse
|
||||
*/
|
||||
public static function fail($msg = '', $code = Code::FAILED): Json
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
]);
|
||||
return json([
|
||||
'code' => $code,
|
||||
'message' => $msg,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\system\model\Attachments;
|
||||
@@ -61,25 +63,30 @@ class CatchUpload
|
||||
*/
|
||||
public function upload(UploadedFile $file): string
|
||||
{
|
||||
$this->initUploadConfig();
|
||||
try {
|
||||
$this->initUploadConfig();
|
||||
|
||||
$path = Filesystem::disk($this->getDriver())->putFile($this->getPath(), $file);
|
||||
$path = Filesystem::disk($this->getDriver())->putFile($this->getPath(), $file);
|
||||
|
||||
if ($path) {
|
||||
if ($path) {
|
||||
|
||||
$url = self::getCloudDomain($this->getDriver()) . '/' . $this->getLocalPath($path);
|
||||
$url = self::getCloudDomain($this->getDriver()) . '/' . $this->getLocalPath($path);
|
||||
|
||||
event('attachment', [
|
||||
'path' => $path,
|
||||
'url' => $url,
|
||||
'driver' => $this->getDriver(),
|
||||
'file' => $file,
|
||||
]);
|
||||
event('attachment', [
|
||||
'path' => $path,
|
||||
'url' => $url,
|
||||
'driver' => $this->getDriver(),
|
||||
'file' => $file,
|
||||
]);
|
||||
|
||||
return $url;
|
||||
return $url;
|
||||
}
|
||||
|
||||
throw new FailedException('Upload Failed, Try Again!');
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new FailedException($exception->getMessage());
|
||||
}
|
||||
|
||||
throw new FailedException('Upload Failed, Try Again!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,11 +341,27 @@ class CatchUpload
|
||||
case CatchUpload::LOCAL:
|
||||
return $driver['domain'];
|
||||
case CatchUpload::OSS:
|
||||
return $driver['end_point'];
|
||||
return self::getOssDomain();
|
||||
case CatchUpload::QCLOUD:
|
||||
return $driver['cdn'];
|
||||
default:
|
||||
throw new FailedException(sprintf('Driver [%s] Not Supported.', $driver));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 OSS Domain
|
||||
*
|
||||
* @time 2021年01月20日
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected static function getOssDomain(): string
|
||||
{
|
||||
$oss = \config('filesystem.disks.oss');
|
||||
if ($oss['is_cname'] === false) {
|
||||
return 'https://' . $oss['bucket'] . '.' . $oss['end_point'];
|
||||
}
|
||||
|
||||
return $oss['end_point'];
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
class Code
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
class Tree
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher;
|
||||
|
||||
use catchAdmin\system\model\Config;
|
||||
@@ -149,6 +151,31 @@ class Utils
|
||||
return \config('database.connections.mysql.prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表前缀
|
||||
*
|
||||
* @time 2020年12月01日
|
||||
* @param string $table
|
||||
* @return string|string[]
|
||||
*/
|
||||
public static function tableWithoutPrefix(string $table)
|
||||
{
|
||||
return str_replace(self::tablePrefix(), '', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加表前缀
|
||||
*
|
||||
* @time 2020年12月26日
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public static function tableWithPrefix(string $table)
|
||||
{
|
||||
return Str::contains($table, self::tablePrefix()) ?
|
||||
$table : self::tablePrefix() . $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是超级管理员
|
||||
*
|
||||
@@ -183,4 +210,23 @@ class Utils
|
||||
{
|
||||
return root_path($path ? 'public/'. $path : 'public');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 过滤空字符字段
|
||||
*
|
||||
* @time 2021年01月16日
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filterEmptyValue($data)
|
||||
{
|
||||
foreach ($data as $k => $v) {
|
||||
if (!$v) {
|
||||
unset($data[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
abstract class CatchController
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,8 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use catcher\CatchQuery;
|
||||
use catcher\traits\db\BaseOptionsTrait;
|
||||
use catcher\traits\db\RewriteTrait;
|
||||
use catcher\traits\db\TransTrait;
|
||||
use think\model\concern\SoftDelete;
|
||||
use catcher\traits\db\ScopeTrait;
|
||||
@@ -15,7 +18,7 @@ use catcher\traits\db\ScopeTrait;
|
||||
*/
|
||||
abstract class CatchModel extends \think\Model
|
||||
{
|
||||
use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait;
|
||||
use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait, RewriteTrait;
|
||||
|
||||
protected $createTime = 'created_at';
|
||||
|
||||
@@ -27,10 +30,22 @@ abstract class CatchModel extends \think\Model
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 分页 Limit
|
||||
public const LIMIT = 10;
|
||||
|
||||
// 开启
|
||||
public const ENABLE = 1;
|
||||
// 禁用
|
||||
public const DISABLE = 2;
|
||||
|
||||
/**
|
||||
* 是否有 field
|
||||
*
|
||||
* @time 2020年11月23日
|
||||
* @param string $field
|
||||
* @return bool
|
||||
*/
|
||||
public function hasField(string $field)
|
||||
{
|
||||
return property_exists($this, 'field') ? in_array($field, $this->field) : false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename CatchRepository.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use app\Request;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\exceptions\ValidateFailedException;
|
||||
use think\App;
|
||||
use catcher\Utils;
|
||||
|
||||
class CatchRequest extends Request
|
||||
{
|
||||
@@ -87,4 +89,22 @@ class CatchRequest extends Request
|
||||
return parent::post($name, $default, $filter); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤空字段
|
||||
*
|
||||
* @time 2021年01月16日
|
||||
* @return $this
|
||||
*/
|
||||
public function filterEmptyField(): CatchRequest
|
||||
{
|
||||
if ($this->isGet()) {
|
||||
$this->get = Utils::filterEmptyValue($this->get);
|
||||
} elseif ($this->isPost()) {
|
||||
$this->post = Utils::filterEmptyValue($this->post);
|
||||
} else {
|
||||
$this->put = Utils::filterEmptyValue($this->put);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\base;
|
||||
|
||||
use think\Validate;
|
||||
|
@@ -178,9 +178,14 @@ class CreateModuleCommand extends Command
|
||||
{
|
||||
$moduleJson = FileSystem::sharedGet(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub');
|
||||
|
||||
$content = str_replace(['{NAME}','{DESCRIPTION}','{MODULE}', '{SERVICE}'],
|
||||
[$this->name, $this->description,
|
||||
$this->module, '\\\\'. str_replace('\\', '\\\\',$this->namespaces . ucfirst($this->module) . 'Service')], $moduleJson);
|
||||
$content = str_replace(['{NAME}','{DESCRIPTION}','{MODULE}', '{SERVICE}', '{KEYWORDS}'],
|
||||
[
|
||||
$this->name, $this->description,
|
||||
$this->module,
|
||||
'\\\\'. str_replace('\\', '\\\\',
|
||||
$this->namespaces . ucfirst($this->module) . 'Service'),
|
||||
''
|
||||
], $moduleJson);
|
||||
|
||||
FileSystem::put($this->moduleDir . 'module.json', $content);
|
||||
}
|
||||
|
@@ -3,16 +3,11 @@ declare (strict_types = 1);
|
||||
|
||||
namespace catcher\command\Tools;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\library\BackUpDatabase;
|
||||
use catcher\library\Zip;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class BackupCommand extends Command
|
||||
{
|
||||
|
34
extend/catcher/command/Tools/InitRootCommand.php
Normal file
34
extend/catcher/command/Tools/InitRootCommand.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace catcher\command\Tools;
|
||||
|
||||
use catchAdmin\permissions\model\Users;
|
||||
use catcher\library\BackUpDatabase;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
|
||||
class InitRootCommand extends Command
|
||||
{
|
||||
protected $table;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('catch:initAdmin')
|
||||
->setDescription('backup data you need');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
if ($user = Users::where('id', config('catch.permissions.super_admin_id'))->find()) {
|
||||
|
||||
$user->password = 'catchadmin';
|
||||
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use Exception;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename WechatResponseException.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\facade;
|
||||
|
||||
use think\Facade;
|
||||
|
@@ -11,6 +11,7 @@ use catcher\generate\build\classes\Uses;
|
||||
use catcher\generate\build\types\Arr;
|
||||
use catcher\traits\db\BaseOptionsTrait;
|
||||
use catcher\traits\db\ScopeTrait;
|
||||
use catcher\Utils;
|
||||
use think\facade\Db;
|
||||
use think\helper\Str;
|
||||
|
||||
@@ -49,7 +50,7 @@ class Model extends Factory
|
||||
{
|
||||
$extra = $params['extra'];
|
||||
|
||||
$table = $params['table'];
|
||||
$table = Utils::tableWithPrefix($params['table']);
|
||||
|
||||
[$modelName, $namespace] = $this->parseFilename($params['model']);
|
||||
|
||||
@@ -80,16 +81,17 @@ class Model extends Factory
|
||||
}
|
||||
|
||||
$class->addProperty(
|
||||
(new Property('name'))->default($table)->docComment('// 表名')
|
||||
(new Property('name'))->default(
|
||||
Utils::tableWithoutPrefix($table)
|
||||
)->docComment('// 表名')
|
||||
);
|
||||
|
||||
$class->when($this->hasTableExists($table), function ($class) use ($table){
|
||||
$class->addProperty(
|
||||
(new Property('field'))->default(
|
||||
(new Arr)->build(Db::getFields($table))
|
||||
))->docComment('// 数据库字段映射');
|
||||
)->docComment('// 数据库字段映射'));
|
||||
});
|
||||
|
||||
})->getContent();
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename Errors.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace catcher\library;
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use think\exception\ClassNotFoundException;
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename ProgressBar.php
|
||||
* @createdAt 2020/6/20
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library;
|
||||
|
||||
use catcher\CatchCacheKeys;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename WeChat.php
|
||||
* @date 2020/6/7
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\client;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\client;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
use catcher\CatchUpload;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
interface ExcelContract
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
trait MacroExcel
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\library\excel;
|
||||
|
||||
interface ShouldTaskContract
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\traits\db;
|
||||
|
||||
|
56
extend/catcher/traits/db/RewriteTrait.php
Normal file
56
extend/catcher/traits/db/RewriteTrait.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace catcher\traits\db;
|
||||
|
||||
/**
|
||||
* 重写 think\Model 的方法
|
||||
*
|
||||
* Trait RewriteTrait
|
||||
* @package catcher\traits\db
|
||||
*/
|
||||
trait RewriteTrait
|
||||
{
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* CatchModel constructor.
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
parent::__construct($data);
|
||||
|
||||
$this->hidden = array_merge($this->hidden, $this->defaultHiddenFields());
|
||||
}
|
||||
|
||||
/**
|
||||
* hidden model fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function defaultHiddenFields(): array
|
||||
{
|
||||
return [$this->deleteTime];
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写 hidden 方法,支持合并 hidden 属性
|
||||
*
|
||||
* @param array $hidden
|
||||
* @return $this
|
||||
*/
|
||||
public function hidden(array $hidden = [])
|
||||
{
|
||||
/**
|
||||
* 合并属性
|
||||
*/
|
||||
if (!count($this->hidden)) {
|
||||
$this->hidden = array_merge($this->hidden, $hidden);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->hidden = $hidden;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @filename ScopeTrait.php
|
||||
* @createdAt 2020/6/21
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\traits\db;
|
||||
|
||||
use think\facade\Db;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
use catcher\library\Trie;
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
class Sometimes implements ValidateInterface
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace catcher\validates;
|
||||
|
||||
interface ValidateInterface
|
||||
|
Reference in New Issue
Block a user