<?php
|
|
namespace app\branch\model\activity;
|
|
use app\common\model\branch\ActivityComment as ActivityCommentModel;
|
|
/**
|
* 活动评论模型
|
*/
|
class Comment extends ActivityCommentModel
|
{
|
/**
|
* 获取列表
|
*/
|
public function getList($params, $branch_id)
|
{
|
$model = $this->with(['user', 'activity'])
|
->where('is_delete', '=', 0);
|
|
// 限制当前分会
|
$model = $model->whereHas('activity', function ($query) use ($branch_id) {
|
$query->where('branch_id', '=', $branch_id);
|
});
|
|
// 按审核状态筛选
|
if (isset($params['status']) && $params['status'] != -1) {
|
$model = $model->where('status', '=', $params['status']);
|
}
|
|
// 按评分筛选
|
if (isset($params['score']) && $params['score'] > 0) {
|
if ($params['score'] == 10) {
|
// 好评 4-5分
|
$model = $model->where('score', '>=', 4);
|
} elseif ($params['score'] == 20) {
|
// 中评 2-3分
|
$model = $model->whereBetween('score', [2, 3]);
|
} elseif ($params['score'] == 30) {
|
// 差评 1分
|
$model = $model->where('score', '=', 1);
|
}
|
}
|
|
// 按活动名称搜索
|
if (isset($params['name']) && !empty($params['name'])) {
|
$model = $model->whereHas('activity', function ($query) use ($params) {
|
$query->where('name', 'like', '%' . $params['name'] . '%');
|
});
|
}
|
|
return $model->order(['sort' => 'asc', 'create_time' => 'desc'])
|
->paginate($params);
|
}
|
|
/**
|
* 获取待审核数量
|
*/
|
public function getStatusNum($branch_id = 0)
|
{
|
$model = $this->where('status', '=', 0)
|
->where('is_delete', '=', 0);
|
|
if ($branch_id) {
|
$model = $model->whereHas('activity', function ($query) use ($branch_id) {
|
$query->where('branch_id', '=', $branch_id);
|
});
|
}
|
|
return $model->count();
|
}
|
|
/**
|
* 更新评论
|
*/
|
public function editComment($data)
|
{
|
return $this->save([
|
'status' => $data['status'] ?? $this['status'],
|
'sort' => $data['sort'] ?? $this['sort'],
|
]);
|
}
|
|
/**
|
* 软删除
|
*/
|
public function setDelete($comment_id)
|
{
|
return $this->where('comment_id', '=', $comment_id)->save(['is_delete' => 1]);
|
}
|
}
|