Files

42 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-09-17 16:25:31 +08:00
<?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 = ['*'];
/**
* 分类列表
*
2026-10-15 16:25:51 +08:00
* @ApiMethod (GET)
* @param string $type 栏目类型,banner 时返回首页轮播(name、image、description)
2026-09-17 16:25:31 +08:00
*/
public function index()
{
try {
2026-10-15 16:25:51 +08:00
$type = (string)$this->request->get('type', '');
if ($type === 'banner') {
$this->success('', CategoryService::getBannerList());
}
2026-09-17 16:25:31 +08:00
$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());
}
}
}