浏览代码

回到以前版本(修改不删除)

曹鹤洋 2 年之前
父节点
当前提交
24fb602318
共有 1 个文件被更改,包括 20 次插入47 次删除
  1. 20 47
      application/api/controller/Index.php

+ 20 - 47
application/api/controller/Index.php

@@ -773,31 +773,18 @@ class Index extends Api
             $res['machine'] = 'GC';
             $res['create'] = $time;
 
-            //查询gc表
-            $id1 = db()->name('gather_txt_gc')->where('data_txt_name',$res['data_txt_name'])->find();
-            if($id1){
-                //删除gc表
-                db()->name('gather_txt_gc')->where('data_txt_name',$res['data_txt_name'])->delete();
-                //删除子表
-                db()->name('gather_txt_check_gc')->where('pid',$id1['id'])->delete();
-            }
-
-            //查询gcms表
-            $id2 = db()->name('gather_txt_gcms')->where('data_txt_name',$res['data_txt_name'])->find();
-            if($id2){
-                //删除gcms表
-                db()->name('gather_txt_gcms')->where('data_txt_name',$res['data_txt_name'])->delete();
-                //删除子表
-                db()->name('gather_txt_check_gcms')->where('pid',$id2['id'])->delete();
-            }
+            $id = db()->name('gather_txt_gc')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
 
-            if($id1 || $id2){
+            if($id){
                 //开启事务
                 db()->startTrans();
                 try {
-                    //新增
-                    $pid = db()->name('gather_txt_gc')->insertGetId($res);
-                    if($pid){
+                    //根据id修改主表数据
+                    $bool = db()->name('gather_txt_gc')->where('id',$id['id'])->update($res);
+                    if($bool){
+                        //根据pid删除子表数据
+                        db()->name('gather_txt_check_gc')->where('pid',$id['id'])->delete();
+
                         //获取子表开始结束索引
                         $srart = $end = 0;
                         $rows = array_values($rows);
@@ -832,7 +819,7 @@ class Index extends Api
                         $row = [];
                         foreach ($arr as $k=>$v){
                             if (count($v)==6){
-                                $row[$k]['pid'] = $pid;
+                                $row[$k]['pid'] = $id['id'];
                                 $row[$k]['time'] = $v[0];
                                 $row[$k]['type'] = $v[1];
                                 $row[$k]['peak_area'] = $v[2];
@@ -853,7 +840,7 @@ class Index extends Api
                                 }
                                 $row[$k]['create'] = $time;
                             }else{
-                                $row[$k]['pid'] = $pid;
+                                $row[$k]['pid'] = $id['id'];
                                 $row[$k]['time'] = $v[0];
                                 $row[$k]['type'] = '';
                                 ($v[1] == '-')?$row[$k]['peak_area'] = '-':$row[$k]['peak_area'] = floatval($v[1]);
@@ -1009,31 +996,17 @@ class Index extends Api
             $res['machine'] = 'GCMS';
             $res['create'] = $time;
 
-            //查询gc表
-            $id1 = db()->name('gather_txt_gc')->where('data_txt_name',$res['data_txt_name'])->find();
-            if($id1){
-                //删除gc表
-                db()->name('gather_txt_gc')->where('data_txt_name',$res['data_txt_name'])->delete();
-                //删除子表
-                db()->name('gather_txt_check_gc')->where('pid',$id1['id'])->delete();
-            }
-
-            //查询gcms表
-            $id2 = db()->name('gather_txt_gcms')->where('data_txt_name',$res['data_txt_name'])->find();
-            if($id2){
-                //删除gcms表
-                db()->name('gather_txt_gcms')->where('data_txt_name',$res['data_txt_name'])->delete();
-                //删除子表
-                db()->name('gather_txt_check_gcms')->where('pid',$id2['id'])->delete();
-            }
-
-            if($id1 || $id2){
+            $id = db()->name('gather_txt_gcms')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
+            if($id){
                 //开启事务
                 db()->startTrans();
                 try {
-                    //新增
-                    $pid = db()->name('gather_txt_gcms')->insertGetId($res);
-                    if($pid) {
+                    //根据id修改主表数据
+                    $bool = db()->name('gather_txt_gcms')->where('id',$id['id'])->update($res);
+                    if($bool) {
+                        //根据pid删除子表数据
+                        db()->name('gather_txt_check_gcms')->where('pid', $id['id'])->delete();
+
                         //获取子表开始结束索引
                         $srart = $end = 0;
                         $rows = array_values($rows);
@@ -1068,7 +1041,7 @@ class Index extends Api
                         $row = [];
                         foreach ($arr as $k=>$v){
                             if (count($v)==8){
-                                $row[$k]['pid'] = $pid;
+                                $row[$k]['pid'] = $id['id'];
                                 $row[$k]['chemical_compound'] = $v[1];
                                 $row[$k]['persist_time'] = $v[2];
                                 $row[$k]['quantitative_ion'] = $v[3];
@@ -1086,7 +1059,7 @@ class Index extends Api
                                 $row[$k]['quanlitative_ion'] = $v[7];
                                 $row[$k]['create'] = $time;
                             }else{
-                                $row[$k]['pid'] = $pid;
+                                $row[$k]['pid'] = $id['id'];
                                 $row[$k]['chemical_compound'] = $v[1];
                                 $row[$k]['persist_time'] = $v[2];
                                 $row[$k]['quantitative_ion'] = $v[3];