审查视图

application/api/model/GoodsComment.php 862 字节
李忠强 authored
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
<?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()
    {
何书鹏 authored
37
        return $this->belongsTo('User', 'user_id')->setEagerlyType(0);
李忠强 authored
38 39
    }
}