Files
guangan/plugs/think-plugs-cms/src/controller/api/Article.php
2024-12-19 11:03:21 +08:00

32 lines
1012 B
PHP

<?php
namespace plugin\cms\controller\api;
use plugin\cms\model\CmsArticle;
use think\admin\Controller;
class Article extends Controller
{
public function index() {
$categoryId = $this->request->get('cid');
$query = CmsArticle::mk()->where('status', 1);
if (is_numeric($categoryId)) {
$query->hasWhere('cateids', function ($subQuery) use ($categoryId) {
$subQuery->where('cid', $categoryId);
});
}
$articles = $query->field('id,title,thumb,author,from,view_count,publish_at')->order('sort asc,id desc')->paginate();
$this->success('获取文章列表', $articles);
}
public function info() {
$id = $this->request->get('id');
$article = CmsArticle::mk()->where('id', $id)->find();
if (empty($article)) {
$this->error('文章不存在');
}
$article->inc('view_count');
$article->save();
$this->success('获取文章详情', $article);
}
}