GoodsAppraise.php 1.2 KB
<?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,$order,$page,$rows)
    {
    	$list = self::with(['user'])
    		->where($where)
            ->order($order)
    		->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']];
    }
}