request->isGet() === false){ $this->error('请求错误'); } $data = []; $sist = ['印后糊盒车间','精品自动化车间','数字化车间']; $department = \db('设备_基本资料') ->distinct(true) ->where('使用部门','in',$sist) ->where('设备编组','<>','') ->order('设备编组') ->column('rtrim(使用部门) as 使用部门'); if (empty($department)){ $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['设备名称']; } } $this->success('成功',$data); } /** * 设备角色列表 * @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(); foreach ($list as $k=>$v){ for ($i = 1; $i <= 15; $i++){ $bh = $v['bh'.$i]; $list[$k]['name'.$i] = ''; if (!empty($bh) && $bh !== ''){ $name = \db('人事_基本资料') ->where('员工编号',$bh) ->value('员工姓名'); $list[$k]['name'.$i] = $name; } } } 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() { // 1. 请求方式验证(严格限制POST请求) if (!$this->request->isPost()) { $this->error('仅支持POST请求'); } // 2. 获取并验证参数(重点适配含#字符的sczl_jtbh字段) $param = $this->request->post(); // 核心修复:验证规则调整,明确允许#字符,兼容特殊字符 $validate = new \think\Validate([ 'sczl_jtbh' => 'require|regex:/^[\w#\x{4e00}-\x{9fa5}]+$/u', // 允许字母、数字、下划线、#、中文 'sczl_gdbh' => 'require', 'sczl_gxmc' => 'require', 'sys_id' => 'require', 'sczl_rq' => 'require|dateFormat:Y-m-d H:i:s', ], [ 'sczl_jtbh.require' => '机组编号不能为空', 'sczl_jtbh.regex' => '机组编号仅支持字母、数字、下划线、#号和中文', 'sczl_gdbh.require' => '工单号不能为空', 'sczl_gxmc.require' => '工序名称不能为空', 'sys_id.require' => '系统ID不能为空', 'sczl_rq.require' => '报工日期不能为空', 'sczl_rq.dateFormat' => '报工日期格式错误(需为Y-m-d H:i:s)', ]); // 验证前处理:仅去除前后空格(不影响#字符) foreach (['sczl_jtbh', 'sczl_gdbh', 'sczl_gxmc', 'sys_id', 'sczl_rq'] as $field) { if (isset($param[$field]) && is_string($param[$field])) { $param[$field] = trim($param[$field]); // 只去空格,保留#等特殊字符 } } // 执行验证 if (!$validate->check($param)) { $this->error($validate->getError()); } // 3. 事务处理(确保数据一致性) $currentTime = date('Y-m-d H:i:s'); $tableClass = '糊盒报工班组'; $tableDevice = '设备_糊盒报工资料'; // 4. 构建班组数据(保留#字符,无需额外处理) $classData = [ 'sys_rq' => $currentTime, 'jtbh' => $param['sczl_jtbh'], // 直接保留含#的原始值 'gdbh' => $param['sczl_gdbh'], 'gxmc' => $param['sczl_gxmc'], 'sys_id' => $param['sys_id'], 'sczl_rq' => $param['sczl_rq'], ]; // 处理动态字段(1-30组bh/rate) $dynamicFields = []; for ($i = 1; $i <= 30; $i++) { $dynamicFields['bh' . $i] = isset($param['bh' . $i]) ? $param['bh' . $i] : ''; $dynamicFields['rate' . $i] = isset($param['rate' . $i]) ? $param['rate' . $i] : ''; } $classData = array_merge($classData, $dynamicFields); // 5. 保存班组数据(框架会自动处理特殊字符转义,避免SQL注入) $classId = Db::name($tableClass)->insertGetId($classData); if (empty($classId)) { throw new \Exception("{$tableClass}数据保存失败"); } // 6. 构建设备数据(适配PHP7.2) $filteredParam = array_filter($param, function ($key) { return !preg_match('/^(bh|rate)\d+$/', $key); }, ARRAY_FILTER_USE_KEY); $deviceData = array_merge([ 'role' => $classId, 'sys_rq' => $currentTime, ], $filteredParam); // 7. 保存设备数据(含#字符的字段会被自动转义,安全插入) $sql = Db::name($tableDevice)->fetchSql(true)->insert($deviceData); $saveResult = db()->query($sql); if ($saveResult !== false) { $this->success('报工提交成功'); }else{ $this->error('报工提交失败'); } } /** * 糊盒机台报工数据菜单 * @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(); 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); } /** * 获取当前生产工单 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ 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('sczl_jtbh',$machine)->order('UID desc')->find(); if (empty($data)){ $this->success('未找到数据'); } $list = []; $list['班组ID'] = $data['班组ID']; $row = []; if (!empty($data['sczl_gdbh'])){ $endTime = \db('工单_工艺资料') ->where('Gy0_gdbh',$data['sczl_gdbh']) ->where('Gy0_yjno',$data['sczl_yjno']) ->where('Gy0_gxh',$data['sczl_gxh']) ->find(); $list['工单编号'] = $data['sczl_gdbh']; if (!empty($endTime)){ $list['印件号'] = $data['sczl_yjno']; $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品名称'); $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['sczl_gdbh'])->value('成品代号'); $list['产品名称'] = rtrim($name); $list['产品代号'] = rtrim($code); $list['工序名称'] = $data['sczl_gxmc']; $list['联数'] = $endTime['Gy0_ls']; } $list['状态'] = rtrim($data['status']); $list['开工时间'] = $data['sczl_kgsj']; }else{ $list['工单编号'] = ''; $list['印件号'] = 0; $list['产品名称'] = ''; $list['工序名称'] = ''; $list['产品代号'] = ''; $list['状态'] = ''; $list['开工时间'] = ''; $list['联数'] = ''; } $list['班组编号'] = rtrim($data['sczl_bzbh']); $idList = explode(',',$data['班组ID']); foreach ($idList as $k=>$v){ $class = \db('设备_糊盒班组资料') ->where('id',$v) ->field("role,rate,bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15") ->find(); if (!empty($class)){ for ($i=1;$i<16;$i++) { if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') { $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find(); $row[] = [ '编号' => $class['bh' . $i], '姓名' => $name['姓名'], '比例' => $class['rate'], '角色' => $class['role'], ]; } } $row = array_values($row); } } $list['班组成员'] = $row; $list['定额代号'] = $machineCode; $this->success('成功',$list); } /** * 设置当前工单和当前班组 * @return void */ 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 = []; $data['status'] = $params['status']; $data['sczl_sj'] = date('Y-m-d H:i:s'); $data['sczl_jtbh'] = $machine; $data['sczl_gdbh'] = empty($params['order']) ? '':$params['order']; $data['sczl_yjno'] = empty($params['yjno']) ? '':$params['yjno']; $data['sczl_gxh'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2); $data['sczl_gxmc'] = empty($params['gy_name']) ? '' : $params['gy_name']; $data['sczl_bzbh'] = $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['sczl_kgsj'] = date('Y-m-d') . ' 08:30:00'; } elseif ($current_time > $end_time1 && $current_time <= $end_time2) { $data['sczl_kgsj'] = date('Y-m-d') . ' 20:30:00'; } elseif ($current_time > $end_time1 && $current_time <= $start_time3) { $data['sczl_kgsj'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00'; }elseif ($current_time > $start_time4 && $current_time <= $start_time3){ $data['sczl_kgsj'] = 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['sczl_gxh']; $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId'); }else{ $data['任务ID'] = ''; } $sql = \db('设备_糊盒报工采集')->fetchSql(true)->insert($data); $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 getGluingReportDataList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if (empty($params['machine']) || empty($params['day'])){ $this->error('参数错误'); } $where = [ 'a.sczl_jtbh' => $params['machine'], 'a.sczl_rq' => ['like',$params['day'].'%'] ]; $field = ['a.sczl_gdbh as 工单编号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量', 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期', 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role', 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号','a.price', 'b.Gd_cpdh as 产品代号','b.Gd_cpmc as 产品名称']; $list = \db('设备_糊盒报工资料') ->alias('a') ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh','left') ->field($field) ->where($where) ->group('a.Uid') ->select(); if (empty($list)){ $this->error('未找到报工数据'); } foreach ($list as $key=>$value) { $list[$key]['class'] = []; $class = \db('糊盒报工班组') ->where('id', $value['role']) ->field("bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15,bh16,bh17,bh18,bh19,bh20,bh21,bh22,bh23, bh24,bh25,bh26,bh27,bh28,bh29,bh30,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8,rate9,rate10,rate11,rate12,rate13,rate14, rate15,rate16,rate17,rate18,rate19,rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28,rate29,rate30") ->find(); if (!empty($class)) { for ($i = 1; $i <=30; $i++) { if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') { $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find(); $list[$key]['class'][] = [ '编号' => $class['bh' . $i], '姓名' => $name['姓名'], '比例' => $class['rate'.$i], ]; } } $list[$key]['class'] = array_values($list[$key]['class']); } } $this->success('成功',$list); } /** * 报工数据详情显示 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getGluingReportDataDetail() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if(!isset($params['id']) || empty($params['id'])){ $this->error('参数错误'); } $where = ['Uid'=>$params['id']]; $field = ['a.sczl_gdbh as 工单编号','a.sczl_gxmc as 工序名称','a.来料数量','a.sczl_cl as 产量', 'a.sczl_zcfp as 制程废品','a.startTime as 开始时间','a.endTime as 结束时间','a.sczl_ls as 联数','a.sczl_rq as 日期', 'a.sczl_dedh as 定额代号','a.工价系数','a.保养工时','a.装版工时','a.异常工时','a.异常类型','a.设备运行工时','a.role', 'a.sys_id as 创建人员','a.sys_rq as 上报时间','a.mod_rq as 修改时间','a.Uid','a.sczl_jtbh as 机台编号','a.price', 'b.Gd_cpdh as 产品代号','b.Gd_cpmc as 产品名称']; $list = \db('设备_糊盒报工资料') ->alias('a') ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh','left') ->where($where) ->field($field) ->find(); $list['class'] = []; $class = \db('糊盒报工班组') ->where('id', $list['role']) ->field("bh1,bh2,bh3,bh4,bh5,bh6,bh7,bh8,bh9,bh10,bh11,bh12,bh13,bh14,bh15,bh16,bh17,bh18,bh19,bh20,bh21,bh22,bh23, bh24,bh25,bh26,bh27,bh28,bh29,bh30,rate1,rate2,rate3,rate4,rate5,rate6,rate7,rate8,rate9,rate10,rate11,rate12,rate13,rate14, rate15,rate16,rate17,rate18,rate19,rate20,rate21,rate22,rate23,rate24,rate25,rate26,rate27,rate28,rate29,rate30") ->find(); if (!empty($class)) { for ($i = 1; $i <=30; $i++) { if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') { $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find(); $list['class'][] = [ '编号' => $class['bh' . $i], '姓名' => $name['姓名'], '比例' => $class['rate'.$i], ]; } } $list['class'] = array_values($list['class']); } $this->success('成功',$list); } /** * 修改糊盒班组报工资料 * @return void * @throws \think\Exception * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function getGluingReportDetailUpdate() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if(!isset($param['id']) || empty($param['id'])){ $this->error('参数错误'); } $id = $param['id']; $role = $param['role']; unset($param['id']); // 核心修复:验证规则调整,明确允许#字符,兼容特殊字符 $validate = new \think\Validate([ 'sczl_jtbh' => 'require|regex:/^[\w#\x{4e00}-\x{9fa5}]+$/u', // 允许字母、数字、下划线、#、中文 'sczl_gdbh' => 'require', 'sczl_gxmc' => 'require', 'sczl_rq' => 'require|dateFormat:Y-m-d H:i:s', ], [ 'sczl_jtbh.require' => '机组编号不能为空', 'sczl_jtbh.regex' => '机组编号仅支持字母、数字、下划线、#号和中文', 'sczl_gdbh.require' => '工单号不能为空', 'sczl_gxmc.require' => '工序名称不能为空', 'sczl_rq.require' => '报工日期不能为空', 'sczl_rq.dateFormat' => '报工日期格式错误(需为Y-m-d H:i:s)', ]); // 验证前处理:仅去除前后空格(不影响#字符) foreach (['sczl_jtbh', 'sczl_gdbh', 'sczl_gxmc', 'sczl_rq'] as $field) { if (isset($param[$field]) && is_string($param[$field])) { $param[$field] = trim($param[$field]); // 只去空格,保留#等特殊字符 } } // 执行验证 if (!$validate->check($param)) { $this->error($validate->getError()); } // 3. 事务处理(确保数据一致性) $currentTime = date('Y-m-d H:i:s'); $tableClass = '糊盒报工班组'; $tableDevice = '设备_糊盒报工资料'; // 4. 构建班组数据(保留#字符,无需额外处理) $classData = [ 'jtbh' => $param['sczl_jtbh'], // 直接保留含#的原始值 'gdbh' => $param['sczl_gdbh'], 'gxmc' => $param['sczl_gxmc'], 'sczl_rq' => $param['sczl_rq'], ]; // 处理动态字段(1-30组bh/rate) $dynamicFields = []; for ($i = 1; $i <= 30; $i++) { $dynamicFields['bh' . $i] = isset($param['bh' . $i]) ? $param['bh' . $i] : ''; $dynamicFields['rate' . $i] = isset($param['rate' . $i]) ? $param['rate' . $i] : ''; } $classData = array_merge($classData, $dynamicFields); // 5. 保存班组数据(框架会自动处理特殊字符转义,避免SQL注入) $classId = Db::name($tableClass)->where('id',$role)->update($classData); // 6. 构建设备数据(适配PHP7.2) $filteredParam = array_filter($param, function ($key) { return !preg_match('/^(bh|rate)\d+$/', $key); }, ARRAY_FILTER_USE_KEY); $deviceData = array_merge([ 'mod_rq' => $currentTime, ], $filteredParam); // 7. 保存设备数据(含#字符的字段会被自动转义,安全插入) $sql = Db::name($tableDevice)->where('Uid',$id)->fetchSql(true)->update($deviceData); $saveResult = db()->query($sql); if ($saveResult !== false) { $this->success('修改成功'); }else{ $this->error('修改失败'); } } /** * 修改报工数据班组 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function UpdateGluingReportClass() { if ($this->request->isPost() === false){ $this->error('请求错误'); } $params = Request::instance()->post(); if(!isset($params['id']) || empty($params['id'])){ $this->error('参数错误'); } $id = $params['id']; $data['role'] = $params['role']; $res = \db('设备_糊盒报工资料')->where('Uid',$id)->update($data); 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 GluingReportList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if (!isset($params['machine']) || empty($params['machine'])){ $this->error('参数错误'); } $machine = $params['machine']; $sczlTime = date('Y-m-d H:i:s',time()); if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime $machine, 'sczl_rq' => $time, ]; $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_dedh) as dedh,rtrim(sczl_gxmc) as gxmc, rtrim(sczl_cl) as 产量,rtrim(sczl_zcfp) as 制程废品,rtrim(装版工时) as 装版工时,rtrim(保养工时) as 保养工时, rtrim(异常工时) as 异常工时,rtrim(设备运行工时) as 通电工时,startTime,endTime,Uid,rtrim(sczl_ls) as ls,来料数量'; $list = \db('设备_糊盒报工资料')->where($where)->field($field)->order('Uid desc')->select(); if (!empty($list)){ foreach ($list as $k=>$v){ $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find(); if ($v['yjno']<10){ $list[$k]['yjno'] = '0'.$v['yjno']; } $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc']; $list[$k]['生产时间段'] = substr($v['startTime'],5,5).' '.substr($v['startTime'],11,5).'<-->'.substr($v['endTime'],5,5).' '.substr($v['endTime'],11,5); $list[$k]['产品名称'] = $name['cpmc']; } } $this->success('成功',$list); } /** * 工单查询 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getWorkOrderList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if (!isset($params['search']) || empty($params['search'])){ $this->error('参数错误'); } $search = $params['search']; $list = \db('工单_基本资料') ->where('Gd_gdbh|Gd_cpmc','like',$search.'%') ->field('Gd_gdbh as 工单编号,Gd_cpdh as 产品代号,Gd_cpmc as 产品名称') ->order('Gd_gdbh desc') ->select(); if (empty($list)){ $this->error('未找到数据'); }else{ $this->success('成功',$list); } } /** * 查询机台编号 * @return void */ public function getMachineList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if (!isset($params['search']) || empty($params['search'])){ $this->error('参数错误'); } $search = $params['search']; $list = \db('设备_基本资料') ->where('使用部门',$search) ->column('设备名称','设备编号'); 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 gitProcessList() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $params = $this->request->param(); if (!isset($params['search']) || empty($params['search'])){ $this->error('参数错误'); } $search = $params['search']; $list = \db('erp_常用字典') ->where('分类','糊盒工艺') ->where('名称','like','%'.$search.'%') ->field('名称') ->select(); $data = []; if (empty($list)){ $this->error('未找到工艺数据'); } foreach ($list as $k=>$v){ $name = explode('_',$v['名称']); $data[] = $name[2]; } $this->success('成功',$data); } }