Merge pull request '新增获取所有部门、所有岗位接口' (#15) from zhangwei into dev
Reviewed-on: #15
This commit is contained in:
commit
df793314b5
@ -18,7 +18,9 @@ use app\adminapi\controller\BaseAdminController;
|
|||||||
use app\adminapi\lists\dept\DeptLists;
|
use app\adminapi\lists\dept\DeptLists;
|
||||||
use app\adminapi\logic\dept\DeptLogic;
|
use app\adminapi\logic\dept\DeptLogic;
|
||||||
use app\adminapi\validate\dept\DeptValidate;
|
use app\adminapi\validate\dept\DeptValidate;
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
use app\common\model\dept\Dept;
|
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();
|
$data = Dept::field('id,name,leader,mobile,status')->where('org_id',$params['org_id'])->select()->toArray();
|
||||||
return $this->success('请求成功',$data);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ use app\adminapi\controller\BaseAdminController;
|
|||||||
use app\adminapi\lists\dept\JobsLists;
|
use app\adminapi\lists\dept\JobsLists;
|
||||||
use app\adminapi\logic\dept\JobsLogic;
|
use app\adminapi\logic\dept\JobsLogic;
|
||||||
use app\adminapi\validate\dept\JobsValidate;
|
use app\adminapi\validate\dept\JobsValidate;
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
use app\common\model\dept\Jobs;
|
use app\common\model\dept\Jobs;
|
||||||
|
|
||||||
|
|
||||||
@ -110,4 +111,14 @@ class JobsController extends BaseAdminController
|
|||||||
return $this->success('请求成功',$data);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -303,3 +303,12 @@ function project_code(): string
|
|||||||
{
|
{
|
||||||
return 'P'.date('Ymd',time()).'-'.mt_rand(100000, 999999);
|
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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user