feat : role
This commit is contained in:
@@ -56,4 +56,27 @@ class AdminRole extends Model
|
|||||||
{
|
{
|
||||||
return $this->where('name', $name)->first();
|
return $this->where('name', $name)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取批量数据
|
||||||
|
* @param $ids
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDataByIds($ids)
|
||||||
|
{
|
||||||
|
$data = $this->whereIn('id', $ids)->get();
|
||||||
|
if (empty($data)){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = [];
|
||||||
|
foreach ($data->toArray() as $one)
|
||||||
|
{
|
||||||
|
$res[$one['id']] = $one;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use App\Constants\Admin\UserCode;
|
|||||||
use App\Exception\AdminException;
|
use App\Exception\AdminException;
|
||||||
use App\Extend\StringUtil;
|
use App\Extend\StringUtil;
|
||||||
use App\Lib\Crypto\CryptoFactory;
|
use App\Lib\Crypto\CryptoFactory;
|
||||||
|
use App\Model\AdminRole;
|
||||||
use App\Model\AdminUser;
|
use App\Model\AdminUser;
|
||||||
use App\Service\Admin\BaseService;
|
use App\Service\Admin\BaseService;
|
||||||
use Exception;
|
use Exception;
|
||||||
@@ -29,6 +30,12 @@ class EmployeeService extends BaseService
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected AdminUser $adminUserModel;
|
protected AdminUser $adminUserModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var AdminRole
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected AdminRole $adminRoleModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入加密工厂
|
* 注入加密工厂
|
||||||
* @var CryptoFactory $cryptoFactory
|
* @var CryptoFactory $cryptoFactory
|
||||||
@@ -51,6 +58,13 @@ class EmployeeService extends BaseService
|
|||||||
|
|
||||||
$list = $this->adminUserModel->where('is_del',UserCode::ENABLE)->paginate($limit,$this->filed)->toArray();
|
$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]);
|
return $this->return->success('success', ['list' => $list]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +168,12 @@ class EmployeeService extends BaseService
|
|||||||
|
|
||||||
if (empty($info)) throw new AdminException('员工不存在');
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user