<?php
namespace app\common\model;

use think\Model;

class DemandReport extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'				=> 'int',
		'demandid'			=> 'int',
		'snatchid'			=> 'int',
		'workerid'			=> 'int',
		'agentid'			=> 'int',
		'brokerid'			=> 'int',
		'realname'			=> 'string',
		'mobile'			=> 'string',
		'idcard'			=> 'string',
		'arrivetime'		=> 'string',
		'remark'			=> 'string',
        'createtime'		=> 'int'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
        'createtime'  => 'timestamp:Y-m-d H:i'
    ];
	
	public function getAgeTextAttr($value,$data)
	{
		$year = substr($data['idcard'], 6, 4);
		$monthDay = substr($data['idcard'], 10, 4);
		$age = date('Y') - $year;
		if ($monthDay > date('md')) {
			$age--;
		}
		return $age;
	}

    public function demand()
    {
        return $this->hasOne(Demand::class, "id", "demandid");
    }

	public function snatch()
	{
	    return $this->hasOne(DemandSnatch::class, "id", "snatchid");
	}

    public function worker()
    {
        return $this->hasOne(Worker::class, "id", "workerid");
    }

	public function agent()
	{
	    return $this->hasOne(Agent::class, "id", "agentid");
	}

	public function broker()
	{
	    return $this->hasOne(Broker::class, "id", "brokerid");
	}

	
}