This commit is contained in:
2024-11-21 16:40:44 +08:00
commit a5029a2be7
69 changed files with 3160 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?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');
CmsArticle::mk()->where('id', $id)->inc('view_count');
$article = CmsArticle::mk()->where('id', $id)->find();
if (empty($article)) {
$this->error('文章不存在');
}
$this->success('获取文章详情', $article);
}
}