chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | 文章CMS后台评论管理
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace addon\articles\controller\backend;
|
||||
|
||||
use think\facade\Request;
|
||||
use think\facade\View;
|
||||
use ywxapp\controller\BackendBase;
|
||||
use addon\articles\model\ArticleComment;
|
||||
use addon\articles\model\Article;
|
||||
use addon\articles\library\ArticleSchema;
|
||||
|
||||
class Comment extends BackendBase
|
||||
{
|
||||
protected $noNeedVerify = ['*'];
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
ArticleSchema::ensure();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$status = Request::param('status', 'all');
|
||||
$keyword = Request::param('keyword', '');
|
||||
$page = Request::param('page', 1);
|
||||
$limit = Request::param('limit', 15);
|
||||
|
||||
if (Request::isAjax()) {
|
||||
$query = ArticleComment::with(['user', 'article']);
|
||||
if ($status !== 'all') {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if ($keyword) {
|
||||
$query->where('content', 'like', "%{$keyword}%");
|
||||
}
|
||||
$paginator = $query->order('create_at', 'desc')
|
||||
->paginate(['list_rows' => $limit, 'page' => $page]);
|
||||
|
||||
$rows = [];
|
||||
foreach ($paginator->items() as $c) {
|
||||
$rows[] = [
|
||||
'id' => $c->id,
|
||||
'nickname' => $c->user->nickname ?? '游客',
|
||||
'article' => $c->article->title ?? '-',
|
||||
'content' => $c->content,
|
||||
'status' => $c->status,
|
||||
'create_at' => $c->create_at,
|
||||
];
|
||||
}
|
||||
return json(['code' => 0, 'msg' => '', 'count' => $paginator->total(), 'data' => $rows]);
|
||||
}
|
||||
return View::fetch('comment/index', ['status' => $status, 'keyword' => $keyword]);
|
||||
}
|
||||
|
||||
public function audit($id = 0)
|
||||
{
|
||||
$id = $id ?: (int) Request::post('id', 0);
|
||||
$comment = ArticleComment::find($id);
|
||||
if ($comment) {
|
||||
$comment->status = 1;
|
||||
$comment->save();
|
||||
Article::where('id', $comment->aid)->inc('comment_count')->update();
|
||||
return json(['code' => 1, 'msg' => '审核通过']);
|
||||
}
|
||||
return json(['code' => 0, 'msg' => '评论不存在']);
|
||||
}
|
||||
|
||||
public function delete($id = 0)
|
||||
{
|
||||
$id = $id ?: (int) Request::post('id', 0);
|
||||
$comment = ArticleComment::find($id);
|
||||
if ($comment) {
|
||||
$comment->delete();
|
||||
return json(['code' => 1, 'msg' => '已删除']);
|
||||
}
|
||||
return json(['code' => 0, 'msg' => '评论不存在']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user