Compare commits
21 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 |
@@ -141,14 +141,15 @@ composer create-project jaguarjack/catchadmin:dev-master
|
||||
|
||||
### 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
|
||||
- [论坛讨论](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)
|
||||
|
@@ -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');
|
@@ -110,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);
|
||||
|
||||
|
@@ -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,11 +18,10 @@
|
||||
],
|
||||
"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",
|
||||
@@ -30,7 +29,8 @@
|
||||
"ext-json": "*",
|
||||
"overtrue/easy-sms": "^1.1",
|
||||
"jaguarjack/migration-generator": "dev-master",
|
||||
"lcobucci/jwt": "3.3"
|
||||
"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,
|
||||
// 开启字段缓存
|
||||
|
@@ -50,7 +50,7 @@ class CatchAdminService extends Service
|
||||
|
||||
$this->app->bind('catch\console', $catchConsole);
|
||||
|
||||
$this->commands($catchConsole->commands());
|
||||
$this->commands($catchConsole->defaultCommands());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@@ -12,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');
|
||||
@@ -54,7 +66,9 @@ class CatchAuth
|
||||
public function attempt($condition)
|
||||
{
|
||||
try {
|
||||
|
||||
$user = $this->authenticate($condition);
|
||||
|
||||
if (!$user) {
|
||||
throw new LoginFailedException();
|
||||
}
|
||||
@@ -62,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);
|
||||
}
|
||||
|
||||
@@ -270,4 +284,17 @@ class CatchAuth
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 忽略密码认证
|
||||
*
|
||||
* @time 2021年01月27日
|
||||
* @return $this
|
||||
*/
|
||||
public function ignorePasswordVerify(): CatchAuth
|
||||
{
|
||||
$this->checkPassword = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@@ -14,9 +14,7 @@ namespace catcher;
|
||||
|
||||
use catcher\library\Composer;
|
||||
use catcher\facade\FileSystem;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
use think\App;
|
||||
use think\console\Command;
|
||||
|
||||
class CatchConsole
|
||||
{
|
||||
@@ -37,7 +35,7 @@ class CatchConsole
|
||||
* @time 2020年07月02日
|
||||
* @return array
|
||||
*/
|
||||
public function commands()
|
||||
public function commands(): array
|
||||
{
|
||||
$commandFiles = FileSystem::allFiles($this->path);
|
||||
|
||||
@@ -62,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, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,7 @@ class CatchConsole
|
||||
* @param $path
|
||||
* @return $this
|
||||
*/
|
||||
public function path($path)
|
||||
public function path($path): CatchConsole
|
||||
{
|
||||
$this->path = $path;
|
||||
|
||||
@@ -99,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;
|
||||
}
|
||||
|
||||
}
|
@@ -138,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日
|
||||
@@ -178,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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 额外的字段
|
||||
*
|
||||
|
@@ -63,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!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,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'];
|
||||
}
|
||||
}
|
@@ -152,7 +152,7 @@ class Utils
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前缀
|
||||
* 删除表前缀
|
||||
*
|
||||
* @time 2020年12月01日
|
||||
* @param string $table
|
||||
@@ -163,6 +163,19 @@ class Utils
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 过滤空字符字段
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -17,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';
|
||||
|
||||
@@ -29,8 +30,8 @@ abstract class CatchModel extends \think\Model
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
// 分页 Limit
|
||||
public const LIMIT = 10;
|
||||
|
||||
// 开启
|
||||
public const ENABLE = 1;
|
||||
// 禁用
|
||||
|
@@ -6,7 +6,7 @@ namespace catcher\base;
|
||||
use app\Request;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\exceptions\ValidateFailedException;
|
||||
use think\App;
|
||||
use catcher\Utils;
|
||||
|
||||
class CatchRequest extends Request
|
||||
{
|
||||
@@ -89,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;
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@@ -50,7 +50,7 @@ class Model extends Factory
|
||||
{
|
||||
$extra = $params['extra'];
|
||||
|
||||
$table = $params['table'];
|
||||
$table = Utils::tableWithPrefix($params['table']);
|
||||
|
||||
[$modelName, $namespace] = $this->parseFilename($params['model']);
|
||||
|
||||
@@ -92,7 +92,6 @@ class Model extends Factory
|
||||
(new Arr)->build(Db::getFields($table))
|
||||
)->docComment('// 数据库字段映射'));
|
||||
});
|
||||
|
||||
})->getContent();
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user