21 Commits
v2.4 ... v2.5

Author SHA1 Message Date
JaguarJack
068234b57c update:auth增加忽略密码验证,适配第三方登陆 2021-01-27 14:01:17 +08:00
JaguarJack
dc1ce92194 update 2021-01-24 20:27:27 +08:00
JaguarJack
937e1745d2 update:更新默认加载commands 2021-01-24 20:24:43 +08:00
JaguarJack
9f6f02ad24 update:更新上传路由 2021-01-20 20:30:04 +08:00
JaguarJack
340e8c356b fixed:捕获异常以Json方式返回 2021-01-20 20:12:08 +08:00
JaguarJack
65d3111e65 fixed:修复oss上传 2021-01-20 20:09:06 +08:00
JaguarJack
22a8574824 fixed:空值配置无法更新 2021-01-20 19:53:19 +08:00
JaguarJack
584477f711 update:更新包 2021-01-20 19:20:09 +08:00
JaguarJack
2ae7efce04 add:新增初始化管理密码命令 2021-01-20 19:19:28 +08:00
JaguarJack
b12edc9439 update:更新调度 2021-01-18 09:29:02 +08:00
JaguarJack
c02297ab91 更新:支持app commands 自动载入 2021-01-17 20:51:05 +08:00
JaguarJack
b2b6dbd5ed Merge branch 'master' of https://github.com/yanwenwu/catch-admin 2021-01-17 11:22:13 +08:00
JaguarJack
3f154e5fb5 更新:定时任务重新修改 2021-01-17 11:21:52 +08:00
JaguarJack
cff7b38058 update:开启短线重连 2021-01-17 11:17:37 +08:00
JaguarJack
849493eea2 add:新增请求过滤空值方法 2021-01-17 09:39:18 +08:00
JaguarJack
8cace712ae update readme 2020-12-27 13:20:44 +08:00
JaguarJack
b44c8838c4 add:新增隐藏字段功能 2020-12-27 12:33:30 +08:00
JaguarJack
901c7f6cd7 update:更新定时任务搜索 2020-12-26 22:27:06 +08:00
JaguarJack
870e81ab9d add:新增快速搜索 2020-12-26 22:26:36 +08:00
JaguarJack
d4ec2d104f fixed:修改命令行无法生成model field 2020-12-26 20:56:10 +08:00
JaguarJack
614448d07a update:更新监控路由 2020-12-26 20:54:34 +08:00
24 changed files with 480 additions and 66 deletions

View File

@@ -141,14 +141,15 @@ composer create-project jaguarjack/catchadmin:dev-master
### Donate ### Donate
如果你觉得项目对你有帮助,可以请作者喝杯咖啡☕️!鼓励下 如果你觉得项目对你有帮助,可以请作者喝杯咖啡☕️!鼓励下
<!--<img src="https://cdn.learnku.com/uploads/images/202008/11/18206/e6qAAM8Bod.jpg!large">--> <img src="https://cdn.learnku.com/uploads/images/202008/11/18206/e6qAAM8Bod.jpg!large">
### Talking ### Talking
- [论坛讨论](http://bbs.catchadmin.com) - [论坛讨论](http://bbs.catchadmin.com)
- 可以提 `ISSUE`,请按照 `issue` 模板提问 - 可以提 `ISSUE`,请按照 `issue` 模板提问
- 加入 Q 群 `302266230` 暗号 `catchadmin`。 - 加入 Q 群 `302266230` 前请先 star 项目支持一下, 备注填写用户名 + 平台。例如: JaguarJack Github
### Thanks ### Thanks
- 感谢 [JetBrains](https://www.jetbrains.com) 提供生产力巨高的 `PHPStorm`和`WebStorm`
> 排名部分先后 > 排名部分先后
- [top-think/think](https://github.com/top-think/think) - [top-think/think](https://github.com/top-think/think)

View File

@@ -36,7 +36,7 @@ class CatchCrontabCommand extends Command
->addOption('pid', '-p', Option::VALUE_REQUIRED, 'you can send signal to the process of pid') ->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('static', '-s', Option::VALUE_REQUIRED, 'default static process number', 1)
->addOption('dynamic', '-dy', Option::VALUE_REQUIRED, 'default dynamic process number', 10) ->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'); ->setDescription('start catch crontab schedule');
} }

View 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;
}
}

View File

