feat : basic

This commit is contained in:
2024-11-12 11:02:38 +08:00
parent 235acbea9c
commit a9f81888b7
26 changed files with 342 additions and 209 deletions

View File

@@ -11,7 +11,7 @@ declare(strict_types=1);
namespace App\Service\Admin\User;
use App\Constants\Admin\UserCode;
use App\Exception\AdminException;
use App\Exception\ErrException;
use App\Extend\StringUtil;
use App\Lib\Crypto\CryptoFactory;
use App\Model\AdminRole;
@@ -81,7 +81,7 @@ class EmployeeService extends BaseService
$oldAccount = $this->adminUserModel->getAdminInfoByAccount($account);
$oldName = $this->adminUserModel->getAdminInfoByName($name);
if (!empty($oldName) && !empty($oldAccount)) throw new AdminException('账号或者员工已存在');
if (!empty($oldName) && !empty($oldAccount)) throw new ErrException('账号或者员工已存在');
$salt = StringUtil::randStr(6);
$defaultPassword = config('system.admin_default_password');
@@ -98,7 +98,7 @@ class EmployeeService extends BaseService
$model->role_id = $this->request->input('role_id', 0);
$model->section_id = $this->request->input('section_id', 0);
if (!$model->save()) throw new AdminException('账号添加失败');
if (!$model->save()) throw new ErrException('账号添加失败');
return $this->return->success();
}
@@ -114,13 +114,13 @@ class EmployeeService extends BaseService
$account = $this->request->input('account');
$info = $this->adminUserModel->getAdminInfoById($id);
if (empty($info)) throw new AdminException('数据不存在');
if (empty($info)) throw new ErrException('数据不存在');
$oldAccount = $this->adminUserModel->getAdminInfoByAccount($account);
$oldName = $this->adminUserModel->getAdminInfoByName($name);
if (!empty($oldName) && $oldName->id != $info->id) throw new AdminException('员工已存在');
if (!empty($oldAccount) && $oldAccount->id != $info->id) throw new AdminException('账号已存在');
if (!empty($oldName) && $oldName->id != $info->id) throw new ErrException('员工已存在');
if (!empty($oldAccount) && $oldAccount->id != $info->id) throw new ErrException('账号已存在');
$info->username = $account;
$info->mobile = $account;
@@ -130,7 +130,7 @@ class EmployeeService extends BaseService
$info->role_id = $this->request->input('role_id', 0);
$info->section_id = $this->request->input('section_id', 0);
if (!$info->save()) throw new AdminException('账号修改失败');
if (!$info->save()) throw new ErrException('账号修改失败');
return $this->return->success();
}
@@ -143,15 +143,15 @@ class EmployeeService extends BaseService
{
$id = (int)$this->request->input('id');
if ($this->adminId == $id) throw new AdminException('不可删除自己');
if ($this->adminId == $id) throw new ErrException('不可删除自己');
$info = $this->adminUserModel->getAdminInfoById($id);
if (empty($info)) throw new AdminException('员工不存在');
if (empty($info)) throw new ErrException('员工不存在');
$info->is_del = UserCode::IS_DEL;
if (!$info->save()) throw new AdminException('账号删除失败');
if (!$info->save()) throw new ErrException('账号删除失败');
return $this->return->success();
}
@@ -166,7 +166,7 @@ class EmployeeService extends BaseService
$info = $this->adminUserModel->where('id', $id)->where('is_del',UserCode::ENABLE)->first($this->filed);
if (empty($info)) throw new AdminException('员工不存在');
if (empty($info)) throw new ErrException('员工不存在');
$roleName = $this->adminRoleModel->where('id', $info->role_id)->value('name');
@@ -187,7 +187,7 @@ class EmployeeService extends BaseService
$info = $this->adminUserModel->getAdminInfoById($id);
if (empty($info)) throw new AdminException('员工不存在');
if (empty($info)) throw new ErrException('员工不存在');
$salt = StringUtil::randStr(6);
$defaultPassword = config('system.admin_default_password');
@@ -195,7 +195,7 @@ class EmployeeService extends BaseService
$info->salt = $salt;
$info->password = $this->cryptoFactory->cryptoClass('admin-password',$defaultPassword,$salt)->encrypt();
if (!$info->save()) throw new AdminException('密码重置失败');
if (!$info->save()) throw new ErrException('密码重置失败');
return $this->return->success();
}

View File

