<?php
namespace app\common\model;

use think\Model;

class ArticleComment extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'userid'		=> 'int',
		'articleid'		=> 'int',
		'puserid'		=> 'int',
		'details'		=> 'string',
        'createtime'	=> 'int',
        'status'		=> 'tinyint'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
        'createtime'  => 'timestamp:Y-m-d H:i:s'
    ];
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'已通过',2=>'待审核'];
		return $status[$data['status']];
	}
	
	// 关联Article
	public function article()
	{
	    return $this->hasOne(Article::class, "id", "articleid");
	}
	
	// 关联User
	public function user()
	{
	    return $this->hasOne(User::class, "id", "userid")->field('id,nickname,avatar');
	}
	
	// 关联User
	public function puser()
	{
	    return $this->hasOne(User::class, "id", "puserid")->field('id,nickname,avatar');
	}

}