BookCategoryController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers\Manage\Book;
  3. use App\Modules\Book\Services\BookCategoryService;
  4. use App\Modules\Book\Services\BookService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. class BookCategoryController extends Controller
  8. {
  9. /**
  10. * @apiDefine Book 图书模块
  11. */
  12. /**
  13. * @apiVersion 1.0.0
  14. * @apiDescription 获取分类
  15. * @api {get} books/getCategory 获取分类
  16. * @apiGroup Book
  17. * @apiName getCategory
  18. * @apiParam {int} [all] 全部
  19. * @apiSuccess {int} code 状态码
  20. * @apiSuccess {String} msg 信息
  21. * @apiSuccess {object} data 结果集
  22. * @apiSuccessExample {json} Success-Response:
  23. * HTTP/1.1 200 OK
  24. * {
  25. * code: 0,
  26. * msg: "",
  27. * data: [
  28. * {
  29. * id: 1,
  30. * name: "男频",
  31. * children: [
  32. * {
  33. * id: 7,
  34. * name: "灵异鬼怪"
  35. * },
  36. * {
  37. * id: 8,
  38. * name: "历史穿越"
  39. * },
  40. * {
  41. * id: 30,
  42. * name: "青春爱情"
  43. * }
  44. * ]
  45. * },
  46. * {
  47. * id: 2,
  48. * name: "女频",
  49. * children: [
  50. * {
  51. * id: 26,
  52. * name: "豪门总裁"
  53. * },
  54. * {
  55. * id: 35,
  56. * name: "民国爱情"
  57. * }
  58. * ]
  59. * }
  60. * ]
  61. * }
  62. */
  63. public function getCategory(Request $request){
  64. $all = $request->input('all');
  65. $res = BookCategoryService::getCategory($all);
  66. foreach ($res as &$v){
  67. $v['value'] = $v['id'];
  68. $v['label'] = $v['name'];
  69. foreach ($v['children'] as &$val){
  70. $val['value'] = $val['id'];
  71. $val['label'] = $val['name'];
  72. }
  73. }
  74. return response()->success($res);
  75. }
  76. }