新增搜索器
This commit is contained in:
parent
3b67f3fb5f
commit
be02170697
@ -24,9 +24,9 @@ class Department extends CatchController
|
|||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
*/
|
*/
|
||||||
public function index(CatchRequest $request): \think\response\Json
|
public function index(): \think\response\Json
|
||||||
{
|
{
|
||||||
return CatchResponse::success(Tree::done($this->department->getList($request->param())));
|
return CatchResponse::success(Tree::done($this->department->getList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,9 +22,9 @@ class Job extends CatchController
|
|||||||
* @param CatchRequest $request
|
* @param CatchRequest $request
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function index(CatchRequest $request): \think\response\Json
|
public function index(): \think\response\Json
|
||||||
{
|
{
|
||||||
return CatchResponse::paginate($this->job->getList($request->param()));
|
return CatchResponse::paginate($this->job->getList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,9 +24,9 @@ class Permission extends CatchController
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
return CatchResponse::success(Tree::done($this->permissions->getList($request->param())));
|
return CatchResponse::success(Tree::done($this->permissions->getList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,9 +23,9 @@ class Role extends CatchController
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
return CatchResponse::success(Tree::done($this->role->getList($request->param())));
|
return CatchResponse::success(Tree::done($this->role->getList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\permissions\model;
|
namespace catchAdmin\permissions\model;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\search\DepartmentSearch;
|
||||||
use catcher\base\CatchModel;
|
use catcher\base\CatchModel;
|
||||||
|
|
||||||
class Department extends CatchModel
|
class Department extends CatchModel
|
||||||
{
|
{
|
||||||
|
use DepartmentSearch;
|
||||||
|
|
||||||
protected $name = 'departments';
|
protected $name = 'departments';
|
||||||
|
|
||||||
protected $field = [
|
protected $field = [
|
||||||
@ -29,19 +32,14 @@ class Department extends CatchModel
|
|||||||
* @param $params
|
* @param $params
|
||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
*/
|
*/
|
||||||
public function getList($params)
|
public function getList(): array
|
||||||
{
|
{
|
||||||
return $this->field([
|
return $this->field([
|
||||||
'id',
|
'id',
|
||||||
'department_name as title', 'parent_id', 'principal', 'mobile', 'email', 'creator_id', 'status', 'sort',
|
'department_name as title', 'parent_id', 'principal', 'mobile', 'email', 'creator_id', 'status', 'sort',
|
||||||
'created_at', 'updated_at'
|
'created_at', 'updated_at'
|
||||||
])
|
])
|
||||||
->when($params['department_name'] ?? false, function ($query) use ($params){
|
->catchSearch()
|
||||||
$query->whereLike('department_name', '%' . $params['department_name'] . '%');
|
|
||||||
})
|
|
||||||
->when($params['status'] ?? false, function ($query) use ($params){
|
|
||||||
$query->where('status', $params['status']);
|
|
||||||
})
|
|
||||||
->select()->toArray();
|
->select()->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,17 +28,9 @@ class Job extends CatchModel
|
|||||||
* @throws \think\db\exception\DbException
|
* @throws \think\db\exception\DbException
|
||||||
* @return \think\Paginator
|
* @return \think\Paginator
|
||||||
*/
|
*/
|
||||||
public function getList($params)
|
public function getList()
|
||||||
{
|
{
|
||||||
return $this->when($params['job_name'] ?? false, function ($query) use ($params){
|
return $this->catchSearch()
|
||||||
$query->whereLike('job_name', '%' . $params['job_name'] . '%');
|
|
||||||
})
|
|
||||||
->when($params['status'] ?? false, function ($query) use ($params){
|
|
||||||
$query->where('status', $params['status']);
|
|
||||||
})
|
|
||||||
->when($params['coding'] ?? false, function ($query) use ($params){
|
|
||||||
$query->whereLike('coding', '%' . $params['coding'] . '%');
|
|
||||||
})
|
|
||||||
->paginate($parmas['limit'] ?? $this->limit);
|
->paginate($parmas['limit'] ?? $this->limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\permissions\model;
|
namespace catchAdmin\permissions\model;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\search\PermissionsSearch;
|
||||||
use catcher\base\CatchModel;
|
use catcher\base\CatchModel;
|
||||||
|
|
||||||
class Permissions extends CatchModel
|
class Permissions extends CatchModel
|
||||||
{
|
{
|
||||||
|
use PermissionsSearch;
|
||||||
|
|
||||||
protected $name = 'permissions';
|
protected $name = 'permissions';
|
||||||
|
|
||||||
protected $field = [
|
protected $field = [
|
||||||
@ -33,25 +36,9 @@ class Permissions extends CatchModel
|
|||||||
public const PUT = 'put';
|
public const PUT = 'put';
|
||||||
public const DELETE = 'delete';
|
public const DELETE = 'delete';
|
||||||
|
|
||||||
public function getList($search = [])
|
public function getList()
|
||||||
{
|
{
|
||||||
return $this->when($search['permission_name'] ?? false, function ($query) use ($search){
|
return $this->catchSearch()
|
||||||
$query->whereLike('permission_name', '%'.$search['permission_name'].'%');
|
|
||||||
})
|
|
||||||
->when($search['id'] ?? false, function ($query) use ($search){
|
|
||||||
$query->where('parent_id', $search['id'])
|
|
||||||
->whereOr('id', $search['id']);
|
|
||||||
})
|
|
||||||
->when($search['role_id'] ?? false, function ($query) use ($search){
|
|
||||||
$permissionIds = [];
|
|
||||||
$permissions = Roles::where('id', $search['role_id'])->find()->getPermissions();
|
|
||||||
foreach ($permissions as $_permission) {
|
|
||||||
$permissionIds[] = $_permission->pivot->permission_id;
|
|
||||||
}
|
|
||||||
if(!empty($permissionIds)) {
|
|
||||||
$query->whereIn('id', $permissionIds);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
->order('sort', 'desc')
|
->order('sort', 'desc')
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->select()
|
->select()
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace catchAdmin\permissions\model;
|
namespace catchAdmin\permissions\model;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\search\RolesSearch;
|
||||||
use catchAdmin\user\model\Users;
|
use catchAdmin\user\model\Users;
|
||||||
use catcher\base\CatchModel;
|
use catcher\base\CatchModel;
|
||||||
|
|
||||||
class Roles extends CatchModel
|
class Roles extends CatchModel
|
||||||
{
|
{
|
||||||
use HasDepartmentsTrait;
|
use HasDepartmentsTrait;
|
||||||
|
use RolesSearch;
|
||||||
|
|
||||||
protected $name = 'roles';
|
protected $name = 'roles';
|
||||||
|
|
||||||
@ -23,15 +25,9 @@ class Roles extends CatchModel
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getList($search = [])
|
public function getList()
|
||||||
{
|
{
|
||||||
return $this->when($search['role_name'] ?? false, function ($query) use ($search){
|
return $this->catchSearch()
|
||||||
$query->whereLike('role_name', $search['role_name']);
|
|
||||||
})
|
|
||||||
->when($search['id'] ?? false, function ($query) use ($search){
|
|
||||||
$query->where('parent_id', $search['id'])
|
|
||||||
->whereOr('id', $search['id']);
|
|
||||||
})
|
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
15
catch/permissions/model/search/DepartmentSearch.php
Normal file
15
catch/permissions/model/search/DepartmentSearch.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
namespace catchAdmin\permissions\model\search;
|
||||||
|
|
||||||
|
trait DepartmentSearch
|
||||||
|
{
|
||||||
|
public function searchDepartmentNameAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('department_name', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchStatusAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->where('status', $value);
|
||||||
|
}
|
||||||
|
}
|
20
catch/permissions/model/search/JobsSearch.php
Normal file
20
catch/permissions/model/search/JobsSearch.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace catchAdmin\permissions\model\search;
|
||||||
|
|
||||||
|
trait JobsSearch
|
||||||
|
{
|
||||||
|
public function searchJobNameAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('job_name', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchCodingAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('coding', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchStatusAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->where('status', $value);
|
||||||
|
}
|
||||||
|
}
|
31
catch/permissions/model/search/PermissionsSearch.php
Normal file
31
catch/permissions/model/search/PermissionsSearch.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
namespace catchAdmin\permissions\model\search;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\Roles;
|
||||||
|
|
||||||
|
trait PermissionsSearch
|
||||||
|
{
|
||||||
|
public function searchPermissionNameAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('permission_name', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchIdAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
$query->where('parent_id', $value)->whereOr('id', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchRoleIdAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
$permissionIds = [];
|
||||||
|
$permissions = Roles::where('id', $value)->find()->getPermissions();
|
||||||
|
|
||||||
|
foreach ($permissions as $_permission) {
|
||||||
|
$permissionIds[] = $_permission->pivot->permission_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($permissionIds)) {
|
||||||
|
$query->whereIn('id', $permissionIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
catch/permissions/model/search/RolesSearch.php
Normal file
16
catch/permissions/model/search/RolesSearch.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
namespace catchAdmin\permissions\model\search;
|
||||||
|
|
||||||
|
trait RolesSearch
|
||||||
|
{
|
||||||
|
public function searchRoleNameAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('role_name', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchIdAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
$query->where('parent_id', $value)->whereOr('id', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
catch/user/model/UserSearch.php
Normal file
1
catch/user/model/UserSearch.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?php
|
Loading…
x
Reference in New Issue
Block a user