42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\common\controller\Api;
|
||
use app\common\service\CategoryService;
|
||
use think\exception\HttpResponseException;
|
||
|
||
class Catalog extends Api
|
||
{
|
||
protected $noNeedLogin = ['index'];
|
||
protected $noNeedRight = ['*'];
|
||
|
||
/**
|
||
* 分类列表
|
||
*
|
||
* @ApiMethod (GET)
|
||
* @param string $type 栏目类型,banner 时返回首页轮播(name、image、description)
|
||
*/
|
||
public function index()
|
||
{
|
||
try {
|
||
$type = (string)$this->request->get('type', '');
|
||
if ($type === 'banner') {
|
||
$this->success('', CategoryService::getBannerList());
|
||
}
|
||
$cateList = CategoryService::getOptions();
|
||
$res = [
|
||
['text' => '全部', 'key' => 0]
|
||
];
|
||
foreach ($cateList as $key => $val) {
|
||
$res[] = ['text' => $val, 'key' => $key];
|
||
}
|
||
$this->success('', $res);
|
||
} catch (\Exception $e) {
|
||
if ($e instanceof HttpResponseException) {
|
||
throw $e;
|
||
}
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
}
|