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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
 
namespace app\common\model\product;
 
use app\common\model\BaseModel;
 
/**
 * 评论模型
 */
class Comment extends BaseModel
{
    protected $name = 'comment';
    protected $px = 'comment_id';
 
    /**
     * 所属订单
     */
    public function orderM()
    {
        return $this->belongsTo('app\\common\\model\\order\\Order');
    }
 
    /**
     * 订单商品
     */
    public function OrderProduct()
    {
        return $this->belongsTo('app\\common\\model\\order\\OrderProduct');
    }
 
    /**
     * 商品
     */
    public function product()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
    }
 
    /**
     * 关联用户表
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
    }
 
    /**
     * 关联评价图片表
     */
    public function image()
    {
        return $this->hasMany('app\\common\\model\\product\\CommentImage', 'comment_id', 'comment_id')->order(['id' => 'asc']);
    }
 
    /**
     * 评价详情
     */
    public static function detail($comment_id)
    {
        return (new static())->where('comment_id', '=', $comment_id)->with(['user','image.file', 'orderM', 'product.image.file'])->find();
    }
 
    /**
     * 获取评价列表
     * @param $params
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getList($params)
    {
        $model = $this;
        if (isset($params['name']) && !empty(trim($params['name']))) {
            $product_model = new Product();
            $res = $product_model->getWhereData($params['name'])->toArray();
            $str = implode(',', array_column($res, 'product_id'));
            $model = $model->where('product_id', 'in', $str);
        }
        if (isset($params['score']) && $params['score'] > 0) {
            $model = $model->where('score', '=', $params['score']);
        }
        if (isset($params['status']) && $params['status'] > -1) {
            $model = $model->where('status', '=', $params['status']);
        }
        if (isset($params['shop_supplier_id']) && $params['shop_supplier_id'] > 0) {
            $model = $model->where('shop_supplier_id', '=', $params['shop_supplier_id']);
        }
        if (isset($params['shop_supplier_ids']) && $params['shop_supplier_ids'] > 0) {
            $model = $model->where('shop_supplier_id', 'in', $params['shop_supplier_ids']);
        }
        return $model->with(['user', 'orderM', 'product.image.file','image.file'])
            ->where('is_delete', '=', 0)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->paginate($params);
    }
 
    /**
     * 获取评论数
     */
    public function getStatusNum($where)
    {
        return $this->where($where)->count();
    }
 
}