GoodsComment.php 862 字节
<?php


namespace app\api\model;


use think\Model;

class GoodsComment extends Model
{
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = '';
    protected $append = [
        'images_text',
        'createtime_text'
    ];

    public function getImagesTextAttr($value,$data)
    {
        $value = !empty($data['images'])?explode(',',$data['images']):[];
        foreach ($value as $key => &$val){
            $val = cdnurl($val,true);
        }
        return $value;
    }

    public function getCreatetimeTextAttr($value,$data)
    {
        $value = !empty($data['createtime'])?date('Y-m-d',$data['createtime']):'';
        return $value;
    }

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