فهرست منبع

作废某个离职单子后,对应的待办数据也要删除

wufeng 2 سال پیش
والد
کامیت
943977f6a7
1فایلهای تغییر یافته به همراه50 افزوده شده و 12 حذف شده
  1. 50 12
      app/admin/controller/Resigninfo.php

+ 50 - 12
app/admin/controller/Resigninfo.php

@@ -3,8 +3,10 @@
 namespace app\admin\controller;
 
 use app\admin\model\ProcessOrder;
+use app\admin\model\ProcessWait;
 use app\BaseController;
 use think\App;
+use think\Exception;
 use think\facade\Db;
 use app\admin\model\ActionLog;
 
@@ -182,19 +184,55 @@ class Resigninfo extends Base
       }
     }
     public function del(){
-        $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
-        $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
-        if($fid==false){
-            return error_show(1002,"离职人员不存在");
-        }
-        $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
-        if($num){
-            $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
-            ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
-            return error_show(0,"删除成功");
-        }else{
-            return error_show(1002,"删除失败");
+
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
+
+        $fid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->find();
+
+        if ($fid == false) return error_show(1002, "离职人员不存在");
+
+        Db::startTrans();
+
+        try {
+            $num = Db::name('resign_info')
+                ->where(['is_del' => 0, 'id' => $id])
+                ->update(['is_del' => 1, 'id' => $id, "updatetime" => date("Y-m-d H:i:s")]);
+            if ($num) {
+                $stn = ["order_code" => "BH", "status" => 0, "action_remark" => '', "action_type" => "delete"];
+                ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
+
+                //将对应的离职交接单流程的数据都删掉(没有相关的中断节点,所以这里直接操作process_wait表)
+                Db::name('process_wait')
+                    ->where([
+                        'order_type' => 'LZJJ',
+                        'order_id' => $id,
+                        'status' => ProcessWait::$status_wait,
+                    ])->update(['status' => ProcessWait::$status_interrupt]);
+
+                Db::commit();
+                return app_show(0, "删除成功");
+            } else throw new Exception("删除失败");
+
+        } catch (Exception $exception) {
+            Db::rollback();
+
+            return error_show(1004, $exception->getMessage());
         }
+
+
+//        $id = isset($this->post['id']) && $this->post['id'] !=="" ? $this->post['id']:"";
+//        $fid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
+//        if($fid==false){
+//            return error_show(1002,"离职人员不存在");
+//        }
+//        $num = Db::name('resign_info')->update(['is_del'=>1,'id'=>$id,"updatetime"=>date("Y-m-d H:i:s")]);
+//        if($num){
+//            $stn = ["order_code"=>"BH","status"=>0,"action_remark"=>'',"action_type"=>"delete"];
+//            ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
+//            return error_show(0,"删除成功");
+//        }else{
+//            return error_show(1002,"删除失败");
+//        }
     }
     public function statu(){
         $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";