2024-02-01 14:40:49 +08:00

72 lines
1.9 KiB
PHP

<?php
namespace app\adminapi\lists\dept;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
class DeptLists extends BaseAdminDataLists implements ListsSearchInterface {
/**
* @notes 设置搜索条件
* @return \string[][]
* @author 段誉
* @date 2022/5/26 9:46
*/
public function setSearch(): array
{
return [
'%like%' => ['name','leader','mobile'],
'=' => ['status']
];
}
/**
* @notes 获取管理列表
* @return array
* @author heshihu
* @date 2022/2/21 17:11
*/
public function lists(): array
{
$params = $this->request->param();
$where = [];
if(isset($params['org_name']) && $params['org_name'] != ''){
$orgs = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id');
$where[] = ['org_id','in',$orgs];
}
return Dept::where($this->searchWhere)->where($where)
->field('id,name,org_id,leader,mobile,status,sort,create_time')
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->each(function($item){
$org = Orgs::where('id',$item['org_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['leader'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
$item['leader'] = $admin['name'];
return $item;
})
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author 段誉
* @date 2022/5/26 9:48
*/
public function count(): int
{
$params = $this->request->param();
$where = [];
if(isset($params['org_name']) && $params['org_name'] != ''){
$orgs = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id');
$where[] = ['org_id','in',$orgs];
}
return Dept::where($this->searchWhere)->where($where)->count();
}
}