文件
fenleixinxi/application/admin/controller/fc/Report.php
MiAn 7e22a66de0 feat: 新增举报功能及我的举报页面
本次更新主要内容:
1. 新增举报功能,支持举报信息和评价,包含防重复提交和频控保护
2. 新增我的举报页面,展示用户提交的举报记录
3. 新增平台客服弹窗,支持微信在线客服和电话客服
4. 优化消息通知,支持跳转业务页面
5. 新增举报原因字典配置,支持自定义举报原因
6. 修复服务电话默认值问题,移除硬编码兜底
7. 新增相关图标和页面组件,完善用户体验
2026-11-18 10:38:18 +08:00

454 行
24 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-举报管理
*
* @icon fa fa-flag
*/
class Report extends Backend
{
/**
* FcReport模型对象
* @var \app\admin\model\FcReport
*/
protected $model = null;
/**
* 控制器初始化方法
* 绑定数据模型与状态字典
*
* @return void
*/
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\FcReport;
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 举报详情与处置工作台
* 聚合全景信息:举报方画像(实名/历史举报数)、被举报方画像(账号状态/发帖数/被举报总数)、
* 被举报标的物全息数据(帖子交易要素/微信号/价格/完整正文/附图,或评价原文/关联原帖背景/双方回复)、
* 用户举证凭证(大图预览)以及联动处置工作台。
*
* @param int|null $ids 举报记录ID
* @return string
*/
public function detail($ids = null)
{
$id = $ids ? $ids : $this->request->param('ids');
$row = $this->model->get($id);
if (!$row) {
$this->error(__('No Results were found'));
}
$row = $row->toArray();
$row['createtime_text'] = !empty($row['createtime']) ? date('Y-m-d H:i:s', (int)$row['createtime']) : '-';
$row['updatetime_text'] = !empty($row['updatetime']) ? date('Y-m-d H:i:s', (int)$row['updatetime']) : '-';
$row['status_tag_text'] = $row['status'] === 'handled' ? '已处理完毕' : '待核实处理';
$row['status_tag_class'] = $row['status'] === 'handled' ? 'fc-tag-handled' : 'fc-tag-pending';
$row['type_tag_text'] = $row['target_type'] === 'post' ? '信息举报' : '评价举报';
$row['type_tag_class'] = $row['target_type'] === 'post' ? 'fc-tag-post' : 'fc-tag-comment';
// 1. 举报人(投诉方)画像
$reporterUser = Db::name('user')->where('id', (int)$row['reporter_id'])->find();
$reporterExt = $reporterUser ? Db::name('fc_user_ext')->where('user_id', $reporterUser['id'])->find() : null;
$reporterReportCount = Db::name('fc_report')->where('reporter_id', (int)$row['reporter_id'])->count();
$reporter = [
'id' => (int)$row['reporter_id'],
'nickname' => $reporterUser ? ($reporterUser['nickname'] ?: $reporterUser['username']) : '未注册/匿名',
'username' => $reporterUser['username'] ?? '-',
'mobile' => $reporterUser['mobile'] ?? '未绑定',
'avatar' => $reporterUser['avatar'] ?? '',
'status' => $reporterUser['status'] ?? 'normal',
'user_type' => $reporterExt ? ($reporterExt['user_type'] == 2 ? '商家' : '个人') : '个人',
'realname' => $reporterExt['realname'] ?? '',
'realname_status'=> $reporterExt ? (int)$reporterExt['realname_status'] : 0,
'realname_text' => ($reporterExt && $reporterExt['realname_status'] == 1) ? ('已实名 (' . ($reporterExt['realname'] ?: '已认证') . ')') : '未实名认证',
'realname_class' => ($reporterExt && $reporterExt['realname_status'] == 1) ? 'text-success' : 'text-muted',
'report_count' => (int)$reporterReportCount,
'createtime' => !empty($reporterUser['createtime']) ? date('Y-m-d', $reporterUser['createtime']) : '-',
];
// 2. 被举报标的与被举报人画像
$targetInfo = [];
$targetImages = [];
$targetAuthor = [];
$relatedPost = []; // 评价举报时关联的原帖全貌
// 本标的累计被举报次数
$targetTotalReports = Db::name('fc_report')
->where('target_type', $row['target_type'])
->where('target_id', $row['target_id'])
->count();
if ($row['target_type'] === 'post') {
$post = Db::name('fc_post')->where('id', (int)$row['target_id'])->find();
if ($post) {
$categoryName = (string)Db::name('fc_category')->where('id', $post['category_id'])->value('name');
$authorUser = Db::name('user')->where('id', $post['user_id'])->find();
$authorExt = $authorUser ? Db::name('fc_user_ext')->where('user_id', $authorUser['id'])->find() : null;
// 作者名下发帖总数与被举报总数
$authorPostCount = Db::name('fc_post')->where('user_id', $post['user_id'])->count();
$authorReportedCount = Db::name('fc_report')->where('target_type', 'post')->where('target_id', 'in', function ($q) use ($post) {
$q->name('fc_post')->where('user_id', $post['user_id'])->field('id');
})->count();
$authorStatus = $authorUser ? ($authorUser['status'] ?? 'normal') : 'normal';
$targetAuthor = [
'id' => $post['user_id'],
'nickname' => $authorUser ? ($authorUser['nickname'] ?: $authorUser['username']) : ('用户' . $post['user_id']),
'mobile' => $authorUser['mobile'] ?? '-',
'status' => $authorStatus,
'status_text' => $authorStatus === 'normal' ? '账号正常' : '账号已受限',
'status_class' => $authorStatus === 'normal' ? 'label-success' : 'label-danger',
'user_type' => $authorExt ? ($authorExt['user_type'] == 2 ? '商家' : '个人') : ($post['identity_type'] == 2 ? '商家' : '个人'),
'realname' => $authorExt['realname'] ?? '',
'realname_status'=> $authorExt ? (int)$authorExt['realname_status'] : 0,
'realname_text' => ($authorExt && $authorExt['realname_status'] == 1) ? ('已实名 (' . ($authorExt['realname'] ?: '已认证') . ')') : '未实名',
'realname_class' => ($authorExt && $authorExt['realname_status'] == 1) ? 'text-success' : 'text-muted',
'is_member' => $authorExt ? (int)$authorExt['is_member'] : 0,
'member_level' => $authorExt['member_level'] ?? '',
'post_count' => (int)$authorPostCount,
'reported_count' => (int)$authorReportedCount,
'reported_class' => $authorReportedCount > 0 ? 'text-danger' : 'text-muted',
];
// 解析帖子图片
if (!empty($post['cover'])) {
$targetImages[] = $post['cover'];
}
if (!empty($post['media'])) {
$mediaList = json_decode($post['media'], true);
if (is_array($mediaList)) {
foreach ($mediaList as $m) {
if (is_string($m) && $m !== '' && !in_array($m, $targetImages, true)) {
$targetImages[] = $m;
}
}
}
}
$targetInfo = [
'id' => $post['id'],
'title' => $post['title'],
'category' => $categoryName ?: '默认分类',
'category_id' => $post['category_id'],
'identity_type' => (int)$post['identity_type'] === 2 ? '商家发布' : '个人发布',
'price' => (float)$post['price'] > 0 ? (string)$post['price'] : '面议',
'price_unit' => $post['price_unit'] ?: '',
'area' => $post['area'] ?: '-',
'address' => $post['address'] ?: '未提供详细地址',
'contact' => $post['contact'] ?: '-',
'phone' => $post['phone'] ?: '-',
'wechat' => $post['wechat'] ?: '-',
'tags' => $post['tags'] ? explode(',', $post['tags']) : [],
'views' => (int)$post['views'],
'likes' => (int)$post['likes'],
'comment_count' => (int)$post['comment_count'],
'is_top' => (int)$post['is_top'] === 1 ? '置顶中' : '未置顶',
'is_paid' => (int)$post['is_paid'] === 1 ? '付费发布' : '免费发布',
'amount' => (float)$post['amount'],
'content' => $post['content'],
'status' => (int)$post['status'] === 1 ? '正常' : '已下架',
'status_val' => (int)$post['status'],
'status_class' => (int)$post['status'] === 1 ? 'label-success' : 'label-danger',
'status_text' => (int)$post['status'] === 1 ? '正常' : '已下架',
'audit_status' => (int)$post['audit_status'] === 1 ? '审核通过' : ((int)$post['audit_status'] === 2 ? '已驳回' : '待审核'),
'createtime' => $post['createtime'] ? date('Y-m-d H:i:s', $post['createtime']) : '-',
'updatetime' => $post['updatetime'] ? date('Y-m-d H:i:s', $post['updatetime']) : '-',
'is_deleted' => false,
];
} else {
$targetInfo = [
'id' => (int)$row['target_id'],
'title' => '(该信息已被物理删除或不存在)',
'category' => '-',
'category_id' => 0,
'identity_type' => '-',
'price' => '-',
'price_unit' => '',
'area' => '-',
'address' => '-',
'contact' => '-',
'phone' => '-',
'wechat' => '-',
'tags' => [],
'views' => 0,
'likes' => 0,
'comment_count' => 0,
'is_top' => '未置顶',
'is_paid' => '免费发布',
'amount' => 0,
'content' => '该帖子已被彻底删除或不存在,无法查看原文细节。',
'status' => '已彻底删除',
'status_val' => 0,
'status_class' => 'label-default',
'status_text' => '已彻底删除',
'audit_status' => '-',
'createtime' => '-',
'updatetime' => '-',
'is_deleted' => true,
];
$targetAuthor = [
'id' => 0,
'nickname' => '未知/账号已注销',
'mobile' => '-',
'status' => 'normal',
'status_text' => '账号未知',
'status_class' => 'label-default',
'user_type' => '个人',
'realname' => '',
'realname_status'=> 0,
'realname_text' => '未实名',
'realname_class' => 'text-muted',
'is_member' => 0,
'member_level' => '',
'post_count' => 0,
'reported_count' => 0,
'reported_class' => 'text-muted',
];
}
} elseif ($row['target_type'] === 'comment') {
$comment = Db::name('fc_comment')->where('id', (int)$row['target_id'])->find();
if ($comment) {
// 评价作者画像(被举报人)
$commentAuthorUser = Db::name('user')->where('id', $comment['user_id'])->find();
$commentAuthorExt = $commentAuthorUser ? Db::name('fc_user_ext')->where('user_id', $commentAuthorUser['id'])->find() : null;
$commentAuthorReportedCount = Db::name('fc_report')->where('target_type', 'comment')->where('target_id', 'in', function ($q) use ($comment) {
$q->name('fc_comment')->where('user_id', $comment['user_id'])->field('id');
})->count();
$cAuthorStatus = $commentAuthorUser ? ($commentAuthorUser['status'] ?? 'normal') : 'normal';
$targetAuthor = [
'id' => $comment['user_id'],
'nickname' => $commentAuthorUser ? ($commentAuthorUser['nickname'] ?: $commentAuthorUser['username']) : ('用户' . $comment['user_id']),
'mobile' => $commentAuthorUser['mobile'] ?? '-',
'status' => $cAuthorStatus,
'status_text' => $cAuthorStatus === 'normal' ? '账号正常' : '账号已受限',
'status_class' => $cAuthorStatus === 'normal' ? 'label-success' : 'label-danger',
'user_type' => $commentAuthorExt ? ($commentAuthorExt['user_type'] == 2 ? '商家' : '个人') : '个人',
'realname' => $commentAuthorExt['realname'] ?? '',
'realname_status'=> $commentAuthorExt ? (int)$commentAuthorExt['realname_status'] : 0,
'realname_text' => ($commentAuthorExt && $commentAuthorExt['realname_status'] == 1) ? ('已实名 (' . ($commentAuthorExt['realname'] ?: '已认证') . ')') : '未实名',
'realname_class' => ($commentAuthorExt && $commentAuthorExt['realname_status'] == 1) ? 'text-success' : 'text-muted',
'is_member' => $commentAuthorExt ? (int)$commentAuthorExt['is_member'] : 0,
'member_level' => $commentAuthorExt['member_level'] ?? '',
'post_count' => (int)Db::name('fc_comment')->where('user_id', $comment['user_id'])->count(),
'reported_count' => (int)$commentAuthorReportedCount,
'reported_class' => $commentAuthorReportedCount > 0 ? 'text-danger' : 'text-muted',
];
// 评价关联的原帖背景信息
$relPost = Db::name('fc_post')->where('id', $comment['post_id'])->find();
if ($relPost) {
$relAuthorUser = Db::name('user')->where('id', $relPost['user_id'])->find();
$relCategoryName = (string)Db::name('fc_category')->where('id', $relPost['category_id'])->value('name');
$relatedPost = [
'id' => $relPost['id'],
'title' => $relPost['title'],
'category' => $relCategoryName ?: '分类',
'author' => $relAuthorUser ? ($relAuthorUser['nickname'] ?: $relAuthorUser['username']) : ('用户' . $relPost['user_id']),
'author_id' => $relPost['user_id'],
'author_mobile' => $relAuthorUser['mobile'] ?? '-',
'price' => (float)$relPost['price'] > 0 ? (string)$relPost['price'] : '面议',
'price_unit' => $relPost['price_unit'] ?: '',
'cover' => $relPost['cover'] ?: '',
'content' => mb_substr(strip_tags($relPost['content']), 0, 80) . '...',
'status' => (int)$relPost['status'] === 1 ? '正常' : '已下架',
];
}
// 评价图片
if (!empty($comment['images'])) {
$cImages = json_decode($comment['images'], true);
if (is_array($cImages)) {
$targetImages = $cImages;
} elseif (is_string($comment['images'])) {
$targetImages = array_filter(explode(',', $comment['images']));
}
}
$cScore = (int)$comment['score'];
$targetInfo = [
'id' => $comment['id'],
'post_id' => $comment['post_id'],
'score' => $cScore,
'score_stars' => str_repeat('★', max(1, min(5, $cScore))),
'content' => $comment['content'],
'reply' => $comment['reply'],
'replytime' => $comment['replytime'] ? date('Y-m-d H:i:s', $comment['replytime']) : '',
'status' => (int)$comment['status'] === 1 ? '正常' : '已屏蔽',
'status_val' => (int)$comment['status'],
'status_class' => (int)$comment['status'] === 1 ? 'label-success' : 'label-danger',
'status_text' => (int)$comment['status'] === 1 ? '正常' : '已屏蔽',
'createtime' => $comment['createtime'] ? date('Y-m-d H:i:s', $comment['createtime']) : '-',
'is_deleted' => false,
];
} else {
$targetInfo = [
'id' => (int)$row['target_id'],
'post_id' => 0,
'score' => 5,
'score_stars' => '★★★★★',
'content' => '该评价已被彻底删除或不存在。',
'reply' => '',
'replytime' => '',
'status' => '已彻底删除',
'status_val' => 0,
'status_class' => 'label-default',
'status_text' => '已彻底删除',
'createtime' => '-',
'is_deleted' => true,
];
$targetAuthor = [
'id' => 0,
'nickname' => '未知/账号已注销',
'mobile' => '-',
'status' => 'normal',
'status_text' => '账号未知',
'status_class' => 'label-default',
'user_type' => '个人',
'realname' => '',
'realname_status'=> 0,
'realname_text' => '未实名',
'realname_class' => 'text-muted',
'is_member' => 0,
'member_level' => '',
'post_count' => 0,
'reported_count' => 0,
'reported_class' => 'text-muted',
];
}
}
// 3. 举报人上传的举证凭证
$images = [];
if (!empty($row['images'])) {
$images = array_filter(explode(',', (string)$row['images']));
}
$this->view->assign('row', $row);
$this->view->assign('reporter', $reporter);
$this->view->assign('targetAuthor', $targetAuthor);
$this->view->assign('targetInfo', $targetInfo);
$this->view->assign('targetImages', $targetImages);
$this->view->assign('relatedPost', $relatedPost);
$this->view->assign('targetTotalReports', $targetTotalReports);
$this->view->assign('images', $images);
return $this->view->fetch();
}
/**
* 处理举报操作
* 支持单个或批量处理,更新 handle_remark 字段(保留用户的原始 remark 补充说明),
* 支持对违规帖子下架或违规评论屏蔽的一键联动处置,
* 并在处理完成后自动向举报人下发系统站内通知消息(附带小程序跳转参数)。
*
* POST 入参:
* - ids: 举报记录 ID 或 ID 数组
* - remark: 管理员处理备注
* - action: 联动处置动作,可选 'none'(默认仅标记)、'offline'(下架被举报信息/屏蔽被举报评论)
*
* @return void
*/
public function handle()
{
$ids = $this->request->post('ids');
$remark = trim((string)$this->request->post('remark', ''));
$action = trim((string)$this->request->post('action', 'none'));
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
$ids = array_filter(array_map('intval', $ids));
if (!$ids) {
$this->error('请选择要处理的举报');
}
$now = time();
$reports = Db::name('fc_report')->where('id', 'in', $ids)->select();
Db::startTrans();
try {
foreach ($reports as $report) {
$targetTitle = '';
$actionDesc = '平台已核实并记录处理';
// 如果勾选联动下架处置
if ($action === 'offline') {
if ($report['target_type'] === 'post') {
$post = Db::name('fc_post')->where('id', $report['target_id'])->find();
$targetTitle = $post ? (string)$post['title'] : '信息';
$actionDesc = '已下架违规信息';
// 下架对应信息(status 置为 0,并记录 audit_reason)
Db::name('fc_post')->where('id', $report['target_id'])->update([
'status' => 0,
'audit_reason' => '因用户举报违规被管理员下架:' . ($remark ?: $report['reason']),
'updatetime' => $now,
]);
} elseif ($report['target_type'] === 'comment') {
$cmt = Db::name('fc_comment')->where('id', $report['target_id'])->find();
$targetTitle = $cmt ? (mb_substr($cmt['content'], 0, 20) . '...') : '评价';
$actionDesc = '已屏蔽违规评价';
// 屏蔽对应评价(status 置为 0)
Db::name('fc_comment')->where('id', $report['target_id'])->update([
'status' => 0,
'updatetime' => $now,
]);
}
} else {
if ($report['target_type'] === 'post') {
$postTitle = Db::name('fc_post')->where('id', $report['target_id'])->value('title');
$targetTitle = $postTitle ? (string)$postTitle : '信息';
} else {
$cmtContent = Db::name('fc_comment')->where('id', $report['target_id'])->value('content');
$targetTitle = $cmtContent ? (mb_substr($cmtContent, 0, 20) . '...') : '评价';
}
}
// 更新举报记录为已处理,写入管理员处理备注
Db::name('fc_report')->where('id', $report['id'])->update([
'status' => 'handled',
'handle_remark' => $remark,
'updatetime' => $now,
]);
// 若举报人为平台注册用户,自动下发系统站内通知消息
$reporterId = (int)$report['reporter_id'];
if ($reporterId > 0) {
$typeCn = $report['target_type'] === 'post' ? '信息' : '评价';
$remarkNote = $remark !== '' ? ";管理员回复:{$remark}" : '';
$msgContent = "您于 " . date('Y-m-d H:i', $report['createtime']) . " 举报的{$typeCn}《{$targetTitle}》(原因:{$report['reason']}),平台已核实完毕。处理结果:{$actionDesc}{$remarkNote}。点击查看我的举报记录详情。感谢您的监督与支持!";
Db::name('fc_message')->insert([
'user_id' => $reporterId,
'type' => 'system',
'title' => '举报处理结果通知',
'content' => $msgContent,
'extra' => json_encode(['path' => '/pages/mine/reports', 'id' => (int)$report['id']], JSON_UNESCAPED_UNICODE),
'isread' => 0,
'createtime' => $now,
'updatetime' => $now,
]);
}
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('处理失败:' . $e->getMessage());
}
$this->success('处理成功并已下发用户通知');
}
}