| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- <?php
- namespace app\api\controller;
- use think\Log;
- use app\common\controller\Api;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $this->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()->name('gather_txt_gc')->where('remak',$res['remak'])->find();
- if($bool){
- return '已存在';
- }
- //开启事务
- db()->startTrans();
- try {
- //连接数据库, 将数据插入主表gather_txt_gc取得pid
- $pid = db()->name('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'] = 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('gather_time',$res['gather_time'])->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)),
- '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,
- ];
- $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 = 18; $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 '找不到记录';
- }
- }
- }
- }
|