Files
2026-10-15 16:25:51 +08:00

42 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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());
}
}
}