huangsanjia 2 år sedan
förälder
incheckning
8719a8ba78

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

@@ -42,14 +42,6 @@ class Entrust extends Backend
     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');
@@ -59,11 +51,14 @@ class Entrust extends Backend
         $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;
+        if ($params['is_two'] == 1){//双样
+            for ($i=0;$i<2;$i++){
+                $data[$i] = $params;
+                $data[$i]['sample_no'] = $params['sample_no'].'-'.($i+1);
+            }
+        }else{//单样
+            $data = $params;
         }
         $result = false;
         Db::startTrans();
@@ -74,7 +69,7 @@ class Entrust extends Backend
                 $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
                 $this->model->validateFailException()->validate($validate);
             }
-            $result = $this->model->allowField(true)->save($params);
+            $result = $this->model->saveAll($data);
             Db::commit();
         } catch (ValidateException|PDOException|Exception $e) {
             Db::rollback();
@@ -102,21 +97,29 @@ class Entrust extends Backend
         }
         /***
          * 提交后,更新此数据的  判定标准、委托状态
-         * 根据批次号绑定检测数据
+         * 根据数据文件名称绑定检测数据
          * 生成检测结果
         */
         $entrust = Db::name('entrust')->where('id',$id)->find();
         /***
          * 无法确认是哪台机器(GC、GCMS)检测
-         * 1、先去找gc表     没有查到数据    再找gcms
+         * 1、先去找gcms表     没有查到数据    再找gc表
         */
-        $gather = Db::name('gather_txt_gcms')->where('bach',$entrust['bach'])->find();
-        if (empty($gather)){
-            $this->error('未获取到检测数据');
+        $data_txt = $entrust['sample_no'].'MS.D'; //如果是GCMS机台,数据文件为委托编号+MS.D
+        $gather_gcms = Db::name('gather_txt_gcms')->where('data_txt_name',$data_txt)->find();
+        if (empty($gather_gcms)){
+            $data_txt_gc = $entrust['sample_no'].'.D';
+            $gather_gc = Db::name('gather_txt_gc')->where('data_txt_name',$data_txt_gc)->find();
+            if (empty($gather_gc)){
+                $this->error('未获取到检测数据');
+            }
+            $gather = $gather_gc;
+            $gather_tab = 'gather_txt_check_gc';
+        }else{
+            $gather = $gather_gcms;
+            $gather_tab = 'gather_txt_check_gcms';
         }
-        $detail_data = Db::name('gather_txt_check_gcms')->where('pid',$gather['id'])->field('chemical_compound,potency')->select();
-
-        $gather_tab = 'gather_txt_gcms';//默认gcms表,后续根据实际查到的数据  更改
+        $detail_data = Db::name($gather_tab)->where('pid',$gather['id'])->field('chemical_compound,potency')->select();
 
         $is_qualified = 1;//默认合格,当有一项不合格时,判定此次检测不合格
         $dis= 0;//溶剂残留总量
@@ -142,14 +145,13 @@ class Entrust extends Backend
                 $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;
@@ -163,7 +165,6 @@ class Entrust extends Backend
                     $is_qualified = 0;
                 }
             }if ($v['params'] == '溶剂杂质苯系物' || $v['params'] == '苯系物'){
-//                $ben_total_ten_thousand = $ben_total * 10000;
                 if ( $ben_total < $v['max']){
                     $is_qualified = 1;
                 }else{
@@ -219,7 +220,7 @@ class Entrust extends Backend
              * 生成检测结果
              */
             $entrust_res = Db::name('entrust')->where('id',$id)->update($entrust_update);
-            $res_check = Db::name('res_check')->insert($params);
+            $res_check = Db::name('res')->insert($params);
             $log_res = Db::name('entrust_log')->insert($log);
             if (!$entrust_res || !$res_check){
                 $result = false;
@@ -264,7 +265,6 @@ class Entrust extends Backend
     //检测数据查看
     public function data(){
         $params = input('id');
-
         if (empty($params)){
             $this->error('参数错误');
         }
@@ -273,18 +273,18 @@ class Entrust extends Backend
             $this->error('此委托单还未提交检测,暂无检测数据');
         }
         //此处根据实际获取到的采集表的数据 gather_tab  去对应表里查数据  重新写一个gc表格页面  js加代码
-        if ($gather_id['gather_tab'] == 'gather_txt_gcms'){
+        if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
             $gather = Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->find();
             $data = Db::name('gather_txt_check_gcms')->where('pid',$gather_id['gather_id'])->select();
             $this->view->assign('gather', $gather);
             $this->view->assign('data', $data);
             return $this->view->fetch();
-        }else{
-            $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();
+        }else if ($gather_id['gather_tab'] == 'gather_txt_check_gc'){
+            $gather = Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->find();
+            $data = Db::name('gather_txt_check_gc')->where('pid',$gather_id['gather_id'])->select();
             $this->view->assign('gather', $gather);
             $this->view->assign('data', $data);
-            return $this->view->fetch('data_gc.html');//此处页面没写
+            return $this->fetch('datagc');
         }
 
     }
@@ -293,6 +293,25 @@ class Entrust extends Backend
 
         return $this->view->fetch();
     }
-
-
+    //生成委托单号
+    public function getNo(){
+        $params = input('temp');
+        $company = input('company');
+        if (empty($params) || empty($company)){
+            $this->error('参数错误');
+        }
+        $num = Db::name('entrust')->where('sample_no','like','%'.$params.'%')->whereTime('create','d')->count();
+       
+        if ($company == '亚欣'){//亚欣送样从100开始
+            $num = $num+100;
+        }else{
+            $num = $num+1;
+        }
+        if ($num < 10){
+            $num = '0'.$num;
+        }
+        //一位样品代号+8位日期+当前样品代号第几次送样+2位检测方式(01代表vocs)
+        $sample_no = date('Ymd').$num.'01';
+        return array('code'=>1,'data'=>$sample_no);
+    }
 }

