zhanglinxin il y a 1 an
Parent
commit
07242cdaee

+ 6 - 3
application/api/controller/Approve.php

@@ -86,9 +86,10 @@ class Approve extends Base
         $id = input('approve_id');
         $status = input('status');
         $remark = input('remark');
+        $params = compact("id", "status", "remark");
         Db::startTrans();
         try {
-            ApproveService::audit($id, $status, $remark, $this->user);
+            ApproveService::make($id, $params, $this->user,'audit');
             Db::commit();
         } catch (Exception $e) {
             Db::rollback();
@@ -122,6 +123,8 @@ class Approve extends Base
         $id = input('approve_id');
         $module = input('module');
         $reason = input('reason');
+        $state = input('state',1);
+        $desc = input('desc','');
         $start_time = input('start_time');
         $end_time = input('end_time');
         $document = input('document');
@@ -130,10 +133,10 @@ class Approve extends Base
         $is_who = input('is_who');
         $remark = input('remark');
         $peer_user = input('peer_user');
-        $params = compact("module", "id", "reason", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user");
+        $params = compact("id", "module", "reason", "state", "desc", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user");
         Db::startTrans();
         try {
-            ApproveService::edit($id, $module, $params, $this->user);
+            ApproveService::make($id,$params, $this->user,'edit');
             Db::commit();
         } catch (Exception $e) {
             Db::rollback();

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

@@ -48,6 +48,8 @@ class Approveinfo extends Base
         $id = input('id');
         $module = input('module');
         $reason = input('reason');
+        $state = input('state');
+        $desc = input('desc');
         $start_time = input('start_time');
         $end_time = input('end_time');
         $document = input('document');
@@ -58,7 +60,7 @@ class Approveinfo extends Base
         $peer_user = input('peer_user');
         $approve_user = input('approve_user');
         $copy_user = input('copy_user');
-        $params = compact("module", "id", "reason", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user", "approve_user", "copy_user");
+        $params = compact("id", "module", "reason", "state", "desc", "start_time", "end_time", "document", "images", "type", "is_who", "remark", "peer_user", "approve_user", "copy_user");
         Db::startTrans();
         try {
             ApproveInfoService::create($id, $module, $params, $this->user);

+ 12 - 9
application/common/service/ApproveInfoService.php

@@ -40,7 +40,7 @@ class ApproveInfoService
             if (!$info) {
                 throw new Exception('申请记录不存在或已删除');
             }
-            if (!$info['module_info']) {
+            if (!$info->module_info) {
                 throw new Exception(CommonConstant::get_module_list()[$module] . '记录不存在或已删除');
             }
             if ($info->status != CommonConstant::STATUS_4) {
@@ -62,11 +62,13 @@ class ApproveInfoService
             'order_no' => $order_no,
             'apply_date' => date("Y-m-d"),
             'reason' => $params['reason'],
+            'state' => $params['state'],
+            'desc' => $params['desc'],
             'start_time' => $params['start_time'],
             'end_time' => $params['end_time'],
         ];
         if ($id > 0) {
-            // 编辑出差申请
+            // 编辑审批申请
             $save_data = [
                 'create_at' => date('Y-m-d H:i:s'),
             ];
@@ -105,11 +107,11 @@ class ApproveInfoService
         $data['is_who'] = $params['is_who'];
         $data['remark'] = $params['remark'];
         if ($type == 'update') {
-            $info->module_info->save($data);
+            $module_result = $info->module_info->save($data);
         } else {
             $models = CommonConstant::get_module_model_list();
             $model = $models[$module];
-            $module_data = $model::create($data);
+            $module_result = $model::create($data);
         }
 
         switch ($module) {
@@ -118,20 +120,20 @@ class ApproveInfoService
                 break;
         }
 
-        return $module_data;
+        return $module_result;
     }
 
     // 添加同行人员
     public static function create_peer_user($info_id, $params, $type)
     {
-        if (!$params) {
-            return true;
-        }
-
         if ($type == 'update') {
             ApproveEvectionPeerUser::where('info_id', $info_id)->delete();
         }
 
+        if (!$params) {
+            return true;
+        }
+
         $data = [];
         foreach ($params as $value) {
             $data[] = [
@@ -346,6 +348,7 @@ class ApproveInfoService
         if (!$info) {
             throw new Exception(CommonConstant::get_module_list()[$info->module] . '记录不存在或已删除');
         }
+
         switch ($type) {
             case 'urging':
                 if ($info->status != CommonConstant::STATUS_2) {

+ 41 - 9
application/common/service/ApproveService.php

@@ -147,15 +147,14 @@ class ApproveService
     }
 
     /**
-     * 审批
+     * 操作方法
      *
      * @param integer $id 审批ID
-     * @param string $status 审批状态
-     * @param string $remark 审批意见
+     * @param array $params 数组
      * @param mixed $user 用户信息
+     * @param string $type 类型:audit=审批,edit=修改
      **/
-    public static function audit($id, $status, $remark, $user)
-    {
+    public static function make($id,$params, $user,$type){
         $userid = $user['userid'];
         $info = Approve::field('id,info_id,status,approve_flow,approve_time')
             ->where('approve_user', $userid)
@@ -180,6 +179,26 @@ class ApproveService
             throw new Exception('非待处理状态无法操作!');
         }
 
+        switch ($type) {
+            case 'audit':
+                self::audit($info,$params['status'],$params['remark']);
+                break;
+            case 'edit':
+                self::edit($info,$params['module'],$params);
+                break;
+        }
+    }
+
+    /**
+     * 审批
+     *
+     * @param mixed $info 审批信息
+     * @param string $status 审批状态
+     * @param string $remark 审批意见
+     **/
+    public static function audit($info, $status, $remark)
+    {
+        $approve_info = $info->approve_info;
         $approve_time = date('Y-m-d H:i:s');
         $duration = time() - strtotime($info['approve_time']);
 
@@ -209,14 +228,27 @@ class ApproveService
     /**
      * 修改
      *
-     * @param integer $id 审批ID
+     * @param mixed $info 审批信息
      * @param integer $module 模块类型
      * @param array $params 数组
-     * @param mixed $user 用户信息
      **/
-    public static function edit($id, $module, $params, $user)
+    public static function edit($info, $module, $params)
     {
-        $userid = $user['userid'];
+        $approve_info = $info->approve_info;
+        $approve_info->module_info;
+
+        $data = [
+            'reason' => $params['reason'],
+            'state' => $params['state'],
+            'desc' => $params['desc'],
+            'start_time' => $params['start_time'],
+            'end_time' => $params['end_time'],
+        ];
+        // 编辑出差申请
+        $approve_info->save($data);
+
+        // 编辑对应模块
+        ApproveInfoService::create_module($approve_info->id, $module, $params, $approve_info, 'update');
     }
 
     /**