<?php namespace App\Http\Controllers\Manage\Book; use App\Modules\Book\Services\BookCategoryService; use App\Modules\Book\Services\BookService; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class BookCategoryController extends Controller { /** * @apiDefine Book 图书模块 */ /** * @apiVersion 1.0.0 * @apiDescription 获取分类 * @api {get} books/getCategory 获取分类 * @apiGroup Book * @apiName getCategory * @apiParam {int} [all] 全部 * @apiSuccess {int} code 状态码 * @apiSuccess {String} msg 信息 * @apiSuccess {object} data 结果集 * @apiSuccessExample {json} Success-Response: * HTTP/1.1 200 OK * { * code: 0, * msg: "", * data: [ * { * id: 1, * name: "男频", * children: [ * { * id: 7, * name: "灵异鬼怪" * }, * { * id: 8, * name: "历史穿越" * }, * { * id: 30, * name: "青春爱情" * } * ] * }, * { * id: 2, * name: "女频", * children: [ * { * id: 26, * name: "豪门总裁" * }, * { * id: 35, * name: "民国爱情" * } * ] * } * ] * } */ public function getCategory(Request $request){ $all = $request->input('all'); $res = BookCategoryService::getCategory($all); foreach ($res as &$v){ $v['value'] = $v['id']; $v['label'] = $v['name']; foreach ($v['children'] as &$val){ $val['value'] = $val['id']; $val['label'] = $val['name']; } } return response()->success($res); } }