wupengfei 2 年之前
父節點
當前提交
770a79b87d
共有 2 個文件被更改,包括 10 次插入14 次删除
  1. 3 1
      application/api/controller/UserLeave.php
  2. 7 13
      application/common/service/LeaveService.php

+ 3 - 1
application/api/controller/UserLeave.php

@@ -134,7 +134,9 @@ class UserLeave extends Base
             $flow_data[] = [
                 'leave_id' => $flow_info->id,
                 'approve_user' => $fv['user_id'],
-                'flow'   =>$flow_num
+                'flow'   =>$flow_num,
+                'create_at'=>date('Y-m-d H:i:s'),
+                'start_time'=> $flow_num == 1 ? date('Y-m-d H:i:s'):null
             ];
         }
         foreach ($copy as $ck=>$cv) {

+ 7 - 13
application/common/service/LeaveService.php

@@ -18,6 +18,7 @@ class LeaveService
 
     /**
      * @param $approve_id  审批记录
+     * @param $user_id     审批会员
      * @param $status      审批状态
      * @param $remark      审批备注
      * @return array
@@ -31,30 +32,23 @@ class LeaveService
             $leave_info  = LeaveInfo::where('id',$approve_info['leave_id'])->find()->toArray();
             if($approve_info['approve_user'] != $user_id) throw new Exception('没有审核权限');
             if($approve_info['status'] == 0) throw new Exception('请等待审核');
-            if($approve_info['status'] != 1) throw new Exception('请假记录已审核');
-            if($leave_info['status'] != 1)  throw new Exception('请假记录已审核或已取消');
+            if($approve_info['status'] != 1) throw new Exception('请假记录已审核');
+            if($leave_info['status'] != 1)  throw new Exception('请假记录已审核或已取消');
             $approve_update = [];
             $approve_update['status'] = $status;
             $approve_update['remark'] = $remark;
             $approve_update['approve_time'] = date('Y-m-d H:i:s');
-            if($approve_info['flow'] == 1){
-                $approve_time = time() - strtotime($approve_info['create_at']);
-            }else{
-                $before_time = LeaveApprove::where(['leave_id'=>$approve_info['leave_id'],'flow'=>$approve_info['flow'] - 1,'approve_type'=>1])->value('approve_time');
-                $approve_time = time() - strtotime($before_time);
-            }
+            $approve_time = time() - strtotime($approve_info['start_time']);
             $approve_update['time'] = $approve_time;
             LeaveApprove::where('id',$approve_id)->update($approve_update);// 更新审批记录
             $leave_data = [];
+            // 审批流程数 + 1
+            $leave_data['cur_num'] = $leave_info['cur_num'] + 1;
             if($approve_info['flow'] < $leave_info['approve_num']){
                 // 更新下一级审批记录状态
-                LeaveApprove::where(['leave_id'=>$approve_info['leave_id'],'flow'=>$approve_info['flow'] + 1,'approve_type'=>1])->update(['status'=>1]);
-                // 审批流程数 + 1
-                $leave_data['cur_num'] = $leave_info['cur_num'] + 1;
+                LeaveApprove::where(['leave_id'=>$approve_info['leave_id'],'flow'=>$approve_info['flow'] + 1,'approve_type'=>1])->update(['status'=>1,'start_time'=>date('Y-m-d H:i:s')]);
                 if($status == 3) $leave_data['status'] = 3;
             } else if($approve_info['flow'] == $leave_info['approve_num']) {
-                // 审批流程数 + 1
-                $leave_data['cur_num'] = $leave_info['cur_num'] + 1;
                 $leave_data['status'] = $status;
             }
             LeaveInfo::where('id',$leave_info['id'])->update($leave_data);// 更新请假状态