model = new \app\admin\model\Entrust; $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 添加 * * @return string * @throws \think\Exception */ public function add() { if (false === $this->request->isPost()) { $num = Db::name('entrust')->whereTime('create', 'd')->count(); $num = $num + 1; if ($num < 10){ $num = '0'.$num; } $sample_no = date('Ymd').$num; $this->view->assign('sample_no', $sample_no); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params['name'] = preg_replace('/\s+/','',$params['name']);//去掉所有空格 $params['user_id'] = Session::get('admin')['id']; $params['user_name'] = Session::get('admin')['username']; $params = $this->preExcludeFields($params); if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); } //提交到检测 public function submit(){ if (false === $this->request->isPost()) { $id = input('id'); $judgeData = Db::name('item_judge')->column('id,name'); $this->view->assign('judgeData', $judgeData); $this->view->assign('id', $id); return $this->view->fetch(); } $id = input('id');//委托单id $temp_id = input('temp');//判定标准id if (empty($id) || empty($temp_id)){ $this->error('参数错误'); } /*** * 提交后,更新此数据的 判定标准、委托状态 * 根据批次号绑定检测数据 * 生成检测结果 */ $entrust = Db::name('entrust')->where('id',$id)->find(); $gather = Db::name('gather_txt')->where('bach',$entrust['bach'])->find(); if (empty($gather)){ $this->error('未获取到检测数据'); } $is_qualified = 1;//默认合格,当有一项不合格时,判定此次检测不合格 $detail_data = Db::name('gather_txt_check')->where('pid',$gather['id'])->select(); $dis= 0;//溶剂残留总量 $dis_impurity_data = [];//溶剂杂质总量 $ben_total_data = [];//苯系物总量 $ben = 0; //苯含量 $all_dis_data = []; //所有杂质含量数组 $ethanol = 0; //乙醇含量 $dis_impurity_arr = ['甲醇','丙酮','正丁醇','苯','2-乙氧基乙醇','4-甲基-2-戊酮','甲苯','乙酸正丁酯','乙苯','间对二甲苯','邻-二甲苯','苯乙烯','2-乙氧基乙基乙酸酯','环己酮']; $ben_arr = ['甲苯','乙苯','间对二甲苯','邻-二甲苯']; foreach ($detail_data as $key=>$value){ $all_dis_data[$key] = $value['potency']; if ($value['chemical_compound'] == '乙醇'){//乙醇含量 $ethanol = $value['potency']; } if ($value['chemical_compound'] == '苯'){//苯含量 $ben = $value['potency']; } if (in_array($value['chemical_compound'],$dis_impurity_arr)){//溶剂杂质总量 $dis_impurity_data[$value['chemical_compound']] = $value['potency']; } if (in_array($value['chemical_compound'],$ben_arr)){//苯系物总量 $ben_total_data[$value['chemical_compound']] = $value['potency']; } } $judge = Db::name('item_judge_detail')->where('pid',$temp_id)->select(); $sum_all_dis_data = array_sum($all_dis_data); $dis = $sum_all_dis_data - $ethanol; //残留总量 $dis_impurity = array_sum($dis_impurity_data); //杂质总量 $ben_total = array_sum($ben_total_data); //苯系物重量 foreach ($judge as $k=>$v){ $v['min'] = $v['min'] * 10000; $v['max'] = $v['max'] * 10000; if ($v['params'] == '溶剂残留总量'){ if ( $dis < $v['max']){ $is_qualified = 1; }else{ $is_qualified = 0; } }if ($v['params'] == '溶剂杂质总量' || $v['params'] == '总量'){ if ( $dis_impurity < $v['max']){ $is_qualified = 1; }else{ $is_qualified = 0; } }if ($v['params'] == '溶剂杂质苯系物' || $v['params'] == '苯系物'){ // $ben_total_ten_thousand = $ben_total * 10000; if ( $ben_total < $v['max']){ $is_qualified = 1; }else{ $is_qualified = 0; } }if ($v['params'] == '溶剂杂质苯' || $v['params'] == '苯'){ if ($ben < $v['max']){ $is_qualified = 1; }else{ $is_qualified = 0; } } } $params = [];//检测结果数据 $params['entrust_no'] = $entrust['no']; $params['entrust_id'] = $entrust['id']; $params['name'] = $entrust['name']; $params['bach'] = $entrust['bach']; $params['sample_no'] = $entrust['sample_no']; $params['standard_id'] = $temp_id; $params['standard_name'] = $judge[0]['name']; $params['dis'] = $dis; $params['dis_impurity'] = $dis_impurity; $params['ben_total'] = $ben_total; $params['ben'] = $ben; $params['unit'] = 'mg/m2'; $params['judge'] = $is_qualified; $params['create'] = date('Y-m-d H:i:s'); $params['maker'] = Session::get('admin')['username']; $params['params'] = Db::name('item_judge')->where('id',$temp_id)->value('list_name'); $params['userid'] = Session::get('admin')['id'];; $params['status'] = 0; //更新数据 $entrust_update = []; $entrust_update['standard_id'] =$temp_id; $entrust_update['standard_name'] =$judge[0]['name']; $entrust_update['status'] =2; $entrust_update['gather_id'] =$gather['id']; $entrust_update['gather_tab'] ='gather_txt'; //日志记录 $log = []; $log['userid'] = Session::get('admin')['id']; $log['username'] = Session::get('admin')['username']; $log['operate'] = '提交委托单id值为'.$id.'到检测'; $log['e_id'] = $id; $log['create'] = date('Y-m-d H:i:s'); $result = true; Db::startTrans(); try { /*** * 提交后,更新此数据的 判定标准、委托状态 * 根据批次号绑定检测数据 * 生成检测结果 */ $entrust_res = Db::name('entrust')->where('id',$id)->update($entrust_update); $res_check = Db::name('res_check')->insert($params); $log_res = Db::name('entrust_log')->insert($log); if (!$entrust_res || !$res_check){ $result = false; } Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); } //日志查看 public function log(){ //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $params = input('filter'); $map = []; if (!empty($params)){ $params = json_decode($params,true); $map['e_id'] = $params['id']; } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = Db::name('entrust_log') ->where($map) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } //检测数据查看 public function data(){ $params = input('id'); if (empty($params)){ $this->error('参数错误'); } $gather_id = Db::name('entrust')->where('id',$params)->find(); if (empty($gather_id['gather_id'])){ $this->error('此委托单还未提交检测,暂无检测数据'); } $gather = Db::name('gather_txt')->where('id',$gather_id['gather_id'])->find(); $data = Db::name('gather_txt_check')->where('pid',$gather_id['gather_id'])->select(); $this->view->assign('gather', $gather); $this->view->assign('data', $data); return $this->view->fetch(); } }