wupengfei 2 years ago
parent
commit
e085d0754d

+ 5 - 5
application/api/controller/Evection.php

@@ -99,7 +99,7 @@ class Evection extends Base
         if(empty($request_param['type'])) $this->error('请选择出差类型');
         if(empty($request_param['user_id'])) $request_param['user_id'] = $this->user_id;
         $request_param['apply_user'] = $this->user_id;// 申请会员id
-
+        $request_param['apply_date'] = date("Y-m-d");
         $flow = ApproveFlow::getApproveUser(3);// 出差审批流程设置
         $flow_user = array_column($flow,'user_id');
         $flow_key = array_search($request_param['user_id'],$flow_user);// 出差人是否在审批流程人员中
@@ -261,7 +261,7 @@ class Evection extends Base
      * @title 审批出差记录
      * @desc 审批出差记录
      * @author qc
-     * @url /api/Evection/approveLeave
+     * @url /api/Evection/approveEvection
      * @method POST
      * @tag  
      * @header name:Authorization require:1 desc:Token
@@ -269,12 +269,12 @@ class Evection extends Base
      * @param name:status type:string default:-- desc:审批状态(2审批通过3审批拒绝)
      * @param name:remark type:string default:-- desc:审批备注
      */
-    public function approveLeave()
+    public function approveEvection()
     {
         $approve_id = input('post.approve_id');
         $status = input('post.status');
         $remark = input('post.remark');
-        $res = ApproveService::approveLeave($approve_id,$this->user_id,$status,$remark);
+        $res = ApproveService::approveEvection($approve_id,$this->user_id,$status,$remark);
         if(!$res['ret_val']) $this->error($res['msg']);
         $this->success('审批完成');
     }
@@ -294,7 +294,7 @@ class Evection extends Base
     public function cancelApply()
     {
         $id  = input('post.id');
-        $apply_info  = EvectionInfo::where('id',$id)->where('user_id|apply_user',$this->user_id)->find();
+        $apply_info  = EvectionInfo::where('id',$id)->where('user_id',$this->user_id)->find();
         if(!$apply_info)$this->error('出差记录有误');
         $apply_info->status = 9;
         $apply_info->save();

+ 51 - 1
application/common/service/ApproveService.php

@@ -5,7 +5,8 @@ namespace app\common\service;
 use app\common\model\CarApprove;
 use app\common\model\CarInfo;
 use app\common\model\LeaveApprove;
-use app\common\model\LeaveInfo;
+use app\common\model\EvectionInfo;
+use app\common\model\EvectionApprove;
 use think\Db;
 use think\Exception;
 
@@ -115,4 +116,53 @@ class ApproveService
 
 
 
+    /**
+     * 出差申请审批
+     * @param $approve_id  审批记录
+     * @param $user_id     审批会员
+     * @param $status      审批状态
+     * @param $remark      审批备注
+     * @return array
+     */
+    public static function approveEvection($approve_id,$user_id,$status,$remark)
+    {
+        Db::startTrans();
+        try {
+            if(!in_array($status,[2,3]))throw new Exception('审批状态错误');
+            $approve_info =EvectionApprove::where('id',$approve_id)->find()->toArray();
+            $car_info  = EvectionInfo::where('id',$approve_info['eve_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($car_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');
+            $approve_time = time() - strtotime($approve_info['start_time']);
+            $approve_update['time'] = $approve_time;
+            $approve_update['time_desc'] = get_stay_time($approve_time);
+            EvectionApprove::where('id',$approve_id)->update($approve_update);// 更新审批记录
+            $Info_up = [];
+            // 审批流程数 + 1
+            $Info_up['cur_num'] = $car_info['cur_num'] + 1;
+            if($approve_info['flow'] < $car_info['approve_num']){
+                // 更新下一级审批记录状态
+                EvectionApprove::where(['eve_id'=>$approve_info['eve_id_id'],'flow'=>$approve_info['flow'] + 1,'approve_type'=>1])->update(['status'=>1,'start_time'=>date('Y-m-d H:i:s')]);
+                if($status == 3) $Info_up['status'] = 3;
+            } else if($approve_info['flow'] == $car_info['approve_num']) {
+                $Info_up['status'] = $status;
+            }
+            EvectionInfo::where('id',$car_info['id'])->update($Info_up);// 更新用车申请状态
+            Db::commit();
+        }catch (\Exception $e) {
+            Db::rollback();
+            static::$ret_val = false;
+            static::$msg = $e->getMessage();
+        }
+        return ['ret_val'=>static::$ret_val ,'msg'=>static::$msg];
+    }
+
+
+
 }