更新动态展示审核表单

This commit is contained in:
yaooo 2023-11-01 14:51:49 +08:00
parent 4f98d14113
commit ad0e46cbe7
1 changed files with 177 additions and 0 deletions

View File

@ -146,4 +146,181 @@ class OaApprove extends ApiController
'field' => $field
]);
}
//添加新增/编辑审批
public function add()
{
$this->checkAuth();
$this->uid = JWT_UID;
$loginAdmin = Db::name('Admin')->where(['id' => $this->uid])->find();
$this->did = $loginAdmin['did'];
$param = get_params();
if (empty($param['flow_id'])) {
$this->apiError("审批类型id不能为空");
}
if (isset($param['detail_time'])) {
$param['detail_time'] = strtotime($param['detail_time']);
}
if (isset($param['start_time'])) {
$param['start_time'] = strtotime($param['start_time']);
}
if (isset($param['end_time'])) {
$param['end_time'] = strtotime($param['end_time']);
if ($param['end_time'] < $param['start_time']) {
$this->apiError('时间选择有误');
}
}
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['end_time'] <= $param['start_time']) {
$this->apiError('结束时间需要大于开始时间');
}
}
$flow_list = Db::name('Flow')->where('id',$param['flow_id'])->value('flow_list');
$flow = unserialize($flow_list);
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$param['check_status'] = 0;
$param['check_step_sort'] = 0;
try {
//删除原来的审核流程和审核记录
Db::name('FlowStep')->where(['action_id'=>$param['id'],'type'=>1,'delete_time'=>0])->update(['delete_time'=>time()]);
Db::name('FlowRecord')->where(['action_id'=>$param['id'],'type'=>1,'delete_time'=>0])->update(['delete_time'=>time()]);
if (!isset($param['check_admin_ids'])) {
if($flow[0]['flow_type'] == 1){
//部门负责人
$leader = get_department_leader($this->uid);
if($leader == 0){
$this->apiError('审批流程设置有问题当前部门负责人还未设置请联系HR或者管理员');
}
else{
$param['check_admin_ids'] = $leader;
}
}
else if($flow[0]['flow_type'] == 2){
//上级部门负责人
$leader = get_department_leader($this->uid,1);
if($leader == 0){
$this->apiError('审批流程设置有问题上级部门负责人还未设置请联系HR或者管理员');
}
else{
$param['check_admin_ids'] = $leader;
}
}
else{
$param['check_admin_ids'] = $flow[0]['flow_uids'];
}
Db::name('Approve')->strict(false)->field(true)->update($param);
foreach ($flow as $key => &$value){
$value['action_id'] = $param['id'];
$value['sort'] = $key;
$value['create_time'] = time();
}
$res = Db::name('FlowStep')->strict(false)->field(true)->insertAll($flow);
}
else{
Db::name('Approve')->strict(false)->field(true)->update($param);
$flow_step = array(
'action_id' => $param['id'],
'flow_uids' => $param['check_admin_ids'],
'create_time' => time()
);
$res = Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);
}
//添加提交申请记录
$checkData=array(
'action_id' => $param['id'],
'check_user_id' => $this->uid,
'content' => '重新提交申请',
'check_time' => time(),
'create_time' => time()
);
$record_id = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('edit', $param['id'], $param);
//发送消息通知
$msg=[
'from_uid'=>$this->uid,
'title' => Db::name('FlowType')->where('id',$param['type'])->value('title'),
'action_id'=>$param['id']
];
$users = $param['check_admin_ids'];
sendMessage($users,21,$msg);
} catch (\Exception $e) {
$this->apiError($e->getError());
}
} else {
$param['admin_id'] = $this->uid;
$param['department_id'] = $this->did;
$param['create_time'] = time();
try {
if (!isset($param['check_admin_ids'])) {
if($flow[0]['flow_type'] == 1){
//部门负责人
$leader = get_department_leader($this->uid);
if($leader == 0){
$this->apiError('当前部门负责人还未设置请联系HR或者管理员');
}
else{
$param['check_admin_ids'] = $leader;
}
}
else if($flow[0]['flow_type'] == 2){
//上级部门负责人
$leader = get_department_leader($this->uid, 1);
if($leader == 0){
$this->apiError('上级部门负责人还未设置请联系HR或者管理员');
}
else{
$param['check_admin_ids'] = $leader;
}
}
else{
$param['check_admin_ids'] = $flow[0]['flow_uids'];
}
$aid = Db::name('Approve')->strict(false)->field(true)->insertGetId($param);
foreach ($flow as $key => &$value){
$value['action_id'] = $aid;
$value['sort'] = $key;
$value['create_time'] = time();
}
$res = Db::name('FlowStep')->strict(false)->field(true)->insertAll($flow);
}
else{
$aid = Db::name('Approve')->strict(false)->field(true)->insertGetId($param);
$flow_step = array(
'action_id' => $aid,
'flow_uids' => $param['check_admin_ids'],
'create_time' => time()
);
$step_id = Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);
}
//添加提交申请记录
$checkData=array(
'action_id' => $aid,
'check_user_id' => $this->uid,
'content' => '提交申请',
'check_time' => time(),
'create_time' => time()
);
$record_id = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('add', $aid, $param);
//给审核人发送消息通知
$msg=[
'from_uid'=>$this->uid,
'title' => Db::name('FlowType')->where('id',$param['type'])->value('title'),
'action_id'=>$aid
];
$users = $param['check_admin_ids'];
sendMessage($users, 21, $msg);
} catch (\Exception $e) {
$this->apiError($e->getError());
}
}
$this->apiSuccess('操作成功');
}
}