'账号', 'name' => '名称', 'role_name' => '角色', 'dept_name' => '部门', 'create_time' => '创建时间', 'login_time' => '最近登录时间', 'login_ip' => '最近登录IP', 'disable_desc' => '状态', ]; } /** * @notes 设置导出文件名 * @return string * @author 段誉 * @date 2021/12/29 10:08 */ public function setFileName(): string { return '管理员列表'; } /** * @notes 设置搜索条件 * @return \string[][] * @author 段誉 * @date 2021/12/29 10:07 */ public function setSearch(): array { return [ '%like%' => ['name', 'account'], '=' => ['org_id','dept_id','job_id'] ]; } /** * @notes 设置支持排序字段 * @return string[] * @author 段誉 * @date 2021/12/29 10:07 * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; */ public function setSortFields(): array { return ['create_time' => 'create_time', 'id' => 'id']; } /** * @notes 设置默认排序 * @return string[] * @author 段誉 * @date 2021/12/29 10:06 */ public function setDefaultOrder(): array { return ['id' => 'desc']; } /** * @notes 获取管理列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2021/12/29 10:05 */ public function lists(): array { $field = [ 'id', 'name', 'account', 'create_time', 'disable', 'root', 'org_id', 'dept_id', 'job_id', 'login_time', 'login_ip', 'multipoint_login', 'avatar' ]; $adminLists = Admin::field($field) ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order($this->sortOrder) ->append(['role_id','disable_desc']) ->select()->each(function($item){ $job = Jobs::field('name')->where('id',$item['job_id'])->findOrEmpty(); $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); $item['job_name'] = $job->isEmpty() ? '' : $job['name']; $item['dept_name'] = $dept->isEmpty() ? '' : $dept['name']; $item['org_name'] = $org->isEmpty() ? '' : $org['name']; return $item; }) ->toArray(); // 角色数组('角色id'=>'角色名称') $roleLists = SystemRole::column('name', 'id'); //管理员列表增加角色名称 foreach ($adminLists as $k => $v) { $roleName = ''; if ($v['root'] == 1) { $roleName = '系统管理员'; } else { foreach ($v['role_id'] as $roleId) { $roleName .= $roleLists[$roleId] ?? ''; $roleName .= '/'; } } $adminLists[$k]['role_name'] = trim($roleName, '/'); } return $adminLists; } /** * @notes 获取数量 * @return int * @author 令狐冲 * @date 2021/7/13 00:52 */ public function count(): int { return Admin::where($this->searchWhere) ->count(); } public function extend() { return []; } }