data_center/app/common/model/company/Company.php

68 lines
1.7 KiB
PHP

<?php
namespace app\common\model\company;
use app\common\model\BaseModel;
use app\common\model\contract\Contract;
use app\common\model\dict\DictData;
use think\facade\Db;
use think\model\concern\SoftDelete;
class Company extends BaseModel
{
use SoftDelete;
protected $connection = 'mysql2';
protected $name = 'la_company';
protected $deleteTime = 'delete_time';
public function getCompanyTypeNameAttr($value)
{
return DictData::where('id', $value)->value('name');
}
public function getProvinceNameAttr($value)
{
return Db::name('geo_province')->where(['province_code' => $this->province])->value('province_name');
}
public function getCityNameAttr($value)
{
return Db::name('geo_city')->where(['city_code' => $this->city])->value('city_name');
}
public function getAreaNameAttr($value)
{
return Db::name('geo_area')->where(['area_code' => $this->area])->value('area_name');
}
public function getStreetNameAttr($value)
{
return Db::name('geo_street')->where(['street_code' => $this->street])->value('street_name');
}
public function getVillageNameAttr($value)
{
return Db::name('geo_village')->where(['village_code' => $this->village])->value('village_name');
}
public function getBrigadeNameAttr($value)
{
return Db::name('geo_brigade')->where(['id' => $this->brigade])->value('brigade_name');
}
public function getAreaManagerNameAttr($value)
{
return Db::name('admin')->where(['id' => $this->area_manager])->value('name');
}
public function getContractAttr()
{
$find=Contract::where('party_a|party_b', $this->id)->field('check_status,status')->find();
if($find){
return $find->toArray();
}else{
return [];
}
}
}