新增部门和岗位
This commit is contained in:
@@ -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', //
|
||||
|
Reference in New Issue
Block a user