| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use \think\Session;
- use \think\Db;
- /**
- * 委托管理管理
- *
- * @icon fa fa-circle-o
- */
- class Entrust extends Backend
- {
- /**
- * Entrust模型对象
- * @var \app\admin\model\Entrust
- */
- protected $model = null;
- protected $searchFields = 'no,sample_no,name,bach,sell_bach,company';
- public function _initialize()
- {
- parent::_initialize();
- $this->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|Json
- * @throws \think\Exception
- * @throws DbException
- */
- public function index()
- {
- //设置过滤方法
- $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();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $user_id = Session::get('admin')['id'];
- if ($user_id == 1){//超级管理员
- $list = $this->model
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- }else{
- $userinfo = Db::name('admin')->where('id',$user_id)->find();
- $pidList = Db::name('company')->where('pid',$userinfo['company'])->select();
- $map = [];
- if (!empty($pidList)){//总公司
- $pid = [];
- foreach ($pidList as $key=>$value){
- $pid[$key] = $value['id'];
- }
- $map['work_unit'] = array('in',$pid);
- }else{//分公司
- $map['work_unit'] = $userinfo['company'];
- }
- $list = $this->model
- ->where($where)
- ->where($map)
- ->order($sort, $order)
- ->paginate($limit);
- }
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- /**
- * 搜索栏检测项目下拉列表
- */
- public function companyselect(){
- $company = Db::name('item_judge')->where('delete',null)->order('weigh asc')->column('name,name');
- if (empty($company)){
- return $this->error('没有检测项目数据');
- }else{
- return json($company);
- }
- }
- /**
- * 添加
- *
- * @return string
- * @throws \think\Exception
- */
- public function add()
- {
- if (false === $this->request->isPost()) {
- $user_id = Session::get('admin')['id'];
- $nickname = Session::get('admin')['nickname'];
- $company_id = Db::name('admin')->where('id',$user_id)->value('company');
- $company = Db::name('company')->where('pid',$company_id)->column('id,name');
- if (empty($company)){
- $company = Db::name('company')->where('id',$company_id)->column('id,name');
- }
- $this->assign('company',$company);
- $judgeData = Db::name('item_judge')->whereNull('delete')->order('weigh asc')->column('id,name');
- $this->view->assign('judgeData', $judgeData);
- $this->view->assign('nickname', $nickname);
- 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'];
- $userinfo = Db::name('admin')->where('id',$params['user_id'])->find();
- $params['project'] = implode(',',$params['project']);
- $params['report_grant'] = implode(',',$params['report_grant']);
- $params['sample_stand'] = implode(',',$params['sample_stand']);
- $params['manufacturer'] = preg_replace('/\s+/','',$params['manufacturer']);
- $params['standard_id'] = preg_replace('/\s+/','',$params['standard_id']);
- $judge = Db::name('item_judge')->where('id',$params['standard_id'])->find();
- $params['standard_name'] = $judge['name'];
- $params['user_name'] = $userinfo['username'];
- $params['work_unit'] = $userinfo['company'];
- $params['work_name'] = Db::name('company')->where('id',$userinfo['company'])->value('name');
- $params['company'] = Db::name('company')->where('id',$params['company'])->value('name');
- $is_exit = false;//默认样品编号唯一
- if ($params['is_two'] == 1){//双样
- for ($i=0;$i<2;$i++){
- $data[$i] = $params;
- $data[$i]['sample_no'] = $params['sample_no'].'-'.($i+1);
- $is_exit = Db::name('entrust')->where('sample_no',$data[$i]['sample_no'])->find();
- if ($is_exit){
- $is_exit = true;
- }
- }
- }else{//单样
- $data[0] = $params;
- $is_exit = Db::name('entrust')->where('sample_no',$params['sample_no'])->find();
- if ($is_exit){
- $is_exit = true;
- }
- }
- if ($is_exit === true){
- $this->error('样品编号已存在,请关闭此页面后重新打开!');
- }
- $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->saveAll($data);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('No rows were inserted'));
- }
- $this->success();
- }
- /**
- * 编辑
- *
- * @param $ids
- * @return string
- * @throws DbException
- * @throws \think\Exception
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- if (false === $this->request->isPost()) {
- $user_id = Session::get('admin')['id'];
- $company_id = Db::name('admin')->where('id',$user_id)->value('company');
- $pid = Db::name('company')->where('id',$company_id)->value('pid');
- $company = Db::name('company')->where('pid',$pid)->column('id,name');
- $report_grant = explode(',',$row['report_grant']);
- $sample_stand = explode(',',$row['sample_stand']);
- $this->assign('company',$company);
- $this->assign('report_grant',$report_grant);
- $this->assign('sample_stand',$sample_stand);
- $this->view->assign('row', $row);
- //修改判定标准
- $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');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $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();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- /**
- * 删除
- *
- * @param $ids
- * @return void
- * @throws DbException
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- */
- public function del($ids = null)
- {
- if (false === $this->request->isPost()) {
- $this->error(__("Invalid parameters"));
- }
- $ids = $ids ?: $this->request->post("ids");
- if (empty($ids)) {
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- $idList = explode(',',$ids);
- $canDel = true;
- foreach ($idList as $key => $value){
- $row = $this->model->get($ids);
- if (!empty($row['gather_id'])){
- $tab = $row['gather_tab'] == 'gather_txt_check_gc'?'gather_txt_gc':'gather_txt_gcms';
- $id = $row['gather_id'];
- $res = Db::name($tab)->where('id',$id)->find();
- if ($res['status'] == 1){
- $canDel = false;
- }
- }
- }
- if ($canDel === false){
- $this->error('检测数据已确认,无法删除!');
- }
- $pk = $this->model->getPk();
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- $this->model->where($this->dataLimitField, 'in', $adminIds);
- }
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- Db::startTrans();
- try {
- foreach ($list as $item) {
- $count += $item->delete();
- }
- Db::commit();
- } catch (PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($count) {
- $this->success();
- }
- $this->error(__('No rows were deleted'));
- }
- //提交到检测
- public function submit()
- {
- $idList = explode(',', input('id'));//委托单id
- if (empty($idList)){
- $this->error('参数错误');
- }
- //检测结果数据
- $params = [];
- //更新数据
- $entrust_update = [];
- //日志记录
- $log = [];
- foreach ($idList as $ke => $id) {
- $temp_id[$ke] = Db::name('entrust')->where('id', $id)->value('standard_id');
- if (empty($temp_id[$ke])) {
- $this->error('序号为'.$id . '未获取到判断标准,请先编辑确认标准');
- }
- /***
- * 提交后,更新此数据的 判定标准、委托状态
- * 根据数据文件名称绑定检测数据
- * 生成检测结果
- */
- $entrust = Db::name('entrust')->where('id', $id)->find();
- /***
- * 无法确认是哪台机器(GC、GCMS)检测
- * 1、先去找gcms表 没有查到数据 再找gc表
- */
- $data_txt = $entrust['sample_no'] . 'MS.D'; //如果是GCMS机台,数据文件为委托编号+MS.D或MSR.D
- $gather_gcms = Db::name('gather_txt_gcms')->where('data_txt_name', ['=',$data_txt],['=',$entrust['sample_no'].'MSR.D'],'or')->order('id desc')->find();
- /**
- * 先都查找一边,按时间先后顺序判定哪个结果是最新的
- * 1、gc和gcms都没有数据 返回错误->没获取到检测数据
- * 2、gc或gcms中有一个有数据,判定这个数据为检测数据
- * 3、gc和gcms都有数据,将创建时间转换为时间戳,判断大小,时间戳大的检测数据此委托单的检测数据
- */
- $data_txt_gc = $entrust['sample_no'] . '.D';
- $gather_gc = Db::name('gather_txt_gc')->where('data_txt_name', ['=',$data_txt_gc],['=',$entrust['sample_no'].'R.D'],'or')->order('id desc')->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],['=',$entrust['sample_no'].'R.D'],'or')->order('id desc')->find();
- // if (empty($gather_gc)) {
- // $this->error('序号为'.$id.'的样品未获取到检测数据,请取消选中');
- // }
- // $gather = $gather_gc;
- // $gather_tab = 'gather_txt_check_gc';
- // } else {
- // $gather = $gather_gcms;
- // $gather_tab = 'gather_txt_check_gcms';
- // }
- $gather_tab = '';
- $gather = '';
- if (empty($gather_gcms) && empty($gather_gc)) {
- $this->error('没获取到检测数据');
- }else if(empty($gather_gcms) && !empty($gather_gc)){
- $gather = $gather_gc;
- $gather_tab = 'gather_txt_check_gc';
- }else if(empty($gather_gc) && !empty($gather_gcms)){
- $gather = $gather_gcms;
- $gather_tab = 'gather_txt_check_gcms';
- }else{
- $gcms_time = strtotime($gather_gcms['create']);//gcms创建时间转换为时间戳
- $gc_time = strtotime($gather_gc['create']); //gc创建时间转换为时间戳
- if($gcms_time > $gc_time){
- //gcms时间最新
- $gather = $gather_gcms;
- $gather_tab = 'gather_txt_check_gcms';
- }else{
- //gc时间最新
- $gather = $gather_gc;
- $gather_tab = 'gather_txt_check_gc';
- }
- }
- $detail_data = Db::name($gather_tab)->where('pid', $gather['id'])->field('chemical_compound,potency')->select();
- $is_qualified = [];//默认合格,当有一项不合格时,判定此次检测不合格
- $dis = 0;//溶剂残留总量
- $dis_impurity_data = [];//溶剂杂质总量
- $ben_total_data = [];//苯系物总量
- $ben = 0; //苯含量
- $all_dis_data = []; //所有杂质含量数组
- $ethanol = 0; //乙醇含量
- $methanol = 0; //甲醇含量
- $ethylacetate = 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'];
- }
- if ($value['chemical_compound'] == '甲醇') {//甲醇含量
- $methanol = $value['potency'];
- }
- if ($value['chemical_compound'] == '乙酸乙酯') {//乙酸乙酯含量
- $ethylacetate = $value['potency'];
- }
- }
- $judge = Db::name('item_judge_detail')->where('pid', $temp_id[$ke])->select();
- $class = Db::name('item_judge')->where('id', $temp_id[$ke])->value('class');//获取判定标准类别
- $sum_all_dis_data = array_sum($all_dis_data);
- if ($ethanol == '-'){
- $ethanol = 0;
- }
- if ($methanol == '-'){
- $methanol = 0;
- }
- if ($ethylacetate == '-'){
- $ethylacetate = 0;
- }
- if ($class == 1) {//常规类 26项减去乙醇 杂质总量14项
- $dis = $sum_all_dis_data - $ethanol; //残留总量
- $dis_impurity = array_sum($dis_impurity_data); //杂质总量
- } else if ($class == 2) {//特殊类1 26项减去乙醇、甲醇、乙酸乙酯,杂质总量减去甲醇
- $dis = $sum_all_dis_data - $ethanol - $methanol - $ethylacetate; //残留总量
- $dis_impurity = array_sum($dis_impurity_data) - $methanol; //杂质总量
- } else {//特殊类2 26项减去乙醇 杂质总量14项减去甲醇
- $dis = $sum_all_dis_data - $ethanol; //残留总量
- $dis_impurity = array_sum($dis_impurity_data) - $methanol; //杂质总量
- }
- $ben_total = array_sum($ben_total_data); //苯系物重量
- /***
- * 如果判定合格,continue
- * 如果判定不合格,定义一个变量$str,在else 拼接不合格原因
- * 假如溶剂残留总量不合格,str = ‘不合格原因:溶剂残留总量检测值:$dis大于标准值:$v['max']’;
- */
- $str = '不合格原因:';
- foreach ($judge as $k => $v) {
- if ($v['params'] == '溶剂残留总量') {
- if ($dis < $v['max']) {
- $is_qualified[$k] = 1;
- } else {
- $is_qualified[$k] = 0;
- $str = $str. '溶剂残留总量检测值:'.$dis.'大于标准值:'.$v['max'].'。';
- }
- }
- if ($v['params'] == '溶剂杂质总量' || $v['params'] == '总量') {
- if ($dis_impurity < $v['max']) {
- $is_qualified[$k] = 1;
- } else {
- $is_qualified[$k] = 0;
- $str = $str. '溶剂杂质总量检测值:'.$dis_impurity.'大于标准值:'.$v['max'].'。';
- }
- }
- if ($v['params'] == '溶剂杂质苯系物' || $v['params'] == '苯系物总量' || $v['params'] == '苯系物') {
- if ($ben_total < $v['max']) {
- $is_qualified[$k] = 1;
- } else {
- $is_qualified[$k] = 0;
- $str = $str. '溶剂杂质苯系物检测值:'.$ben_total.'大于标准值:'.$v['max'].'。';
- }
- }
- if ($v['params'] == '溶剂杂质苯' || $v['params'] == '苯含量' || $v['params'] == '苯') {
- if ($ben < $v['max']) {
- $is_qualified[$k] = 1;
- } else {
- $is_qualified[$k] = 0;
- $str = $str. '溶剂杂质苯检测值:'.$ben.'大于标准值:'.$v['max'].'。';
- }
- }
- }
- $is_pass = array_sum($is_qualified);//4项都合格,sum=4才判定合格 不等于4就说明有不合格的
- $params[$ke]['judge'] = 0;
- if ($is_pass == 4) {
- $params[$ke]['judge'] = 1;
- $str = '';
- }
- $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]['sell_bach'] = $entrust['sell_bach'];
- $params[$ke]['sample_no'] = $entrust['sample_no'];
- $params[$ke]['standard_id'] = $temp_id[$ke];
- $params[$ke]['standard_name'] = $judge[0]['name'];
- if (is_numeric($dis)){
- $params[$ke]['dis'] = number_format($dis,'2','.','');
- }else{
- $params[$ke][$dis] = $dis;
- }
- if (is_numeric($dis_impurity)){
- $params[$ke]['dis_impurity'] = number_format($dis_impurity,'2','.','');
- }else{
- $params[$ke]['dis_impurity'] = $dis_impurity;
- }
- if (is_numeric($ben_total)){
- $params[$ke]['ben_total'] = number_format($ben_total,'2','.','');
- }else{
- $params[$ke]['ben_total'] = $ben_total;
- }
- if (is_numeric($ben)){
- $params[$ke]['ben'] = number_format($ben,'4','.','');
- }else{
- $params[$ke]['ben'] = $ben;
- }
- $params[$ke]['unit'] = 'mg/m2';
- $params[$ke]['remark'] = $str;
- $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]['sample_info'] = $entrust['sample_info'];
- $params[$ke]['work_name'] = $entrust['work_name'];
- $params[$ke]['send_sample'] = $entrust['send_sample'];
- // $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;
- $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');
- }
- $result = 0;
- Db::startTrans();
- try {
- /***
- * 提交后,更新此数据的 判定标准、委托状态
- * 根据批次号绑定检测数据
- * 生成检测结果
- */
- $record = [];
- for ($i=0;$i<count($idList);$i++){
- $entrust_res = Db::name('entrust')->where('id', $idList[$i])->update($entrust_update[$i]);
- // Db::name('res')->where('entrust_id',$idList[$i])->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
- // $res_check = Db::name('res')->insert($params[$i]);
- $entrust_id = Db::name('res')->where('entrust_id',$idList[$i])->order('id desc')->find();
- if (empty($entrust_id)) {
- $res_check = Db::name('res')->insert($params[$i]);
- } else {
- if ($entrust_id['status'] != 1){
- $data =Db::name('res')
- ->where('id',$entrust_id['id'])
- ->update(['delete_time'=>date('Y-m-d H:i:s',time())]);
- $res_check = Db::name('res')->insert($params[$i]);
- }else{
- $res_check = true;
- }
- }
- $log_res = Db::name('entrust_log')->insert($log[$i]);
- if (!$log_res || !$res_check) {
- $record[$i] = $idList[$i];
- }else{
- $result += 1;
- }
- }
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== count($idList)) {
- $res_log = implode(',',$record);
- $this->error(__('序号为'.$res_log.'的委托单没有提交成功,请重新提交'));
- }
- $this->success();
- }
- //日志查看
- public function log(){
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- $params = $this->request->param("ids");
- if (false === $this->request->isAjax()) {
- $this->view->assign('id', $params);
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- $id = $this->request->param("ids");
- $map = [];
- if (!empty($params)){
- $map['e_id'] = $id;
- }
- // print_r($map);die;
- [$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_tab 去对应表里查数据 重新写一个gc表格页面 js加代码
- 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);
- $this->view->assign('id', $params);
- return $this->view->fetch();
- }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);
- $this->view->assign('id', $params);
- return $this->fetch('datagc');
- }
- }
- //检测数据确认
- public function dataSure(){
- $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('此委托单还未提交检测,暂无检测数据');
- }
- if ($gather_id['gather_tab'] == 'gather_txt_check_gcms'){
- Db::name('gather_txt_gcms')->where('id',$gather_id['gather_id'])->setField('status',1);
- }else{
- Db::name('gather_txt_gc')->where('id',$gather_id['gather_id'])->setField('status',1);
- }
- $this->success('确认成功');
- }
- //委托单页面
- public function commissionsheet(){
- //获取样品名称
- $id = input('id');
- if (empty($id)){
- $this->error('参数错误');
- }
- $this->assign('name',Db::name('entrust')->where('id',$id)->find());
- //委托单上传
- return $this->view->fetch();
- }
- //委托单上传
- public function commissionsheetup(){
- $params = [];
- if (true === $this->request->isPost()){
- $params['entrust_user'] = input('entrust_user');
- $params['entrust_time'] = input('entrust_time');
- $params['entrust_id'] = input('entrust_id');
- $params['name'] = input('name');
- $params['status'] = input('status');
- $params['num'] = input('num');
- $params['project'] = input('project');
- $params['no'] = input('no');
- $params['requirement'] = input('requirement');
- $params['reportnumber'] = input('reportnumber');
- $params['deal'] = input('deal');
- $params['condition'] = input('condition');
- $params['isue'] = input('isue');
- $params['testcost'] = input('testcost');
- $params['standard'] = input('standard');
- }
- $judgment = Db::name('entrust_print')->where('entrust_user',$params['entrust_user'])
- ->where('entrust_id',$params['entrust_id'])
- ->where('entrust_time',$params['entrust_time'])
- ->where('name',$params['name'])
- ->where('no',$params['no'])->find();
- if (empty($judgment)){
- $res = Db::name('entrust_print')->insert($params);
- if (!empty($res)){
- $this->success();
- }
- }else{
- $this->error('该委托单已存在,不需要重新添加');
- }
- }
- //委托单批量打印页面
- public function printing(){
- $datas=$res = array();
- if ($this->request->isGet()){
- $ids =explode(',',$this->request->get('ids')) ;
- for($i=0;$i<count($ids);$i++){
- $datas[$i] = Db::name('entrust')->where('id',$ids[$i])->find();
- $res['entrust_id'][$i]=$datas[$i]['no'];
- $res['set'][$i]['name'] = $datas[$i]['name'];
- $res['set'][$i]['no'] = $datas[$i]['sample_no'];
- }
- $res['entrust_time'] = $datas[0]['create'];
- $res['entrust_id'] = implode('、',array_unique($res['entrust_id']));
- $this->view->assign('row',$res);
- }
- return $this->view->fetch();
- }
- //委托单批量上传
- public function printingup(){
- $params = [];
- if (true === $this->request->isPost()){
- $sampledata = input('sampledata/a');
- for ($i=0;$i<count($sampledata);$i++){
- $params['entrust_user'] = input('entrust_user');
- $params['entrust_time'] = input('entrust_time');
- $params['entrust_id'] = input('entrust_id');
- $params['requirement'] = input('requirement');
- $params['reportnumber'] = input('reportnumber');
- $params['deal'] = input('deal');
- $params['condition'] = input('condition');
- $params['isue'] = input('isue');
- $params['testcost'] = input('testcost');
- $params['standard'] = input('standard');
- $params['name'] = $sampledata[$i][0];
- $params['status'] = $sampledata[$i][1];
- $params['num'] = $sampledata[$i][2];
- $params['project'] = $sampledata[$i][3];
- $params['no'] = $sampledata[$i][4];
- $res[$i] = Db::name('entrust_print')->insert($params);
- }
- if (!empty($res)){
- $this->success();
- }
- }
- }
- //生成委托单号
- 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位日期+当前样品代号第几次送样
- $sample_no = date('Ymd').$num;
- return array('code'=>1,'data'=>$sample_no);
- }
- }
|