117 lines
3.3 KiB
PHP
Executable File
117 lines
3.3 KiB
PHP
Executable File
<?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\adminapi\logic\dept;
|
||
|
||
use app\common\enum\YesNoEnum;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Jobs;
|
||
use app\common\model\dept\Orgs;
|
||
|
||
|
||
/**
|
||
* 部门管理逻辑
|
||
* Class DeptLogic
|
||
* @package app\adminapi\logic\dept
|
||
*/
|
||
class DeptLogic extends BaseLogic
|
||
{
|
||
|
||
/**
|
||
* @notes 添加部门
|
||
* @param array $params
|
||
* @author 段誉
|
||
* @date 2022/5/25 18:20
|
||
*/
|
||
public static function add(array $params)
|
||
{
|
||
Dept::create([
|
||
'org_id' => $params['org_id'],
|
||
'name' => $params['name'],
|
||
'leader' => $params['leader'] ?? 0,
|
||
'mobile' => $params['mobile'],
|
||
'status' => $params['status'],
|
||
'sort' => $params['sort'] ?? 0
|
||
]);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑部门
|
||
* @param array $params
|
||
* @return bool
|
||
* @author 段誉
|
||
* @date 2022/5/25 18:39
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
try {
|
||
Dept::update([
|
||
'id' => $params['id'],
|
||
'org_id' => $params['org_id'],
|
||
'name' => $params['name'],
|
||
'leader' => $params['leader'] ?? 0,
|
||
'mobile' => $params['mobile'],
|
||
'status' => $params['status'],
|
||
'sort' => $params['sort'] ?? 0
|
||
]);
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除部门
|
||
* @param array $params
|
||
* @author 段誉
|
||
* @date 2022/5/25 18:40
|
||
*/
|
||
public static function delete(array $params)
|
||
{
|
||
$jobs = Jobs::where('dept_id',$params['id'])->findOrEmpty();
|
||
if(!$jobs->isEmpty()){
|
||
self::setError('当前部门下存在岗位数据,不能删除');
|
||
return false;
|
||
}
|
||
return Dept::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取部门详情
|
||
* @param $params
|
||
* @return array
|
||
* @author 段誉
|
||
* @date 2022/5/25 18:40
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = Dept::field('id,name,org_id,leader,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return [];
|
||
}
|
||
$org = Orgs::where('id',$data['org_id'])->findOrEmpty();
|
||
$data['org_name'] = $org->isEmpty() ? '' : $org['name'];
|
||
$data['status_text'] = $data->status_text;
|
||
$admin = Admin::field('name')->where('id',$data['leader'])->findOrEmpty();
|
||
$data['leader_name'] = $admin['name'];
|
||
return $data->toArray();
|
||
}
|
||
|
||
} |