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)); $res['name'] = trim(substr($req[2],stripos($req[2],':')+1)); $res['remak'] = trim($req[3]); $res['author'] = trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))); $res['line'] = trim(substr($req[4],strripos($req[4],':')+1)); $res['instrument'] = trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))); $res['position'] = trim(substr($req[5],strripos($req[5],':')+1)); $res['in_date'] = trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))); $res['in_times'] = trim(substr($req[6],strripos($req[6],':')+1)); $res['in_type'] = trim(substr($req[7],stripos($req[7],':')+1)); $num = 18; if(strpos($req[12], '方法信息') !== false){ if(strpos($req[13], '附加信息') !== false){ $num = 19; $res['gather_method'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['update_date_one'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['analysis_method'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['update_date_two'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['method_info'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['add_info'] = trim(mb_substr($req[13],5)); $res['sort'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['check_data_time'] = trim(substr($req[15],stripos($req[15],':')+1)); $res['sample_product_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['dilution_factor'] = trim(substr($req[17],strripos($req[17],':')+1)); $res['signal_one'] = trim(substr($req[18],stripos($req[18],':')+1)); }else{ $num = 18; $res['gather_method'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['update_date_one'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['analysis_method'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['update_date_two'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['method_info'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['sort'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['check_data_time'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['sample_product_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['dilution_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['signal_one'] = trim(substr($req[17],stripos($req[17],':')+1)); } }else{ if(strpos($req[13], '附加信息') !== false){ $num = 18; $res['sequence_file'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['method'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['update_date_two'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['method_info'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['add_info'] = trim(substr($req[12],5)); $res['sort'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['check_data_time'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['sample_product_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['dilution_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['signal_one'] = trim(substr($req[17],stripos($req[17],':')+1)); }else{ $num = 17; $res['sequence_file'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['method'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['update_date_two'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['method_info'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['sort'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['check_data_time'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['sample_product_factor'] = trim(substr($req[14],strripos($req[14],':')+1)); $res['dilution_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['signal_one'] = trim(substr($req[16],stripos($req[16],':')+1)); } } $res['create'] = $time; //查询记录是否存在 $bool = db()->name('gather_txt_gc')->where('data_txt_name',$res['data_txt_name'])->find(); if($bool){ return '已存在'; } //开启事务 db()->startTrans(); try { //连接数据库, 将数据插入主表gather_txt_gc取得pid $pid = db()->name('gather_txt_gc')->insertGetId($res); $row = []; $j = 0; for($i = $num; $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'] = floatval($arr[3]); ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($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'] = floatval($arr[2]); ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[3]); $row[$j]['chemical_compound'] = $arr[4]; $row[$j]['create'] = $time; } $j++; } //将检测数据插入子表gather_txt_check_gc db()->name('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()->name('gather_txt_gcms')->where('data_txt_name',$res['data_txt_name'])->find(); if($bool){ return '已存在'; } //开启事务 db()->startTrans(); try { //连接数据库, 将数据插入主表gather_txt_gc取得pid $pid = db()->name('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++; } //将检测数据插入子表gather_txt_check_gc $id = db()->name('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(); } } } /** * vocs * 修改 */ public function updateVocs() { $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)); $res['name'] = trim(substr($req[2],stripos($req[2],':')+1)); $res['remak'] = trim($req[3]); $res['author'] = trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))); $res['line'] = trim(substr($req[4],strripos($req[4],':')+1)); $res['instrument'] = trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))); $res['position'] = trim(substr($req[5],strripos($req[5],':')+1)); $res['in_date'] = trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))); $res['in_times'] = trim(substr($req[6],strripos($req[6],':')+1)); $res['in_type'] = trim(substr($req[7],stripos($req[7],':')+1)); $num = 18; if(strpos($req[12], '方法信息') !== false){ if(strpos($req[13], '附加信息') !== false){ $num = 19; $res['gather_method'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['update_date_one'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['analysis_method'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['update_date_two'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['method_info'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['add_info'] = trim(mb_substr($req[13],5)); $res['sort'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['check_data_time'] = trim(substr($req[15],stripos($req[15],':')+1)); $res['sample_product_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['dilution_factor'] = trim(substr($req[17],strripos($req[17],':')+1)); $res['signal_one'] = trim(substr($req[18],stripos($req[18],':')+1)); }else{ $num = 18; $res['gather_method'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['update_date_one'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['analysis_method'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['update_date_two'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['method_info'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['sort'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['check_data_time'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['sample_product_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['dilution_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['signal_one'] = trim(substr($req[17],stripos($req[17],':')+1)); } }else{ if(strpos($req[13], '附加信息') !== false){ $num = 18; $res['sequence_file'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['method'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['update_date_two'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['method_info'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['add_info'] = trim(substr($req[12],5)); $res['sort'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['check_data_time'] = trim(substr($req[14],stripos($req[14],':')+1)); $res['sample_product_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['dilution_factor'] = trim(substr($req[16],strripos($req[16],':')+1)); $res['signal_one'] = trim(substr($req[17],stripos($req[17],':')+1)); }else{ $num = 17; $res['sequence_file'] = trim(substr($req[8],stripos($req[8],':')+1)); $res['method'] = trim(substr($req[9],stripos($req[9],':')+1)); $res['update_date_two'] = trim(substr($req[10],stripos($req[10],':')+1)); $res['method_info'] = trim(substr($req[11],stripos($req[11],':')+1)); $res['sort'] = trim(substr($req[12],stripos($req[12],':')+1)); $res['check_data_time'] = trim(substr($req[13],stripos($req[13],':')+1)); $res['sample_product_factor'] = trim(substr($req[14],strripos($req[14],':')+1)); $res['dilution_factor'] = trim(substr($req[15],strripos($req[15],':')+1)); $res['signal_one'] = trim(substr($req[16],stripos($req[16],':')+1)); } } $res['create'] = $time; $id = db()->name('gather_txt_gc')->field('id')->where('data_txt_name',$res['data_txt_name'])->find(); if($id){ //开启事务 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(); //根据id新增子表数据 $row = []; $j = 0; for($i = $num; $i < count($req); $i++){ $str = trim($req[$i]); $arr = preg_split('/\s+/', $str); if (count($arr)==6){ $row[$j]['pid'] = $id['id']; $row[$j]['time'] = $arr[0]; $row[$j]['type'] = $arr[1]; $row[$j]['peak_area'] = $arr[2]; ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[3]); ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[4]); $row[$j]['chemical_compound'] = $arr[5]; $row[$j]['create'] = $time; }else{ $row[$j]['pid'] = $id['id']; $row[$j]['time'] = $arr[0]; $row[$j]['type'] = ''; $row[$j]['peak_area'] = $arr[1]; ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[2]); ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[3]); $row[$j]['chemical_compound'] = $arr[4]; $row[$j]['create'] = $time; } $j++; } //将检测数据插入子表gather_txt_check_gc db()->name('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{ return '找不到记录'; } }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, ]; $id = db()->name('gather_txt_gcms')->field('id')->where('data_txt_name',$res['data_txt_name'])->find(); if($id){ //开启事务 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(); //根据id新增子表数据 $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'] = $id['id']; $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'] = $id['id']; $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++; } //将检测数据插入子表gather_txt_check_gc db()->name('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(); } }else{ return '找不到记录'; } } } }