10 Commits
v2.3 ... v2.4

Author SHA1 Message Date
JaguarJack
dcbe82f398 fixed:修复创建模块 2020-12-13 10:16:46 +08:00
JaguarJack
afe70d39b9 fixed:修复CatchJoin无法连接同一个模型两次 2020-12-13 10:16:28 +08:00
JaguarJack
9118e07d7b fixed 2020-12-04 21:09:50 +08:00
JaguarJack
c0f05fcf8f fixed:模型生成数据库字段注释标记错误 2020-12-01 17:58:53 +08:00
JaguarJack
35445f37e1 fixed:模型name属性多加了表前缀 2020-12-01 17:55:36 +08:00
JaguarJack
94c430f491 update 2020-11-29 09:29:14 +08:00
JaguarJack
97efb82971 update:强制依赖jwt包 2020-11-29 09:18:07 +08:00
JaguarJack
5f49a22a5e add:新增用户token字段 2020-11-23 19:57:49 +08:00
JaguarJack
85f4fc0df8 update:个人信息校验邮箱唯一性 2020-11-21 20:07:36 +08:00
JaguarJack
04a7818608 fixed bug 2020-11-21 12:33:55 +08:00
70 changed files with 279 additions and 65 deletions

View File

@@ -141,7 +141,7 @@ 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)

View File

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

View File

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

View File

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

View File

@@ -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 已删除
];
/**

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

View File

@@ -15,9 +15,4 @@ class UpdateRequest extends CatchRequest
'email|邮箱' => 'require|email|unique:'.Users::class,
];
}
protected function message()
{
// TODO: Implement message() method.
}
}

View File

@@ -29,7 +29,8 @@
"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"
},
"require-dev": {
"topthink/think-trace": "^1.0",

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use think\helper\Arr;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use catcher\event\LoadModuleRoutes;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use catchAdmin\permissions\model\Users;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename CacheKeys.php
* @createdAt 2020/1/17

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
@@ -12,6 +14,7 @@ namespace catcher;
use catcher\library\Composer;
use catcher\facade\FileSystem;
use Symfony\Component\Finder\SplFileInfo;
use think\App;
use think\console\Command;
@@ -40,12 +43,12 @@ class CatchConsole
$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;
}
}

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use app\ExceptionHandle;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use catcher\library\excel\Excel;

View File

@@ -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);
}
}

View File

@@ -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,
]);
}
}

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use catchAdmin\system\model\Attachments;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
class Code

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
class Tree

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher;
use catchAdmin\system\model\Config;
@@ -149,6 +151,18 @@ 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);
}
/**
* 是否是超级管理员
*

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\base;
abstract class CatchController

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\base;
use catcher\CatchQuery;
@@ -33,4 +35,16 @@ abstract class CatchModel extends \think\Model
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;
}
}

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename CatchRepository.php
* @createdAt 2020/6/21

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\base;
use app\Request;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\base;
use think\Validate;

View File

@@ -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);
}

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;
use Exception;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;
use catcher\Code;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;
use catcher\Code;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;
use catcher\Code;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\exceptions;
use catcher\Code;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename WechatResponseException.php
* @createdAt 2020/6/21

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\facade;
use think\Facade;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\facade;
use think\Facade;

View File

@@ -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;
@@ -80,14 +81,16 @@ 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();

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library;
use catcher\CatchAdmin;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename Errors.php
* @createdAt 2020/6/21

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,6 +1,8 @@
<?php
namespace catcher\library;
declare(strict_types=1);
namespace catcher\library;
use think\exception\ClassNotFoundException;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename ProgressBar.php
* @createdAt 2020/6/20

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library;
use catcher\CatchCacheKeys;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename WeChat.php
* @date 2020/6/7

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\client;
use catcher\exceptions\FailedException;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\client;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\excel;
use catcher\CatchUpload;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\excel;
interface ExcelContract

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\excel;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\excel;
trait MacroExcel

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\library\excel;
interface ShouldTaskContract

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace catcher\traits\db;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
/**
* @filename ScopeTrait.php
* @createdAt 2020/6/21

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\traits\db;
use think\facade\Db;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\validates;
use catcher\library\Trie;

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\validates;
class Sometimes implements ValidateInterface

View File

@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace catcher\validates;
interface ValidateInterface