success('请求成功'); } //vocs public function vocs() { $req=$this->request->param(); Log::record($req); if($req[0]=='C'){ $time = date('Y/m/d H:i:s'); $res = [ 'data_txt_name' => trim(substr($req[1],strripos($req[1],'\\')+1)), 'name' => trim(substr($req[2],stripos($req[2],':')+1)), 'remak' => trim($req[3]), 'author' => trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))), 'line' => trim(substr($req[4],strripos($req[4],':')+1)), 'instrument' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))), 'position' => trim(substr($req[5],strripos($req[5],':')+1)), 'in_date' => trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))), 'in_times' => trim(substr($req[6],strripos($req[6],':')+1)), 'in_type' => trim(substr($req[7],stripos($req[7],':')+1)), 'gather_method' => trim(substr($req[8],stripos($req[8],':')+1)), 'update_date_one' => trim(substr($req[9],stripos($req[9],':')+1)), 'analysis_method' => trim(substr($req[10],stripos($req[10],':')+1)), 'update_date_two' => trim(substr($req[11],stripos($req[11],':')+1)), 'method_info' => trim(substr($req[12],stripos($req[12],':')+1)), 'sort' => trim(substr($req[13],stripos($req[13],':')+1)), 'check_data_time' => trim(substr($req[14],stripos($req[14],':')+1)), 'sample_product_factor' => trim(substr($req[15],strripos($req[15],':')+1)), 'dilution_factor' => trim(substr($req[16],strripos($req[16],':')+1)), 'signal_one' => trim(substr($req[17],stripos($req[17],':')+1)), 'create' => $time, ]; //查询记录是否存在 $bool = db()->table('gather_txt_gc')->where('remak',$res['remak'])->find(); if($bool){ return '已存在'; } //开启事务 db()->startTrans(); try { //连接数据库, 将数据插入主表vocs_gather_txt_gc取得pid $pid = db()->table('gather_txt_gc')->insertGetId($res); $row = []; $j = 0; for($i = 18; $i < count($req); $i++){ $str = trim($req[$i]); $arr = preg_split('/\s+/', $str); if (count($arr)==6){ $row[$j]['pid'] = $pid; $row[$j]['time'] = $arr[0]; $row[$j]['type'] = $arr[1]; $row[$j]['peak_area'] = $arr[2]; ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = $arr[3]; ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = $arr[4]; $row[$j]['chemical_compound'] = $arr[5]; $row[$j]['create'] = $time; }else{ $row[$j]['pid'] = $pid; $row[$j]['time'] = $arr[0]; $row[$j]['type'] = ''; $row[$j]['peak_area'] = $arr[1]; ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = $arr[2]; ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = $arr[3]; $row[$j]['chemical_compound'] = $arr[4]; $row[$j]['create'] = $time; } $j++; } //将检测数据插入子表vocs_gather_txt_check_gc db()->table('gather_txt_check_gc')->insertAll($row); //提交事务 db()->commit(); return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]); } catch (\Exception $e){ //失败回滚 db()->rollback(); Log::record($e->getMessage()); return $e->getMessage(); } }else{ $string = trim(substr($req[1],stripos($req[1],':')+1)); $bach = ''; if (preg_match('/\d+$/', $string, $matches)) { $bach = $matches[0]; } $name = str_replace($bach,'',$string); $time = date('Y/m/d H:i:s'); $res = [ 'data_txt_name' => trim(substr($req[2],strripos($req[2],':')+1)), 'name' => $name, 'bach' => $bach, 'gather_time' => trim(substr($req[3],stripos($req[3],':')+1)), 'data_txt_path' => trim(substr($req[4],stripos($req[4],':')+1)), 'ALS' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'样品乘积因子')-1-stripos($req[5],':'))), 'sample_product_factor' => trim(substr($req[5],strripos($req[5],':')+1)), 'author' => trim(substr($req[6],stripos($req[6],':')+1)), 'other' => trim(substr($req[7],stripos($req[7],':')+1)), 'title' => trim(substr($req[8],stripos($req[8],':')+1)), 'quantify_time' => trim(substr($req[9],stripos($req[9],':')+1)), 'quantify_method' => trim(substr($req[10],stripos($req[10],':')+1)), 'last_quantify_time' => trim(substr($req[11],stripos($req[11],':')+1)), 'response' => trim(substr($req[12],stripos($req[12],':')+1)), 'machine' => 1, 'create' => $time, ]; //查询记录是否存在 $bool = db()->table('gather_txt_gcms')->where('gather_time',$res['gather_time'])->find(); if($bool){ return '已存在'; } //开启事务 db()->startTrans(); try { //连接数据库, 将数据插入主表vocs_gather_txt_gc取得pid $pid = db()->table('gather_txt_gcms')->insertGetId($res); $row = []; $j = 0; for($i = 13; $i < count($req); $i++){ $str = trim($req[$i]); $arr = preg_split('/\s+/', $str); if (count($arr)==8){ $row[$j]['pid'] = $pid; $row[$j]['chemical_compound'] = $arr[1]; $row[$j]['persist_time'] = $arr[2]; $row[$j]['quantitative_ion'] = $arr[3]; $row[$j]['response_value'] = $arr[4]; $row[$j]['potency'] = $arr[5]; $row[$j]['unit'] = $arr[6]; $row[$j]['quanlitative_ion'] = $arr[7]; $row[$j]['create'] = $time; }else{ $row[$j]['pid'] = $pid; $row[$j]['chemical_compound'] = $arr[1]; $row[$j]['persist_time'] = $arr[2]; $row[$j]['quantitative_ion'] = $arr[3]; $row[$j]['response_value'] = $arr[3]; $row[$j]['potency'] = $arr[3]; $row[$j]['unit'] = $arr[3]; $row[$j]['quanlitative_ion'] = $arr[3]; $row[$j]['create'] = $time; } $j++; } //将检测数据插入子表vocs_gather_txt_check_gc $id = db()->table('gather_txt_check_gcms')->insertAll($row); //提交事务 db()->commit(); return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]); } catch (\Exception $e){ //失败回滚 db()->rollback(); Log::record($e->getMessage()); return $e->getMessage(); } } } }