lihaiMiddleOffice/app/oa/logic/works/hr/OaPersonalQuitLogic.php

129 lines
4.2 KiB
PHP
Raw Permalink Normal View History

2025-02-27 09:55:33 +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
// +----------------------------------------------------------------------
2025-02-27 17:52:22 +08:00
namespace app\oa\logic\works\hr;
2025-02-27 09:55:33 +08:00
use app\common\model\auth\Admin;
use app\common\model\works\rlzy\OaPersonalQuit;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 离职档案逻辑
* Class OaPersonalQuitLogic
2025-02-27 17:52:22 +08:00
* @package app\adminapi\logic\works\hr
2025-02-27 09:55:33 +08:00
*/
class OaPersonalQuitLogic extends BaseLogic
{
/**
* @notes 添加离职档案
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/23 09:43
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
OaPersonalQuit::create([
'uid' => $params['uid'],
'remark' => $params['remark'] ?? '',
'admin_id' => $admin_id,
'lead_admin_id' => $params['lead_admin_id'],
'connect_uids' => $params['connect_uids'],
'connect_id' => $params['connect_id'],
'connect_time' => !empty($params['connect_time']) ? strtotime($params['connect_time']) : 0,
'quit_time' => !empty($params['quit_time']) ? strtotime($params['quit_time']) : 0,
]);
Admin::where('id',$params['uid'])->update(['status'=>2]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑离职档案
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/23 09:43
*/
public static function edit(array $params,$admin_id): bool
{
Db::startTrans();
try {
OaPersonalQuit::where('id', $params['id'])->update([
'uid' => $params['uid'],
'remark' => $params['remark'] ?? '',
'admin_id' => $admin_id,
'lead_admin_id' => $params['lead_admin_id'],
'connect_uids' => $params['connect_uids'],
'connect_id' => $params['connect_id'],
'connect_time' => !empty($params['connect_time']) ? strtotime($params['connect_time']) : 0,
'quit_time' => !empty($params['quit_time']) ? strtotime($params['quit_time']) : 0,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除离职档案
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/23 09:43
*/
public static function delete(array $params): bool
{
return OaPersonalQuit::destroy($params['id']);
}
/**
* @notes 获取离职档案详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/05/23 09:43
*/
public static function detail($params): array
{
$data = OaPersonalQuit::findOrEmpty($params['id']);
$user = Admin::where('id',$data['uid'])->findOrEmpty();
$other_user = Admin::where('id','in',[$data['lead_admin_id'],$data['connect_id']])->column('name','id');
$connect_users = Admin::where('id','in',$data['connect_uids'])->column('name');
$data['user_name'] = $user['name'];
$data['lead_admin_name'] = $other_user[$data['lead_admin_id']] ?? '';
$data['connect_user_name'] = $other_user[$data['connect_id']] ?? '';
$data['connect_users'] = implode(',',$connect_users);
return $data->toArray();
}
}