success('请求成功'); } /** * 获取工单基本数据 * * @ApiMethod GET * @params string order */ public function getData(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $order = $params['order']; if (!isset($order)){ $this->error('参数不能为空'); } $map = array(); $map['a.Gd_gdbh'] = $order; $map['a.行号'] = 1; //胶印车间计量单位为”张“,凹印车间计量单位一般为”吨“ $info = db('工单_基本资料')->alias('a') ->join('工单_bom资料 b ',' a.Gd_gdbh=b.BOM_工单编号','left') ->field('a.成品代号,a.产品版本号,b.BOM_计划用量,b.BOM_物料名称') ->where($map) ->where('b.BOM_产出单位',['eq','张'],['eq','吨'],'or') ->select(); $res =array(); $product_number = ''; if (count($info) > 1){ foreach ($info as $k=>$v){ $product_number = rtrim($v['成品代号']); $str = rtrim($v['BOM_物料名称']); $res['paper'][$k] ['bom_物料名称'] = $str; $res['paper'][$k] ['产品版本号'] = rtrim($v['产品版本号']); $res['paper'][$k] ['bom_计划用量'] = intval($v['BOM_计划用量']); } $list = Db::connect('db2')->name('qr_history_peijian') ->where('FIND_IN_SET(:product_number, product_number)') ->bind(['product_number' => $product_number]) ->field('id,peijian_name')->select(); $res['peijian'] = $list; }else{ $res['paper'][0]['bom_物料名称'] = rtrim($info[0]['BOM_物料名称']); $res['paper'][0]['产品版本号'] = rtrim($info[0]['产品版本号']); $res['paper'][0]['bom_计划用量'] = intval($info[0]['BOM_计划用量']); } $res['num'] = count($info); $this->success('请求成功',$res); } /** * 获取历史工艺信息 * * @ApiMethod GET * @params string order */ public function getHistory(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $order = $params['order']; if (!isset($params['order'])){ $this->error('参数不能为空'); } $where = array(); $where['Gd_gdbh'] = $order; $where['行号'] = 1; $product = db('工单_基本资料') ->where($where) ->field('成品代号') ->find(); $map =array(); $map['product_number'] = rtrim($product['成品代号']); if ($params['peijian'] > 0){ $map['peijian'] = $params['peijian']; } $res = Db::connect('db2')->name('qr_history')->where($map)->order('id desc')->field('data,update')->find(); $result = array(); $result['update'] = '暂无'; $result['data'] = ''; $result['num'] = 0; $result['department'] = '车间'; if ($res){ $data = explode(',',$res['data']); $result['num'] = 1; $result['data'] = $data; $result['update'] = $res['update']; } $this->success('请求成功',$result); } /** * 保存产品工艺信息 * * @ApiMethod POST * @params */ public function saveData(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['order'])){ $this->error('参数不能为空'); } $ip = request()->ip(); //定义各部门ip地址 $JYarray=array('20.0.3.253','60.190.242.28','127.0.0.1'); $WYarray=array('20.0.3.110','60.190.242.26'); $MQarray=array('20.0.2.200','60.190.242.29'); $department = -1; //确认是不是凹印车间,ip确认部门不准 $explode_data = explode(',',$params['data']); if (in_array($ip,$MQarray)){ $department = 3; }elseif (in_array($ip,$WYarray) || $explode_data[0] == '卷凹' || $explode_data[0] == '凹印'){ $department = 2; }else{ $department = 1; } $data = []; $data['department'] = $department; $data['data'] = substr($params['data'],0,-1); $where = array(); $where['Gd_gdbh'] = $params['order']; $where['行号'] = 1; $product = db('工单_基本资料') ->where($where) ->field('成品代号') ->find(); $data['product_number'] = rtrim($product['成品代号']); $map['product_number'] = $data['product_number']; $map['department'] = $department; if ($params['peijian']){ $map['peijian'] = $params['peijian']; } $data['update'] = date('Y-m-d H:i:s'); $data['ip'] =$ip; $isNull = Db::connect('db2')->name('qr_history')->where($map)->find(); if ($isNull){//去更新工艺及时间 $res = Db::connect('db2')->name('qr_history')->where('id',$isNull['id'])->update($data); }else{//新增 $res = Db::connect('db2')->name('qr_history')->insert($data); } if ($res){ $this->success('更新成功'); }else{ $this->error('更新失败'); } } /** * 获取流程单头部信息 * * @ApiMethod POST * @params string order */ public function getInfo(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $data = Request::instance()->param(); if (!isset($data['order'])){ $this->error('参数不能为空'); } $str = '原纸'; $where = [ 'Gd_gdbh'=> $data['order'], ]; $field = 'Gd_gdbh,rtrim(销售订单号) as 销售订单号,rtrim(Gd_cpmc) as Gd_cpmc,rtrim(成品名称) as 成品名称,计划投料,实际投料,rtrim(产品版本号) as 产品版本号,rtrim(警语版面) as 警语版面, rtrim(Gd_desc) as Gd_desc'; $gdinfo = db('工单_基本资料') ->where($where) ->field($field) ->select(); $length = count($gdinfo); if (!empty($data['num'])){ $gdinfo[0]['计划投料'] = $data['num']; } if (rtrim($gdinfo[0]['成品名称']) == ''){ $cpmc = trim($gdinfo[0]['Gd_cpmc']); $gdinfo[0]['成品名称'] = $cpmc; } $gdinfo[0]['mabao'] = $data['mabao']; $gdinfo[0]['version'] = $data['version']; $gdinfo[0]['liucheng_num'] = ''; $newdata = explode(',',$data['string']); $gdinfo['gy_data'] = array_filter($newdata); $gdinfo['technique_sequence'] = trim($gdinfo[0]['version']).'、'.trim($gdinfo[0]['警语版面']).'、'.trim($gdinfo[0]['Gd_desc']); $gdinfo['total_liuchen'] = ceil(($gdinfo[0]['计划投料']?$gdinfo[0]['计划投料']:$gdinfo[0]['实际投料']*10000)/$data['tldx']); //总的流程数 $gdinfo['length'] = $length; $this->success('请求成功',$gdinfo); } }