@@ -116,7 +116,7 @@ trait RegisterSignal
$process->exit(); $process->exit();
}); });
$process->start(); $process->start();
Process::alarm($this->interval); Process::alarm($this->interval);
}); });

View File

@@ -121,7 +121,7 @@ trait Store
{ {
$pidFile = config('catch.crontab.master_pid_file'); $pidFile = config('catch.crontab.master_pid_file');
if (!file_exists($pidFile)) { if (!FileSystem::exists($pidFile)) {
return 0; return 0;
} }
@@ -136,7 +136,7 @@ trait Store
*/ */
public function renderStatus() public function renderStatus()
{ {
return file_get_contents(self::statusPath()); return FileSystem::sharedGet(self::statusPath());
} }
/** /**

View File

@@ -19,6 +19,6 @@ trait CrontabSearch
public function searchStatusAttr($query, $value, $data) public function searchStatusAttr($query, $value, $data)
{ {
return $query->whereLike('status', $value); return $query->where('status', $value);
} }
} }

View File

@@ -16,7 +16,7 @@ $router->group('monitor', function () use ($router){
$router->put('crontab/enable/<id>', '\catchAdmin\monitor\controller\Crontab@disOrEnable'); $router->put('crontab/enable/<id>', '\catchAdmin\monitor\controller\Crontab@disOrEnable');
// crontab 日志 // crontab 日志
$router->get('crontab/log', '\catchAdmin\monitor\controller\CrontabLog@index'); $router->get('crontab/log/list', '\catchAdmin\monitor\controller\CrontabLog@index');
$router->delete('crontab/log/<id>', '\catchAdmin\monitor\controller\CrontabLog@delete'); $router->delete('crontab/log/list/<id>', '\catchAdmin\monitor\controller\CrontabLog@delete');
})->middleware('auth'); })->middleware('auth');

View File

@@ -110,7 +110,7 @@ class User extends CatchController
*/ */
public function update($id, UpdateRequest $request) public function update($id, UpdateRequest $request)
{ {
$this->user->updateBy($id, $request->param()); $this->user->updateBy($id, $request->filterEmptyField()->param());
$user = $this->user->findBy($id); $user = $this->user->findBy($id);

View File

@@ -66,15 +66,13 @@ class Config extends CatchModel
$config = []; $config = [];
foreach ($data as $key => $item) { foreach ($data as $key => $item) {
foreach ($item as $k => $value) { foreach ($item as $k => $value) {
if ($value) { $config[$key . '.' .$k] = [
$config[$key . '.' .$k] = [ 'pid' => $parentConfig['id'],
'pid' => $parentConfig['id'], 'key' => $key . '.' . $k,
'key' => $key . '.' . $k, 'value' => $value,
'value' => $value, 'created_at' => time(),
'created_at' => time(), 'updated_at' => time(),
'updated_at' => time(), ];
];
}
} }
} }

View File

@@ -15,8 +15,10 @@ $router->group(function () use ($router) {
$router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@backup'); $router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@backup');
// 上传 // 上传
$router->post('upload/image', '\catchAdmin\system\controller\Upload@image'); $router->group('upload', function () use ($router){
$router->post('upload/file', '\catchAdmin\system\controller\Upload@file'); $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'); $router->resource('attachments', '\catchAdmin\system\controller\Attachments');

View File

@@ -18,11 +18,10 @@
], ],
"require": { "require": {
"php": ">=7.1.0", "php": ">=7.1.0",
"topthink/framework": "6.0.5", "topthink/framework": "6.0.6",
"topthink/think-orm": "2.0.33", "topthink/think-orm": "2.0.33",
"topthink/think-migration": "^3.0", "topthink/think-migration": "^3.0",
"thans/tp-jwt-auth": "1.1", "thans/tp-jwt-auth": "1.1",
"jaguarjack/think-filesystem-cloud": "dev-master",
"overtrue/wechat": "^4.2", "overtrue/wechat": "^4.2",
"phpoffice/phpspreadsheet": "^1.12", "phpoffice/phpspreadsheet": "^1.12",
"dragonmantank/cron-expression": "^3.0", "dragonmantank/cron-expression": "^3.0",
@@ -30,7 +29,8 @@
"ext-json": "*", "ext-json": "*",
"overtrue/easy-sms": "^1.1", "overtrue/easy-sms": "^1.1",
"jaguarjack/migration-generator": "dev-master", "jaguarjack/migration-generator": "dev-master",
"lcobucci/jwt": "3.3" "lcobucci/jwt": "3.3",
"jaguarjack/think-filesystem-cloud": "1.0"
}, },
"require-dev": { "require-dev": {
"topthink/think-trace": "^1.0", "topthink/think-trace": "^1.0",

View File

@@ -49,7 +49,7 @@ return [
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 是否需要断线重连 // 是否需要断线重连
'break_reconnect' => false, 'break_reconnect' => true,
// 监听SQL // 监听SQL
'trigger_sql' => true, 'trigger_sql' => true,
// 开启字段缓存 // 开启字段缓存

View File

@@ -50,7 +50,7 @@ class CatchAdminService extends Service
$this->app->bind('catch\console', $catchConsole); $this->app->bind('catch\console', $catchConsole);
$this->commands($catchConsole->commands()); $this->commands($catchConsole->defaultCommands());
} }
} }
/** /**

View File

@@ -12,18 +12,30 @@ use think\helper\Str;
class CatchAuth class CatchAuth
{ {
/**
* @var mixed
*/
protected $auth; protected $auth;
/**
* @var mixed
*/
protected $guard; protected $guard;
// 默认获取 // 默认获取
protected $username = 'email'; protected $username = 'email';
// 校验字段 // 校验字段
protected $password = 'password'; protected $password = 'password';
// 保存用户信息 // 保存用户信息
protected $user = []; protected $user = [];
/**
* @var bool
*/
protected $checkPassword = true;
public function __construct() public function __construct()
{ {
$this->auth = config('catch.auth'); $this->auth = config('catch.auth');
@@ -54,7 +66,9 @@ class CatchAuth
public function attempt($condition) public function attempt($condition)
{ {
try { try {
$user = $this->authenticate($condition); $user = $this->authenticate($condition);
if (!$user) { if (!$user) {
throw new LoginFailedException(); throw new LoginFailedException();
} }
@@ -62,7 +76,7 @@ class CatchAuth
throw new LoginFailedException('该用户已被禁用|' . $user->username, Code::USER_FORBIDDEN); 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); throw new LoginFailedException('登录失败|' . $user->username);
} }
@@ -270,4 +284,17 @@ class CatchAuth
return $this; return $this;
} }
/**
* 忽略密码认证
*
* @time 2021年01月27日
* @return $this
*/
public function ignorePasswordVerify(): CatchAuth
{
$this->checkPassword = false;
return $this;
}
} }

View File

@@ -14,9 +14,7 @@ namespace catcher;
use catcher\library\Composer; use catcher\library\Composer;
use catcher\facade\FileSystem; use catcher\facade\FileSystem;
use Symfony\Component\Finder\SplFileInfo;
use think\App; use think\App;
use think\console\Command;
class CatchConsole class CatchConsole
{ {
@@ -37,7 +35,7 @@ class CatchConsole
* @time 2020年07月02日 * @time 2020年07月02日
* @return array * @return array
*/ */
public function commands() public function commands(): array
{ {
$commandFiles = FileSystem::allFiles($this->path); $commandFiles = FileSystem::allFiles($this->path);
@@ -62,20 +60,23 @@ class CatchConsole
* @time 2020年07月19日 * @time 2020年07月19日
* @return string * @return string
*/ */
protected function parseNamespace() protected function parseNamespace(): string
{ {
// 没有设置 namespace 默认使用 extend 目录 $psr4 = (new Composer)->psr4Autoload();
if (!$this->namespace) {
return root_path(). 'extend'; 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 . return rtrim($path, '/');
str_replace('\\', DIRECTORY_SEPARATOR, substr($this->namespace, strpos($this->namespace, '\\') + 1));
} }
/** /**
@@ -85,7 +86,7 @@ class CatchConsole
* @param $path * @param $path
* @return $this * @return $this
*/ */
public function path($path) public function path($path): CatchConsole
{ {
$this->path = $path; $this->path = $path;
@@ -99,11 +100,40 @@ class CatchConsole
* @param $namespace * @param $namespace
* @return $this * @return $this
*/ */
public function setNamespace($namespace) public function setNamespace($namespace): CatchConsole
{ {
$this->namespace = $namespace; $this->namespace = $namespace;
return $this; 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;
}
} }

View File

@@ -138,6 +138,57 @@ class CatchQuery extends Query
return $this; 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日 * @time 2020年01月13日
@@ -178,6 +229,28 @@ class CatchQuery extends Query
return parent::whereLike($field, $condition, $logic); 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');
}
/** /**
* 额外的字段 * 额外的字段
* *

View File

@@ -63,25 +63,30 @@ class CatchUpload
*/ */
public function upload(UploadedFile $file): string 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', [ event('attachment', [
'path' => $path, 'path' => $path,
'url' => $url, 'url' => $url,
'driver' => $this->getDriver(), 'driver' => $this->getDriver(),
'file' => $file, '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!');
} }
/** /**
@@ -336,11 +341,27 @@ class CatchUpload
case CatchUpload::LOCAL: case CatchUpload::LOCAL:
return $driver['domain']; return $driver['domain'];
case CatchUpload::OSS: case CatchUpload::OSS:
return $driver['end_point']; return self::getOssDomain();
case CatchUpload::QCLOUD: case CatchUpload::QCLOUD:
return $driver['cdn']; return $driver['cdn'];
default: default:
throw new FailedException(sprintf('Driver [%s] Not Supported.', $driver)); 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'];
}
} }

View File

@@ -152,7 +152,7 @@ class Utils
} }
/** /**
* 删除前缀 * 删除前缀
* *
* @time 2020年12月01日 * @time 2020年12月01日
* @param string $table * @param string $table
@@ -163,6 +163,19 @@ class Utils
return str_replace(self::tablePrefix(), '', $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;
}
/** /**
* 是否是超级管理员 * 是否是超级管理员
* *
@@ -197,4 +210,23 @@ class Utils
{ {
return root_path($path ? 'public/'. $path : 'public'); 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;
}
} }

View File

@@ -5,6 +5,7 @@ namespace catcher\base;
use catcher\CatchQuery; use catcher\CatchQuery;
use catcher\traits\db\BaseOptionsTrait; use catcher\traits\db\BaseOptionsTrait;
use catcher\traits\db\RewriteTrait;
use catcher\traits\db\TransTrait; use catcher\traits\db\TransTrait;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use catcher\traits\db\ScopeTrait; use catcher\traits\db\ScopeTrait;
@@ -17,7 +18,7 @@ use catcher\traits\db\ScopeTrait;
*/ */
abstract class CatchModel extends \think\Model abstract class CatchModel extends \think\Model
{ {
use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait; use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait, RewriteTrait;
protected $createTime = 'created_at'; protected $createTime = 'created_at';
@@ -29,8 +30,8 @@ abstract class CatchModel extends \think\Model
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
// 分页 Limit
public const LIMIT = 10; public const LIMIT = 10;
// 开启 // 开启
public const ENABLE = 1; public const ENABLE = 1;
// 禁用 // 禁用

View File

@@ -6,7 +6,7 @@ namespace catcher\base;
use app\Request; use app\Request;
use catcher\exceptions\FailedException; use catcher\exceptions\FailedException;
use catcher\exceptions\ValidateFailedException; use catcher\exceptions\ValidateFailedException;
use think\App; use catcher\Utils;
class CatchRequest extends Request class CatchRequest extends Request
{ {
@@ -89,4 +89,22 @@ class CatchRequest extends Request
return parent::post($name, $default, $filter); // TODO: Change the autogenerated stub 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;
}
} }

View File

@@ -3,16 +3,11 @@ declare (strict_types = 1);
namespace catcher\command\Tools; namespace catcher\command\Tools;
use catcher\CatchAdmin;
use catcher\facade\FileSystem;
use catcher\library\BackUpDatabase; use catcher\library\BackUpDatabase;
use catcher\library\Zip;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Argument; use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output; use think\console\Output;
use think\facade\Db;
class BackupCommand extends Command class BackupCommand extends Command
{ {

View 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();
}
}
}

View File

@@ -50,7 +50,7 @@ class Model extends Factory
{ {
$extra = $params['extra']; $extra = $params['extra'];
$table = $params['table']; $table = Utils::tableWithPrefix($params['table']);
[$modelName, $namespace] = $this->parseFilename($params['model']); [$modelName, $namespace] = $this->parseFilename($params['model']);
@@ -92,7 +92,6 @@ class Model extends Factory
(new Arr)->build(Db::getFields($table)) (new Arr)->build(Db::getFields($table))
)->docComment('// 数据库字段映射')); )->docComment('// 数据库字段映射'));
}); });
})->getContent(); })->getContent();
} }
} }

View 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;
}
}