新增部门和岗位

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

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

View File

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

View File

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

View File

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

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

View File

@@ -5,7 +5,7 @@ use catcher\base\CatchModel;
class Job extends CatchModel
{
protected $name = 'job';
protected $name = 'jobs';
protected $field = [
'id', //

View File

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