<?php
namespace app\common\model;

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

class Agent extends Model
{
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = 0;
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'userid'		=> 'int',
		'workerid'		=> 'int',
		'loginname'		=> 'string',
		'password'		=> 'string',
		'idnumber'		=> 'string',
		'title'			=> 'string',
		'tilpic'		=> 'string',
		'picall'		=> 'string',
        'realname'		=> 'string',
		'mobile'		=> 'string',
		'telephone'		=> 'string',
		'latitude'		=> 'float',
		'longitude'		=> 'float',
		'province'      => 'string',
		'city'       	=> 'string',
		'district'     	=> 'string',
		'address'       => 'string',
		'details'       => 'string',
		'priority'		=> 'int',
		'remark'		=> 'string',
		'status'		=> 'tinyint',
		'createtime'    => 'int',
		'wxampcode'		=> 'string'
    ];
	
	// 设置字段自动转换类型
	protected $type = [
		'picall'		=> 'json',
		'createtime'	=> 'timestamp:Y-m-d H:i:s'
    ];
	protected $jsonAssoc = true; 
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'正常',2=>'禁用'];
		return $status[$data['status']];
	}
	
	// 关联User
	public function muser()
	{
	    return $this->hasOne(User::class, "id", "userid");
	}
	
	// 关联Worker
	public function worker()
	{
	    return $this->hasOne(Worker::class, "id", "workerid");
	}
	
	// 关联Broker
	public function broker()
	{
	    return $this->hasMany(Broker::class, "agentid", "id");
	}
	
	// 关联Partjob
	public function partjob()
	{
	    return $this->hasMany(Partjob::class, "agentid", "id");
	} 
	
}