<?php

namespace App\Models;

use App\Models\BaseModel;

/**
 * @description 挖掘线索
 * @author  system;
 * @version    1.0
 * @date 2018-11-19 08:23:08
 *
 */
class CompanyInfoModel extends BaseModel
{
    /**
     * 数据表名
     *
     * @var string
     *
     */
    protected $table = 'company_info';
    /**
     * 主键
     */
    protected $primaryKey = 'id';

    //分页
    protected $perPage = PAGE_NUMS;

    /**
     * 可以被集体附值的表的字段
     *
     * @var string
     */
    protected $fillable = [
        'company_name',
        'reg_no',
        'org_no',
        'legal_person',
        'open_status',
        'start_date',
        'open_time',
        'annual_date',
        'reg_capital',
        'ent_type',
        'industry',
        'district',
        'authority',
        'reg_addr',
        'scope',
        'website'
    ];

    /***
     * 是否已加为线索
     * @return mixed
     */
    public function isThread()
    {
        $ower_id = \Auth::guard('admin')->user()->id;
        return UserThreadsModel::where('ower_id', $ower_id)->where('company_id', $this->id)->count();
    }

    /***
     * 联系人
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function contacts()
    {
        return $this->hasMany('App\Models\CompanyContactsModel', 'company_id');
    }

    /***
     * 表更纪录
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function changeds(){
        return $this->hasMany('App\Models\CompanyChangedModel','company_id')->get();
    }

    /***
     * 主要人员
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function mainpersons(){
        return $this->hasMany('App\Models\CompanyMainpersonsModel','company_id')->get();
    }

    /***
     * 股东
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function shareholders(){
        return $this->hasMany('App\Models\CompanyShareholdersModel','company_id')->get();
    }

    public $filterFields = [
        'district' => [
            ['value' => '成都', 'name' => '成都'],
            ['value' => '上海', 'name' => '上海'],
            ['value' => '北京', 'name' => '北京'],
            ['value' => '广州', 'name' => '广州'],
        ],
        'industry' => [
            ['value' => '软件开发', 'name' => '软件开发'],
            ['value' => '信息传输', 'name' => '信息传输'],
            ['value' => '批发和零售业', 'name' => '批发和零售业'],
            ['value' => '软件和信息技术服务业', 'name' => '软件和信息技术服务业'],
        ],
        'reg_capital' => [
            ['value' => '-50', 'name' => '小于50万'],
            ['value' => '50-100', 'name' => '50～100万'],
            ['value' => '100-500', 'name' => '100～500万'],
            ['value' => '500-1000', 'name' => '500～1000'],
            ['value' => '1000-', 'name' => '1000万以上'],
        ],
        'start_date' => [
            ['value' => '2014', 'name' => '2014'],
            ['value' => '2015', 'name' => '2015'],
            ['value' => '2016', 'name' => '2016'],
            ['value' => '2017', 'name' => '2017'],
        ],
        'ent_type' => [
            ['value' => '有限责任公司', 'name' => '有限责任公司'],
        ],
        'open_status' => [
            ['value' => '开业', 'name' => '开业'],
            ['value' => '停业', 'name' => '停业'],
        ],
    ];

}