quanwei
18 hours ago b90b528cb5c6eaebe03fba972fef658a741ce896
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
 
namespace app\shop\model\branch;
 
use app\common\model\branch\ActivityComment as ActivityCommentModel;
 
/**
 * 活动评论模型
 */
class ActivityComment extends ActivityCommentModel
{
    /**
     * 获取列表
     */
    public function getList($params)
    {
        $model = $this->with(['user', 'activity', 'activity.branch'])
            ->where('is_delete', '=', 0);
 
        // 按审核状态筛选
        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()
    {
        return $this->where('status', '=', 0)
            ->where('is_delete', '=', 0)
            ->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]);
    }
}