feat: 开放API文章相关

This commit is contained in:
2025-05-21 16:59:48 +08:00
parent 9ecc9ac957
commit e712030e3e
7 changed files with 299 additions and 8 deletions

View File

@@ -0,0 +1,50 @@
<?php
declare (strict_types = 1);
namespace app\openapi\controller\v1;
use app\openapi\model\ArticleCategoryModel;
class ArticleCategory
{
/**
* 文章分类列表
*/
public function list()
{
$params = request()->get([
'parent_id',
'language' => 'zh-cn',
'page/d' => 1,
'size/d' => 50
]);
if ($params['size'] > 200) {
// 每页不超过200条
$params['size'] = 200;
}
$categories = ArticleCategoryModel::withoutField([
'language_id',
'unique_label',
'created_at',
'updated_at',
])
->language($params['language']??'zh-cn')
->parent($params['parent_id']??null)
->order(['sort' => 'asc', 'id' => 'desc'])
->paginate([
'list_rows' => $params['size'],
'page' => $params['page'],
])
->each(function($item) {
if (!empty($item['icon']) && !str_starts_with($item['icon'], 'http')){
$item['icon'] = image_domain_concat($item['icon']);
}
return $item;
});
return success('success', $categories);
}
}