<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\customer;

use app\model\BaseModel;
use think\model\concern\SoftDelete;
use think\facade\Cache;

class Company extends BaseModel{
	
	use SoftDelete;
	protected $deleteTime = 'delete_time';
	protected $defaultSoftDelete = 0;

	
	public $insertFieldAlis = [
		'企业编号'  => ['name'  => 'org_code', 'table' => 'company'],
		'公司名称'  => ['name'  => 'name', 'table' => 'company'],
		'网址'      => ['name'  => 'web_site', 'table' => 'company'],
		'一级行业'  => ['name'  => 'industry', 'table' => 'company'],
		'二级行业'  => ['name'  => 'industry_sub', 'table' => 'company'],
		'三级行业'  => ['name'  => 'industry_three', 'table' => 'company'],
		'省份'      => ['name'  => 'province', 'table' => 'company'],
		'城市'      => ['name'  => 'city', 'table' => 'company'],
		'区县'      => ['name'  => 'area', 'table' => 'company'],
		'年营业额'  => ['name'  => 'turnover_text', 'table' => 'company',],
		'员工人数'  => ['name'  => 'staff_num_text', 'table' => 'company'],
		'注册资金'  => ['name'  => 'reg_capital', 'table' => 'company'],
		'资金类型'  => ['name'  => 'reg_capital_type', 'table' => 'company'],
		'PC数量'    => ['name'  => 'pc_num_text', 'table' => 'company'],
		'营收规模'  => ['name'  => 'turnover', 'table' => 'company'],
		'社保人数'  => ['name'  => 'social_insurance', 'table' => 'company'],
		'企业性质'  => ['name'  => 'company_type', 'table' => 'company'],
		'是否上市'  => ['name'  => 'is_ipo_text', 'table' => 'company'],
		'融资信息'  => ['name'  => 'finance_info', 'table' => 'company'],
		'企业标签'  => ['name'  => 'tags', 'table' => 'company'],
		'企业状态'  => ['name'  => 'status', 'table' => 'company'],
		'成立时间'  => ['name'  => 'reg_date', 'table' => 'company'],
		'注册地址'  => ['name'  => 'reg_address', 'table' => 'company'],
		'联系人'   => ['name'  => 'name', 'table' => 'contact'],
		'岗位'      => ['name'  => 'job','table' => 'contact'],
		'固定电话'  => ['name'  => 'phone', 'table' => 'contact'],
		'手机号码'     => ['name'  => 'mobile', 'table' => 'contact'],
		'邮箱'      => ['name'  => 'email', 'table' => 'contact'],
		'是否法人'      => ['name'  => 'is_faren', 'table' => 'contact']
	];

	public function getAreaTAttr($value, $data){
		$text = [$data['province'], $data['city'], $data['area']];
		return implode(",", array_filter($text));
	}

	public function getIndustryTAttr($value, $data){
		$text = [$data['industry'], $data['industry_sub'], $data['industry_three']];
		return implode(",", array_filter($text));
	}

	public function contact(){
		return $this->hasMany(Contact::class);
	}
}