更新离职记录

This commit is contained in:
yaooo 2023-10-31 18:10:08 +08:00
parent 591482ad16
commit d6b1e87775
3 changed files with 271 additions and 3 deletions

View File

@ -0,0 +1,269 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-3.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\ApiController;
use app\api\middleware\Auth;
use app\oa\model\Schedule as ScheduleList;
use schedule\Schedule as ScheduleIndex;
use think\facade\Db;
class OaSchedule extends ApiController
{
protected $middleware = [
Auth::class => ['except' => []]
];
public function index() {
$this->checkAuth();
$this->uid = JWT_UID;
$param = get_params();
$tid = isset($param['tid']) ? $param['tid'] : 0;
$where = [];
if ($tid>0) {
$task_ids = Db::name('ProjectTask')->where(['delete_time' => 0, 'project_id' => $param['tid']])->column('id');
$where[] = ['a.tid', 'in', $task_ids];
}
else{
if (!empty($param['uid'])) {
$where[] = ['a.admin_id', '=', $param['uid']];
} else {
$where[] = ['a.admin_id', '=', $this->uid];
}
if (!empty($param['keywords'])) {
$where[] = ['a.title', 'like', '%' . trim($param['keywords']) . '%'];
}
//按时间检索
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['a.start_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
}
}
$where[] = ['a.delete_time', '=', 0];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$schedule = ScheduleList::where($where)
->field('a.*,u.name,d.title as department,w.title as work_cate')
->alias('a')
->join('Admin u', 'a.admin_id = u.id', 'LEFT')
->join('Department d', 'u.did = d.id', 'LEFT')
->join('WorkCate w', 'w.id = a.cid', 'LEFT')
->order('a.end_time desc')
->paginate($rows, false)
->each(function ($item, $key) {
$item->labor_type_string = '案头工作';
if($item->labor_type == 2){
$item->labor_type_string = '外勤工作';
}
if($item->tid > 0){
$task = Db::name('ProjectTask')->where(['id' => $item->tid])->find();
$item->task = $task['title'];
$item->project = Db::name('Project')->where(['id' => $task['project_id']])->value('name');
}
$item->start_time_a = empty($item->start_time) ? '' : date('Y-m-d', $item->start_time);
$item->start_time_b = empty($item->start_time) ? '' : date('H:i', $item->start_time);
$item->end_time_a = empty($item->end_time) ? '' : date('Y-m-d', $item->end_time);
$item->end_time_b = empty($item->end_time) ? '' : date('H:i', $item->end_time);
$item->start_time = empty($item->start_time) ? '' : date('Y-m-d H:i', $item->start_time);
//$item->end_time = empty($item->end_time) ? '': date('Y-m-d H:i', $item->end_time);
$item->end_time = empty($item->end_time) ? '' : date('H:i', $item->end_time);
});
$this->apiSuccess('获取成功', $schedule);
}
//保存日志数据
public function add()
{
$this->checkAuth();
$param = get_params();
if (empty($param['start_time_a'])) {
$this->apiError("开始日期不能为空");
}
if (empty($param['start_time_b'])) {
$this->apiError("开始时分不能为空");
}
if (empty($param['end_time_a'])) {
$this->apiError("结束日期不能为空");
}
if (empty($param['end_time_b'])) {
$this->apiError("结束时分不能为空");
}
if (empty($param['title'])) {
$this->apiError("任务内容不能为空");
}
if (empty($param['labor_type'])) {
$this->apiError("工作类型不能为空");
}
$this->uid = JWT_UID;
$admin_id = $this->uid;
if (empty($param['id'])) {
if (isset($param['start_time_a'])) {
$param['start_time'] = strtotime($param['start_time_a'] . '' . $param['start_time_b']);
}
if (isset($param['end_time_a'])) {
$param['end_time'] = strtotime($param['end_time_a'] . '' . $param['end_time_b']);
}
if($param['start_time']>time()){
$this->apiError('开始时间不能大于现在时间');
}
if ($param['end_time'] <= $param['start_time']) {
$this->apiError('结束时间需要大于开始时间');
}
$where1[] = ['delete_time', '=', 0];
$where1[] = ['admin_id', '=', $admin_id];
$where1[] = ['start_time', 'between', [$param['start_time'], $param['end_time'] - 1]];
$where2[] = ['delete_time', '=', 0];
$where2[] = ['admin_id', '=', $admin_id];
$where2[] = ['start_time', '<=', $param['start_time']];
$where2[] = ['start_time', '>=', $param['end_time']];
$where3[] = ['delete_time', '=', 0];
$where3[] = ['admin_id', '=', $admin_id];
$where3[] = ['end_time', 'between', [$param['start_time'] + 1, $param['end_time']]];
$record = Db::name('Schedule')
->where(function ($query) use ($where1) {
$query->where($where1);
})
->whereOr(function ($query) use ($where2) {
$query->where($where2);
})
->whereOr(function ($query) use ($where3) {
$query->where($where3);
})
->count();
if ($record > 0) {
$this->apiError('您所选的时间区间已有工作记录,请重新选时间');
}
$param['labor_time'] = ($param['end_time'] - $param['start_time']) / 3600;
$param['admin_id'] = $admin_id;
$param['did'] = get_admin($admin_id)['did'];
$param['create_time'] = time();
$sid = Db::name('Schedule')->strict(false)->field(true)->insertGetId($param);
if ($sid > 0) {
add_log('add', $sid, $param);
$this->apiSuccess('操作成功');
} else {
$this->apiError('操作失败');
}
} else {
$param['update_time'] = time();
$res = Db::name('Schedule')->strict(false)->field(true)->update($param);
if ($res !== false) {
add_log('edit', $param['id'], $param);
$this->apiSuccess('操作成功');
} else {
$this->apiError('操作失败');
}
}
}
//更改工时
public function update_labor_time()
{
$param = get_params();
if (isset($param['start_time_a'])) {
$param['start_time'] = strtotime($param['start_time_a'] . '' . $param['start_time_b']);
}
if (isset($param['end_time_a'])) {
$param['end_time'] = strtotime($param['end_time_a'] . '' . $param['end_time_b']);
}
if($param['start_time']>time()){
return to_assign(1, "开始时间不能大于当前时间");
}
if ($param['end_time'] <= $param['start_time']) {
return to_assign(1, "结束时间需要大于开始时间");
}
$where1[] = ['delete_time', '=', 0];
$where1[] = ['id', '<>', $param['id']];
$where1[] = ['admin_id', '=', $param['admin_id']];
$where1[] = ['start_time', 'between', [$param['start_time'], $param['end_time'] - 1]];
$where2[] = ['delete_time', '=', 0];
$where2[] = ['id', '<>', $param['id']];
$where2[] = ['admin_id', '=', $param['admin_id']];
$where2[] = ['start_time', '<=', $param['start_time']];
$where2[] = ['start_time', '>=', $param['end_time']];
$where3[] = ['delete_time', '=', 0];
$where3[] = ['id', '<>', $param['id']];
$where3[] = ['admin_id', '=', $param['admin_id']];
$where3[] = ['end_time', 'between', [$param['start_time'] + 1, $param['end_time']]];
$record = Db::name('Schedule')
->where(function ($query) use ($where1) {
$query->where($where1);
})
->whereOr(function ($query) use ($where2) {
$query->where($where2);
})
->whereOr(function ($query) use ($where3) {
$query->where($where3);
})
->count();
if ($record > 0) {
return to_assign(1, "您所选的时间区间已有工作记录,请重新选时间");
}
$param['labor_time'] = ($param['end_time'] - $param['start_time']) / 3600;
$res = Db::name('Schedule')->strict(false)->field(true)->update($param);
if ($res !== false) {
return to_assign(0, "操作成功");
add_log('edit', $param['id'], $param);
} else {
return to_assign(1, "操作失败");
}
}
//删除工作记录
public function delete()
{
$id = get_params("id");
$data['id'] = $id;
$data['delete_time'] = time();
if (Db::name('schedule')->update($data) !== false) {
add_log('delete', $data['id'], $data);
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
}
public function detail($id)
{
$id = get_params('id');
$schedule = Db::name('Schedule')->where(['id' => $id])->find();
if (!empty($schedule)) {
$schedule['start_time_1'] = date('H:i', $schedule['start_time']);
$schedule['end_time_1'] = date('H:i', $schedule['end_time']);
$schedule['start_time'] = date('Y-m-d', $schedule['start_time']);
$schedule['end_time'] = date('Y-m-d', $schedule['end_time']);
$schedule['create_time'] = date('Y-m-d H:i:s', $schedule['create_time']);
$schedule['name'] = Db::name('Admin')->where(['id' => $schedule['admin_id']])->value('name');
$schedule['labor_type_string'] = '案头工作';
if($schedule['labor_type'] == 2){
$schedule['labor_type_string'] = '外勤工作';
}
$schedule['department'] = get_admin($schedule['admin_id'])['department'];
$schedule['work_cate'] = Db::name('WorkCate')->where(['id' => $schedule['cid']])->value('title');
if($schedule['tid']>0){
$task = Db::name('ProjectTask')->where(['id' => $schedule['tid']])->find();
$schedule['task'] = $task['title'];
$schedule['project'] = Db::name('Project')->where(['id' => $task['project_id']])->value('name');
}
}
if (request()->isAjax()) {
return to_assign(0, "", $schedule);
} else {
return $schedule;
}
}
}

View File

@ -7,7 +7,6 @@
declare (strict_types = 1); declare (strict_types = 1);
namespace app\api\controller; namespace app\api\controller;
use app\api\ApiController; use app\api\ApiController;

View File

@ -149,7 +149,7 @@ class UserPersonal extends ApiController
if ($res!==false) { if ($res!==false) {
Db::name('Admin')->where('id', $param['uid'])->update(['status' => 2]); Db::name('Admin')->where('id', $param['uid'])->update(['status' => 2]);
} }
$this->apiError("操作成功"); $this->apiSuccess("操作成功");
} }
//删除离职档案 //删除离职档案
@ -167,7 +167,7 @@ class UserPersonal extends ApiController
$uid = Db::name('PersonalQuit')->where('id', $id)->value('uid'); $uid = Db::name('PersonalQuit')->where('id', $id)->value('uid');
Db::name('Admin')->where('id', $uid)->update(['status' => 1]); Db::name('Admin')->where('id', $uid)->update(['status' => 1]);
add_log('delete', $id); add_log('delete', $id);
$this->apiError("删除成功"); $this->apiSuccess("删除成功");
} else { } else {
$this->apiError("删除失败"); $this->apiError("删除失败");
} }