This commit is contained in:
weiz 2024-05-22 15:04:12 +08:00
parent 1fd96738aa
commit 3e364fcafb
10 changed files with 23 additions and 62 deletions

View File

@ -106,7 +106,7 @@ class DeptController extends BaseAdminController
if(empty($params['org_id'])){
return $this->fail('参数错误');
}
$data = Dept::field('id,name,leader,mobile,status')->where('org_id',$params['org_id'])->select()->toArray();
$data = Dept::field('id,name,mobile,status')->where('org_id',$params['org_id'])->select()->toArray();
return $this->success('请求成功',$data);
}

View File

@ -108,7 +108,7 @@ class OrgsController extends BaseAdminController
//获取所有组织
public function getAll(): \think\response\Json
{
$data = Orgs::field('id,name,master,status,create_time')->select();
$data = Orgs::field('id,name,status,create_time')->select();
return $this->success('请求成功',$data->toArray());
}
}

View File

@ -4,12 +4,11 @@
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
class DeptLists extends BaseAdminDataLists implements ListsSearchInterface {
private $where = [];
/**
* @notes 设置搜索条件
* @return \string[][]
@ -19,7 +18,7 @@
public function setSearch(): array
{
return [
'%like%' => ['name','leader','mobile'],
'%like%' => ['name','mobile'],
'=' => ['status']
];
}
@ -34,20 +33,18 @@
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['org_name']) && $params['org_name'] != ''){
$orgs = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id');
$where[] = ['org_id','in',$orgs];
$this->where[] = ['org_id','in',$orgs];
}
return Dept::where($this->searchWhere)->where($where)
->field('id,name,org_id,leader,mobile,status,sort,create_time')
return Dept::where($this->searchWhere)->where($this->where)
->field('id,name,org_id,mobile,status,sort,create_time')
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->each(function($item){
$org = Orgs::where('id',$item['org_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['leader'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
$item['leader'] = $admin['name'];
$item['status_text'] = $item->status_text;
return $item;
})
->toArray();
@ -61,12 +58,6 @@
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['org_name']) && $params['org_name'] != ''){
$orgs = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id');
$where[] = ['org_id','in',$orgs];
}
return Dept::where($this->searchWhere)->where($where)->count();
return Dept::where($this->searchWhere)->where($this->where)->count();
}
}

View File

@ -27,7 +27,7 @@ use app\common\model\dept\Orgs;
*/
class JobsLists extends BaseAdminDataLists implements ListsSearchInterface
{
private $where = [];
/**
* @notes 设置搜索条件
* @return \string[][]
@ -51,13 +51,11 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['dept_name']) && $params['dept_name'] != ''){
$deps = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id');
$where[] = ['dept_id','in',$deps];
$this->where[] = ['dept_id','in',$deps];
}
return Jobs::where($this->searchWhere)->where($where)->field('id,dept_id,name,status,sort,create_time')
return Jobs::where($this->searchWhere)->where($this->where)->field('id,dept_id,name,status,sort,create_time')
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->each(function($item){
@ -65,6 +63,7 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface
$org = Orgs::field('name')->where('id',$dept['org_id'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
$item['dept_name'] = $dept->isEmpty() ? '' : $dept['name'];
$item['status_text'] = $item->status_text;
return $item;
})
->toArray();
@ -79,13 +78,7 @@ class JobsLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['dept_name']) && $params['dept_name'] != ''){
$deps = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id');
$where[] = ['dept_id','in',$deps];
}
return Jobs::where($this->searchWhere)->where($where)->count();
return Jobs::where($this->searchWhere)->where($this->where)->count();
}
}

View File

@ -39,7 +39,7 @@
{
return [
'=' => ['status'],
'%like%' => ['name', 'master'],
'%like%' => ['name'],
];
}
@ -56,7 +56,7 @@
public function lists(): array
{
return Orgs::where($this->searchWhere)
->field(['id', 'name', 'master', 'status', 'create_time'])
->field(['id', 'name', 'status', 'create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($data) {

View File

@ -41,8 +41,7 @@ class DeptLogic extends BaseLogic
Dept::create([
'org_id' => $params['org_id'],
'name' => $params['name'],
'leader' => $params['leader'] ?? 0,
'mobile' => $params['mobile'],
'mobile' => $params['mobile'] ?? '',
'status' => $params['status'],
'sort' => $params['sort'] ?? 0
]);
@ -63,8 +62,7 @@ class DeptLogic extends BaseLogic
'id' => $params['id'],
'org_id' => $params['org_id'],
'name' => $params['name'],
'leader' => $params['leader'] ?? 0,
'mobile' => $params['mobile'],
'mobile' => $params['mobile'] ?? '',
'status' => $params['status'],
'sort' => $params['sort'] ?? 0
]);
@ -102,15 +100,13 @@ class DeptLogic extends BaseLogic
*/
public static function detail($params): array
{
$data = Dept::field('id,name,org_id,leader,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
$data = Dept::field('id,name,org_id,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
if($data->isEmpty()){
return [];
}
$org = Orgs::where('id',$data['org_id'])->findOrEmpty();
$data['org_name'] = $org->isEmpty() ? '' : $org['name'];
$data['status_text'] = $data->status_text;
$admin = Admin::field('name')->where('id',$data['leader'])->findOrEmpty();
$data['leader_name'] = $admin['name'];
return $data->toArray();
}

View File

@ -96,9 +96,6 @@ class JobsLogic extends BaseLogic
public static function detail($params) : array
{
$jobs = Jobs::field('id,dept_id,name,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
if($jobs->isEmpty()){
return [];
}
$dept = Dept::where('id',$jobs['dept_id'])->findOrEmpty();
$org = Orgs::where('id',$dept['org_id'])->findOrEmpty();
$jobs['dept_name'] = $dept->isEmpty() ? '' : $dept['name'];

View File

@ -43,7 +43,6 @@ class OrgsLogic extends BaseLogic
try {
Orgs::create([
'name' => $params['name'],
'master' => $params['master'],
'status' => $params['status']
]);
@ -70,7 +69,6 @@ class OrgsLogic extends BaseLogic
try {
Orgs::where('id', $params['id'])->update([
'name' => $params['name'],
'master' => $params['master'],
'status' => $params['status']
]);
@ -112,7 +110,7 @@ class OrgsLogic extends BaseLogic
*/
public static function detail($params): array
{
$res = Orgs::field('id,name,master,status,create_time')->findOrEmpty($params['id']);
$res = Orgs::field('id,name,status,create_time')->findOrEmpty($params['id']);
$res['status_text'] = $res->status_text;
return $res->toArray();
}

View File

@ -33,7 +33,6 @@
'id' => 'require|checkDept',
'org_id' => 'require|checkOrg',
'name' => 'require|length:1,30',
'leader' => 'checkLeader',
'mobile' => 'mobile',
'status' => 'require|in:0,1',
'sort' => 'egt:0',
@ -46,7 +45,6 @@
'name.require' => '请填写部门名称',
'name.length' => '部门名称长度须在1-30位字符',
'name.unique' => '部门名称已存在',
'leader.require' => '请选择部门负责人',
'mobile.require' => '请填写部门负责人联系电话',
'mobile.mobile' => '部门负责人联系电话格式错误',
'status.require' => '请选择部门状态',
@ -86,7 +84,7 @@
*/
public function sceneEdit()
{
return $this->only(['id', 'org_id', 'name', 'leader', 'mobile', 'status'])->append('name', 'checkUniqueByEdit');;
return $this->only(['id', 'org_id', 'name', 'mobile', 'status'])->append('name', 'checkUniqueByEdit');;
}
@ -140,14 +138,4 @@
return true;
}
public function checkLeader($value)
{
if (empty($value)) return true;
$data = Admin::where('id', $value)->findOrEmpty();
if ($data->isEmpty()) {
return '负责人信息不存在';
}
return true;
}
}

View File

@ -34,7 +34,6 @@
protected $rule = [
'id' => 'require',
'name' => 'require',
'master' => 'require',
'status' => 'require|integer|in:0,1',
];
@ -46,7 +45,6 @@
protected $field = [
'id' => 'id',
'name' => '组织名称',
'master' => '组织负责人',
'status' => '组织状态',
];
@ -59,7 +57,7 @@
*/
public function sceneAdd()
{
return $this->only(['name', 'master', 'status'])->append('name', 'checkUniqueByAdd');
return $this->only(['name', 'status'])->append('name', 'checkUniqueByAdd');
}
@ -71,7 +69,7 @@
*/
public function sceneEdit()
{
return $this->only(['id', 'name', 'master', 'status'])->append('name', 'checkUniqueByEdit');
return $this->only(['id', 'name', 'status'])->append('name', 'checkUniqueByEdit');
}