74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
declare(strict_types=1);
|
|
|
|
namespace addon\forum\controller\backend;
|
|
|
|
use addon\forum\model\ForumReply;
|
|
use ywxapp\controller\BackendBase;
|
|
|
|
class Reply extends BackendBase
|
|
{
|
|
protected $noNeedLogin = [];
|
|
protected $noNeedVerify = ['*'];
|
|
|
|
public function index()
|
|
{
|
|
// layui.table 动态加载
|
|
if ($this->request->isAjax()) {
|
|
$page = $this->request->param('page/d', 1);
|
|
$limit = $this->request->param('limit/d', 20);
|
|
|
|
$map = [];
|
|
// 主题 ID 过滤
|
|
if ($topicId = $this->request->param('topic_id/d')) {
|
|
$map[] = ['r.topic_id', '=', $topicId];
|
|
}
|
|
// 关键词搜索(内容模糊匹配)
|
|
if ($keyword = $this->request->param('keyword/s')) {
|
|
$map[] = ['r.content', 'like', '%' . $keyword . '%'];
|
|
}
|
|
|
|
$rows = ForumReply::alias('r')
|
|
->join('forum_topic t', 't.id = r.topic_id', 'left')
|
|
->join('user u', 'u.uid = r.user_id', 'left')
|
|
->where($map)
|
|
->field([
|
|
'r.*',
|
|
't.title as topic_title',
|
|
'u.nickname as user_name',
|
|
])
|
|
->order('r.create_at', 'desc')
|
|
->paginate([
|
|
'list_rows' => $limit,
|
|
'page' => $page,
|
|
]);
|
|
|
|
$list = $rows->items();
|
|
$total = $rows->total();
|
|
foreach ($list as &$item) {
|
|
$item['content_preview'] = mb_substr(strip_tags($item['content'] ?? ''), 0, 40);
|
|
}
|
|
unset($item);
|
|
|
|
return $this->result->setCount($total)->success($list);
|
|
}
|
|
|
|
$this->assign('title', '回复管理');
|
|
return $this->fetch('reply/index');
|
|
}
|
|
|
|
public function delete($id = 0)
|
|
{
|
|
$id = $id ?: $this->request->param('id/d');
|
|
$row = ForumReply::find($id);
|
|
if ($row) {
|
|
$row->status = -1;
|
|
$row->save();
|
|
}
|
|
return $this->success([], '删除成功');
|
|
}
|
|
}
|