1.优化工作台页面/dashboard/console

2.移除岗位管理相关代码和数据库
This commit is contained in:
2026-05-18 11:41:34 +08:00
parent 52b5ccb8e4
commit 085454fb78
30 changed files with 201 additions and 1123 deletions

View File

@@ -27,7 +27,6 @@ class UserInfoCache
'expire' => 60 * 60 * 4,
'dept' => 'saiadmin:user_cache:dept_',
'role' => 'saiadmin:user_cache:role_',
'post' => 'saiadmin:user_cache:post_',
]);
}
@@ -73,11 +72,6 @@ class UserInfoCache
$tags[] = $cache['role'] . $role['id'];
}
}
if (!empty($data['postList'])) {
foreach ($data['postList'] as $post) {
$tags[] = $cache['post'] . $post['id'];
}
}
Cache::tag($tags)->set($cache['prefix'] . $uid, $data, $cache['expire']);
return $data;
}
@@ -125,21 +119,4 @@ class UserInfoCache
return Cache::tag($tags)->clear();
}
/**
* 清理岗位下所有用户缓存
*/
public static function clearUserInfoByPostId($post_id): bool
{
$cache = static::cacheConfig();
if (is_array($post_id)) {
$tags = [];
foreach ($post_id as $id) {
$tags[] = $cache['post'] . $id;
}
} else {
$tags = $cache['post'] . $post_id;
}
return Cache::tag($tags)->clear();
}
}

View File

@@ -1,177 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\controller\system;
use plugin\saiadmin\basic\BaseController;
use plugin\saiadmin\app\logic\system\SystemPostLogic;
use plugin\saiadmin\app\validate\system\SystemPostValidate;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
/**
* 岗位信息控制器
*/
class SystemPostController extends BaseController
{
/**
* 构造
*/
public function __construct()
{
$this->logic = new SystemPostLogic();
$this->validate = new SystemPostValidate;
parent::__construct();
}
/**
* 数据列表
* @param Request $request
* @return Response
*/
#[Permission('岗位数据列表', 'core:post:index')]
public function index(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
$query = $this->logic->search($where);
$data = $this->logic->getList($query);
return $this->success($data);
}
/**
* 读取数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据读取', 'core:post:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
$model = $this->logic->read($id);
if ($model) {
$data = is_array($model) ? $model : $model->toArray();
return $this->success($data);
} else {
return $this->fail('not found');
}
}
/**
* 保存数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据添加', 'core:post:save')]
public function save(Request $request): Response
{
$data = $request->post();
$this->validate('save', $data);
$result = $this->logic->add($data);
if ($result) {
return $this->success('add success');
} else {
return $this->fail('add failed');
}
}
/**
* 更新数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据修改', 'core:post:update')]
public function update(Request $request): Response
{
$data = $request->post();
$this->validate('update', $data);
$result = $this->logic->edit($data['id'], $data);
if ($result) {
return $this->success('update success');
} else {
return $this->fail('update failed');
}
}
/**
* 删除数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据删除', 'core:post:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
if (empty($ids)) {
return $this->fail('please select data to delete');
}
$result = $this->logic->destroy($ids);
if ($result) {
return $this->success('delete success');
} else {
return $this->fail('delete failed');
}
}
/**
* 导入数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导入', 'core:post:import')]
public function import(Request $request): Response
{
$file = current($request->file());
if (!$file || !$file->isValid()) {
return $this->fail('uploaded file not found');
}
$this->logic->import($file);
return $this->success('import success');
}
/**
* 导出数据
* @param Request $request
* @return Response
*/
#[Permission('岗位数据导出', 'core:post:export')]
public function export(Request $request): Response
{
$where = $request->more([
['name', ''],
['code', ''],
['status', ''],
]);
return $this->logic->export($where);
}
/**
* 下载导入模板
* @return Response
*/
public function downloadTemplate(): Response
{
$file_name = "template.xlsx";
return downloadFile($file_name);
}
/**
* 可操作岗位
* @param Request $request
* @return Response
*/
public function accessPost(Request $request): Response
{
$where = ['status' => 1];
$data = $this->logic->accessPost($where);
return $this->success($data);
}
}

View File

