151 行
4.9 KiB
PHP
151 行
4.9 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\fc;
|
|
|
|
use app\common\controller\Backend;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 同城-评价
|
|
*
|
|
* @icon fa fa-circle-o
|
|
*/
|
|
class Comment extends Backend
|
|
{
|
|
|
|
/**
|
|
* FcComment模型对象
|
|
* @var \app\admin\model\FcComment
|
|
*/
|
|
protected $model = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\FcComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
*/
|
|
|
|
/**
|
|
* 回复评价
|
|
*/
|
|
public function reply()
|
|
{
|
|
$ids = $this->request->post('ids');
|
|
$reply = $this->request->post('reply');
|
|
if (trim((string)$reply) === '') {
|
|
$this->error('回复内容不能为空');
|
|
}
|
|
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
|
|
$ids = array_filter($ids);
|
|
if (!$ids) {
|
|
$this->error('请选择要回复的评价');
|
|
}
|
|
$comments = Db::name('fc_comment')->where('id', 'in', $ids)->select();
|
|
if (!$comments) {
|
|
$this->error('评价不存在');
|
|
}
|
|
foreach ($comments as $comment) {
|
|
Db::name('fc_comment')->where('id', $comment['id'])->update([
|
|
'reply' => $reply,
|
|
'replytime' => time(),
|
|
'updatetime' => time(),
|
|
]);
|
|
Db::name('fc_message')->insert([
|
|
'user_id' => $comment['user_id'],
|
|
'type' => 'interact',
|
|
'title' => '评价回复',
|
|
'content' => '您的评价已收到回复:' . $reply,
|
|
'isread' => 0,
|
|
'createtime' => time(),
|
|
]);
|
|
}
|
|
$this->success('回复成功');
|
|
}
|
|
|
|
/**
|
|
* 评价置顶/取消置顶
|
|
*/
|
|
public function top()
|
|
{
|
|
$ids = $this->request->post('ids');
|
|
$top = (int)$this->request->post('top');
|
|
if (!in_array($top, [0, 1])) {
|
|
$this->error('置顶状态错误');
|
|
}
|
|
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
|
|
$ids = array_filter($ids);
|
|
if (!$ids) {
|
|
$this->error('请选择要操作的评价');
|
|
}
|
|
Db::name('fc_comment')->where('id', 'in', $ids)->update([
|
|
'top' => $top,
|
|
'updatetime' => time(),
|
|
]);
|
|
$this->success($top === 1 ? '置顶成功' : '取消置顶成功');
|
|
}
|
|
|
|
/**
|
|
* 切换评价显示/隐藏状态(支持单条与批量)
|
|
*
|
|
* @return void
|
|
*/
|
|
public function status()
|
|
{
|
|
$ids = $this->request->post('ids');
|
|
$status = (int)$this->request->post('status', -1);
|
|
$reason = trim((string)$this->request->post('reason', ''));
|
|
if (!in_array($status, [0, 1], true)) {
|
|
$this->error('状态参数错误');
|
|
}
|
|
|
|
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
|
|
$ids = array_filter(array_map('intval', $ids));
|
|
if (!$ids) {
|
|
$this->error('请选择要操作的评价');
|
|
}
|
|
|
|
$now = time();
|
|
$comments = $status === 0
|
|
? Db::name('fc_comment')->where('id', 'in', $ids)->field('id,user_id,post_id,content,status')->select()
|
|
: [];
|
|
|
|
Db::name('fc_comment')->where('id', 'in', $ids)->update([
|
|
'status' => $status,
|
|
'updatetime' => $now,
|
|
]);
|
|
|
|
// 隐藏评价时,向对应评价发布者发送系统站内信通知
|
|
if ($status === 0 && $comments) {
|
|
foreach ($comments as $cmt) {
|
|
if ((int)$cmt['status'] === 0 || (int)$cmt['user_id'] <= 0) {
|
|
continue;
|
|
}
|
|
$snippet = mb_substr((string)$cmt['content'], 0, 20) . (mb_strlen((string)$cmt['content']) > 20 ? '...' : '');
|
|
$reasonText = $reason !== '' ? ",原因:{$reason}" : '';
|
|
Db::name('fc_message')->insert([
|
|
'user_id' => (int)$cmt['user_id'],
|
|
'type' => 'system',
|
|
'title' => '评价隐藏通知',
|
|
'content' => "您发布的评价「{$snippet}」已被管理员隐藏{$reasonText}。您仍可在原信息详情页查看或删除该评价。",
|
|
'extra' => json_encode(['path' => '/pages/detail/detail', 'id' => (int)$cmt['post_id']], JSON_UNESCAPED_UNICODE),
|
|
'isread' => 0,
|
|
'createtime' => $now,
|
|
'updatetime' => $now,
|
|
]);
|
|
}
|
|
}
|
|
|
|
$this->success($status === 1 ? '已恢复显示' : '已隐藏评价');
|
|
}
|
|
|
|
}
|