Commit 07301e85 by 庄欣

分类修改

parent 040c570d
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Category\Controller; namespace App\Http\Controllers\Category\Controller;
use App\Http\Controllers\ControllerBase; use App\Http\Controllers\ControllerBase;
use App\Lib\Response\Response;
class Category extends ControllerBase class Category extends ControllerBase
{ {
...@@ -10,13 +11,11 @@ class Category extends ControllerBase ...@@ -10,13 +11,11 @@ class Category extends ControllerBase
public function pretty() public function pretty()
{ {
empty($query) && $query = request()->getQueryString();
try { try {
$client = app("client"); $client = app("client");
$client->setUrl($this->prefix."?".$query); $client->setUrl($this->prefix."/pretty");
$client->setMethod("get"); $client->setMethod("get");
$res = $client->curl(); $res = $client->curl();
$res = $this->list_to_tree($res,"id","previous");
return Response::success($res); return Response::success($res);
} catch (\Exception $e) { } catch (\Exception $e) {
return Response::error($e->getMessage()); return Response::error($e->getMessage());
...@@ -29,26 +28,18 @@ class Category extends ControllerBase ...@@ -29,26 +28,18 @@ class Category extends ControllerBase
return parent::index($query, $checkUid); return parent::index($query, $checkUid);
} }
protected function list_to_tree($list, $pk='id', $pid = 'pid', $child = 'child', $root = 0) {
$tree = array(); public function child($id)
if(is_array($list)) { {
$refer = array(); try {
foreach ($list as $key => $data) { $client = app("client");
$refer[$data[$pk]] =& $list[$key]; $client->setUrl($this->prefix."/$id/pretty");
} $client->setMethod("get");
foreach ($list as $key => $data) { $res = $client->curl();
$parentId = $data[$pid]; return Response::success($res);
if ($root == $parentId) { } catch (\Exception $e) {
$tree[] =& $list[$key]; return Response::error($e->getMessage());
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$parent[$child][] =& $list[$key];
}
}
}
} }
return $tree;
} }
} }
\ No newline at end of file
...@@ -122,4 +122,6 @@ Route::group(["prefix" => "category", 'namespace' => Provider::getNamespace("cat ...@@ -122,4 +122,6 @@ Route::group(["prefix" => "category", 'namespace' => Provider::getNamespace("cat
Route::get ("/" , "Category@index"); Route::get ("/" , "Category@index");
//格式化分类 //格式化分类
Route::get ("/pretty" , "Category@pretty"); Route::get ("/pretty" , "Category@pretty");
//某分类下的子分类
Route::get ("/{id}/child" , "Category@child")->where(['id' => '\d+']);
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment