新增部门和岗位

This commit is contained in:
yanwenwu
2020-01-12 09:30:56 +08:00
parent 5ec9939cbf
commit 8b93c63883
11 changed files with 100 additions and 11 deletions

View File

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

View File

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

View File

@@ -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'] . '%');
})