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