添加轮播图
This commit is contained in:
@@ -4,9 +4,7 @@ namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\service\CategoryService;
|
||||
use fast\Tree;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Validate;
|
||||
|
||||
class Catalog extends Api
|
||||
{
|
||||
@@ -16,16 +14,16 @@ class Catalog extends Api
|
||||
/**
|
||||
* 分类列表
|
||||
*
|
||||
* @ApiMethod (POST)
|
||||
* @param string $desc 需求描述
|
||||
* @param array $images 图片数组
|
||||
* @param array $files 文件数组
|
||||
* @param string $contact 联系方式
|
||||
* @ApiMethod (GET)
|
||||
* @param string $type 栏目类型,banner 时返回首页轮播(name、image、description)
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$params = $this->request->get();
|
||||
$type = (string)$this->request->get('type', '');
|
||||
if ($type === 'banner') {
|
||||
$this->success('', CategoryService::getBannerList());
|
||||
}
|
||||
$cateList = CategoryService::getOptions();
|
||||
$res = [
|
||||
['text' => '全部', 'key' => 0]
|
||||
|
||||
@@ -29,6 +29,28 @@ class CategoryService
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页轮播:分类类型 banner,仅正常状态,按权重从高到低
|
||||
* @return array
|
||||
*/
|
||||
public static function getBannerList()
|
||||
{
|
||||
$list = self::getList(['type' => 'banner', 'status' => 'normal'], 0, 'weigh desc,id desc');
|
||||
$rows = [];
|
||||
foreach ($list as $item) {
|
||||
$image = (string)($item['image'] ?? '');
|
||||
if ($image === '') {
|
||||
continue;
|
||||
}
|
||||
$rows[] = [
|
||||
'name' => (string)($item['name'] ?? ''),
|
||||
'image' => cdnurl($image, true),
|
||||
'description' => (string)($item['description'] ?? ''),
|
||||
];
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function transformTree($data)
|
||||
{
|
||||
return array_map(function ($item) {
|
||||
|
||||
Reference in New Issue
Block a user