审查视图

application/common/model/GoodsAppraise.php 1.1 KB
何书鹏 authored
1 2 3 4 5 6
<?php

namespace app\common\model;

use think\Model;
1  
何书鹏 authored
7
class GoodsAppraise extends Model
何书鹏 authored
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
{
	/**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'user_id',
        'goods_id',
        'order_id'
    ];

	public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

	/**
1  
何书鹏 authored
25
     * 评价图片
何书鹏 authored
26 27 28 29
     */
    public function getAppraiseImagesAttr($value, $data)
    {
    	$list = !empty($value) ? explode(',',$value) : [];
何书鹏 authored
30 31 32 33
        foreach($list as &$v){
            $v = cdnurl($v,true);
        }
        return $list;
何书鹏 authored
34 35 36 37 38
    }

    /**
     * 评价列表
     */
何书鹏 authored
39
    public static function getList($where,$page,$rows)
何书鹏 authored
40 41 42
    {
    	$list = self::with(['user'])
    		->where($where)
1  
何书鹏 authored
43
            ->order(['star'=>'desc'])
何书鹏 authored
44
    		->paginate($rows,false,['page'=>$page])
何书鹏 authored
45
    		->each(function($v){
何书鹏 authored
46
    			$v->getRelation('user')->visible(['nickname','avatar']);
何书鹏 authored
47 48 49 50 51
            	$v->createtime = date('Y-m-d',$v->createtime);
    		})->toArray();
        return ['total'=>$list['total'],'list'=>$list['data']];
    }
}