更新工作记录工时

This commit is contained in:
yaooo 2023-10-31 18:28:07 +08:00
parent d6b1e87775
commit 5eeb6ec3dd
1 changed files with 23 additions and 8 deletions

View File

@ -169,7 +169,20 @@ class OaSchedule extends ApiController
//更改工时
public function update_labor_time()
{
$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 (isset($param['start_time_a'])) {
$param['start_time'] = strtotime($param['start_time_a'] . '' . $param['start_time_b']);
}
@ -177,25 +190,27 @@ class OaSchedule extends ApiController
$param['end_time'] = strtotime($param['end_time_a'] . '' . $param['end_time_b']);
}
if($param['start_time']>time()){
return to_assign(1, "开始时间不能大于当前时间");
$this->apiError('开始时间不能大于当前时间');
}
if ($param['end_time'] <= $param['start_time']) {
return to_assign(1, "结束时间需要大于开始时间");
$this->apiError('结束时间需要大于开始时间');
}
$this->uid = JWT_UID;
$admin_id = $this->uid;
$where1[] = ['delete_time', '=', 0];
$where1[] = ['id', '<>', $param['id']];
$where1[] = ['admin_id', '=', $param['admin_id']];
$where1[] = ['admin_id', '=', $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[] = ['admin_id', '=', $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[] = ['admin_id', '=', $admin_id];
$where3[] = ['end_time', 'between', [$param['start_time'] + 1, $param['end_time']]];
$record = Db::name('Schedule')
@ -210,15 +225,15 @@ class OaSchedule extends ApiController
})
->count();
if ($record > 0) {
return to_assign(1, "您所选的时间区间已有工作记录,请重新选时间");
$this->apiError('您所选的时间区间已有工作记录,请重新选时间');
}
$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);
$this->apiSuccess('操作成功');
} else {
return to_assign(1, "操作失败");
$this->apiError('操作失败');
}
}