Catalog.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\service\CategoryService;
  5. use fast\Tree;
  6. use think\exception\HttpResponseException;
  7. use think\Validate;
  8. class Catalog extends Api
  9. {
  10. protected $noNeedLogin = ['index'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 分类列表
  14. *
  15. * @ApiMethod (POST)
  16. * @param string $desc 需求描述
  17. * @param array $images 图片数组
  18. * @param array $files 文件数组
  19. * @param string $contact 联系方式
  20. */
  21. public function index()
  22. {
  23. try {
  24. $params = $this->request->get();
  25. $cateList = CategoryService::getOptions();
  26. $res = [
  27. ['text' => '全部', 'key' => 0]
  28. ];
  29. foreach ($cateList as $key => $val) {
  30. $res[] = ['text' => $val, 'key' => $key];
  31. }
  32. $this->success('', $res);
  33. } catch (\Exception $e) {
  34. if ($e instanceof HttpResponseException) {
  35. throw $e;
  36. }
  37. $this->error($e->getMessage());
  38. }
  39. }
  40. }