新增获取所有部门、所有岗位接口

This commit is contained in:
weiz 2023-12-11 11:25:15 +08:00
parent 3dc5e2e47f
commit 1e0ceaa66b
3 changed files with 36 additions and 0 deletions

View File

@ -18,7 +18,9 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\dept\DeptLists;
use app\adminapi\logic\dept\DeptLogic;
use app\adminapi\validate\dept\DeptValidate;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
/**
* 部门管理控制器
@ -107,4 +109,18 @@ class DeptController extends BaseAdminController
$data = Dept::field('id,name,leader,mobile,status')->where('org_id',$params['org_id'])->select()->toArray();
return $this->success('请求成功',$data);
}
//获取所有部门
public function getAllDept(): \think\response\Json
{
$data = Dept::field('id,name,org_id')->select()->each(function($item){
$org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
$item['admin_num'] = Admin::where('dept_id',$item['id'])->count();
unset($item['org_id']);
return $item;
})->toArray();
$result = group_by($data, 'org_name');
return $this->success('请求成功',$result);
}
}

View File

@ -18,6 +18,7 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\dept\JobsLists;
use app\adminapi\logic\dept\JobsLogic;
use app\adminapi\validate\dept\JobsValidate;
use app\common\model\auth\Admin;
use app\common\model\dept\Jobs;
@ -109,5 +110,15 @@ class JobsController extends BaseAdminController
$data = Jobs::field('id,name,status,sort,create_time')->where('dept_id',$params['dept_id'])->select()->toArray();
return $this->success('请求成功',$data);
}
//获取所有岗位
public function getAllJobs(): \think\response\Json
{
$data = Jobs::field('id,name')->select()->each(function($item){
$item['admin_num'] = Admin::where('job_id',$item['id'])->count();
return $item;
})->toArray();
return $this->success('请求成功',$data);
}
}

View File

@ -303,3 +303,12 @@ function project_code(): string
{
return 'P'.date('Ymd',time()).'-'.mt_rand(100000, 999999);
}
function group_by($array, $key): array
{
$result = [];
foreach ($array as $item) {
$result[$item[$key]][] = $item;
}
return $result;
}