@@ -182,7 +182,6 @@ class SystemUserController extends BaseController
{
$data = $request->post();
unset($data['deptList']);
unset($data['postList']);
unset($data['roleList']);
$result = $this->logic->updateInfo($this->adminId, $data);
if ($result) {

View File

@@ -1,95 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\logic\system;
use plugin\saiadmin\app\model\system\SystemPost;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\service\OpenSpoutWriter;
use OpenSpout\Reader\XLSX\Reader;
/**
* 岗位管理逻辑层
*/
class SystemPostLogic extends BaseLogic
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new SystemPost();
}
/**
* 可操作岗位
* @param array $where
* @return array
*/
public function accessPost(array $where = []): array
{
$query = $this->search($where);
$query->field('id, id as value, name as label, name, code');
return $this->getAll($query);
}
/**
* 导入数据
*/
public function import($file)
{
$path = $this->getImport($file);
$reader = new Reader();
try {
$reader->open($path);
$data = [];
foreach ($reader->getSheetIterator() as $sheet) {
$isHeader = true;
foreach ($sheet->getRowIterator() as $row) {
if ($isHeader) {
$isHeader = false;
continue;
}
$cells = $row->getCells();
$data[] = [
'name' => $cells[0]->getValue(),
'code' => $cells[1]->getValue(),
'sort' => $cells[2]->getValue(),
'status' => $cells[3]->getValue(),
];
}
}
$this->saveAll($data);
} catch (\Exception $e) {
throw new ApiException('Import file error, please upload correct xlsx file');
}
}
/**
* 导出数据
*/
public function export($where = [])
{
$query = $this->search($where)->field('id,name,code,sort,status,create_time');
$data = $this->getAll($query);
$file_name = '岗位数据.xlsx';
$header = ['编号', '岗位名称', '岗位标识', '排序', '状态', '创建时间'];
$filter = [
'status' => [
['value' => 1, 'label' => '正常'],
['value' => 2, 'label' => '禁用']
]
];
$writer = new OpenSpoutWriter($file_name);
$writer->setWidth([15, 15, 20, 15, 15, 25]);
$writer->setHeader($header);
$writer->setData($data, null, $filter);
$file_path = $writer->returnFile();
return response()->download($file_path, urlencode($file_name));
}
}

View File

@@ -69,7 +69,6 @@ class SystemUserLogic extends BaseLogic
$admin = $this->model->findOrEmpty($id);
$data = $admin->hidden(['password'])->toArray();
$data['roleList'] = $admin->roles->toArray() ?: [];
$data['postList'] = $admin->posts->toArray() ?: [];
$data['deptList'] = $admin->depts ? $admin->depts->toArray() : [];
return $data;
}
@@ -101,7 +100,6 @@ class SystemUserLogic extends BaseLogic
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
return $this->transaction(function () use ($data) {
$role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
if ($this->adminInfo['id'] > 1) {
// 部门保护
if (!$this->deptProtect($this->adminInfo['deptList'], $data['dept_id'])) {
@@ -114,11 +112,7 @@ class SystemUserLogic extends BaseLogic
}
$user = SystemUser::create($data);
$user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
return $user;
});
}
@@ -134,7 +128,6 @@ class SystemUserLogic extends BaseLogic
unset($data['password']);
return $this->transaction(function () use ($data, $id) {
$role_ids = $data['role_ids'] ?? [];
$post_ids = $data['post_ids'] ?? [];
// 超级管理员可修改任意用户,普通管理员仅可修改当前部门和子部门的用户
$query = $this->model->where('id', $id);
if (isset($this->adminInfo['id']) && $this->adminInfo['id'] > 1) {
@@ -157,11 +150,7 @@ class SystemUserLogic extends BaseLogic
$result = parent::edit($id, $data);
if ($result) {
$user->roles()->detach();
$user->posts()->detach();
$user->roles()->saveAll($role_ids);
if (!empty($post_ids)) {
$user->posts()->save($post_ids);
}
UserInfoCache::clearUserInfo($id);
UserAuthCache::clearUserAuth($id);
UserMenuCache::clearUserMenu($id);

View File

@@ -1,37 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use plugin\saiadmin\basic\think\BaseModel;
/**
* 岗位模型
*
* sa_system_post 岗位信息表
*
* @property $id 主键
* @property $name 岗位名称
* @property $code 岗位代码
* @property $sort 排序
* @property $status 状态
* @property $remark 备注
* @property $created_by 创建者
* @property $updated_by 更新者
* @property $create_time 创建时间
* @property $update_time 修改时间
*/
class SystemPost extends BaseModel
{
/**
* 数据表主键
* @var string
*/
protected $pk = 'id';
protected $table = 'sa_system_post';
}

View File

@@ -103,14 +103,6 @@ class SystemUser extends BaseModel
return $this->belongsToMany(SystemRole::class, SystemUserRole::class, 'role_id', 'user_id');
}
/**
* 通过中间表关联岗位
*/
public function posts()
{
return $this->belongsToMany(SystemPost::class, SystemUserPost::class, 'post_id', 'user_id');
}
/**
* 通过中间表关联部门
*/

View File

@@ -1,25 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\model\system;
use think\model\Pivot;
/**
* 用户岗位关联模型
*
* sa_system_user_post 用户与岗位关联表
*
* @property $id 主键
* @property $user_id 用户主键
* @property $post_id 岗位主键
*/
class SystemUserPost extends Pivot
{
protected $pk = 'id';
protected $table = 'sa_system_user_post';
}

View File

@@ -1,50 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: sai <1430792918@qq.com>
// +----------------------------------------------------------------------
namespace plugin\saiadmin\app\validate\system;
use plugin\saiadmin\basic\BaseValidate;
/**
* 用户角色验证器
*/
class SystemPostValidate extends BaseValidate
{
/**
* 定义验证规则
*/
protected $rule = [
'name' => 'require',
'code' => 'require',
'status' => 'require',
];
/**
* 定义错误信息
*/
protected $message = [
'name' => '岗位名称必须填写',
'code' => '岗位标识必须填写',
'status' => '状态必须填写',
];
/**
* 定义场景
*/
protected $scene = [
'save' => [
'name',
'code',
'status',
],
'update' => [
'name',
'code',
'status',
],
];
}