初始化
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Article;
|
||||
use App\Models\ForumReply;
|
||||
use App\Models\ForumThread;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 统一审核队列:文章投稿 / 论坛帖子 / 论坛回复 的待审内容。
|
||||
* 入口按权限展示对应 Tab(articles.moderate / forum.moderate)。
|
||||
*/
|
||||
class ModerationController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
$tab = $request->query('tab', 'articles');
|
||||
|
||||
$canArticles = $user->canPerm('articles.moderate');
|
||||
$canForum = $user->canPerm('forum.moderate');
|
||||
|
||||
if (! $canArticles && ! $canForum) {
|
||||
abort(403, '无审核权限');
|
||||
}
|
||||
|
||||
if ($tab === 'threads' && ! $canForum) {
|
||||
$tab = $canArticles ? 'articles' : 'replies';
|
||||
}
|
||||
if ($tab === 'replies' && ! $canForum) {
|
||||
$tab = $canArticles ? 'articles' : 'threads';
|
||||
}
|
||||
|
||||
$articles = $canArticles
|
||||
? Article::where('status', 'pending')->with('user', 'category')->orderByDesc('created_at')->paginate(10, ['*'], 'ap')
|
||||
: null;
|
||||
|
||||
$threads = $canForum
|
||||
? ForumThread::where('status', 'pending')->with('user', 'board')->orderByDesc('created_at')->paginate(10, ['*'], 'tp')
|
||||
: null;
|
||||
|
||||
$replies = $canForum
|
||||
? ForumReply::where('status', 'pending')->with('user', 'thread')->orderByDesc('created_at')->paginate(10, ['*'], 'rp')
|
||||
: null;
|
||||
|
||||
return view('admin.moderation.index', compact('tab', 'articles', 'threads', 'replies', 'canArticles', 'canForum'));
|
||||
}
|
||||
|
||||
public function approveArticle(Article $article)
|
||||
{
|
||||
$article->update([
|
||||
'status' => 'approved',
|
||||
'published_at' => $article->published_at ?? now(),
|
||||
]);
|
||||
|
||||
return back()->with('success', "已通过文章《{$article->title}》");
|
||||
}
|
||||
|
||||
public function rejectArticle(Article $article)
|
||||
{
|
||||
$article->update(['status' => 'rejected']);
|
||||
|
||||
return back()->with('success', "已驳回文章《{$article->title}》");
|
||||
}
|
||||
|
||||
public function approveThread(ForumThread $thread)
|
||||
{
|
||||
$thread->update(['status' => ForumThread::STATUS_APPROVED]);
|
||||
|
||||
return back()->with('success', "已通过帖子《{$thread->title}》");
|
||||
}
|
||||
|
||||
public function rejectThread(ForumThread $thread)
|
||||
{
|
||||
$thread->update(['status' => ForumThread::STATUS_REJECTED]);
|
||||
|
||||
return back()->with('success', "已驳回帖子《{$thread->title}》");
|
||||
}
|
||||
|
||||
public function approveReply(ForumReply $reply)
|
||||
{
|
||||
$reply->update(['status' => ForumReply::STATUS_APPROVED]);
|
||||
|
||||
return back()->with('success', '已通过该回复');
|
||||
}
|
||||
|
||||
public function rejectReply(ForumReply $reply)
|
||||
{
|
||||
$reply->update(['status' => ForumReply::STATUS_REJECTED]);
|
||||
|
||||
return back()->with('success', '已驳回该回复');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user