<?php
/**
* @author 龙虾 <15108148@qq.com>
* @copyright 睿谷信息 <www.rgxx.com>
* @todo 自定义模型类
*/
namespace app\common\model;
use think\Model;
use app\common\model\Site;
use think\model\concern\SoftDelete;

class Blockattamodel extends Model
{
	use SoftDelete;
	protected $defaultSoftDelete = 0;
	protected $json = ['extend'];
    protected $jsonAssoc = true;

    public function getCreateTimeAttr($value)
    {
        return date("Y-m-d H:i:s",intval($value));
    }
    public function getUpdateTimeAttr($value)
    {
        return date("Y-m-d H:i:s",intval($value));
    }
    public function getDeleteTimeAttr($value)
    {
        return date("Y-m-d H:i:s",intval($value));
    }
	// 关联站点
	public function site()
	{
		return $this->belongsTo('Site');
	}
	// URL
    public function getUrlAttr($value,$data)
    {
        $alias = Site::cache(config("app.home.homecache"))->getFieldById($data['site_id'],'alias');
    	return url("content/detail",["lang" => $alias,"mid" => $data["cmsmodels_id"],"id" => $data["id"]]);
    }
	// 关联评论
	public function comment()
	{
		return $this->hasMany('Comment');
	}
	// 关联用户
	public function user()
	{
		return $this->belongsTo('User')->field(['password','salt'],true);
	}
	// 关联管理员
	public function admin()
	{
		return $this->belongsTo('Admin')->field(['password','salt'],true);
	}
	// 关联模型
	public function cmsmodels()
	{
		return $this->belongsTo('Cmsmodels');
	}
}