feat : role

This commit is contained in:
2024-11-12 09:46:50 +08:00
parent 901d9569dd
commit 235acbea9c
2 changed files with 43 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ use App\Constants\Admin\UserCode;
use App\Exception\AdminException;
use App\Extend\StringUtil;
use App\Lib\Crypto\CryptoFactory;
use App\Model\AdminRole;
use App\Model\AdminUser;
use App\Service\Admin\BaseService;
use Exception;
@@ -29,6 +30,12 @@ class EmployeeService extends BaseService
#[Inject]
protected AdminUser $adminUserModel;
/**
* @var AdminRole
*/
#[Inject]
protected AdminRole $adminRoleModel;
/**
* 注入加密工厂
* @var CryptoFactory $cryptoFactory
@@ -51,6 +58,13 @@ class EmployeeService extends BaseService
$list = $this->adminUserModel->where('is_del',UserCode::ENABLE)->paginate($limit,$this->filed)->toArray();
$roleIds = array_column($list['data'], 'role_id');
$roleList = $this->adminRoleModel->getDataByIds($roleIds);
foreach ($list['data'] as &$item) {
$item['role_name'] = $roleList[$item['role_id']]['name'] ?? '普通管理员';
}
return $this->return->success('success', ['list' => $list]);
}
@@ -154,7 +168,12 @@ class EmployeeService extends BaseService
if (empty($info)) throw new AdminException('员工不存在');
return $this->return->success('success', ['info' => $info->toArray()]);
$roleName = $this->adminRoleModel->where('id', $info->role_id)->value('name');
$res = $info->toArray();
$res['role_name'] = $roleName ?? '普通管理员';
return $this->return->success('success', ['info' => $res]);
}
/**