refactor: 修改附件分类支持上下级

This commit is contained in:
2025-04-14 18:11:41 +08:00
parent e6e5f260fb
commit 941e103258
3 changed files with 80 additions and 32 deletions

View File

@@ -11,20 +11,48 @@ use app\admin\validate\v1\AttachmentCategoryValidate;
*/
class AttachmentCategory
{
/**
* 列表树形结构
*/
public function tree()
{
$params = request()->param([
'name',
'is_show'
]);
$categorys = AttachmentCategoryModel::field([
'id',
'pid',
'name'
])
->withSearch(['name'], [
'name' => $params['name']??null
])
->where(function($query) use($params) {
if (isset($params['is_show'])) {
$query->where('is_show', '=', $params['is_show']);
}
})
->language(request()->lang_id)
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
return success('获取成功', array_to_tree($categorys->toArray(), 0, 'pid', 1, false));
}
/**
* 分页数据
*/
public function index()
{
$params = request()->param([
'name',
'is_show',
'page/d' => 1,
'size/d' => 10
'name'
]);
$categorys = AttachmentCategoryModel::field([
'id',
'pid',
'name',
'sort',
'is_show'
@@ -33,23 +61,10 @@ class AttachmentCategory
'name' => $params['name']??null
])
->language(request()->lang_id)
->order(['sort' => 'asc', 'id' => 'desc']);
if (!request()->has('scene')) {
$categorys = $categorys->paginate([
'list_rows' => $params['size'],
'page' => $params['page']
]);
} else if ('all' == request()->param('scene')) {
$categorys = $categorys->where(function($query) use($params) {
if (isset($params['is_show'])) {
$query->where('is_show', '=', $params['is_show']);
}
})
->select()
->hidden(['sort', 'is_show']);
}
->order(['sort' => 'asc', 'id' => 'desc'])
->select();
return success('获取成功', $categorys);
return success('获取成功', array_to_tree($categorys->toArray(), 0, 'pid', 1, false));
}
/**
@@ -80,6 +95,7 @@ class AttachmentCategory
public function save()
{
$post = request()->post([
'pid' => 0,
'name',
'sort',
'is_show'
@@ -105,6 +121,7 @@ class AttachmentCategory
{
$id = request()->param('id');
$put = request()->put([
'pid' => 0,
'name',
'sort',
'is_show'