success('请求成功'); } /** * 设置机台状态 * @ApiMethod POST * @params */ public function setMachineStatus(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->post(); if (!isset($params['machine']) || empty($params['machine'])){ $this->error('参数不能为空'); } $machine = $params['machine'].'#'; $data = []; $lastData = Db::name('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find(); if ($lastData['UniqId'] < 160000000){ $id = 160000000; }else{ $id = $lastData['UniqId'] + 1; } if (empty($params['order'])){ unset($lastData['UniqId']); $data = $lastData; $data['当前状态'] = $params['status']; }else{ $data['当前状态'] = $params['status']; $data['时间'] = date('Y-m-d H:i:s'); $data['设备编号'] = $machine; $data['工单编号'] = $params['order']; $data['印件号'] = $params['yjno']; $data['工序号'] = (int)substr($params['gy_name'],0,2); $data['工序名称'] = $params['gy_name']; $data['当班产量'] = $params['production_now']; $data['累计产量'] = $params['production_all']; $class = explode(',',$params['class']); $where = []; $where['sczl_jtbh'] = $machine; for ($i=1;$i<=count($class);$i++){ $where['sczl_bh'.$i] = $class[$i-1]; } $classData = Db::name('设备_班组资料')->where($where)->field('sczl_bzdh,UniqId')->find(); $data['班组编号'] = $classData['sczl_bzdh']; $data['班组ID'] = $classData['UniqId']; // 获取当前时间 $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'); // 判断当前时间属于哪个时间范围 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'; } $option['Gy0_gdbh'] = $params['order']; $option['Gy0_yjno'] = $params['yjno']; $option['Gy0_gxh'] = $data['工序号']; $data['任务ID'] = Db::name('工单_工艺资料')->where($option)->value('UniqId'); } $data['UniqId'] = $id; $sql = Db::name('设备_产量采集')->fetchSql(true)->insert($data); $res = Db::query($sql); if ($res === false){ $this->success('设置失败'); }else{ $this->error('设置成功'); } } /** * 设置工单工序完工 * @ApiMethod POST * @params string order * @params string yjno * @params string gxh */ public function setProcessStatus(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->post(); if (!isset($params['order']) || empty($params['order'])){ $this->error('参数不能为空'); } if (!isset($params['yjno']) || empty($params['yjno'])){ $this->error('参数不能为空'); } if (!isset($params['gxh']) || empty($params['gxh'])){ $this->error('参数不能为空'); } $where['Gy0_gdbh'] = $params['order']; $where['Gy0_yjno'] = $params['yjno']; $where['Gy0_gxh'] = $params['gxh']; $date = date('Y-m-d H:i:s'); $res = Db::name('工单_工艺资料')->where($where)->setField('PD_WG',$date); if ($res === false){ $this->success('设置失败'); }else{ $this->error('设置成功'); } } /** * 根据机台获取生产信息 * @ApiMethod GET * @params string machine */ public function getProduceInfo(){ if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['machine']) || empty($params['machine'])) { $this->error('参数错误'); } $machine = $params['machine'].'#'; $data = Db::name('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find(); $list = []; $list['order'] = $data['工单编号']; $list['yjno'] = $data['印件号']; $name = Db::name('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称'); $list['product_name'] = rtrim($name); $where['Gy0_gdbh'] = $data['工单编号']; $where['Gy0_yjno'] = $data['印件号']; $where['Gy0_gxh'] = $data['工序号']; $gxmc = Db::name('工单_工艺资料')->where($where)->value('Gy0_gxmc'); $list['gxmc'] = rtrim($gxmc); $this->success('请求成功',$list); } /** * 根据员工编号获取姓名 * @ApiMethod GET * @params string code */ public function getStaffName(){ if (Request::instance()->isGet() == false) { $this->error('非法请求'); } $params = Request::instance()->param(); if (!isset($params['code']) || empty($params['code'])) { $this->error('参数错误'); } if (substr($params['code'],0,2) == 'ZM'){ $code = $params['code']; }else{ if (strlen($params['code']) != 5){ $length = strlen($params['code']); $len = 5 -$length; $str = ''; for ($i=0;$i<$len;$i++){ $str .= '0'; } $code = 'ZM'.$str.$params['code']; }else{ $code = 'ZM'.$params['code']; } } $data = Db::name('人事_基本资料')->where('员工编号',$code)->value('员工姓名'); $this->success('请求成功',rtrim($data)); } /** * 提交巡查记录 * @ApiMethod POST * @params */ public function submitPatrolRecord(){ } }