<?php
namespace app\common\model;

use think\Model;

class Article extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'cateid'		=> 'int',
		'title'			=> 'string',
		'tilpic'		=> 'string',
		'author'		=> 'string',
		'summary'		=> 'string',
		'atype'			=> 'tinyint',
		'details'		=> 'string',
		'tilurl'		=> 'string',
		'priority'		=> 'int',
        'createtime'	=> 'int',
        'status'		=> 'tinyint',
        'volume'		=> 'int'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
        'createtime'  => 'timestamp:Y-m-d H:i:s'
    ];
	
	public function getAtypeTextAttr($value,$data)
	{
		$atype = [1=>'文章详情',2=>'系统链接',3=>'网络链接'];
		return $atype[$data['atype']];
	}
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'已发布',2=>'待修改'];
		return $status[$data['status']];
	}
	
	public function getCreatetimeTextAttr($value,$data)
	{
		return date('Y-m-d', $data['createtime']);
	}
	
	// 关联ArticleCate
	public function articleCate()
	{
	    return $this->hasOne(ArticleCate::class, "id", "cateid");
	}
	
	// 关联ArticleComment
	public function articleComment()
	{
	    return $this->hasMany(ArticleComment::class, "articleid", "id");
	}
	
	// 关联ArticleThumb
	public function articleThumb()
	{
	    return $this->hasMany(ArticleThumb::class, "articleid", "id");
	}
	
	// 关联ArticleCollect
	public function articleCollect()
	{
	    return $this->hasMany(ArticleCollect::class, "articleid", "id");
	}
	
	
}