lihaiMiddleOffice/app/admin/controller/auth/AdminController.php

221 lines
7.3 KiB
PHP
Raw Normal View History

2025-02-26 10:13:24 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\controller\auth;
use app\admin\controller\BaseAdminController;
use app\admin\lists\auth\AdminLists;
use app\admin\validate\auth\AdminValidate;
use app\admin\logic\auth\AdminLogic;
use app\admin\validate\auth\editSelfValidate;
2025-03-06 17:49:09 +08:00
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Jobs;
use app\common\model\dept\Orgs;
2025-02-26 10:13:24 +08:00
/**
* 管理员控制器
* Class AdminController
* @package app\admin\controller\auth
*/
class AdminController extends BaseAdminController
{
/**
* @notes 查看管理员列表
* @author 乔峰
* @date 2021/12/29 9:55
*/
public function lists()
{
return $this->dataLists(new AdminLists());
}
/**
* @notes 添加管理员
* @author 乔峰
* @date 2021/12/29 10:21
*/
public function add()
{
$params = (new AdminValidate())->post()->goCheck('add');
$result = AdminLogic::add($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(AdminLogic::getError());
}
/**
* @notes 编辑管理员
* @author 乔峰
* @date 2021/12/29 11:03
*/
public function edit()
{
$params = (new AdminValidate())->post()->goCheck('edit');
$result = AdminLogic::edit($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(AdminLogic::getError());
}
/**
* @notes 删除管理员
* @author 乔峰
* @date 2021/12/29 11:03
*/
public function delete()
{
$params = (new AdminValidate())->post()->goCheck('delete');
$result = AdminLogic::delete($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(AdminLogic::getError());
}
/**
* @notes 查看管理员详情
* @author 乔峰
* @date 2021/12/29 11:07
*/
public function detail()
{
$params = (new AdminValidate())->goCheck('detail');
$result = AdminLogic::detail($params);
return $this->data($result);
}
/**
* @notes 获取当前管理员信息
* @author 乔峰
* @date 2021/12/31 10:53
*/
public function mySelf()
{
$result = AdminLogic::detail(['id' => $this->adminId], 'auth');
return $this->data($result);
}
/**
* @notes 编辑超级管理员信息
* @author 乔峰
* @date 2022/4/8 17:54
*/
public function editSelf()
{
$params = (new editSelfValidate())->post()->goCheck('', ['admin_id' => $this->adminId]);
$result = AdminLogic::editSelf($params);
return $this->success('操作成功', [], 1, 1);
}
2025-03-06 17:49:09 +08:00
//获取所有人员
public function getAdminsByAll()
{
$params = $this->request->get();
$where = [];
if(!empty($params['exclude_id'])){
$where[] = ['id','<>',$params['exclude_id']];
}
if(!empty($params['org_id'])){
$where[] = ['org_id','=',$params['org_id']];
}
$data = Admin::field('id,name,avatar,org_id,dept_id,job_id')->where($where)->select()->each(function($item){
if (empty($item['job_id'])) {
$item['job_name'] = '';
} else {
$job = Jobs::field('name')->where('id',$item['job_id'])->findOrEmpty();
$item['job_name'] = $job->isEmpty()? '' : $job['name'];
}
if (empty($item['dept_id'])) {
$item['dept_name'] = '';
} else {
$dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty();
$item['dept_name'] = $dept->isEmpty() ? '' : $dept['name'];
}
if (empty($item['org_id'])) {
$item['org_name'] = '';
} else {
$org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
}
return $item;
})->toArray();
foreach($data as $k=>$v){
unset($data[$k]['role_id']);
}
return $this->success('请求成功',$data);
}
//获取某个部门下的所有人员
public function getAdminsByDept()
{
$params = $this->request->get();
if(empty($params['dept_id'])){
return $this->fail('参数错误');
}
$where = [];
if(!empty($params['exclude_id'])){
$where[] = ['id','<>',$params['exclude_id']];
}
$data = Admin::field('id,name,avatar,org_id,dept_id,job_id')->where('dept_id',$params['dept_id'])->where($where)->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();
foreach($data as $k=>$v){
unset($data[$k]['role_id']);
}
return $this->success('请求成功',$data);
}
//获取某个岗位下的所有人员
public function getAdminsByJob()
{
$params = $this->request->get();
if(empty($params['job_id'])){
return $this->fail('参数错误');
}
$where = [];
if(!empty($params['exclude_id'])){
$where[] = ['id','<>',$params['exclude_id']];
}
$data = Admin::field('id,name,avatar,org_id,dept_id,job_id')->where('job_id',$params['job_id'])->where($where)->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();
foreach($data as $k=>$v){
unset($data[$k]['role_id']);
}
return $this->success('请求成功',$data);
}
2025-02-26 10:13:24 +08:00
}