request->isGet() === false){ $this->error('请求错误'); } $sist = ['印后糊盒车间','精品自动化车间','数字化车间']; $list = db('设备_基本资料') ->where('使用部门','in',$sist) ->whereNotNull('sys_sbID') ->column('CONCAT(设备编号,"->",设备名称)'); if (empty($list)){ $this->error('未找到设备数据'); }else{ $this->success('成功',$list); } } /** * 设备角色列表 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getGluingcoleList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $list = db('设备_糊盒班组角色') ->where('jtbh',$param['machine']) ->select(); if (empty($list)){ $this->error('未找到数据'); }else{ $this->success('成功',$list); } } /** * 设备角色资料详情 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getGluingcoleDetail() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $list = db('设备_糊盒班组角色') ->where('id',$param['id']) ->find(); if (empty($list)){ $this->error('未找到数据详情'); }else{ $this->success('成功',$list); } } /** * 新增机台班组角色 * @return void */ public function saveGluingcoleDetail(){ if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $param['sys_rq'] = date('Y-m-d H:i:s',time()); $res = db('设备_糊盒班组角色')->insert($param); if (empty($res)){ $this->error('新增失败'); }else{ $this->success('新增成功'); } } /** * 修改设备角色资料 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function getGluingcoleDetaiEdit() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param['id'])){ $this->error('参数错误'); } $id = intval($param['id']); $param['mod_rq'] = date('Y-m-d H:i:s',time()); unset($param['id']); $res = db('设备_糊盒班组角色') ->where('id',$id) ->update($param); if ($res === false){ $this->error('修改失败'); }else{ $this->success('修改成功'); } } /** * 设备当前班组角色 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function UpdateGluingcoleStatus() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['id']) || empty($param['jtbh'])){ $this->error('参数错误'); } $updateRes = db('设备_糊盒班组角色') ->where('jtbh',$param['jtbh']) ->update(['status' => 0]); $res = db('设备_糊盒班组角色') ->where('id',$param['id']) ->update(['status' => 1]); if ($updateRes === false || $res === false){ $this->error('更新失败'); }else{ $this->success('更新成功'); } } /** * 设备班组资料列表 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getGluingClassLList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $list = db('设备_糊盒班组资料') ->where('jtbh',$param['machine']) ->select(); if (empty($list)){ $this->error('未找到数据'); }else{ $this->success('成功',$list); } } /** * 获取设备角色数据 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getGluingcole() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $list = db('设备_糊盒班组角色') ->where('jtbh',$param['machine']) ->where('status',1) ->find(); if (empty($list)){ $this->error('未找到角色资料'); }else{ $this->success('成功',$list); } } /** * 新增糊盒机台班组资料 * @return void */ public function AddGluingClass() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $param['sys_rq'] = date('Y-m-d H:i:s',time()); $res = db('设备_糊盒班组资料')->insert($param); if ($res === false){ $this->error('新增失败'); }else{ $this->success('新增失败'); } } /** * 修改设备糊盒班组资料 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function UpdateGluingClass() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param['id'])){ $this->error('参数错误'); } $id = intval($param['id']); $param['mod_rq'] = date('Y-m-d H:i:s',time()); unset($param['id']); $res = db('设备_糊盒班组资料') ->where('id',$id) ->update($param); if ($res === false){ $this->error('修改成功'); }else{ $this->success('修改失败'); } } /** * 糊盒机台报工 * @return void * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function AddGluingReportData() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $param['sys_rq'] = date('Y-m-d H:i:s',time()); $Sql = db('设备_糊盒报工资料')->fetchSql(true)->insert($param); $res = db()->query($Sql); if ($res === false){ $this->error('报工失败'); }else{ $this->success('报工成功'); } } /** * 糊盒机台报工数据菜单 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getTab() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $data = []; $date = date('Y-m-d 00:00:00',time()-3888000); $sist = ['印后糊盒车间','精品自动化车间','数字化车间']; $department = \db('设备_基本资料') ->distinct(true) ->where('使用部门','in',$sist) ->where('设备编组','<>','') ->where('sys_sbID','<>','') ->order('设备编组') ->column('rtrim(使用部门) as 使用部门'); if (empty($department)){ $this->success('为获取到机台数据'); } $list = \db('设备_糊盒报工资料') ->field([ 'DISTINCT(sczl_rq)' => '时间', 'rtrim(sczl_jtbh)' => '机台编号' ]) ->where('sczl_rq','>',$date) ->order('sczl_rq desc') ->select(); if (empty($list)){ $this->success('未找到机台生产记录'); } foreach ($department as $value){ $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select(); foreach ($machine as $k=>$v){ $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = []; foreach ($list as $kk=>$vv){ if ($v['设备编号'] === $vv['机台编号']){ array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间']))); } } } } $this->success('成功',$data); } // public function gitGluingReportList() // { // if ($this->request->isGet() === false){ // $this->error('请求错误'); // } // $param = $this->request->param(); // if (empty($param)){ // $this->error('参数错误'); // } // $where = [ // 'a.sczl_jtbh' => $param['machine'], // 'a.sys_rq' => $param['date'], // ]; // $list = \db('设备_糊盒报工资料') // ->alias('a') // ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh') // ->join('设备_糊盒班组资料 c','a. = c.Gd_gdbh') // } public function GetProduction() { if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['machine']) || empty($params['machine'])) { $this->error('参数错误'); } $machine = $params['machine']; $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh'); $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find(); $list = []; $row = []; if (!empty($data['工单编号'])){ $endTime = \db('工单_工艺资料') ->where('Gy0_gdbh',$data['工单编号']) ->where('Gy0_yjno',$data['印件号']) ->where('Gy0_gxh',$data['工序号']) ->find(); $list['工单编号'] = $data['工单编号']; if (!empty($endTime)){ $list['印件号'] = $data['印件号']; $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称'); $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号'); $list['产品名称'] = rtrim($name); $list['产品代号'] = rtrim($code); $list['工序名称'] = $data['工序名称']; } $list['状态'] = rtrim($data['当前状态']); $list['开工时间'] = $data['开工时间']; }else{ $list['工单编号'] = ''; $list['印件号'] = 0; $list['产品名称'] = ''; $list['工序名称'] = ''; $list['产品代号'] = ''; $list['状态'] = ''; $list['开工时间'] = ''; } $list['班组编号'] = rtrim($data['班组编号']); $list['班组Id'] = rtrim($data['班组ID']); $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4, rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9, rtrim(sczl_bh10) as bh10")->find(); if (!empty($class)){ for ($i=1;$i<11;$i++) { if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') { $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find(); $row[$i] = [ '编号' => $class['bh' . $i], '姓名' => $name['姓名'] ]; } } $row = array_values($row); } $list['班组成员'] = $row; $list['定额代号'] = $machineCode; $this->success('成功',$list); } public function setMachineTeam() { if (Request::instance()->isPost() == false) { $this->error('非法请求'); } $params = Request::instance()->post(); if (!isset($params['machine']) || empty($params['machine'] )) { $this->error('参数不能为空'); } if (empty($params['team_id']) || empty($params['sczl_bzdh'])){ $this->error('请先选择班组成员'); } $machine = $params['machine'] . '#'; $data = []; $lastData = \db('设备_产量采集') ->order('UniqId desc') ->find(); $id = $lastData['UniqId']+1; $data['当前状态'] = $params['status']; $data['时间'] = date('Y-m-d H:i:s'); $data['设备编号'] = $machine; $data['工单编号'] = empty($params['order']) ? '':$params['order']; $data['印件号'] = empty($params['yjno']) ? '':$params['yjno']; $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2); $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name']; $data['当班产量'] = $params['production_now']; $data['累计产量'] = $params['production_all']; $data['班组编号'] = $params['sczl_bzdh']; $data['班组ID'] = $params['team_id']; // 获取当前时间 $current_time = time(); // 设置时间范围 $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00'); $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00'); $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00'); $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00'); $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00'); // 判断当前时间属于哪个时间范围 if ($current_time >= $start_time1 && $current_time <= $end_time1) { $data['开工时间'] = date('Y-m-d') . ' 08:30:00'; } elseif ($current_time > $end_time1 && $current_time <= $end_time2) { $data['开工时间'] = date('Y-m-d') . ' 20:30:00'; } elseif ($current_time > $end_time1 && $current_time <= $start_time3) { $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00'; }elseif ($current_time > $start_time4 && $current_time <= $start_time3){ $data['开工时间'] = date('Y-m-d') . ' 20:30:00'; } if (!empty($params['order']) && !empty($params['yjno'])){ $option['Gy0_gdbh'] = $params['order']; $option['Gy0_yjno'] = $params['yjno']; $option['Gy0_gxh'] = $data['工序号']; $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId'); }else{ $data['任务ID'] = ''; } $data['UniqId'] = $id; $sql = \db('设备_产量采集')->fetchSql(true)->insert($data); $res = Db::query($sql); if ($res === false) { $this->error('设置失败'); } else { $this->success('设置成功'); } } }