Index.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\api\controller;
  3. use think\Log;
  4. use app\common\controller\Api;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. //vocs
  21. public function vocs()
  22. {
  23. $req=$this->request->param();
  24. Log::record($req);
  25. if($req[0]=='C'){
  26. $time = date('Y/m/d H:i:s');
  27. $res = [
  28. 'data_txt_name' => trim(substr($req[1],strripos($req[1],'\\')+1)),
  29. 'name' => trim(substr($req[2],stripos($req[2],':')+1)),
  30. 'remak' => trim($req[3]),
  31. 'author' => trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))),
  32. 'line' => trim(substr($req[4],strripos($req[4],':')+1)),
  33. 'instrument' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))),
  34. 'position' => trim(substr($req[5],strripos($req[5],':')+1)),
  35. 'in_date' => trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))),
  36. 'in_times' => trim(substr($req[6],strripos($req[6],':')+1)),
  37. 'in_type' => trim(substr($req[7],stripos($req[7],':')+1)),
  38. 'gather_method' => trim(substr($req[8],stripos($req[8],':')+1)),
  39. 'update_date_one' => trim(substr($req[9],stripos($req[9],':')+1)),
  40. 'analysis_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  41. 'update_date_two' => trim(substr($req[11],stripos($req[11],':')+1)),
  42. 'method_info' => trim(substr($req[12],stripos($req[12],':')+1)),
  43. 'sort' => trim(substr($req[13],stripos($req[13],':')+1)),
  44. 'check_data_time' => trim(substr($req[14],stripos($req[14],':')+1)),
  45. 'sample_product_factor' => trim(substr($req[15],strripos($req[15],':')+1)),
  46. 'dilution_factor' => trim(substr($req[16],strripos($req[16],':')+1)),
  47. 'signal_one' => trim(substr($req[17],stripos($req[17],':')+1)),
  48. 'create' => $time,
  49. ];
  50. //查询记录是否存在
  51. $bool = db()->table('gather_txt_gc')->where('remak',$res['remak'])->find();
  52. if($bool){
  53. return '已存在';
  54. }
  55. //开启事务
  56. db()->startTrans();
  57. try {
  58. //连接数据库, 将数据插入主表vocs_gather_txt_gc取得pid
  59. $pid = db()->table('gather_txt_gc')->insertGetId($res);
  60. $row = [];
  61. $j = 0;
  62. for($i = 18; $i < count($req); $i++){
  63. $str = trim($req[$i]);
  64. $arr = preg_split('/\s+/', $str);
  65. if (count($arr)==6){
  66. $row[$j]['pid'] = $pid;
  67. $row[$j]['time'] = $arr[0];
  68. $row[$j]['type'] = $arr[1];
  69. $row[$j]['peak_area'] = $arr[2];
  70. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = $arr[3];
  71. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = $arr[4];
  72. $row[$j]['chemical_compound'] = $arr[5];
  73. $row[$j]['create'] = $time;
  74. }else{
  75. $row[$j]['pid'] = $pid;
  76. $row[$j]['time'] = $arr[0];
  77. $row[$j]['type'] = '';
  78. $row[$j]['peak_area'] = $arr[1];
  79. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = $arr[2];
  80. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = $arr[3];
  81. $row[$j]['chemical_compound'] = $arr[4];
  82. $row[$j]['create'] = $time;
  83. }
  84. $j++;
  85. }
  86. //将检测数据插入子表vocs_gather_txt_check_gc
  87. db()->table('gather_txt_check_gc')->insertAll($row);
  88. //提交事务
  89. db()->commit();
  90. return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]);
  91. } catch (\Exception $e){
  92. //失败回滚
  93. db()->rollback();
  94. Log::record($e->getMessage());
  95. return $e->getMessage();
  96. }
  97. }else{
  98. $string = trim(substr($req[1],stripos($req[1],':')+1));
  99. $bach = '';
  100. if (preg_match('/\d+$/', $string, $matches)) {
  101. $bach = $matches[0];
  102. }
  103. $name = str_replace($bach,'',$string);
  104. $time = date('Y/m/d H:i:s');
  105. $res = [
  106. 'data_txt_name' => trim(substr($req[2],strripos($req[2],':')+1)),
  107. 'name' => $name,
  108. 'bach' => $bach,
  109. 'gather_time' => trim(substr($req[3],stripos($req[3],':')+1)),
  110. 'data_txt_path' => trim(substr($req[4],stripos($req[4],':')+1)),
  111. 'ALS' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'样品乘积因子')-1-stripos($req[5],':'))),
  112. 'sample_product_factor' => trim(substr($req[5],strripos($req[5],':')+1)),
  113. 'author' => trim(substr($req[6],stripos($req[6],':')+1)),
  114. 'other' => trim(substr($req[7],stripos($req[7],':')+1)),
  115. 'title' => trim(substr($req[8],stripos($req[8],':')+1)),
  116. 'quantify_time' => trim(substr($req[9],stripos($req[9],':')+1)),
  117. 'quantify_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  118. 'last_quantify_time' => trim(substr($req[11],stripos($req[11],':')+1)),
  119. 'response' => trim(substr($req[12],stripos($req[12],':')+1)),
  120. 'machine' => 1,
  121. 'create' => $time,
  122. ];
  123. //查询记录是否存在
  124. $bool = db()->table('gather_txt_gcms')->where('gather_time',$res['gather_time'])->find();
  125. if($bool){
  126. return '已存在';
  127. }
  128. //开启事务
  129. db()->startTrans();
  130. try {
  131. //连接数据库, 将数据插入主表vocs_gather_txt_gc取得pid
  132. $pid = db()->table('gather_txt_gcms')->insertGetId($res);
  133. $row = [];
  134. $j = 0;
  135. for($i = 13; $i < count($req); $i++){
  136. $str = trim($req[$i]);
  137. $arr = preg_split('/\s+/', $str);
  138. if (count($arr)==8){
  139. $row[$j]['pid'] = $pid;
  140. $row[$j]['chemical_compound'] = $arr[1];
  141. $row[$j]['persist_time'] = $arr[2];
  142. $row[$j]['quantitative_ion'] = $arr[3];
  143. $row[$j]['response_value'] = $arr[4];
  144. $row[$j]['potency'] = $arr[5];
  145. $row[$j]['unit'] = $arr[6];
  146. $row[$j]['quanlitative_ion'] = $arr[7];
  147. $row[$j]['create'] = $time;
  148. }else{
  149. $row[$j]['pid'] = $pid;
  150. $row[$j]['chemical_compound'] = $arr[1];
  151. $row[$j]['persist_time'] = $arr[2];
  152. $row[$j]['quantitative_ion'] = $arr[3];
  153. $row[$j]['response_value'] = $arr[3];
  154. $row[$j]['potency'] = $arr[3];
  155. $row[$j]['unit'] = $arr[3];
  156. $row[$j]['quanlitative_ion'] = $arr[3];
  157. $row[$j]['create'] = $time;
  158. }
  159. $j++;
  160. }
  161. //将检测数据插入子表vocs_gather_txt_check_gc
  162. $id = db()->table('gather_txt_check_gcms')->insertAll($row);
  163. //提交事务
  164. db()->commit();
  165. return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]);
  166. } catch (\Exception $e){
  167. //失败回滚
  168. db()->rollback();
  169. Log::record($e->getMessage());
  170. return $e->getMessage();
  171. }
  172. }
  173. }
  174. }