Merge branch 'develop'
This commit is contained in:
@@ -8,86 +8,7 @@ use support\Log;
|
||||
|
||||
class RoleLogic
|
||||
{
|
||||
/**
|
||||
* 获取角色列表
|
||||
*/
|
||||
public function getRoleList(array $params)
|
||||
{
|
||||
// 假设我们需要根据system_id进行过滤,其他过滤条件也可以添加
|
||||
$query = Role::query();
|
||||
|
||||
|
||||
if (isset($params['system_id'])) {
|
||||
$query->where('system_id', $params['system_id']);
|
||||
}
|
||||
if (isset($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
|
||||
// 添加分页
|
||||
$roles = $query->paginate($params['per_page'] ?? 15);
|
||||
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色详情
|
||||
*/
|
||||
public function getRoleDetail(int $roleId)
|
||||
{
|
||||
$role = Role::find($roleId);
|
||||
if (!$role) {
|
||||
throw new BusinessException('角色不存在', 404);
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
*/
|
||||
public function createRole(array $data)
|
||||
{
|
||||
$role = new Role();
|
||||
$role->fill($data); // 根据字段填充数据
|
||||
try {
|
||||
$role->save();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('创建角色失败:'.$e->getMessage());
|
||||
throw new BusinessException('创建角色失败', 500);
|
||||
}
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
*/
|
||||
public function updateRole(array $data)
|
||||
{
|
||||
$role = Role::find($data['id']);
|
||||
if (!$role) {
|
||||
throw new BusinessException('角色不存在', 404);
|
||||
}
|
||||
|
||||
$role->update($data); // 更新字段
|
||||
return $role;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*/
|
||||
public function deleteRole(int $roleId)
|
||||
{
|
||||
$role = Role::find($roleId);
|
||||
if (!$role) {
|
||||
throw new BusinessException('角色不存在', 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$role->delete();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('删除角色失败:'.$e->getMessage());
|
||||
throw new BusinessException('删除角色失败', 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user