data_center/app/common/model/contract/Contract.php

47 lines
1.6 KiB
PHP

<?php
namespace app\common\model\contract;
use app\common\model\BaseModel;
use app\common\model\company\Company;
use app\common\model\dict\WorkerDictData;
class Contract extends BaseModel
{
protected $connection = 'mysql2';
protected $name = 'la_contract';
public function companyName(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'company_id')->bind(['company_name']);
}
public function company(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'company_id');
}
public function partyAInfo(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'party_a')->field('id,company_name,organization_code,master_name,master_phone,master_email,area_manager');
}
public function partyBInfo(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'party_b')->field('id,company_name,organization_code,master_name,master_phone,master_email,area_manager');
}
public function partyA(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'party_a')->bind(['party_a_name' => 'company_name']);
}
public function partyB(): \think\model\relation\HasOne
{
return $this->hasOne(Company::class, 'id', 'party_b')->bind(['party_b_name' => 'company_name']);
}
public function contractType(): \think\model\relation\HasOne
{
return $this->hasOne(WorkerDictData::class, 'id', 'contract_type')->bind(['contract_type_name' => 'name']);
}
public function getContractTypeNameAttr($value)
{
return WorkerDictData::where(['id' => $this->contract_type])->value('name');
}
}