@@ -12,7 +12,7 @@ namespace App\Service\Admin\User;
use App\Cache\Redis\Admin\MenuCache;
use App\Constants\Admin\AuthCode;
use App\Exception\AdminException;
use App\Exception\ErrException;
use App\Model\AdminMenu;
use App\Service\Admin\BaseService;
use Exception;
@@ -60,14 +60,14 @@ class RoleMenuService extends BaseService
public function add(): array
{
$url = $this->request->input('menu_url');
if (!empty($this->adminMenuModel->getMenuByUrl($url))) throw new AdminException('已存在相同路由的权限菜单');
if (!empty($this->adminMenuModel->getMenuByUrl($url))) throw new ErrException('已存在相同路由的权限菜单');
$insertButtonArr = [];
if (!empty($permissionList = $this->request->input('permission_list'))) {
$permissionList = json_decode($permissionList, true);
foreach ($permissionList as $one) {
if (empty($one['value'])) throw new AdminException('按钮权限值错误');
if (empty($one['menu_url'])) throw new AdminException('按钮路由值错误');
if (empty($one['value'])) throw new ErrException('按钮权限值错误');
if (empty($one['menu_url'])) throw new ErrException('按钮路由值错误');
$insertButtonArr[] = [
'url' => $one['menu_url'],
'value' => $one['value'],
@@ -104,7 +104,7 @@ class RoleMenuService extends BaseService
$this->reconfigurationCache();
} catch (Exception $exception) {
Db::rollBack();
throw new AdminException($exception->getMessage());
throw new ErrException($exception->getMessage());
}
return $this->return->success();
@@ -122,8 +122,8 @@ class RoleMenuService extends BaseService
$url = $this->request->input('menu_url');
$oldUrlInfo = $this->adminMenuModel->getMenuByUrl($url);
$menuInfo = $this->adminMenuModel->where('id',$menuId)->first();
if (!empty($oldUrlInfo) && $oldUrlInfo->id != $menuId) throw new AdminException('已存在相同路由的权限菜单');
if (empty($menuInfo)) throw new AdminException('路由不存在');
if (!empty($oldUrlInfo) && $oldUrlInfo->id != $menuId) throw new ErrException('已存在相同路由的权限菜单');
if (empty($menuInfo)) throw new ErrException('路由不存在');
$childrenType = $this->adminMenuModel->getChildMenuType($menuId);
$permissionList = $this->request->input('permission_list');
@@ -131,8 +131,8 @@ class RoleMenuService extends BaseService
if (!empty($permissionList) && $childrenType != AuthCode::MENU_TYPE_LIST) {
$permissionList = json_decode($permissionList, true);
foreach ($permissionList as $one) {
if (empty($one['value'])) throw new AdminException('按钮权限值错误');
if (empty($one['menu_url'])) throw new AdminException('按钮路由值错误');
if (empty($one['value'])) throw new ErrException('按钮权限值错误');
if (empty($one['menu_url'])) throw new ErrException('按钮路由值错误');
$insertButtonArr[] = [
'parent_id' => $menuId,
'url' => $one['menu_url'],
@@ -168,7 +168,7 @@ class RoleMenuService extends BaseService
$this->reconfigurationCache();
} catch (Exception $exception) {
Db::rollBack();
throw new AdminException($exception->getMessage());
throw new ErrException($exception->getMessage());
}
return $this->return->success();
@@ -185,7 +185,7 @@ class RoleMenuService extends BaseService
{
$menuId = $this->request->input('menu_id');
$res = $this->adminMenuModel->where('id',$menuId)->first();
if (!$res) throw new AdminException('路由不存在');
if (!$res) throw new ErrException('路由不存在');
$ids = [$res->id];
$topIds = [$res->id];
@@ -210,7 +210,7 @@ class RoleMenuService extends BaseService
{
$menuId = $this->request->input('menu_id');
$res = $this->adminMenuModel->where('id',$menuId)->first();
if (!$res) throw new AdminException('路由不存在');
if (!$res) throw new ErrException('路由不存在');
$res = $res->toArray();
//获取子集

View File

@@ -14,7 +14,7 @@ use App\Cache\Redis\Admin\MenuCache;
use App\Cache\Redis\Admin\RoleCache;
use App\Constants\Admin\AuthCode;
use App\Constants\Common\RoleCode;
use App\Exception\AdminException;
use App\Exception\ErrException;
use App\Model\AdminRole;
use App\Model\AdminRoleMenu;
use App\Service\Admin\BaseService;
@@ -80,7 +80,7 @@ class RoleService extends BaseService
{
$name = $this->request->input('role_name');
if ($this->adminRoleModel->getInfoByName($name)) throw new AdminException('角色已存在');
if ($this->adminRoleModel->getInfoByName($name)) throw new ErrException('角色已存在');
Db::beginTransaction();
try {
@@ -112,7 +112,7 @@ class RoleService extends BaseService
$this->roleCache->getRoleCache($model->id);
} catch (Exception $e) {
Db::rollBack();
throw new AdminException($e->getMessage());
throw new ErrException($e->getMessage());
}
return $this->return->success();
@@ -128,11 +128,11 @@ class RoleService extends BaseService
{
$id = (int)$this->request->input('role_id');
if (!$info = $this->adminRoleModel->getInfoById($id)) throw new AdminException('角色不存在');
if (!$info = $this->adminRoleModel->getInfoById($id)) throw new ErrException('角色不存在');
$name = $this->request->input('role_name');
$oldInfo = $this->adminRoleModel->getInfoByName($name);
if ($oldInfo->id != $id) throw new AdminException('角色已存在');
if ($oldInfo->id != $id) throw new ErrException('角色已存在');
Db::beginTransaction();
try {
@@ -165,7 +165,7 @@ class RoleService extends BaseService
$this->roleCache->getRoleCache($info->id);
} catch (Exception $e) {
Db::rollBack();
throw new AdminException($e->getMessage());
throw new ErrException($e->getMessage());
}
return $this->return->success();
@@ -179,13 +179,13 @@ class RoleService extends BaseService
public function changeStatus(): array
{
$id = (int)$this->request->input('role_id');
if ($id == RoleCode::SUPER_ADMIN) throw new AdminException('超级管理员不可关闭');
if ($id == RoleCode::SUPER_ADMIN) throw new ErrException('超级管理员不可关闭');
if (!$info = $this->adminRoleModel->getInfoById($id)) throw new AdminException('角色不存在');
if (!$info = $this->adminRoleModel->getInfoById($id)) throw new ErrException('角色不存在');
$info->status = $this->request->input('role_status', 0);
if (!$info->save()) throw new AdminException('修改失败');
if (!$info->save()) throw new ErrException('修改失败');
return $this->return->success();
}
@@ -201,7 +201,7 @@ class RoleService extends BaseService
{
$roleId = $this->request->input('role_id');
$res = $this->adminRoleModel->where('id',$roleId)->first($this->field);
if (!$res) throw new AdminException('角色不存在');
if (!$res) throw new ErrException('角色不存在');
$data = $this->roleCache->getRoleCache((int)$roleId);

View File

@@ -11,7 +11,7 @@ declare(strict_types=1);
namespace App\Service\Admin\User;
use App\Cache\Redis\Admin\SectionCache;
use App\Exception\AdminException;
use App\Exception\ErrException;
use App\Model\AdminSection;
use App\Model\AdminUser;
use App\Service\Admin\BaseService;
@@ -76,7 +76,7 @@ class SectionService extends BaseService
$model->remark = $this->request->input('remark');
$model->status = $this->request->input('status',1);
if (!$model->save()) throw new AdminException('添加失败');
if (!$model->save()) throw new ErrException('添加失败');
$this->sectionCache->delList();
@@ -94,7 +94,7 @@ class SectionService extends BaseService
$id = (int)$this->request->input('id');
$info = $this->adminSectionModel->getInfoById($id);
if (empty($info)) throw new AdminException('数据不存在');
if (empty($info)) throw new ErrException('数据不存在');
$info->name = $this->request->input('name');
$info->pid = $this->request->input('pid',0);
@@ -102,7 +102,7 @@ class SectionService extends BaseService
$info->remark = $this->request->input('remark');
$info->status = $this->request->input('status',1);
if (!$info->save()) throw new AdminException('修改失败');
if (!$info->save()) throw new ErrException('修改失败');
$this->sectionCache->delList();
return $this->return->success();
}
@@ -118,10 +118,10 @@ class SectionService extends BaseService
$id = (int)$this->request->input('id');
$info = $this->adminSectionModel->getInfoById($id);
if (empty($info)) throw new AdminException('数据不存在');
if (empty($info)) throw new ErrException('数据不存在');
$children = $this->adminSectionModel->getInfoByPid($info->id);
if (empty($children)) throw new AdminException('请先删除下级数据');
if (empty($children)) throw new ErrException('请先删除下级数据');
$this->adminUserModel->where('section_id',$id)->update(['section_id'=>0]);
@@ -138,7 +138,7 @@ class SectionService extends BaseService
$id = (int)$this->request->input('id');
$info = $this->adminSectionModel->getInfoById($id);
if (empty($info)) throw new AdminException('数据不存在');
if (empty($info)) throw new ErrException('数据不存在');
return $this->return->success('success',$info->toArray());
}