| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Request;
- class GluingReport extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 设备角色菜单
- * @return void
- */
- public function getGluingcoleTab()
- {
- if ($this->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)
- ->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'],
- 'sczl_bzdh' => $param['sczl_bzdh'],
- ];
- // 处理动态字段(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('设备编组','<>','')
- ->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)
- ->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 产品名称','a.sczl_bzdh 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 产品名称','a.sczl_bzdh 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'],
- 'sczl_bzdh' => $param['sczl_bzdh'],
- ];
- // 处理动态字段(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<date('Y-m-d 08:30:00')){
- $time = date('Y-m-d 00:00:00',time()-86400);
- }else{
- $time = date('Y-m-d 00:00:00');
- }
- $where = [
- 'sczl_jtbh' => $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);
- }
- //最新糊盒班组查询
- public function classifyList()
- {
- // 1. 请求方法验证
- if (!$this->request->isGet()) {
- $this->error('请使用GET请求');
- }
- // 2. 参数验证
- $params = $this->request->param();
- // 验证必需参数
- $requiredParams = ['sczl_jtbh', 'sczl_bzdh'];
- foreach ($requiredParams as $param) {
- if (empty($params[$param] ?? null)) {
- $this->error("缺少必要参数: {$param}");
- }
- }
- $jtbh = trim($params['sczl_jtbh']);
- $bzdh = trim($params['sczl_bzdh']);
- // 3. 查询糊盒报工资料
- $role = \db('设备_糊盒报工资料')
- ->where('sczl_jtbh', $jtbh)
- ->where('sczl_bzdh', $bzdh)
- ->order('Uid', 'desc')
- ->value('role');
- if (empty($role)) {
- $this->error('未找到对应的报工班组信息');
- }
- // 4. 动态生成字段列表
- $fields = [];
- for ($i = 1; $i <= 30; $i++) {
- $fields[] = "bh{$i}";
- $fields[] = "rate{$i}";
- }
- // 5. 查询班组信息
- $class = \db('糊盒报工班组')
- ->where('id', $role)
- ->field($fields)
- ->find();
- if (empty($class)) {
- $this->error('班组信息不存在');
- }
- // 6. 处理班组成员信息
- $members = [];
- $employeeIds = [];
- // 收集所有有效的员工编号
- for ($i = 1; $i <= 30; $i++) {
- $bh = $class["bh{$i}"] ?? '';
- $rate = $class["rate{$i}"] ?? 0;
- // 验证员工编号是否有效
- $bh = trim($bh);
- if (!empty($bh) && $bh !== '000000') {
- $employeeIds[$bh] = [
- 'index' => $i,
- 'rate' => $rate
- ];
- }
- }
- // 如果有有效的员工编号,批量查询员工信息
- if (!empty($employeeIds)) {
- $employeeNames = [];
- $ids = array_keys($employeeIds);
- // 批量查询员工信息(减少数据库查询次数)
- $result = \db('人事_基本资料')
- ->whereIn('员工编号', $ids)
- ->field('员工编号, rtrim(员工姓名) as 姓名')
- ->select();
- foreach ($result as $item) {
- $employeeNames[$item['员工编号']] = $item['姓名'];
- }
- // 组装返回数据
- foreach ($employeeIds as $employeeId => $info) {
- $members[] = [
- '编号' => $employeeId,
- '姓名' => $employeeNames[$employeeId] ?? '未知',
- '比例' => $info['rate']
- ];
- }
- }
- $this->success('获取成功', array_values($members));
- }
- }
|