Commit 52197e33 by 庄欣

分类

parent 9ad2c06e
...@@ -7,7 +7,39 @@ class Category extends ControllerBase ...@@ -7,7 +7,39 @@ class Category extends ControllerBase
{ {
public function pretty() public function pretty()
{ {
$data = parent::index("",false); empty($query) && $query = request()->getQueryString();
try {
$client = app("client");
$client->setUrl($this->prefix."?".$query);
$client->setMethod("get");
$res = $client->curl();
$res = $this->list_to_tree($res,"id","previous");
return Response::success($res);
} catch (\Exception $e) {
return Response::error($e->getMessage());
}
}
protected function list_to_tree($list, $pk='id', $pid = 'pid', $child = 'child', $root = 0) {
$tree = array();
if(is_array($list)) {
$refer = array();
foreach ($list as $key => $data) {
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] =& $list[$key];
}else{
if (isset($refer[$parentId])) {
$parent =& $refer[$parentId];
$parent[$child][] =& $list[$key];
}
} }
}
}
return $tree;
}
} }
\ No newline at end of file
...@@ -34,6 +34,7 @@ require __DIR__.'/../bootstrap/autoload.php'; ...@@ -34,6 +34,7 @@ require __DIR__.'/../bootstrap/autoload.php';
*/ */
header( 'Access-Control-Allow-Origin:*' ); header( 'Access-Control-Allow-Origin:*' );
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
$app = require_once __DIR__.'/../bootstrap/app.php'; $app = require_once __DIR__.'/../bootstrap/app.php';
......
...@@ -116,3 +116,11 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")] ...@@ -116,3 +116,11 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")]
//解禁 //解禁
Route::put("/{id}/resume" ,"Sets@resume"); Route::put("/{id}/resume" ,"Sets@resume");
}); });
Route::group(["prefix" => "category", 'namespace' => Provider::getNamespace("category")],function(){
//列表
Route::get ("/" , "Category@index");
//格式化分类
Route::get ("/pretty" , "Category@pretty");
});
\ 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