+ 7 - 8
application/admin/view/entrust/add.html

@@ -24,7 +24,7 @@
         <label class="control-label col-xs-12 col-sm-2">{:__('Company')}:</label>
         <div class="col-xs-12 col-sm-8">
 <!--            <input id="c-company" data-rule="required" class="form-control" name="row[company]" >-->
-            {:build_select('row[company]', ['浙江美浓'=>'浙江美浓', '翌星'=>'翌星', '亚欣'=>'亚欣', '美浓涂料'=>'美浓涂料'], 10)}
+            {:build_select('row[company]', ['美浓'=>'美浓', '翌星'=>'翌星', '亚欣'=>'亚欣', '涂料'=>'涂料','其他'=>'其他'], 10,['class'=>'form-control company'])}
         </div>
     </div>
     <div class="form-group">
@@ -36,7 +36,6 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Sample_no')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input type="hidden" id="hidden" value="{$sample_no}">
             <input id="c-sample_no" data-rule="required" class="form-control" name="row[sample_no]" type="text" value="">
         </div>
     </div>
@@ -46,12 +45,12 @@
             <input id="c-no" data-rule="required" class="form-control" name="row[no]" type="text">
         </div>
     </div>
-<!--    <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 id="c-standard_name" class="form-control" name="row[standard_name]" type="text">-->
-<!--        </div>-->
-<!--    </div>-->
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">是否双样:</label>
+        <div class="col-xs-12 col-sm-8">
+            {:build_select('row[is_two]', ['0'=>'否', '1'=>'是'], null,['class'=>'form-control'])}
+        </div>
+    </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Sample_status')}:</label>
         <div class="col-xs-12 col-sm-8">

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

@@ -36,7 +36,12 @@
             <input id="c-sample_no" data-rule="required" class="form-control" name="row[sample_no]" type="text" value="{$row.sample_no|htmlentities}">
         </div>
     </div>
-
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">是否双样:</label>
+        <div class="col-xs-12 col-sm-8">
+            {:build_select('row[is_two]', ['0'=>'否', '1'=>'是'], null,['class'=>'form-control'])}
+        </div>
+    </div>
     <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">

+ 24 - 7
public/assets/js/backend/entrust.js

@@ -34,7 +34,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'sell_bach', title: __('Sell_bach'), operate: 'LIKE'},
                         {field: 'company', title: __('Company')},
                         {field: 'sample_no', title: __('Sample_no'), operate: 'LIKE'},
-                        // {field: 'standard_id', title: __('Standard_id')},
+                        {field: 'is_two', title: __('是否双样'),operate:false,formatter: function (value,row,index) {
+                                if (value == 0){
+                                    value = '单样';
+                                    return '<span style="color: #18bc9c">' +value+ '</span>';
+                                }else {
+                                    value = '双样';
+                                    return '<span style="color: #f75444">' + value + '</span>';
+                                }
+                            }},
                         {field: 'standard_name', title: __('Standard_name'), operate:false},
                         {field: 'sample_status', title: __('Sample_status'), operate:false, formatter: Table.api.formatter.status},
                         {field: 'create', title: __('Create'), operate:false, addclass:'datetimerange', autocomplete:false},
@@ -133,7 +141,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             })
             $('.mark').change(function () {
                 var mark = parseInt($(this).val());
-                console.log(mark)
+                var company = $('.company').val();
+
                 switch (mark) {
                     case 1:
                         mark = 'A';
@@ -148,12 +157,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         mark = 'D';
                         break;
                 }
-                var sample_no = $('#hidden').val();
-                var last_sample_no = mark + sample_no;
-                $('#c-sample_no').val(last_sample_no);
-                var no = 'JC-'+last_sample_no;
-                $('#c-no').val(no);
+                Fast.api.ajax({
+                    url: "entrust/getNo",
+                    type: "post",
+                    data:{temp: mark,company:company}
+                }, function (data) {
 
+                    var last_sample_no = mark + data;
+                    $('#c-sample_no').val(last_sample_no);
+                    var no = 'JC-'+last_sample_no;
+                    $('#c-no').val(no);
+                    return false;
+                },function () {
+                    return false;
+                });
             })
             Controller.api.bindevent();
         },