Merge pull request '管理员新增编辑接口增加org_id参数' (#7) from zhangwei into dev

Reviewed-on: #7
This commit is contained in:
weiz 2023-12-09 17:14:42 +08:00
commit abc1f7a3fd
3 changed files with 69 additions and 22 deletions

View File

@ -24,6 +24,7 @@ use app\common\model\auth\AdminRole;
use app\common\model\auth\SystemRole;
use app\common\model\dept\Dept;
use app\common\model\dept\Jobs;
use app\common\model\dept\Orgs;
/**
* 管理员列表
@ -143,12 +144,14 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
->where($this->queryWhere())
->limit($this->limitOffset, $this->limitLength)
->order($this->sortOrder)
->append(['role_id', 'dept_id', 'jobs_id', 'disable_desc'])
->append(['role_id', 'org_id', 'dept_id', 'jobs_id', 'disable_desc'])
->select()
->toArray();
// 角色数组('角色id'=>'角色名称')
$roleLists = SystemRole::column('name', 'id');
// 组织列表
$orgLists = Orgs::column('name', 'id');
// 部门列表
$deptLists = Dept::column('name', 'id');
// 岗位列表
@ -165,6 +168,12 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
$roleName .= '/';
}
}
$orgName = '';
foreach ($v['org_id'] as $orgId) {
$orgName .= $orgLists[$orgId] ?? '';
$orgName .= '/';
}
$deptName = '';
foreach ($v['dept_id'] as $deptId) {
@ -179,6 +188,7 @@ class AdminLists extends BaseAdminDataLists implements ListsExtendInterface, Lis
}
$adminLists[$k]['role_name'] = trim($roleName, '/');
$adminLists[$k]['$orgName'] = trim($orgName, '/');
$adminLists[$k]['dept_name'] = trim($deptName, '/');
$adminLists[$k]['jobs_name'] = trim($jobsName, '/');
}

View File

@ -20,6 +20,7 @@ use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\auth\AdminDept;
use app\common\model\auth\AdminJobs;
use app\common\model\auth\AdminOrgs;
use app\common\model\auth\AdminRole;
use app\common\model\auth\AdminSession;
use app\common\cache\AdminTokenCache;
@ -62,10 +63,12 @@ class AdminLogic extends BaseLogic
// 角色
self::insertRole($admin['id'], $params['role_id'] ?? []);
// 组织
self::insertOrg($admin['id'], $params['org_id'] ?? 0);
// 部门
self::insertDept($admin['id'], $params['dept_id'] ?? []);
self::insertDept($admin['id'], $params['dept_id'] ?? 0);
// 岗位
self::insertJobs($admin['id'], $params['jobs_id'] ?? []);
self::insertJobs($admin['id'], $params['jobs_id'] ?? 0);
Db::commit();
return true;
@ -125,14 +128,17 @@ class AdminLogic extends BaseLogic
// 删除旧的关联信息
AdminRole::delByUserId($params['id']);
AdminOrgs::delByUserId($params['id']);
AdminDept::delByUserId($params['id']);
AdminJobs::delByUserId($params['id']);
// 角色
self::insertRole($params['id'], $params['role_id']);
// 组织
self::insertOrg($params['id'], $params['org_id'] ?? 0);
// 部门
self::insertDept($params['id'], $params['dept_id'] ?? []);
self::insertDept($params['id'], $params['dept_id'] ?? 0);
// 岗位
self::insertJobs($params['id'], $params['jobs_id'] ?? []);
self::insertJobs($params['id'], $params['jobs_id'] ?? 0);
Db::commit();
return true;
@ -170,6 +176,7 @@ class AdminLogic extends BaseLogic
// 删除旧的关联信息
AdminRole::delByUserId($params['id']);
AdminOrgs::delByUserId($params['id']);
AdminDept::delByUserId($params['id']);
AdminJobs::delByUserId($params['id']);
@ -286,7 +293,25 @@ class AdminLogic extends BaseLogic
(new AdminRole())->saveAll($roleData);
}
}
/**
* @notes 新增组织
* @param $adminId
* @param $orgIds
* @throws \Exception
* @author 段誉
* @date 2022/11/25 14:22
*/
public static function insertOrg($adminId, $orgIds)
{
// 岗位
if (!empty($orgsIds)) {
(new AdminOrgs())->save([
'admin_id' => $adminId,
'org_id' => $orgsIds
]);
}
}
/**
* @notes 新增部门
@ -300,14 +325,10 @@ class AdminLogic extends BaseLogic
{
// 部门
if (!empty($deptIds)) {
$deptData = [];
foreach ($deptIds as $deptId) {
$deptData[] = [
'admin_id' => $adminId,
'dept_id' => $deptId
];
}
(new AdminDept())->saveAll($deptData);
(new AdminDept())->save([
'admin_id' => $adminId,
'dept_id' => $deptIds
]);
}
}
@ -324,14 +345,10 @@ class AdminLogic extends BaseLogic
{
// 岗位
if (!empty($jobsIds)) {
$jobsData = [];
foreach ($jobsIds as $jobsId) {
$jobsData[] = [
'admin_id' => $adminId,
'jobs_id' => $jobsId
];
}
(new AdminJobs())->saveAll($jobsData);
(new AdminJobs())->save([
'admin_id' => $adminId,
'jobs_id' => $jobsIds
]);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\model\auth;
use app\common\model\BaseModel;
class AdminOrgs extends BaseModel
{
/**
* @notes 删除用户关联岗位
* @param $adminId
* @return bool
* @author 段誉
* @date 2022/11/25 14:14
*/
public static function delByUserId($adminId)
{
return self::where(['admin_id' => $adminId])->delete();
}
}