浏览代码

优化委托编辑

liuhairui 2 年之前
父节点
当前提交
e18490fbb0
共有 2 个文件被更改,包括 59 次插入59 次删除
  1. 58 52
      application/admin/controller/Entrust.php
  2. 1 7
      application/admin/view/entrust/edit.html

+ 58 - 52
application/admin/controller/Entrust.php

@@ -192,6 +192,12 @@ class Entrust extends Backend
             $this->assign('report_grant',$report_grant);
             $this->assign('sample_stand',$sample_stand);
             $this->view->assign('row', $row);
+            //修改判定标准
+//            $entrust = Db::name('entrust')->where('id',$ids)->find();
+//            $item_judge = $entrust['standard_id'];
+//            $this->assign('item_judge',$item_judge);
+            $judgeData = Db::name('item_judge')->whereNull('delete')->column('id,name');
+            $this->view->assign('judgeData', $judgeData);
             return $this->view->fetch();
         }
         $params = $this->request->post('row/a');
@@ -201,6 +207,9 @@ class Entrust extends Backend
         $params['project'] = implode(',',$params['project']);
         $params['report_grant'] = implode(',',$params['report_grant']);
         $params['sample_stand'] = implode(',',$params['sample_stand']);
+        $item_judge = Db::name('item_judge')->field('id,name')->where('id',$params['standard_id'])->find();
+        $params['standard_id'] = $item_judge['id'];
+        $params['standard_name'] = $item_judge['name'];
         $params = $this->preExcludeFields($params);
         $result = false;
         Db::startTrans();
