From 09603ee33ab1f48073f9a463acff3f2b3528d14f Mon Sep 17 00:00:00 2001 From: "LAPTOP-7SGDREK0\\shiweijun" <411582373@qq.com> Date: Thu, 27 Feb 2025 17:34:05 +0800 Subject: [PATCH] feat:material_category --- .../Admin/Material/MaterialCategoryService.php | 18 ++++++++++++++++-- sync/http/admin/auth.http | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Service/Admin/Material/MaterialCategoryService.php b/app/Service/Admin/Material/MaterialCategoryService.php index 9ecdfb6..5946ab1 100644 --- a/app/Service/Admin/Material/MaterialCategoryService.php +++ b/app/Service/Admin/Material/MaterialCategoryService.php @@ -111,8 +111,22 @@ class MaterialCategoryService extends BaseService{ ->when($cityId > 0,function($query) use($cityId){ $query->where('city_id',$cityId); }) - ->where('is_del',MaterialCode::IS_NO_DEL)->get(); + ->where('is_del',MaterialCode::IS_NO_DEL)->get()->toArray(); - return $this->return->success('success',['list' => $list->toArray()]); + $tree = []; + $map = []; + + foreach ($list as &$category) { + $category['children'] = []; + $map[$category['id']] = &$category; + + if ($category['parent_id'] && isset($map[$category['parent_id']])) { + $map[$category['parent_id']]['children'][] = &$category; + } else { + $tree[] = &$category; + } + } + + return $this->return->success('success',$tree); } } \ No newline at end of file diff --git a/sync/http/admin/auth.http b/sync/http/admin/auth.http index 6c7488e..3a25829 100644 --- a/sync/http/admin/auth.http +++ b/sync/http/admin/auth.http @@ -324,6 +324,11 @@ GET {{host}}/admin/material_category/findById?query_id=1 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{admin_token}} +### 材料种类列表 +GET {{host}}/admin/material_category/list?query_city_id=1 +content-type: application/json +Authorization: Bearer {{admin_token}} + ### 材料列表 GET {{host}}/admin/material/list?limit=10 content-type: application/json