wupengfei 2 سال پیش
والد
کامیت
218671ac5a
3فایلهای تغییر یافته به همراه32 افزوده شده و 7 حذف شده
  1. 22 5
      application/api/controller/UserLeave.php
  2. 8 0
      application/common/model/LeaveApprove.php
  3. 2 2
      application/common/model/LeaveFlow.php

+ 22 - 5
application/api/controller/UserLeave.php

@@ -1,6 +1,8 @@
 <?php
 namespace app\api\controller;
+use app\common\model\LeaveApprove;
 use app\common\model\LeaveFlow;
+use app\common\model\LeaveInfo;
 use app\common\model\LeaveType;
 use think\Db;
 use app\common\model\User;
@@ -58,12 +60,27 @@ class UserLeave extends Base
         if(empty($request_param['start_date']) || empty($request_param['end_date'])) $this->error('请选择请假期');
         if(empty($request_param['type'])) $this->error('请选择请假类型');
         if(empty($request_param['user_id'])) $request_param['user_id'] = $this->user_id;
-        $flow = LeaveFlow::order('sort asc ,id asc')->select()->toArray();
+        $request_param['apply_user'] = $this->user_id;// 申请会员id
+        $flow = LeaveFlow::order('sort asc ,id asc')->select()->toArray();// 请假审批流程设置
         $flow_user = array_column($flow,'user_id');
-        $found_key = array_search($request_param['user_id'],$flow_user);
-        var_dump($request_param['user_id'],$found_key);
-
-
+        $flow_key = array_search($request_param['user_id'],$flow_user);// 请假人是否在审批流程人员中
+        $flow_info = LeaveInfo::create($request_param);//生成请假记录
+        $flow_data = [];// 审批流程
+        $flow_num = 1;
+        foreach ($flow as $fk=>$fv) {
+            if($flow_key !== false && $flow_key<= $fk) continue;
+            $flow_data[] = [
+                'leave_id' => $flow_info->id,
+                'approve_user' => $fv['user_id'],
+                'flow'   =>$flow_num
+            ];
+            $flow_num++;
+        }
+        if(!empty($flow_data)) {
+            LeaveFlow::where('id',$flow_info->id)->update(['approve_num'=>$flow_num]);
+            (new LeaveApprove())->saveAll($flow_data);
+        }
+        $this->success('请假已提交,请等待审核',['detail'=>$flow_info->toArray()]);
     }
 
 

+ 8 - 0
application/common/model/LeaveApprove.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model;
+use think\Model;
+// 请假审批记录
+class LeaveApprove extends Model
+{
+
+}

+ 2 - 2
application/common/model/LeaveFlow.php

@@ -1,9 +1,9 @@
 <?php
 namespace app\common\model;
 use think\Model;
-// 请假审批流程
+// 请假审批流程设置
 class LeaveFlow extends Model
 {
-    protected $resultSetType = 'array';
+
 
 }