@@ -283,19 +292,10 @@ class Entrust extends Backend
     //提交到检测
     public function submit()
     {
-//        if (false === $this->request->isPost()) {
-//            $id = input('id');
-//            $judgeData = Db::name('item_judge')->whereNull('delete')->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('参数错误');
-//        }
         $idList = explode(',', input('id'));//委托单id
+        if (empty($idList)){
+            $this->error('参数错误');
+        }
         //检测结果数据
         $params = [];
         //更新数据
@@ -315,7 +315,6 @@ class Entrust extends Backend
          * 生成检测结果
          */
         $entrust = Db::name('entrust')->where('id', $id)->find();
-
         /***
          * 无法确认是哪台机器(GC、GCMS)检测
          * 1、先去找gcms表     没有查到数据    再找gc表
@@ -368,7 +367,7 @@ class Entrust extends Backend
             }
         }
         $judge = Db::name('item_judge_detail')->where('pid', $temp_id[$ke])->select();
-        $class = Db::name('item_judge')->where('id', $temp_id[$ke])->value('class');//获取判定标准类别
+        $class = Db::name('item_judge')->where('id', $id)->value('class');//获取判定标准类别
         $sum_all_dis_data = array_sum($all_dis_data);
         if ($class == 1) {//常规类  26项减去乙醇 杂质总量14项
             $dis = $sum_all_dis_data - $ethanol;    //残留总量
@@ -416,44 +415,41 @@ class Entrust extends Backend
         if ($is_pass == 4) {
             $params[$ke]['judge'] = 1;
         }
-            $params[$ke]['entrust_no'] = $entrust['no'];
-            $params[$ke]['entrust_id'] = $entrust['id'];
-            $params[$ke]['machine'] = 'GCMS';
+        $params[$ke]['entrust_no'] = $entrust['no'];
+        $params[$ke]['entrust_id'] = $entrust['id'];
+        $params[$ke]['machine'] = 'GCMS';
         if ($gather_tab == 'gather_txt_check_gc') {
             $params[$ke]['machine'] = 'GC';
         }
-            $params[$ke]['name'] = $entrust['name'];
-            $params[$ke]['bach'] = $entrust['bach'];
-            $params[$ke]['sample_no'] = $entrust['sample_no'];
-            $params[$ke]['standard_id'] = $temp_id[$ke];
-            $params[$ke]['standard_name'] = $judge[0]['name'];
-            $params[$ke]['dis'] = $dis;
-            $params[$ke]['dis_impurity'] = $dis_impurity;
-            $params[$ke]['ben_total'] = $ben_total;
-            $params[$ke]['ben'] = $ben;
-            $params[$ke]['unit'] = 'mg/m2';
-            $params[$ke]['create'] = date('Y-m-d H:i:s');
-            $params[$ke]['maker'] = Session::get('admin')['username'];
-            $params[$ke]['params'] = Db::name('item_judge')->where('id', $temp_id[$ke])->value('list_name');
-            $params[$ke]['userid'] = Session::get('admin')['id'];;
-            $params[$ke]['status'] = 0;
-            $params[$ke]['work_unit'] = $entrust['work_unit'];
-            $params[$ke]['work_name'] = $entrust['work_name'];
+        $params[$ke]['name'] = $entrust['name'];
+        $params[$ke]['bach'] = $entrust['bach'];
+        $params[$ke]['sample_no'] = $entrust['sample_no'];
+        $params[$ke]['standard_id'] = $temp_id[$ke];
+        $params[$ke]['standard_name'] = $judge[0]['name'];
+        $params[$ke]['dis'] = $dis;
+        $params[$ke]['dis_impurity'] = $dis_impurity;
+        $params[$ke]['ben_total'] = $ben_total;
+        $params[$ke]['ben'] = $ben;
+        $params[$ke]['unit'] = 'mg/m2';
+        $params[$ke]['create'] = date('Y-m-d H:i:s');
+        $params[$ke]['maker'] = Session::get('admin')['username'];
+        $params[$ke]['params'] = Db::name('item_judge')->where('id', $temp_id[$ke])->value('list_name');
+        $params[$ke]['userid'] = Session::get('admin')['id'];;
+        $params[$ke]['status'] = 0;
+        $params[$ke]['work_unit'] = $entrust['work_unit'];
+        $params[$ke]['work_name'] = $entrust['work_name'];
 //            $entrust_update[$ke]['standard_id'] = $temp_id[$ke];
 //            $entrust_update[$ke]['standard_name'] = $judge[0]['name'];
-            $entrust_update[$ke]['status'] = 2;
-            $entrust_update[$ke]['gather_id'] = $gather['id'];
-            $entrust_update[$ke]['gather_tab'] = $gather_tab;
+        $entrust_update[$ke]['status'] = 2;
+        $entrust_update[$ke]['gather_id'] = $gather['id'];
+        $entrust_update[$ke]['gather_tab'] = $gather_tab;
 
         $log[$ke]['userid'] = Session::get('admin')['id'];
-            $log[$ke]['username'] = Session::get('admin')['username'];
-            $log[$ke]['operate'] = '提交委托单id值为' . $id . '到检测';
-            $log[$ke]['content'] = '选用检测标准为:"' . $judge[0]['name']. '",检测数据为:' . $gather_tab . '/' . $gather['id'];
-            $log[$ke]['e_id'] = $id;
-            $log[$ke]['create'] = date('Y-m-d H:i:s');
-//        if ($result === false) {
-//            $this->error(__('No rows were inserted'));
-//        }
+        $log[$ke]['username'] = Session::get('admin')['username'];
+        $log[$ke]['operate'] = '提交委托单id值为' . $id . '到检测';
+        $log[$ke]['content'] = '选用检测标准为:"' . $judge[0]['name']. '",检测数据为:' . $gather_tab . '/' . $gather['id'];
+        $log[$ke]['e_id'] = $id;
+        $log[$ke]['create'] = date('Y-m-d H:i:s');
     }
         $result = 0;
         Db::startTrans();
@@ -465,14 +461,24 @@ class Entrust extends Backend
              */
             for ($i=0;$i<count($idList);$i++){
                 $entrust_res = Db::name('entrust')->where('id', $idList[$i])->update($entrust_update[$i]);
-                $res_check = Db::name('res')->insert($params[$i]);
+                $entrust_id = Db::name('res')->where('entrust_id',$idList[$i])->find();
+                if (empty($entrust_id)) {
+                    $res_check = Db::name('res')->insert($params[$i]);
+                } else {
+                    $data =Db::name('res')
+                        ->whereIn('entrust_id',$idList[$i])
+                        ->update(['delete_time'=>date('Y-m-d H:i:s')]);
+                    if (!$data){
+                        $result = false;
+                    }
+                    $res_check = Db::name('res')->insert($params[$i]);
+                }
                 $log_res = Db::name('entrust_log')->insert($log[$i]);
-            }
-
-            if (!$log_res || !$res_check) {
-                $result = false;
-            }else{
-                $result += 1;
+                if (!$log_res || !$res_check) {
+                    $result = false;
+                }else{
+                    $result += 1;
+                }
             }
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {

+ 1 - 7
application/admin/view/entrust/edit.html

@@ -85,13 +85,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Standard_name')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input type="hidden" value="{$standard_name.id}">
-            <select id="c-standard_name" data-rule="required"  class="control-label col-xs-12 col-sm-8 form-control selectpicker" name="row[standard_name]" type="text" value="{$row.id|htmlentities}">
-                <option value="{$standard_name.id}">{$standard_name.name}</option>
-                {foreach $item_judge as $key=>$vvo}
-                <option value="{$vvo.id}">{$vvo.name}</option>
-                {/foreach}
-            </select>
+            {:build_select('row[standard_id]', $judgeData, $row['standard_id'],['class'=>'form-control selectpicker','data-rule'=>'required'])}
             <!--<input id="c-standard_name" class="form-control" name="row[standard_name]" type="text" value="{$row.standard_name|htmlentities}" readonly>-->
         </div>
     </div>