You've already forked guangan
1
This commit is contained in:
31
plugs/think-plugs-cms/src/controller/api/Article.php
Normal file
31
plugs/think-plugs-cms/src/controller/api/Article.php
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user