data_center/app/adminapi/lists/contract/ContractLists.php

96 lines
2.8 KiB
PHP

<?php
namespace app\adminapi\lists\contract;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\contract\Contract;
use app\common\lists\ListsSearchInterface;
use app\common\model\company\Company;
use app\common\model\WorkerAdmin\WorkerAdmin;
use think\facade\Db;
/**
* Contract列表
* Class ContractLists
* @package app\adminapi\listscontract
*/
class ContractLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function setSearch(): array
{
return [
'=' => ['contract_type', 'contract_no', 'status'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function lists(): array
{
$params=$this->request->param();
$where=[];
if(isset($params['company_id']) && $params['company_id']!=''){
$arr= Company::where('company_name','like','%'.$params['company_id'].'%')->column('id');
if($arr){
$where[]=['party_a|party_b','in',$arr];
}
}
if(isset($params['area_manager']) && $params['area_manager']!=''){
$arr= WorkerAdmin::where('name','like','%'.$params['area_manager'].'%')->column('id');
if($arr){
$where[]=['area_manager','in',$arr];
}
}
return Contract::where($this->searchWhere)->where($where)->with(['companyName','party_a_info','contractType'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item, $key) {
if($item->type==1){
$item->party_b_name=Db::connect('mysql2')->name('la_company')->where('id',$item->party_b)->value('company_name');
}else{
$item->party_b_name=Db::connect('mysql2')->name('la_user')->where('id',$item->party_b)->value('nickname');
}
if(!empty($item->party_a_info)){
$area_manager_name=Db::connect('mysql2')->name('la_admin')->where('id',$item->party_a_info->area_manager)->value('name');
if($area_manager_name){
$item->area_manager_name=$area_manager_name;
}else{
$item->area_manager_name='暂无片区经理';
}
}else{
$item->area_manager_name='暂无片区经理';
}
$item->contract_type_name=Db::connect('mysql2')->name('la_dict_data')->where('id',$item->contract_type)->value('name');
$item->status_name=$item->status==1?'已签约':'未签约';
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/07/18 14:28
*/
public function count(): int
{
return Contract::where($this->searchWhere)->count();
}
}