Entrust.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use \think\Session;
  5. use \think\Db;
  6. /**
  7. * 委托管理管理
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Entrust extends Backend
  12. {
  13. /**
  14. * Entrust模型对象
  15. * @var \app\admin\model\Entrust
  16. */
  17. protected $model = null;
  18. protected $searchFields = 'no,sample_no,name,bach,sell_bach,company';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\Entrust;
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. *
  33. * @return string|Json
  34. * @throws \think\Exception
  35. * @throws DbException
  36. */
  37. public function index()
  38. {
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if (false === $this->request->isAjax()) {
  42. return $this->view->fetch();
  43. }
  44. //如果发送的来源是 Selectpage,则转发到 Selectpage
  45. if ($this->request->request('keyField')) {
  46. return $this->selectpage();
  47. }
  48. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  49. $user_id = Session::get('admin')['id'];
  50. if ($user_id == 1){//超级管理员
  51. $list = $this->model
  52. ->where($where)
  53. ->order($sort, $order)
  54. ->paginate($limit);
  55. }else{
  56. $userinfo = Db::name('admin')->where('id',$user_id)->find();
  57. // $pidList = Db::name('company')->where('pid',$userinfo['company'])->select();
  58. // $map = [];
  59. // if (!empty($pidList)){//总公司
  60. // $pid = [];
  61. // foreach ($pidList as $key=>$value){
  62. // $pid[$key] = $value['id'];
  63. // }
  64. // $map['work_unit'] = array('in',$pid);
  65. // }else{//分公司
  66. // $map['work_unit'] = $userinfo['company'];
  67. // }
  68. $map['work_unit'] = $userinfo['company'];
  69. $list = $this->model
  70. ->where($where)
  71. ->where($map)
  72. ->order($sort, $order)
  73. ->paginate($limit);
  74. }
  75. $result = ['total' => $list->total(), 'rows' => $list->items()];
  76. return json($result);
  77. }
  78. /**
  79. * 所属公司搜索
  80. */
  81. public function company()
  82. {
  83. $company = Db::name('company')->select();
  84. $data = [];
  85. for ($i=0;$i<count($company);$i++){
  86. $data[$i]['id'] = $company[$i]['name'];
  87. $data[$i]['name'] = $company[$i]['name'];
  88. }
  89. return json(['list'=>$data,'total'=>count($data)]);
  90. }
  91. /**
  92. * 搜索栏检测项目下拉列表
  93. */
  94. public function companyselect(){
  95. $company = Db::name('item_judge')->where('delete',null)->order('weigh asc')->column('name,name');
  96. if (empty($company)){
  97. return $this->error('没有检测项目数据');
  98. }else{
  99. return json($company);
  100. }
  101. }
  102. /**
  103. * 添加
  104. *
  105. * @return string
  106. * @throws \think\Exception
  107. */
  108. public function add()
  109. {
  110. if (false === $this->request->isPost()) {
  111. $user_id = Session::get('admin')['id'];
  112. $nickname = Session::get('admin')['nickname'];
  113. $company_id = Db::name('admin')->where('id',$user_id)->value('company');
  114. $company = Db::name('company')->where('pid',$company_id)->column('id,name');
  115. if (empty($company)){
  116. $company = Db::name('company')->where('id',$company_id)->column('id,name');
  117. }
  118. // $judgeData = Db::name('item_judge')->whereNull('delete')->order('weigh asc')->column('id,name');
  119. $judgeData = Db::name('item_judge')->whereNull('delete')->order('weigh asc')->select();
  120. $receiveData = Db::name('receive_people')->where('company_id',$company_id)->column('id,name');
  121. $nick_id = Db::name('receive_people')->where('name',$nickname)->value('id');
  122. $this->assign('company',$company);
  123. $this->view->assign('judgeData', $judgeData);
  124. $this->view->assign('nickname', $nick_id);
  125. $this->view->assign('receiveData', $receiveData);
  126. return $this->view->fetch();
  127. }
  128. $params = $this->request->post('row/a');
  129. if (empty($params)) {
  130. $this->error(__('Parameter %s can not be empty', ''));
  131. }
  132. $params['name'] = preg_replace('/\s+/','',$params['name']);//去掉所有空格
  133. $params['user_id'] = Session::get('admin')['id'];
  134. $userinfo = Db::name('admin')->where('id',$params['user_id'])->find();
  135. $params['project'] = implode(',',$params['project']);
  136. $params['report_grant'] = implode(',',$params['report_grant']);
  137. $params['sample_stand'] = implode(',',$params['sample_stand']);
  138. $params['manufacturer'] = preg_replace('/\s+/','',$params['manufacturer']);
  139. $params['standard_id'] = preg_replace('/\s+/','',$params['standard_id']);
  140. $judge = Db::name('item_judge')->where('id',$params['standard_id'])->find();
  141. $params['standard_name'] = $judge['name'];
  142. $params['receive_sample'] = Db::name('receive_people')->where('id',$params['receive_sample'])->value('name');
  143. $params['user_name'] = $userinfo['username'];
  144. $params['work_unit'] = $userinfo['company'];
  145. $params['work_name'] = Db::name('company')->where('id',$userinfo['company'])->value('name');
  146. $params['company'] = Db::name('company')->where('id',$params['company'])->value('name');
  147. $is_exit = false;//默认样品编号唯一
  148. if ($params['is_two'] == 1){//双样
  149. for ($i=0;$i<2;$i++){
  150. $data[$i] = $params;
  151. $data[$i]['sample_no'] = $params['sample_no'].'-'.($i+1);
  152. $is_exit = Db::name('entrust')->where('sample_no',$data[$i]['sample_no'])->find();
  153. if ($is_exit){
  154. $is_exit = true;
  155. }
  156. }
  157. }else{//单样
  158. $data[0] = $params;
  159. $is_exit = Db::name('entrust')->where('sample_no',$params['sample_no'])->find();
  160. if ($is_exit){
  161. $is_exit = true;
  162. }
  163. }
  164. if ($is_exit === true){
  165. $this->error('样品编号已存在,请关闭此页面后重新打开!');
  166. }
  167. $result = false;
  168. Db::startTrans();
  169. try {
  170. //是否采用模型验证
  171. if ($this->modelValidate) {
  172. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  173. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  174. $this->model->validateFailException()->validate($validate);
  175. }
  176. $result = $this->model->saveAll($data);
  177. Db::commit();
  178. } catch (ValidateException|PDOException|Exception $e) {
  179. Db::rollback();
  180. $this->error($e->getMessage());
  181. }
  182. if ($result === false) {
  183. $this->error(__('No rows were inserted'));
  184. }
  185. $this->success();
  186. }
  187. /**
  188. * 编辑
  189. *
  190. * @param $ids
  191. * @return string
  192. * @throws DbException
  193. * @throws \think\Exception
  194. */
  195. public function edit($ids = null)
  196. {
  197. $row = $this->model->get($ids);
  198. if (!$row) {
  199. $this->error(__('No Results were found'));
  200. }
  201. $adminIds = $this->getDataLimitAdminIds();
  202. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  203. $this->error(__('You have no permission'));
  204. }
  205. if (false === $this->request->isPost()) {
  206. $user_id = Session::get('admin')['id'];
  207. $company_id = Db::name('admin')->where('id',$user_id)->value('company');
  208. $pid = Db::name('company')->where('id',$company_id)->value('pid');
  209. $company = Db::name('company')->where('pid',$pid)->column('id,name');
  210. $report_grant = explode(',',$row['report_grant']);
  211. $sample_stand = explode(',',$row['sample_stand']);
  212. $receiveData = Db::name('receive_people')->where('company_id',$company_id)->column('id,name');
  213. $this->view->assign('receiveData', $receiveData);
  214. $this->assign('company',$company);
  215. $this->assign('report_grant',$report_grant);
  216. $this->assign('sample_stand',$sample_stand);
  217. $this->view->assign('row', $row);
  218. //修改判定标准
  219. // $judgeData = Db::name('item_judge')->whereNull('delete')->column('id,name');
  220. $judgeData = Db::name('item_judge')->whereNull('delete')->order('weigh asc')->select();
  221. $this->view->assign('judgeData', $judgeData);
  222. return $this->view->fetch();
  223. }
  224. $params = $this->request->post('row/a');
  225. if (empty($params)) {
  226. $this->error(__('Parameter %s can not be empty', ''));
  227. }
  228. $params['project'] = implode(',',$params['project']);
  229. $params['report_grant'] = implode(',',$params['report_grant']);
  230. $params['sample_stand'] = implode(',',$params['sample_stand']);
  231. $item_judge = Db::name('item_judge')->field('id,name')->where('id',$params['standard_id'])->find();
  232. $params['standard_id'] = $item_judge['id'];
  233. $params['standard_name'] = $item_judge['name'];
  234. $params['receive_sample'] = Db::name('receive_people')->where('id',$params['receive_sample'])->value('name');
  235. $params = $this->preExcludeFields($params);
  236. $result = false;
  237. Db::startTrans();
  238. try {
  239. //是否采用模型验证
  240. if ($this->modelValidate) {
  241. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  242. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  243. $row->validateFailException()->validate($validate);
  244. }
  245. $result = $row->allowField(true)->save($params);
  246. Db::commit();
  247. } catch (ValidateException|PDOException|Exception $e) {
  248. Db::rollback();
  249. $this->error($e->getMessage());
  250. }
  251. if (false === $result) {
  252. $this->error(__('No rows were updated'));
  253. }
  254. $this->success();
  255. }
  256. /**
  257. * 删除
  258. *
  259. * @param $ids
  260. * @return void
  261. * @throws DbException
  262. * @throws DataNotFoundException
  263. * @throws ModelNotFoundException
  264. */
  265. public function del($ids = null)
  266. {
  267. if (false === $this->request->isPost()) {
  268. $this->error(__("Invalid parameters"));
  269. }
  270. $ids = $ids ?: $this->request->post("ids");
  271. if (empty($ids)) {
  272. $this->error(__('Parameter %s can not be empty', 'ids'));
  273. }
  274. $idList = explode(',',$ids);
  275. $canDel = true;
  276. foreach ($idList as $key => $value){
  277. $row = $this->model->get($ids);
  278. if (!empty($row['gather_id'])){
  279. $tab = $row['gather_tab'] == 'gather_txt_check_gc'?'gather_txt_gc':'gather_txt_gcms';
  280. $id = $row['gather_id'];
  281. $res = Db::name($tab)->where('id',$id)->find();
  282. if ($res['status'] == 1){
  283. $canDel = false;
  284. }
  285. }
  286. }
  287. if ($canDel === false){
  288. $this->error('检测数据已确认,无法删除!');
  289. }
  290. $pk = $this->model->getPk();
  291. $adminIds = $this->getDataLimitAdminIds();
  292. if (is_array($adminIds)) {
  293. $this->model->where($this->dataLimitField, 'in', $adminIds);
  294. }
  295. $list = $this->model->where($pk, 'in', $ids)->select();
  296. $count = 0;
  297. Db::startTrans();
  298. try {
  299. foreach ($list as $item) {
  300. $count += $item->delete();
  301. }
  302. Db::commit();
  303. } catch (PDOException|Exception $e) {
  304. Db::rollback();
  305. $this->error($e->getMessage());
  306. }
  307. if ($count) {
  308. $this->success();
  309. }
  310. $this->error(__('No rows were deleted'));
  311. }
  312. //提交到检测
  313. public function submit()
  314. {
  315. $idList = explode(',', input('id'));//委托单id
  316. if (empty($idList)){
  317. $this->error('参数错误');
  318. }
  319. //检测结果数据
  320. $params = [];
  321. //更新数据
  322. $entrust_update = [];
  323. //日志记录
  324. $log = [];
  325. foreach ($idList as $ke => $id) {
  326. $temp_id[$ke] = Db::name('entrust')->where('id', $id)->value('standard_id');
  327. if (empty($temp_id[$ke])) {
  328. $this->error('序号为'.$id . '未获取到判断标准,请先编辑确认标准');
  329. }
  330. /***
  331. * 提交后,更新此数据的 判定标准、委托状态
  332. * 根据数据文件名称绑定检测数据
  333. * 生成检测结果
  334. */
  335. $entrust = Db::name('entrust')->where('id', $id)->find();
  336. /***
  337. * 无法确认是哪台机器(GC、GCMS)检测
  338. * 1、先去找gcms表 没有查到数据 再找gc表
  339. */
  340. $data_txt = $entrust['sample_no'] . 'MS.D'; //如果是GCMS机台,数据文件为委托编号+MS.D或MSR.D
  341. $gather_gcms = Db::name('gather_txt_gcms')->where('data_txt_name', ['=',$data_txt],['=',$entrust['sample_no'].'MSR.D'],'or')->order('id desc')->find();
  342. /**
  343. * 先都查找一边,按时间先后顺序判定哪个结果是最新的
  344. * 1、gc和gcms都没有数据 返回错误->没获取到检测数据
  345. * 2、gc或gcms中有一个有数据,判定这个数据为检测数据
  346. * 3、gc和gcms都有数据,将创建时间转换为时间戳,判断大小,时间戳大的检测数据此委托单的检测数据
  347. */
  348. $data_txt_gc = $entrust['sample_no'] . '.D';
  349. $gather_gc = Db::name('gather_txt_gc')->where('data_txt_name', ['=',$data_txt_gc],['=',$entrust['sample_no'].'R.D'],'or')->order('id desc')->find();
  350. // if (empty($gather_gcms)) {
  351. // $data_txt_gc = $entrust['sample_no'] . '.D';
  352. // $gather_gc = Db::name('gather_txt_gc')->where('data_txt_name', ['=',$data_txt_gc],['=',$entrust['sample_no'].'R.D'],'or')->order('id desc')->find();
  353. // if (empty($gather_gc)) {
  354. // $this->error('序号为'.$id.'的样品未获取到检测数据,请取消选中');
  355. // }
  356. // $gather = $gather_gc;
  357. // $gather_tab = 'gather_txt_check_gc';
  358. // } else {
  359. // $gather = $gather_gcms;
  360. // $gather_tab = 'gather_txt_check_gcms';
  361. // }
  362. $gather_tab = '';
  363. $gather = '';
  364. if (empty($gather_gcms) && empty($gather_gc)) {
  365. $this->error('没获取到检测数据');
  366. }else if(empty($gather_gcms) && !empty($gather_gc)){
  367. $gather = $gather_gc;
  368. $gather_tab = 'gather_txt_check_gc';
  369. }else if(empty($gather_gc) && !empty($gather_gcms)){
  370. $gather = $gather_gcms;
  371. $gather_tab = 'gather_txt_check_gcms';
  372. }else{
  373. $gcms_time = strtotime($gather_gcms['create']);//gcms创建时间转换为时间戳
  374. $gc_time = strtotime($gather_gc['create']); //gc创建时间转换为时间戳
  375. if($gcms_time > $gc_time){
  376. //gcms时间最新
  377. $gather = $gather_gcms;
  378. $gather_tab = 'gather_txt_check_gcms';
  379. }else{
  380. //gc时间最新
  381. $gather = $gather_gc;
  382. $gather_tab = 'gather_txt_check_gc';
  383. }
  384. }
  385. $detail_data = Db::name($gather_tab)->where('pid', $gather['id'])->field('chemical_compound,potency')->select();
  386. $is_qualified = [];//默认合格,当有一项不合格时,判定此次检测不合格
  387. $dis = 0;//溶剂残留总量
  388. $dis_impurity_data = [];//溶剂杂质总量
  389. $ben_total_data = [];//苯系物总量
  390. $ben = 0; //苯含量
  391. $all_dis_data = []; //所有杂质含量数组
  392. $ethanol = 0; //乙醇含量
  393. $methanol = 0; //甲醇含量
  394. $ethylacetate = 0; //乙酸乙酯含量
  395. $dis_impurity_arr = ['甲醇', '丙酮', '正丁醇', '苯', '2-乙氧基乙醇', '4-甲基-2-戊酮', '甲苯', '乙酸正丁酯', '乙苯', '间对二甲苯', '邻-二甲苯', '苯乙烯', '2-乙氧基乙基乙酸酯', '环己酮'];
  396. $ben_arr = ['甲苯', '乙苯', '间对二甲苯', '邻-二甲苯'];
  397. foreach ($detail_data as $key => $value) {
  398. $all_dis_data[$key] = $value['potency'];
  399. if ($value['chemical_compound'] == '乙醇') {//乙醇含量
  400. $ethanol = $value['potency'];
  401. }
  402. if ($value['chemical_compound'] == '苯') {//苯含量
  403. $ben = $value['potency'];
  404. }
  405. if (in_array($value['chemical_compound'], $dis_impurity_arr)) {//溶剂杂质总量
  406. $dis_impurity_data[$value['chemical_compound']] = $value['potency'];
  407. }
  408. if (in_array($value['chemical_compound'], $ben_arr)) {//苯系物总量
  409. $ben_total_data[$value['chemical_compound']] = $value['potency'];
  410. }
  411. if ($value['chemical_compound'] == '甲醇') {//甲醇含量
  412. $methanol = $value['potency'];
  413. }
  414. if ($value['chemical_compound'] == '乙酸乙酯') {//乙酸乙酯含量
  415. $ethylacetate = $value['potency'];
  416. }
  417. }
  418. $judge = Db::name('item_judge_detail')->where('pid', $temp_id[$ke])->select();
  419. $class = Db::name('item_judge')->where('id', $temp_id[$ke])->value('class');//获取判定标准类别
  420. $sum_all_dis_data = array_sum($all_dis_data);
  421. if ($ethanol == '-'){
  422. $ethanol = 0;
  423. }
  424. if ($methanol == '-'){
  425. $methanol = 0;
  426. }
  427. if ($ethylacetate == '-'){
  428. $ethylacetate = 0;
  429. }
  430. if ($class == 1) {//常规类 26项减去乙醇 杂质总量14项
  431. $dis = $sum_all_dis_data - $ethanol; //残留总量
  432. $dis_impurity = array_sum($dis_impurity_data); //杂质总量
  433. } else if ($class == 2) {//特殊类1 26项减去乙醇、甲醇、乙酸乙酯,杂质总量减去甲醇
  434. $dis = $sum_all_dis_data - $ethanol - $methanol - $ethylacetate; //残留总量
  435. $dis_impurity = array_sum($dis_impurity_data) - $methanol; //杂质总量
  436. } else {//特殊类2 26项减去乙醇 杂质总量14项减去甲醇
  437. $dis = $sum_all_dis_data - $ethanol; //残留总量
  438. $dis_impurity = array_sum($dis_impurity_data) - $methanol; //杂质总量
  439. }
  440. $ben_total = array_sum($ben_total_data); //苯系物重量
  441. /***
  442. * 如果判定合格,continue
  443. * 如果判定不合格,定义一个变量$str,在else 拼接不合格原因
  444. * 假如溶剂残留总量不合格,str = ‘不合格原因:溶剂残留总量检测值:$dis大于标准值:$v['max']’;
  445. */
  446. $str = '不合格原因:';
  447. foreach ($judge as $k => $v) {
  448. if ($v['params'] == '溶剂残留总量') {
  449. if ($dis < $v['max']) {
  450. $is_qualified[$k] = 1;
  451. } else {
  452. $is_qualified[$k] = 0;
  453. $str = $str. '溶剂残留总量检测值:'.number_format($dis,'2','.','').'大于标准值:'.$v['max'].'。';
  454. }
  455. }
  456. if ($v['params'] == '溶剂杂质总量' || $v['params'] == '总量') {
  457. if ($dis_impurity < $v['max']) {
  458. $is_qualified[$k] = 1;
  459. } else {
  460. $is_qualified[$k] = 0;
  461. $str = $str. '溶剂杂质总量检测值:'.number_format($dis_impurity,'2','.','').'大于标准值:'.$v['max'].'。';
  462. }
  463. }
  464. if ($v['params'] == '溶剂杂质苯系物' || $v['params'] == '苯系物总量' || $v['params'] == '苯系物') {
  465. if ($ben_total < $v['max']) {
  466. $is_qualified[$k] = 1;
  467. } else {
  468. $is_qualified[$k] = 0;
  469. $str = $str. '苯系物总量检测值:'.number_format($ben_total,'2','.','').'大于标准值:'.$v['max'].'。';
  470. }
  471. }
  472. if ($v['params'] == '溶剂杂质苯' || $v['params'] == '苯含量' || $v['params'] == '苯') {
  473. if ($ben < $v['max']) {
  474. $is_qualified[$k] = 1;
  475. } else {
  476. $is_qualified[$k] = 0;
  477. $str = $str. '苯含量检测值:'.number_format($ben,'4','.','').'大于标准值:'.$v['max'].'。';
  478. }
  479. }
  480. }
  481. $is_pass = array_sum($is_qualified);//4项都合格,sum=4才判定合格 不等于4就说明有不合格的
  482. $params[$ke]['judge'] = 0;
  483. if ($is_pass == 4) {
  484. $params[$ke]['judge'] = 1;
  485. $str = '';
  486. }
  487. $params[$ke]['entrust_no'] = $entrust['no'];
  488. $params[$ke]['entrust_id'] = $entrust['id'];
  489. $params[$ke]['machine'] = 'GCMS';
  490. if ($gather_tab == 'gather_txt_check_gc') {
  491. $params[$ke]['machine'] = 'GC';
  492. }
  493. $params[$ke]['name'] = $entrust['name'];
  494. $params[$ke]['bach'] = $entrust['bach'];
  495. $params[$ke]['sell_bach'] = $entrust['sell_bach'];
  496. $params[$ke]['sample_no'] = $entrust['sample_no'];
  497. $params[$ke]['standard_id'] = $temp_id[$ke];
  498. $params[$ke]['standard_name'] = $judge[0]['name'];
  499. if (is_numeric($dis)){
  500. $params[$ke]['dis'] = number_format($dis,'2','.','');
  501. }else{
  502. $params[$ke][$dis] = $dis;
  503. }
  504. if (is_numeric($dis_impurity)){
  505. $params[$ke]['dis_impurity'] = number_format($dis_impurity,'2','.','');
  506. }else{
  507. $params[$ke]['dis_impurity'] = $dis_impurity;
  508. }
  509. if (is_numeric($ben_total)){
  510. $params[$ke]['ben_total'] = number_format($ben_total,'2','.','');
  511. }else{
  512. $params[$ke]['ben_total'] = $ben_total;
  513. }
  514. if (is_numeric($ben)){
  515. $params[$ke]['ben'] = number_format($ben,'4','.','');
  516. }else{
  517. $params[$ke]['ben'] = $ben;
  518. }
  519. $params[$ke]['unit'] = 'mg/m2';
  520. $params[$ke]['remark'] = $str;
  521. $params[$ke]['create'] = date('Y-m-d H:i:s');
  522. $params[$ke]['maker'] = Session::get('admin')['username'];
  523. $params[$ke]['params'] = Db::name('item_judge')->where('id', $temp_id[$ke])->value('list_name');
  524. $params[$ke]['userid'] = Session::get('admin')['id'];;
  525. $params[$ke]['status'] = 0;
  526. $params[$ke]['work_unit'] = $entrust['work_unit'];
  527. $params[$ke]['sample_info'] = $entrust['sample_info'];
  528. $params[$ke]['work_name'] = $entrust['work_name'];
  529. $params[$ke]['send_sample'] = $entrust['send_sample'];
  530. // $entrust_update[$ke]['standard_id'] = $temp_id[$ke];
  531. // $entrust_update[$ke]['standard_name'] = $judge[0]['name'];
  532. $entrust_update[$ke]['status'] = 2;
  533. $entrust_update[$ke]['gather_id'] = $gather['id'];
  534. $entrust_update[$ke]['gather_tab'] = $gather_tab;
  535. $log[$ke]['userid'] = Session::get('admin')['id'];
  536. $log[$ke]['username'] = Session::get('admin')['username'];
  537. $log[$ke]['operate'] = '提交委托单id值为' . $id . '到检测';
  538. $log[$ke]['content'] = '选用检测标准为:"' . $judge[0]['name']. '",检测数据为:' . $gather_tab . '/' . $gather['id'];
  539. $log[$ke]['e_id'] = $id;
  540. $log[$ke]['create'] = date('Y-m-d H:i:s');
  541. }
  542. $result = 0;
  543. Db::startTrans();
  544. try {
  545. /***
  546. * 提交后,更新此数据的 判定标准、委托状态
  547. * 根据批次号绑定检测数据
  548. * 生成检测结果
  549. */
  550. $record = [];
  551. for ($i=0;$i<count($idList);$i++){
  552. $entrust_res = Db::name('entrust')->where('id', $idList[$i])->update($entrust_update[$i]);
  553. // Db::name('res')->where('entrust_id',$idList[$i])->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
  554. // $res_check = Db::name('res')->insert($params[$i]);
  555. $entrust_id = Db::name('res')->where('entrust_id',$idList[$i])->order('id desc')->find();
  556. if (empty($entrust_id)) {
  557. $res_check = Db::name('res')->insert($params[$i]);
  558. } else {
  559. if ($entrust_id['status'] != 1){
  560. $data =Db::name('res')
  561. ->where('id',$entrust_id['id'])
  562. ->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
  563. $res_check = Db::name('res')->insert($params[$i]);
  564. }else{
  565. $res_check = true;
  566. }
  567. }
  568. $log_res = Db::name('entrust_log')->insert($log[$i]);
  569. if (!$log_res || !$res_check) {
  570. $record[$i] = $idList[$i];
  571. }else{
  572. $result += 1;
  573. }
  574. }
  575. Db::commit();
  576. } catch (ValidateException|PDOException|Exception $e) {
  577. Db::rollback();
  578. $this->error($e->getMessage());
  579. }
  580. if ($result !== count($idList)) {
  581. $res_log = implode(',',$record);
  582. $this->error(__('序号为'.$res_log.'的委托单没有提交成功,请重新提交'));
  583. }
  584. $this->success();
  585. }
  586. //日志查看
  587. public function log(){
  588. //设置过滤方法
  589. $this->request->filter(['strip_tags', 'trim']);
  590. $params = $this->request->param("ids");
  591. if (false === $this->request->isAjax()) {
  592. $this->view->assign('id', $params);
  593. return $this->view->fetch();
  594. }
  595. //如果发送的来源是 Selectpage,则转发到 Selectpage
  596. if ($this->request->request('keyField')) {
  597. return $this->selectpage();
  598. }
  599. $id = $this->request->param("ids");
  600. $map = [];
  601. if (!empty($params)){
  602. $map['e_id'] = $id;
  603. }
  604. // print_r($map);die;
  605. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  606. $list = Db::name('entrust_log')
  607. ->where($map)
  608. ->order($sort, $order)
  609. ->paginate($limit);
  610. $result = ['total' => $list->total(), 'rows' => $list->items()];
  611. return json($result);
  612. }
  613. //检测数据查看
  614. public function data(){
  615. $params = input('id');
  616. if (empty($params)){
  617. $this->error('参数错误');
  618. }
  619. $gather_id = Db::name('entrust')->where('id',$params)->find();
  620. if (empty($gather_id['gather_id'])){
  621. $this->error('此委托单还未提交检测,暂无检测数据');
  622. }
  623. //此处根据实际获取到的采集表的数据 gather_tab 去对应表里查数据 重新写一个gc表格页面 js加代码
  624. if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
  625. $gather = Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->find();
  626. $data = Db::name('gather_txt_check_gcms')->where('pid',$gather_id['gather_id'])->select();
  627. $this->view->assign('gather', $gather);
  628. $this->view->assign('data', $data);
  629. $this->view->assign('id', $params);
  630. return $this->view->fetch();
  631. }else if ($gather_id['gather_tab'] == 'gather_txt_check_gc'){
  632. $gather = Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->find();
  633. $data = Db::name('gather_txt_check_gc')->where('pid',$gather_id['gather_id'])->select();
  634. $this->view->assign('gather', $gather);
  635. $this->view->assign('data', $data);
  636. $this->view->assign('id', $params);
  637. return $this->fetch('datagc');
  638. }
  639. }
  640. //检测数据确认
  641. public function dataSure(){
  642. $params = input('id');
  643. if (empty($params)){
  644. $this->error('参数错误');
  645. }
  646. $gather_id = Db::name('entrust')->where('id',$params)->find();
  647. if (empty($gather_id['gather_id'])){
  648. $this->error('此委托单还未提交检测,暂无检测数据');
  649. }
  650. if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
  651. Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->setField('status',1);
  652. }else{
  653. Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->setField('status',1);
  654. }
  655. $this->success('确认成功');
  656. }
  657. //委托单页面
  658. public function commissionsheet(){
  659. //获取样品名称
  660. $id = input('id');
  661. if (empty($id)){
  662. $this->error('参数错误');
  663. }
  664. $this->assign('name',Db::name('entrust')->where('id',$id)->find());
  665. //委托单上传
  666. return $this->view->fetch();
  667. }
  668. //委托单上传
  669. public function commissionsheetup(){
  670. $params = [];
  671. if (true === $this->request->isPost()){
  672. $params['entrust_user'] = input('entrust_user');
  673. $params['entrust_time'] = input('entrust_time');
  674. $params['entrust_id'] = input('entrust_id');
  675. $params['name'] = input('name');
  676. $params['status'] = input('status');
  677. $params['num'] = input('num');
  678. $params['project'] = input('project');
  679. $params['no'] = input('no');
  680. $params['requirement'] = input('requirement');
  681. $params['reportnumber'] = input('reportnumber');
  682. $params['deal'] = input('deal');
  683. $params['condition'] = input('condition');
  684. $params['isue'] = input('isue');
  685. $params['testcost'] = input('testcost');
  686. $params['standard'] = input('standard');
  687. }
  688. $judgment = Db::name('entrust_print')->where('entrust_user',$params['entrust_user'])
  689. ->where('entrust_id',$params['entrust_id'])
  690. ->where('entrust_time',$params['entrust_time'])
  691. ->where('name',$params['name'])
  692. ->where('no',$params['no'])->find();
  693. if (empty($judgment)){
  694. $res = Db::name('entrust_print')->insert($params);
  695. if (!empty($res)){
  696. $this->success();
  697. }
  698. }else{
  699. $this->error('该委托单已存在,不需要重新添加');
  700. }
  701. }
  702. //委托单批量打印页面
  703. public function printing(){
  704. $datas=$res = array();
  705. if ($this->request->isGet()){
  706. $ids =explode(',',$this->request->get('ids')) ;
  707. for($i=0;$i<count($ids);$i++){
  708. $datas[$i] = Db::name('entrust')->where('id',$ids[$i])->find();
  709. $res['entrust_id'][$i]=$datas[$i]['no'];
  710. $res['set'][$i]['name'] = $datas[$i]['name'];
  711. $res['set'][$i]['no'] = $datas[$i]['sample_no'];
  712. }
  713. $res['entrust_time'] = $datas[0]['create'];
  714. $res['entrust_id'] = implode('、',array_unique($res['entrust_id']));
  715. $this->view->assign('row',$res);
  716. }
  717. return $this->view->fetch();
  718. }
  719. //委托单批量上传
  720. public function printingup(){
  721. $params = [];
  722. if (true === $this->request->isPost()){
  723. $sampledata = input('sampledata/a');
  724. for ($i=0;$i<count($sampledata);$i++){
  725. $params['entrust_user'] = input('entrust_user');
  726. $params['entrust_time'] = input('entrust_time');
  727. $params['entrust_id'] = input('entrust_id');
  728. $params['requirement'] = input('requirement');
  729. $params['reportnumber'] = input('reportnumber');
  730. $params['deal'] = input('deal');
  731. $params['condition'] = input('condition');
  732. $params['isue'] = input('isue');
  733. $params['testcost'] = input('testcost');
  734. $params['standard'] = input('standard');
  735. $params['name'] = $sampledata[$i][0];
  736. $params['status'] = $sampledata[$i][1];
  737. $params['num'] = $sampledata[$i][2];
  738. $params['project'] = $sampledata[$i][3];
  739. $params['no'] = $sampledata[$i][4];
  740. $res[$i] = Db::name('entrust_print')->insert($params);
  741. }
  742. if (!empty($res)){
  743. $this->success();
  744. }
  745. }
  746. }
  747. //生成委托单号
  748. public function getNo(){
  749. $params = input('temp');
  750. $company = input('company');
  751. if (empty($params) || empty($company)){
  752. $this->error('参数错误');
  753. }
  754. $beginTime = date('Y-m-d 00:00:00');
  755. $endTime = date('Y-m-d 23:59:59');
  756. $num = Db::name('entrust')->where('sample_no','like','%'.$params.'%')->where('create','between',[$beginTime,$endTime])->count();
  757. // if ($company == '亚欣'){//亚欣送样从100开始
  758. // $num = $num+100;
  759. // }else{
  760. // $num = $num+1;
  761. // }
  762. $num = $num+1;
  763. if ($num < 10){
  764. $num = '0'.$num;
  765. }
  766. //一位样品代号+8位日期+当前样品代号第几次送样
  767. $sample_no = date('Ymd').$num;
  768. return array('code'=>1,'data'=>$sample_no);
  769. }
  770. }