新增部门和岗位
This commit is contained in:
parent
5ec9939cbf
commit
8b93c63883
@ -6,7 +6,6 @@ use catchAdmin\permissions\OperateLogListener;
|
||||
use catchAdmin\permissions\PermissionsMiddleware;
|
||||
use catchAdmin\system\event\LoginLogEvent;
|
||||
use catchAdmin\system\event\OperateLogEvent;
|
||||
use catchAdmin\user\Auth;
|
||||
use catcher\command\BackupCommand;
|
||||
use catcher\command\CompressPackageCommand;
|
||||
use catcher\command\CreateModuleCommand;
|
||||
@ -15,7 +14,6 @@ use catcher\command\MigrateRunCommand;
|
||||
use catcher\command\ModelGeneratorCommand;
|
||||
use catcher\command\ModuleCacheCommand;
|
||||
use catcher\command\SeedRunCommand;
|
||||
use catcher\event\AddCreatorId;
|
||||
use catcher\event\LoadModuleRoutes;
|
||||
use catcher\validates\Sometimes;
|
||||
use think\facade\Validate;
|
||||
|
@ -63,4 +63,17 @@ class Job extends CatchController
|
||||
{
|
||||
return CatchResponse::success($this->job->deleteBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有
|
||||
*
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return CatchResponse::success($this->job->field(['id', 'job_name'])->select());
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class Department extends Migrator
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('department',['engine'=>'Innodb', 'comment' => '部门表', 'signed' => false]);
|
||||
$table = $this->table('departments',['engine'=>'Innodb', 'comment' => '部门表', 'signed' => false]);
|
||||
$table->addColumn('department_name', 'string',['limit' => 15,'default'=>'','comment'=>'部门名称'])
|
||||
->addColumn('parent_id', 'integer',['default'=>0,'comment'=>'父级ID', 'signed' => false])
|
||||
->addColumn('principal', 'string', ['default' => '', 'comment' => '负责人', 'limit' => 20])
|
||||
|
@ -28,7 +28,7 @@ class Job extends Migrator
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$table = $this->table('job',['engine'=>'Innodb', 'comment' => '岗位表', 'signed' => false]);
|
||||
$table = $this->table('jobs',['engine'=>'Innodb', 'comment' => '岗位表', 'signed' => false]);
|
||||
$table->addColumn('job_name', 'string',['limit' => 15,'default'=>'','comment'=>'岗位名称'])
|
||||
->addColumn('coding', 'string', ['default' => '', 'comment' => '编码', 'limit' => 50])
|
||||
->addColumn('creator_id', 'integer',['default' => 0, 'comment'=>'创建人ID'])
|
||||
|
@ -5,7 +5,7 @@ use catcher\base\CatchModel;
|
||||
|
||||
class Department extends CatchModel
|
||||
{
|
||||
protected $name = 'department';
|
||||
protected $name = 'departments';
|
||||
|
||||
protected $field = [
|
||||
'id', //
|
||||
@ -31,7 +31,12 @@ class Department extends CatchModel
|
||||
*/
|
||||
public function getList($params)
|
||||
{
|
||||
return $this->when($params['department_name'] ?? false, function ($query) use ($params){
|
||||
return $this->field([
|
||||
'id',
|
||||
'department_name as title', 'parent_id', 'principal', 'mobile', 'email', 'creator_id', 'status', 'sort',
|
||||
'created_at', 'updated_at'
|
||||
])
|
||||
->when($params['department_name'] ?? false, function ($query) use ($params){
|
||||
$query->whereLike('department_name', '%' . $params['department_name'] . '%');
|
||||
})
|
||||
->when($params['status'] ?? false, function ($query) use ($params){
|
||||
|
58
catch/permissions/model/HasJobsTrait.php
Normal file
58
catch/permissions/model/HasJobsTrait.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\model;
|
||||
|
||||
trait HasJobsTrait
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月08日
|
||||
* @return mixed
|
||||
*/
|
||||
public function jobs()
|
||||
{
|
||||
return $this->belongsToMany(Job::class, 'user_has_jobs', 'job_id', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月08日
|
||||
* @param array $fields
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJobs()
|
||||
{
|
||||
return $this->jobs()->select();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月08日
|
||||
* @param array $jobs
|
||||
* @return mixed
|
||||
*/
|
||||
public function attachJobs(array $jobs)
|
||||
{
|
||||
if (empty($jobs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sort($jobs);
|
||||
|
||||
return $this->jobs()->attach($jobs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月08日
|
||||
* @param array $jobs
|
||||
* @return mixed
|
||||
*/
|
||||
public function detachJobs(array $jobs = [])
|
||||
{
|
||||
if (empty($jobs)) {
|
||||
return $this->jobs()->detach();
|
||||
}
|
||||
|
||||
return $this->jobs()->detach($jobs);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ use catcher\base\CatchModel;
|
||||
|
||||
class Job extends CatchModel
|
||||
{
|
||||
protected $name = 'job';
|
||||
protected $name = 'jobs';
|
||||
|
||||
protected $field = [
|
||||
'id', //
|
||||
|
@ -9,3 +9,5 @@ $router->resource('permissions', '\catchAdmin\permissions\controller\Permission'
|
||||
$router->resource('departments', '\catchAdmin\permissions\controller\Department');
|
||||
// 岗位
|
||||
$router->resource('jobs', '\catchAdmin\permissions\controller\Job');
|
||||
|
||||
$router->get('jobs/all', '\catchAdmin\permissions\controller\Job@getAll');
|
||||
|
@ -81,6 +81,8 @@ class User extends CatchController
|
||||
|
||||
$this->user->attach($request->param('roles'));
|
||||
|
||||
$this->user->attachJobs($request->param('jobs'));
|
||||
|
||||
return CatchResponse::success('', '添加成功');
|
||||
}
|
||||
|
||||
@ -94,6 +96,7 @@ class User extends CatchController
|
||||
{
|
||||
$user = $this->user->findBy($id);
|
||||
$user->roles = $user->getRoles();
|
||||
$user->jobs = $user->getJobs();
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
@ -117,11 +120,14 @@ class User extends CatchController
|
||||
$user = $this->user->findBy($id);
|
||||
|
||||
$user->detach();
|
||||
$user->detachJobs();
|
||||
|
||||
if (!empty($request->param('roles'))) {
|
||||
$user->attach($request->param('roles'));
|
||||
}
|
||||
|
||||
if (!empty($request->param('jobs'))) {
|
||||
$user->attachJobs($request->param('jobs'));
|
||||
}
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
@ -136,8 +142,11 @@ class User extends CatchController
|
||||
$ids = Utils::stringToArrayBy($id);
|
||||
|
||||
foreach ($ids as $_id) {
|
||||
$user = $this->user->findBy($_id);
|
||||
// 删除角色
|
||||
$this->user->findBy($_id)->detach();
|
||||
$user->detach();
|
||||
// 删除岗位
|
||||
$user->detachJobs();
|
||||
|
||||
$this->user->deleteBy($_id);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class Users extends Migrator
|
||||
->addColumn('password', 'string',array('limit' => 255,'comment'=>'用户密码'))
|
||||
->addColumn('email', 'string',array('limit' => 100, 'comment'=>'邮箱 登录'))
|
||||
->addColumn('creator_id', 'integer',['default' => 0, 'comment'=>'创建人ID'])
|
||||
->addColumn('department_id', 'integer',['default' => 0, 'comment'=>'部门ID'])
|
||||
->addColumn('status', 'boolean',array('limit' => 1,'default'=> 1,'comment'=>'用户状态 1 正常 2 禁用'))
|
||||
->addColumn('last_login_ip', 'string',array('limit' => 30,'default'=>0,'comment'=>'最后登录IP'))
|
||||
->addColumn('last_login_time', 'integer',array('default'=>0,'comment'=>'最后登录时间', 'signed' => false))
|
||||
|
@ -1,12 +1,14 @@
|
||||
<?php
|
||||
namespace catchAdmin\user\model;
|
||||
|
||||
use catchAdmin\permissions\model\HasJobsTrait;
|
||||
use catchAdmin\permissions\model\HasRolesTrait;
|
||||
use catcher\base\CatchModel;
|
||||
|
||||
class Users extends CatchModel
|
||||
{
|
||||
use HasRolesTrait;
|
||||
use HasJobsTrait;
|
||||
|
||||
protected $name = 'users';
|
||||
|
||||
@ -15,7 +17,8 @@ class Users extends CatchModel
|
||||
'username', // 用户名
|
||||
'password', // 用户密码
|
||||
'email', // 邮箱 登录
|
||||
'creator_id',
|
||||
'creator_id', // 创建者ID
|
||||
'department_id', // 部门ID
|
||||
'status', // 用户状态 1 正常 2 禁用
|
||||
'last_login_ip', // 最后登录IP
|
||||
'last_login_time', // 最后登录时间
|
||||
@ -48,7 +51,7 @@ class Users extends CatchModel
|
||||
public function getList($search): \think\Paginator
|
||||
{
|
||||
return (($search['trash'] ?? false) ? static::onlyTrashed() : $this)
|
||||
->field(['id', 'username', 'email', 'status','last_login_time','last_login_ip', 'created_at', 'updated_at'])
|
||||
->field(['id', 'username', 'email', 'status','last_login_time','last_login_ip', 'department_id','created_at', 'updated_at'])
|
||||
->when($search['username'] ?? false, function ($query) use ($search){
|
||||
$query->whereLike('username', '%' . $search['username'] . '%');
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user