wupengfei 2 years ago
parent
commit
3c3a7140dd

+ 23 - 1
application/api/controller/UserCar.php

@@ -4,6 +4,7 @@ use AlibabaCloud\SDK\Dingtalk\Vyida_1_0\Models\GetFormDataByIDResponseBody\origi
 use app\common\model\CarApprove;
 use app\common\model\CarFlow;
 use app\common\model\CarInfo;
+use app\common\service\ApproveService;
 use think\Db;
 
 /**
@@ -255,7 +256,7 @@ class UserCar extends Base
     }
 
     /**
-     * @title 撤销y申请
+     * @title 撤销用车申请
      * @desc 撤销用车申请
      * @author qc
      * @url /api/User_car/cancelApply
@@ -275,6 +276,27 @@ class UserCar extends Base
         $this->success('撤销成功');
     }
 
+    /**
+     * @title 审批请假记录
+     * @desc 审批请假记录
+     * @author qc
+     * @url /api/User_car/approveLeave
+     * @method POST
+     * @tag
+     * @header name:Authorization require:1 desc:Token
+     * @param name:approve_id type:string default:-- desc:审批记录id
+     * @param name:status type:string default:-- desc:审批状态(2审批通过3审批拒绝)
+     * @param name:remark type:string default:-- desc:审批备注
+     */
+    public function approveCar()
+    {
+        $approve_id = input('post.approve_id');
+        $status = input('post.status');
+        $remark = input('post.remark');
+        $res = ApproveService::approveCar($approve_id,$this->user_id,$status,$remark);
+        if(!$res['ret_val']) $this->error($res['msg']);
+        $this->success('审批完成');
+    }
 
 
 

+ 2 - 2
application/api/controller/UserLeave.php

@@ -5,7 +5,7 @@ use app\common\model\LeaveApprove;
 use app\common\model\LeaveFlow;
 use app\common\model\LeaveInfo;
 use app\common\model\LeaveType;
-use app\common\service\LeaveService;
+use app\common\service\ApproveService;
 use think\Db;
 use app\common\model\User;
 /**
@@ -295,7 +295,7 @@ class UserLeave extends Base
         $approve_id = input('post.approve_id');
         $status = input('post.status');
         $remark = input('post.remark');
-        $res = LeaveService::approveLeave($approve_id,$this->user_id,$status,$remark);
+        $res = ApproveService::approveLeave($approve_id,$this->user_id,$status,$remark);
         if(!$res['ret_val']) $this->error($res['msg']);
         $this->success('审批完成');
     }

+ 53 - 3
application/common/service/LeaveService.php → application/common/service/ApproveService.php

@@ -2,21 +2,24 @@
 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 think\Db;
 use think\Exception;
 
 /**
- * 会员请假
- * Class LeaveService
+ * 审批
+ * Class ApproveService
  */
-class LeaveService
+class ApproveService
 {
     protected static $ret_val = true;
     protected static $msg = '';
 
     /**
+     * 请假审批
      * @param $approve_id  审批记录
      * @param $user_id     审批会员
      * @param $status      审批状态
@@ -62,5 +65,52 @@ class LeaveService
     }
 
 
+    /**
+     * 用车申请审批
+     * @param $approve_id  审批记录
+     * @param $user_id     审批会员
+     * @param $status      审批状态
+     * @param $remark      审批备注
+     * @return array
+     */
+    public static function approveCar($approve_id,$user_id,$status,$remark)
+    {
+        Db::startTrans();
+        try {
+            if(!in_array($status,[2,3]))throw new Exception('审批状态错误');
+            $approve_info = CarApprove::where('id',$approve_id)->find()->toArray();
+            $car_info  = CarInfo::where('id',$approve_info['car_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;
+            CarApprove::where('id',$approve_id)->update($approve_update);// 更新审批记录
+            $car_data = [];
+            // 审批流程数 + 1
+            $car_data['cur_num'] = $car_info['cur_num'] + 1;
+            if($approve_info['flow'] < $car_info['approve_num']){
+                // 更新下一级审批记录状态
+                CarApprove::where(['car_id'=>$approve_info['car_id'],'flow'=>$approve_info['flow'] + 1,'approve_type'=>1])->update(['status'=>1,'start_time'=>date('Y-m-d H:i:s')]);
+                if($status == 3) $car_data['status'] = 3;
+            } else if($approve_info['flow'] == $car_info['approve_num']) {
+                $car_data['status'] = $status;
+            }
+            LeaveInfo::where('id',$car_info['id'])->update($car_data);// 更新用车申请状态
+            Db::commit();
+        }catch (\Exception $e) {
+            Db::rollback();
+            static::$ret_val = false;
+            static::$msg = $e->getMessage();
+        }
+        return ['ret_val'=>static::$ret_val ,'msg'=>static::$msg];
+    }
+
+
 
 }