cqp 4 недель назад
Родитель
Сommit
5c74891b25
3 измененных файлов с 42 добавлено и 9 удалено
  1. 1 0
      app/Model/Draft.php
  2. 8 4
      app/Service/ItemService.php
  3. 33 5
      app/Service/WorkFlowService.php

+ 1 - 0
app/Model/Draft.php

@@ -19,5 +19,6 @@ class Draft extends DataScopeBaseModel
      */
     protected $casts = [
         'content' => 'array', // 声明 content 字段读取时自动转为数组
+        'user' => 'array', // 声明 content 字段读取时自动转为数组
     ];
 }

+ 8 - 4
app/Service/ItemService.php

@@ -217,11 +217,15 @@ class ItemService extends Service
         return [true, ''];
     }
 
-    public function itemEdit($data,$user){
+    public function itemEdit($data, $user){
         list($status,$msg) = $this->itemRule($data, $user, false);
         if(!$status) return [$status,$msg];
-        $origin_data = $msg;
 
+        list($status, $msg) = $this->itemEditSave($data, $user);
+        return [$status, $msg];
+    }
+
+    public function itemEditSave($data, $user){
         try {
             DB::beginTransaction();
 
@@ -230,7 +234,7 @@ class ItemService extends Service
 
             if(isset($data['draft'])){
                 // 创建草稿
-                $this->createDraft($origin_data, $user, $tableName);
+                $this->createDraft($data, $user, $tableName);
                 // 更新项目状态
                 $model->approval_state = Item::TYPE_MINUS_ONE;
                 $model->save();
@@ -860,7 +864,7 @@ class ItemService extends Service
             }
         }
 
-        return [true, $origin_data];
+        return [true, ''];
     }
 
     public function fillData($data){

+ 33 - 5
app/Service/WorkFlowService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Model\Draft;
 use App\Model\Employee;
 use App\Model\SysMenu;
 use App\Model\WorkFlowInstances;
@@ -295,16 +296,43 @@ class WorkFlowService extends Service
         list($status, $msg, $result) = $this->approve($data, $user);
         if(! $status) return [false, $msg];
 
-        $instance_id = $msg;
-        if($result == 1){
-
-        }elseif ($result == 2){
-
+        if($result == 1 || $result == 2){
+            $instance_id = $msg;
+            $this->businessSettle($result, $instance_id);
         }
 
         return [true, ''];
     }
 
+    public function businessSettle($result, $instance_id){
+        $w = WorkFlowInstances::where('id', $instance_id)->first();
+        if(empty($w)) return;
+        $w = $w->toArray();
+
+        if($result == 1){
+            $draft = Draft::where('del_time',0)
+                ->where('document_type', $w['document_type'])
+                ->where('document_id', $w['document_id'])
+                ->where('top_depart_id', $w['top_depart_id'])
+                ->latest()
+                ->first();
+            if(! empty($draft)){
+                $draft = $draft->toArray();
+                if($draft['opt_type'] == 1){
+                    //调用编辑接口 覆盖数据
+                    if($draft['document_type'] == 'item'){
+                        (new ItemService())->itemEditSave($draft['content'], $draft['user']);
+                    }
+                }else{
+                    //单纯更新某个字段
+                }
+            }
+        }else{
+            //审核状态标记改回去
+            DB::table($w['document_type'])->where('id', $w['document_id'])->update(['approval_state' => 0]);
+        }
+    }
+
     /**
      * @param int $nodeInstanceId 节点实例ID
      * @param int $status 结果:2-通过,3-驳回