Index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. /**
  21. * vocs
  22. * 创建
  23. */
  24. public function vocs()
  25. {
  26. $req=$this->request->param();
  27. Log::record($req);
  28. if($req[0]=='C'){
  29. $time = date('Y/m/d H:i:s');
  30. $res = [
  31. 'data_txt_name' => trim(substr($req[1],strripos($req[1],'\\')+1)),
  32. 'name' => trim(substr($req[2],stripos($req[2],':')+1)),
  33. 'remak' => trim($req[3]),
  34. 'author' => trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))),
  35. 'line' => trim(substr($req[4],strripos($req[4],':')+1)),
  36. 'instrument' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))),
  37. 'position' => trim(substr($req[5],strripos($req[5],':')+1)),
  38. 'in_date' => trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))),
  39. 'in_times' => trim(substr($req[6],strripos($req[6],':')+1)),
  40. 'in_type' => trim(substr($req[7],stripos($req[7],':')+1)),
  41. 'gather_method' => trim(substr($req[8],stripos($req[8],':')+1)),
  42. 'update_date_one' => trim(substr($req[9],stripos($req[9],':')+1)),
  43. 'analysis_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  44. 'update_date_two' => trim(substr($req[11],stripos($req[11],':')+1)),
  45. 'method_info' => trim(substr($req[12],stripos($req[12],':')+1)),
  46. 'sort' => trim(substr($req[13],stripos($req[13],':')+1)),
  47. 'check_data_time' => trim(substr($req[14],stripos($req[14],':')+1)),
  48. 'sample_product_factor' => trim(substr($req[15],strripos($req[15],':')+1)),
  49. 'dilution_factor' => trim(substr($req[16],strripos($req[16],':')+1)),
  50. 'signal_one' => trim(substr($req[17],stripos($req[17],':')+1)),
  51. 'create' => $time,
  52. ];
  53. //查询记录是否存在
  54. $bool = db()->name('gather_txt_gc')->where('remak',$res['remak'])->find();
  55. if($bool){
  56. return '已存在';
  57. }
  58. //开启事务
  59. db()->startTrans();
  60. try {
  61. //连接数据库, 将数据插入主表gather_txt_gc取得pid
  62. $pid = db()->name('gather_txt_gc')->insertGetId($res);
  63. $row = [];
  64. $j = 0;
  65. for($i = 18; $i < count($req); $i++){
  66. $str = trim($req[$i]);
  67. $arr = preg_split('/\s+/', $str);
  68. if (count($arr)==6){
  69. $row[$j]['pid'] = $pid;
  70. $row[$j]['time'] = $arr[0];
  71. $row[$j]['type'] = $arr[1];
  72. $row[$j]['peak_area'] = $arr[2];
  73. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[3]);
  74. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[4]);
  75. $row[$j]['chemical_compound'] = $arr[5];
  76. $row[$j]['create'] = $time;
  77. }else{
  78. $row[$j]['pid'] = $pid;
  79. $row[$j]['time'] = $arr[0];
  80. $row[$j]['type'] = '';
  81. $row[$j]['peak_area'] = $arr[1];
  82. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[2]);
  83. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[3]);
  84. $row[$j]['chemical_compound'] = $arr[4];
  85. $row[$j]['create'] = $time;
  86. }
  87. $j++;
  88. }
  89. //将检测数据插入子表gather_txt_check_gc
  90. db()->name('gather_txt_check_gc')->insertAll($row);
  91. //提交事务
  92. db()->commit();
  93. return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]);
  94. } catch (\Exception $e){
  95. //失败回滚
  96. db()->rollback();
  97. Log::record($e->getMessage());
  98. return $e->getMessage();
  99. }
  100. }else{
  101. $string = trim(substr($req[1],stripos($req[1],':')+1));
  102. $bach = '';
  103. if (preg_match('/\d+$/', $string, $matches)) {
  104. $bach = $matches[0];
  105. }
  106. $name = str_replace($bach,'',$string);
  107. $time = date('Y/m/d H:i:s');
  108. $res = [
  109. 'data_txt_name' => trim(substr($req[2],strripos($req[2],':')+1)),
  110. 'name' => $name,
  111. 'bach' => $bach,
  112. 'gather_time' => trim(substr($req[3],stripos($req[3],':')+1)),
  113. 'data_txt_path' => trim(substr($req[4],stripos($req[4],':')+1)),
  114. 'ALS' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'样品乘积因子')-1-stripos($req[5],':'))),
  115. 'sample_product_factor' => trim(substr($req[5],strripos($req[5],':')+1)),
  116. 'author' => trim(substr($req[6],stripos($req[6],':')+1)),
  117. 'other' => trim(substr($req[7],stripos($req[7],':')+1)),
  118. 'title' => trim(substr($req[8],stripos($req[8],':')+1)),
  119. 'quantify_time' => trim(substr($req[9],stripos($req[9],':')+1)),
  120. 'quantify_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  121. 'last_quantify_time' => trim(substr($req[11],stripos($req[11],':')+1)),
  122. 'response' => trim(substr($req[12],stripos($req[12],':')+1)),
  123. 'machine' => 1,
  124. 'create' => $time,
  125. ];
  126. //查询记录是否存在
  127. $bool = db()->name('gather_txt_gcms')->where('gather_time',$res['gather_time'])->find();
  128. if($bool){
  129. return '已存在';
  130. }
  131. //开启事务
  132. db()->startTrans();
  133. try {
  134. //连接数据库, 将数据插入主表gather_txt_gc取得pid
  135. $pid = db()->name('gather_txt_gcms')->insertGetId($res);
  136. $row = [];
  137. $j = 0;
  138. for($i = 13; $i < count($req); $i++){
  139. $str = trim($req[$i]);
  140. $arr = preg_split('/\s+/', $str);
  141. if (count($arr)==8){
  142. $row[$j]['pid'] = $pid;
  143. $row[$j]['chemical_compound'] = $arr[1];
  144. $row[$j]['persist_time'] = $arr[2];
  145. $row[$j]['quantitative_ion'] = $arr[3];
  146. $row[$j]['response_value'] = $arr[4];
  147. $row[$j]['potency'] = $arr[5];
  148. $row[$j]['unit'] = $arr[6];
  149. $row[$j]['quanlitative_ion'] = $arr[7];
  150. $row[$j]['create'] = $time;
  151. }else{
  152. $row[$j]['pid'] = $pid;
  153. $row[$j]['chemical_compound'] = $arr[1];
  154. $row[$j]['persist_time'] = $arr[2];
  155. $row[$j]['quantitative_ion'] = $arr[3];
  156. $row[$j]['response_value'] = $arr[3];
  157. $row[$j]['potency'] = $arr[3];
  158. $row[$j]['unit'] = $arr[3];
  159. $row[$j]['quanlitative_ion'] = $arr[3];
  160. $row[$j]['create'] = $time;
  161. }
  162. $j++;
  163. }
  164. //将检测数据插入子表gather_txt_check_gc
  165. $id = db()->name('gather_txt_check_gcms')->insertAll($row);
  166. //提交事务
  167. db()->commit();
  168. return json_encode(['code'=>'0','msg'=>'成功','time'=>$time,'data'=>[$res,$row]]);
  169. } catch (\Exception $e){
  170. //失败回滚
  171. db()->rollback();
  172. Log::record($e->getMessage());
  173. return $e->getMessage();
  174. }
  175. }
  176. }
  177. /**
  178. * vocs
  179. * 修改
  180. */
  181. public function updateVocs()
  182. {
  183. $req=$this->request->param();
  184. Log::record($req);
  185. if($req[0]=='C'){
  186. $time = date('Y/m/d H:i:s');
  187. $res = [
  188. 'data_txt_name' => trim(substr($req[1],strripos($req[1],'\\')+1)),
  189. 'name' => trim(substr($req[2],stripos($req[2],':')+1)),
  190. 'remak' => trim($req[3]),
  191. 'author' => trim(substr($req[4],stripos($req[4],':')+1,strripos($req[4],'序列号')-1-stripos($req[4],':'))),
  192. 'line' => trim(substr($req[4],strripos($req[4],':')+1)),
  193. 'instrument' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'位置')-1-stripos($req[5],':'))),
  194. 'position' => trim(substr($req[5],strripos($req[5],':')+1)),
  195. 'in_date' => trim(substr($req[6],stripos($req[6],':')+1,strripos($req[6],'进样次数')-1-stripos($req[6],':'))),
  196. 'in_times' => trim(substr($req[6],strripos($req[6],':')+1)),
  197. 'in_type' => trim(substr($req[7],stripos($req[7],':')+1)),
  198. 'gather_method' => trim(substr($req[8],stripos($req[8],':')+1)),
  199. 'update_date_one' => trim(substr($req[9],stripos($req[9],':')+1)),
  200. 'analysis_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  201. 'update_date_two' => trim(substr($req[11],stripos($req[11],':')+1)),
  202. 'method_info' => trim(substr($req[12],stripos($req[12],':')+1)),
  203. 'sort' => trim(substr($req[13],stripos($req[13],':')+1)),
  204. 'check_data_time' => trim(substr($req[14],stripos($req[14],':')+1)),
  205. 'sample_product_factor' => trim(substr($req[15],strripos($req[15],':')+1)),
  206. 'dilution_factor' => trim(substr($req[16],strripos($req[16],':')+1)),
  207. 'signal_one' => trim(substr($req[17],stripos($req[17],':')+1)),
  208. 'create' => $time,
  209. ];
  210. $id = db()->name('gather_txt_gc')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
  211. if($id){
  212. //开启事务
  213. db()->startTrans();
  214. try {
  215. //根据id修改主表数据
  216. $bool = db()->name('gather_txt_gc')->where('id',$id['id'])->update($res);
  217. if($bool){
  218. //根据pid删除子表数据
  219. db()->name('gather_txt_check_gc')->where('pid',$id['id'])->delete();
  220. //根据id新增子表数据
  221. $row = [];
  222. $j = 0;
  223. for($i = 18; $i < count($req); $i++){
  224. $str = trim($req[$i]);
  225. $arr = preg_split('/\s+/', $str);
  226. if (count($arr)==6){
  227. $row[$j]['pid'] = $id['id'];
  228. $row[$j]['time'] = $arr[0];
  229. $row[$j]['type'] = $arr[1];
  230. $row[$j]['peak_area'] = $arr[2];
  231. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[3]);
  232. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[4]);
  233. $row[$j]['chemical_compound'] = $arr[5];
  234. $row[$j]['create'] = $time;
  235. }else{
  236. $row[$j]['pid'] = $id['id'];
  237. $row[$j]['time'] = $arr[0];
  238. $row[$j]['type'] = '';
  239. $row[$j]['peak_area'] = $arr[1];
  240. ($arr[3] == '-')?$row[$j]['val'] = '-':$row[$j]['val'] = floatval($arr[2]);
  241. ($arr[4] == '-')?$row[$j]['potency'] = '-':$row[$j]['potency'] = floatval($arr[3]);
  242. $row[$j]['chemical_compound'] = $arr[4];
  243. $row[$j]['create'] = $time;
  244. }
  245. $j++;
  246. }
  247. //将检测数据插入子表gather_txt_check_gc
  248. db()->name('gather_txt_check_gc')->insertAll($row);
  249. //提交事务
  250. db()->commit();
  251. return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
  252. }
  253. } catch (\Exception $e){
  254. //失败回滚
  255. db()->rollback();
  256. Log::record($e->getMessage());
  257. return $e->getMessage();
  258. }
  259. }else{
  260. return '找不到记录';
  261. }
  262. }else{
  263. $string = trim(substr($req[1],stripos($req[1],':')+1));
  264. $bach = '';
  265. if (preg_match('/\d+$/', $string, $matches)) {
  266. $bach = $matches[0];
  267. }
  268. $name = str_replace($bach,'',$string);
  269. $time = date('Y/m/d H:i:s');
  270. $res = [
  271. 'data_txt_name' => trim(substr($req[2],strripos($req[2],':')+1)),
  272. 'name' => $name,
  273. 'bach' => $bach,
  274. 'gather_time' => trim(substr($req[3],stripos($req[3],':')+1)),
  275. 'data_txt_path' => trim(substr($req[4],stripos($req[4],':')+1)),
  276. 'ALS' => trim(substr($req[5],stripos($req[5],':')+1,strripos($req[5],'样品乘积因子')-1-stripos($req[5],':'))),
  277. 'sample_product_factor' => trim(substr($req[5],strripos($req[5],':')+1)),
  278. 'author' => trim(substr($req[6],stripos($req[6],':')+1)),
  279. 'other' => trim(substr($req[7],stripos($req[7],':')+1)),
  280. 'title' => trim(substr($req[8],stripos($req[8],':')+1)),
  281. 'quantify_time' => trim(substr($req[9],stripos($req[9],':')+1)),
  282. 'quantify_method' => trim(substr($req[10],stripos($req[10],':')+1)),
  283. 'last_quantify_time' => trim(substr($req[11],stripos($req[11],':')+1)),
  284. 'response' => trim(substr($req[12],stripos($req[12],':')+1)),
  285. 'machine' => 1,
  286. 'create' => $time,
  287. ];
  288. $id = db()->name('gather_txt_gcms')->field('id')->where('data_txt_name',$res['data_txt_name'])->find();
  289. if($id){
  290. //开启事务
  291. db()->startTrans();
  292. try {
  293. //根据id修改主表数据
  294. $bool = db()->name('gather_txt_gcms')->where('id',$id['id'])->update($res);
  295. if($bool) {
  296. //根据pid删除子表数据
  297. db()->name('gather_txt_check_gcms')->where('pid', $id['id'])->delete();
  298. //根据id新增子表数据
  299. $row = [];
  300. $j = 0;
  301. for($i = 13; $i < count($req); $i++){
  302. $str = trim($req[$i]);
  303. $arr = preg_split('/\s+/', $str);
  304. if (count($arr)==8){
  305. $row[$j]['pid'] = $id['id'];
  306. $row[$j]['chemical_compound'] = $arr[1];
  307. $row[$j]['persist_time'] = $arr[2];
  308. $row[$j]['quantitative_ion'] = $arr[3];
  309. $row[$j]['response_value'] = $arr[4];
  310. $row[$j]['potency'] = $arr[5];
  311. $row[$j]['unit'] = $arr[6];
  312. $row[$j]['quanlitative_ion'] = $arr[7];
  313. $row[$j]['create'] = $time;
  314. }else{
  315. $row[$j]['pid'] = $id['id'];
  316. $row[$j]['chemical_compound'] = $arr[1];
  317. $row[$j]['persist_time'] = $arr[2];
  318. $row[$j]['quantitative_ion'] = $arr[3];
  319. $row[$j]['response_value'] = $arr[3];
  320. $row[$j]['potency'] = $arr[3];
  321. $row[$j]['unit'] = $arr[3];
  322. $row[$j]['quanlitative_ion'] = $arr[3];
  323. $row[$j]['create'] = $time;
  324. }
  325. $j++;
  326. }
  327. //将检测数据插入子表gather_txt_check_gc
  328. db()->name('gather_txt_check_gcms')->insertAll($row);
  329. //提交事务
  330. db()->commit();
  331. return json_encode(['code'=>'0','msg'=>'修改成功','time'=>$time,'data'=>[$res,$row]]);
  332. }
  333. } catch (\Exception $e){
  334. //失败回滚
  335. db()->rollback();
  336. Log::record($e->getMessage());
  337. return $e->getMessage();
  338. }
  339. }else{
  340. return '找不到记录';
  341. }
  342. }
  343. }
  344. }