<?php
namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class Demand extends Model
{
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = 0;
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'workerid'		=> 'int',
		'title'			=> 'string',
		'video'			=> 'string',
		'cateid'		=> 'int',
		
		'province'		=> 'string',
		'city'			=> 'string',
		'district'		=> 'string',
		
		'agegroup'		=> 'string',
		'tags'			=> 'string',
		'enddate'		=> 'int',
		'requirement'	=> 'string',
		'comdetails'	=> 'string',
		'picall'		=> 'string',

		'wtype'			=> 'tinyint',
		'bwagall'		=> 'string',
		'zwagall'		=> 'string',
		
		'ftype'			=> 'tinyint',
		'fwagall'		=> 'string',
		'telephone'		=> 'string',
		'remark'		=> 'string',
		'status'		=> 'tinyint',
		'isfree'		=> 'tinyint',
		'priority'		=> 'int',
		'updatetime'	=> 'int',
        'createtime'	=> 'int',
		'volume'		=> 'int',
		'telearr'		=> 'string'
    ];

	// 设置字段自动转换类型
	protected $type = [
		'tags'			=> 'json', 
		'telearr'		=> 'json',
		'picall'		=> 'json',
		'enddate'		=> 'timestamp:Y-m-d',
		'updatetime'	=> 'timestamp:Y-m-d H:i:s',
        'createtime'	=> 'timestamp:Y-m-d H:i:s'
    ]; 
	// 设置JSON数据返回数组
	protected $jsonAssoc = true;
	
	public function getWtypeTextAttr($value,$data)
	{
		$wtype = [1=>'月薪',2=>'日薪',3=>'时薪',4=>'面议'];
		return $wtype[$data['wtype']];
	}
	
	public function getFtypeTextAttr($value,$data)
	{
		$ftype = [1=>'一次性',2=>'小时工',3=>'管理费',4=>'其他'];
		return $ftype[$data['ftype']];
	}
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'待修改',2=>'待审核',3=>'已上架',4=>'已停招',5=>'已下架'];
		return $status[$data['status']];
	}
	
	public function getIsfreeTextAttr($value,$data)
	{
		$isfree = [1=>'否',2=>'是'];
		return $isfree[$data['isfree']];
	}
	
	// 关联DemandCate
	public function demandCate()
	{
	    return $this->hasOne(DemandCate::class, "id", "cateid");
	}
	
	// 关联Worker
	public function worker()
	{
	    return $this->hasOne(Worker::class, "id", "workerid");
	}
	
	// 关联DemandLog
	public function demandLog()
	{
	    return $this->hasMany(DemandLog::class, "demandid", "id");
	}
	
	
}