<?php
namespace app\common\model;

use think\Model;

class Notice extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'cateid'		=> 'int',
		'title'			=> 'string',
		'details'		=> 'string',
		'priority'		=> 'int',
        'createtime'	=> 'int',
        'status'		=> 'tinyint',
        'volume'		=> 'int'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
        'createtime'  => 'timestamp:Y-m-d H:i:s'
    ];
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'已发布',2=>'待修改'];
		return $status[$data['status']];
	}
	
	public function getCreatetimeTextAttr($value,$data)
	{
		return date('Y-m-d H:i', $data['createtime']);
	}
	
	// 关联NoticeCate
	public function noticeCate()
	{
	    return $this->hasOne(NoticeCate::class, "id", "cateid");
	}
	
	
}