瀏覽代碼

Merge branch 'master' of https://gitee.com/huangsanjia/qua-vocs.com

liuhairui 2 年之前
父節點
當前提交
1d2e5b9a33
共有 1 個文件被更改,包括 65 次插入26 次删除
  1. 65 26
      application/api/controller/Index.php

+ 65 - 26
application/api/controller/Index.php

@@ -33,7 +33,12 @@ class Index extends Api
 
         $time = date('Y/m/d H:i:s');
         $rows = $req;
-        if($req[0]=='C'){
+        $lx = explode(',',$req[0]);
+        if(count($lx)>1){
+            $res['company'] = $lx[1];
+            $res['machine_no'] = $lx[2];
+        }
+        if($lx[0]=='C'){
             //查询匹配主表数据
             foreach($rows as $k=>$v){
                 preg_match('/数据文件/', $v, $matches);
@@ -571,7 +576,12 @@ class Index extends Api
 
         $time = date('Y/m/d H:i:s');
         $rows = $req;
-        if($req[0]=='C'){
+        $lx = explode(',',$req[0]);
+        if(count($lx)>1){
+            $res['company'] = $lx[1];
+            $res['machine_no'] = $lx[2];
+        }
+        if($lx[0]=='C'){
             //查询匹配主表数据
             foreach($rows as $k=>$v){
                 preg_match('/数据文件/', $v, $matches);
@@ -760,20 +770,34 @@ class Index extends Api
                     break;
                 }
             }
+            $res['machine'] = 'GC';
             $res['create'] = $time;
 
-            $id = db()->name('gather_txt_gc')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
+            //查询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();
+            }
 
-            if($id){
+            //查询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){
                 //开启事务
                 db()->startTrans();
                 try {
-                    //根据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();
-
+                    //新增
+                    $pid = db()->name('gather_txt_gc')->insertGetId($res);
+                    if($pid){
                         //获取子表开始结束索引
                         $srart = $end = 0;
                         $rows = array_values($rows);
@@ -808,7 +832,7 @@ class Index extends Api
                         $row = [];
                         foreach ($arr as $k=>$v){
                             if (count($v)==6){
-                                $row[$k]['pid'] = $id['id'];
+                                $row[$k]['pid'] = $pid;
                                 $row[$k]['time'] = $v[0];
                                 $row[$k]['type'] = $v[1];
                                 $row[$k]['peak_area'] = $v[2];
@@ -829,7 +853,7 @@ class Index extends Api
                                 }
                                 $row[$k]['create'] = $time;
                             }else{
-                                $row[$k]['pid'] = $id['id'];
+                                $row[$k]['pid'] = $pid;
                                 $row[$k]['time'] = $v[0];
                                 $row[$k]['type'] = '';
                                 ($v[1] == '-')?$row[$k]['peak_area'] = '-':$row[$k]['peak_area'] = floatval($v[1]);
@@ -863,13 +887,13 @@ class Index extends Api
 
                         //提交事务
                         db()->commit();
-                        Log::record(['成功'=>'样品编号为'.$res['data_txt_name'].'数据插入成功']);
+                        Log::record(['成功'=>'样品编号为'.$res['data_txt_name'].'数据修改成功']);
                         return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
                     }
                 } catch (\Exception $e){
                     //失败回滚
                     db()->rollback();
-                    Log::record(['失败'=>'样品编号为'.$res['data_txt_name'].'数据插入失败','原因'=>$e->getMessage()]);
+                    Log::record(['失败'=>'样品编号为'.$res['data_txt_name'].'数据修改失败','原因'=>$e->getMessage()]);
                     return $e->getMessage();
                 }
             }else{
@@ -982,19 +1006,34 @@ class Index extends Api
                     break;
                 }
             }
+            $res['machine'] = 'GCMS';
             $res['create'] = $time;
 
-            $id = db()->name('gather_txt_gcms')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
-            if($id){
+            //查询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){
                 //开启事务
                 db()->startTrans();
                 try {
-                    //根据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();
-
+                    //新增
+                    $pid = db()->name('gather_txt_gcms')->insertGetId($res);
+                    if($pid) {
                         //获取子表开始结束索引
                         $srart = $end = 0;
                         $rows = array_values($rows);
@@ -1029,7 +1068,7 @@ class Index extends Api
                         $row = [];
                         foreach ($arr as $k=>$v){
                             if (count($v)==8){
-                                $row[$k]['pid'] = $id['id'];
+                                $row[$k]['pid'] = $pid;
                                 $row[$k]['chemical_compound'] = $v[1];
                                 $row[$k]['persist_time'] = $v[2];
                                 $row[$k]['quantitative_ion'] = $v[3];
@@ -1047,7 +1086,7 @@ class Index extends Api
                                 $row[$k]['quanlitative_ion'] = $v[7];
                                 $row[$k]['create'] = $time;
                             }else{
-                                $row[$k]['pid'] = $id['id'];
+                                $row[$k]['pid'] = $pid;
                                 $row[$k]['chemical_compound'] = $v[1];
                                 $row[$k]['persist_time'] = $v[2];
                                 $row[$k]['quantitative_ion'] = $v[3];
@@ -1071,13 +1110,13 @@ class Index extends Api
 
                         //提交事务
                         db()->commit();
-                        Log::record(['成功'=>'样品编号为'.$res['data_txt_name'].'数据插入成功']);
+                        Log::record(['成功'=>'样品编号为'.$res['data_txt_name'].'数据修改成功']);
                         return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
                     }
                 } catch (\Exception $e){
                     //失败回滚
                     db()->rollback();
-                    Log::record(['失败'=>'样品编号为'.$res['data_txt_name'].'数据插入失败','原因'=>$e->getMessage()]);
+                    Log::record(['失败'=>'样品编号为'.$res['data_txt_name'].'数据修改失败','原因'=>$e->getMessage()]);
                     return $e->getMessage();
                 }
             }else{