GoodsAppraise.php
1.3 KB
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
<?php
namespace app\common\model;
use think\Model;
class GoodsAppraise extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'user_id',
'goods_id',
'order_id'
];
public function user()
{
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
/**
* 评价图片
*/
public function getImagesAttr($value, $data)
{
$list = !empty($value) ? explode(',',$value) : [];
foreach($list as &$v){
$v = cdnurl($v,true);
}
return $list;
}
/**
* 评价列表
*/
public static function getList($where,$page,$rows)
{
$list = self::with(['user'])
->where($where)
->order(['star'=>'desc'])
->paginate($rows,false,['page'=>$page])
->each(function($v){
$v->getRelation('user')->visible(['nickname','avatar']);
$v->createtime = date('Y-m-d',$v->createtime);
})->toArray();
return ['total'=>$list['total'],'list'=>$list['data']];
}
}