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\dept;
|
|
|
|
|
|
|
|
|
|
use app\admin\controller\BaseAdminController;
|
|
|
|
|
use app\admin\logic\dept\DeptLogic;
|
|
|
|
|
use app\admin\validate\dept\DeptValidate;
|
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\Orgs;
|
2025-02-26 10:13:24 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 部门管理控制器
|
|
|
|
|
* Class DeptController
|
|
|
|
|
* @package app\admin\controller\dept
|
|
|
|
|
*/
|
|
|
|
|
class DeptController extends BaseAdminController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 部门列表
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/25 18:07
|
|
|
|
|
*/
|
|
|
|
|
public function lists()
|
|
|
|
|
{
|
|
|
|
|
$params = $this->request->get();
|
|
|
|
|
$result = DeptLogic::lists($params);
|
2025-03-06 17:49:09 +08:00
|
|
|
|
return $this->success('', $result);
|
2025-02-26 10:13:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 上级部门
|
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/26 18:36
|
|
|
|
|
*/
|
|
|
|
|
public function leaderDept()
|
|
|
|
|
{
|
|
|
|
|
$result = DeptLogic::leaderDept();
|
2025-03-06 17:49:09 +08:00
|
|
|
|
return $this->success('', $result);
|
2025-02-26 10:13:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 添加部门
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/25 18:40
|
|
|
|
|
*/
|
|
|
|
|
public function add()
|
|
|
|
|
{
|
|
|
|
|
$params = (new DeptValidate())->post()->goCheck('add');
|
|
|
|
|
DeptLogic::add($params);
|
|
|
|
|
return $this->success('添加成功', [], 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 编辑部门
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/25 18:41
|
|
|
|
|
*/
|
|
|
|
|
public function edit()
|
|
|
|
|
{
|
|
|
|
|
$params = (new DeptValidate())->post()->goCheck('edit');
|
|
|
|
|
$result = DeptLogic::edit($params);
|
|
|
|
|
if (true === $result) {
|
|
|
|
|
return $this->success('编辑成功', [], 1, 1);
|
|
|
|
|
}
|
|
|
|
|
return $this->fail(DeptLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 删除部门
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/25 18:41
|
|
|
|
|
*/
|
|
|
|
|
public function delete()
|
|
|
|
|
{
|
|
|
|
|
$params = (new DeptValidate())->post()->goCheck('delete');
|
|
|
|
|
DeptLogic::delete($params);
|
|
|
|
|
return $this->success('删除成功', [], 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 获取部门详情
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/5/25 18:41
|
|
|
|
|
*/
|
|
|
|
|
public function detail()
|
|
|
|
|
{
|
|
|
|
|
$params = (new DeptValidate())->goCheck('detail');
|
|
|
|
|
$result = DeptLogic::detail($params);
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 获取部门数据
|
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
* @author 乔峰
|
|
|
|
|
* @date 2022/10/13 10:28
|
|
|
|
|
*/
|
|
|
|
|
public function all()
|
|
|
|
|
{
|
|
|
|
|
$result = DeptLogic::getAllData();
|
|
|
|
|
return $this->data($result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-06 17:49:09 +08:00
|
|
|
|
//某个组织下面的部门
|
|
|
|
|
public function listToOrg()
|
|
|
|
|
{
|
|
|
|
|
$params = $this->request->get();
|
|
|
|
|
$data = Dept::field('id,name,mobile,status')->where('org_id', $params['org_id'])->where('status', 0)->select()->toArray();
|
|
|
|
|
return $this->success('请求成功', $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取所有部门
|
|
|
|
|
public function getAllDept()
|
|
|
|
|
{
|
|
|
|
|
$data = Dept::field('id,name,org_id')->where('status', 1)->select()->each(function ($item) {
|
|
|
|
|
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'];
|
|
|
|
|
}
|
|
|
|
|
$item['admin_num'] = Admin::where('dept_id', $item['id'])->count();
|
|
|
|
|
unset($item['org_id']);
|
|
|
|
|
return $item;
|
|
|
|
|
})->toArray();
|
|
|
|
|
$result = group_by($data, 'org_name');
|
|
|
|
|
return $this->success('请求成功', $result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 10:13:24 +08:00
|
|
|
|
|
|
|
|
|
}
|