request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } if ($param['status'] === '计划中'){ $status = '3-计划中'; }else{ $status = '1-已完工'; } $page = 0; $limit = 15; if (isset($param['page'])){ $page = $param['page']; } if (isset($param['limit'])){ $limit = $param['limit']; } $where = [ 'gd_statu' => $status, '行号' => '1', ]; if (isset($param['search'])){ $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%']; } $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(成品名称) as 成品名称, rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称, rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间, rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号'; $list = \db('工单_基本资料')->where($where)->field($field)->limit(($page-1)*$limit,$limit)->order('Uniqid desc')->select(); $total = \db('工单_基本资料')->where($where)->count(); if (empty($list)){ $this->success('',[]); } foreach ($list as $key=>$value){ $list[$key]['订单数量'] = rtrim((float)$value['订单数量']); $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称']; $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count(); if ($number === 0){ $list[$key]['status'] = 0; }else{ $list[$key]['status'] = 1; } unset($list[$key]['成品名称']); } $this->success('成功',['data'=>$list,'total'=>$total]); } /** * 计划中工单->工艺资料 * @ApiMethod (GET) * @param string $Gd_gdbh 工单编号 * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function projectCraft() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $Gd_gdbh = input('Gd_gdbh'); if (empty($Gd_gdbh)){ $this->error('参数错误'); } $where = [ 'Gy0_gdbh' => $Gd_gdbh ]; $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注, rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时, rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID'; $list = \db('工单_工艺资料')->where($where)->field($filed)->select(); if (empty($list)){ $this->success('',[]); } foreach ($list as $key=>$value){ if ((int)$value['Gy0_yjno'] <10){ $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']); } if ((int)$value['Gy0_gxh'] <10){ $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']); } if (rtrim($value['Add_gxmc']) == ''){ $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']); }else{ $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】'; } unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']); } $this->success('成功',$list); } /** * 计划中工单->印件资料 * @ApiMethod (GET) * @param string $Gd_gdbh 工单编号 * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function projectPrint() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $Gd_gdbh = input('Gd_gdbh'); if (empty($Gd_gdbh)){ $this->error('参数错误'); } $where = [ 'Yj_Gdbh' => $Gd_gdbh, ]; $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称, rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料, rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户, rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID'; $list = \db('工单_印件资料')->where($where)->field($field)->select(); if (empty($list)){ $this->success(''); } foreach ($list as $key=>$value){ $list[$key]['成品数量'] = rtrim((float)$value['成品数量']); $list[$key]['实际投料'] = rtrim((float)$value['实际投料']); } $this->success('成功',$list); } /** * 排程中/制程中工单 */ public function Schedule(){ if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $where = ''; if (!empty($param['search'])){ $where = " a.Gd_gdbh LIKE '%{$param['search']}%' OR a.`成品名称` LIKE '%{$param['search']}%' "; } if ($param['status'] === '排程中'){ $list = db('工单_基本资料')->alias('a') ->field([ 'rtrim(a.Gd_gdbh)' => '工单编号', 'rtrim(a.Gd_cpdh)' => '产品代号', 'rtrim(a.Gd_cpmc)' => '产品名称', 'rtrim(a.接单日期)' => '接单日期', 'rtrim(a.交货日期)' => '交货日期', 'rtrim(a.订单数量)' => '订单数量', 'rtrim(a.计量单位)' => '计量单位', 'rtrim(a.销售订单号)' => '销售订单号', 'rtrim(a.Gd_客户代号)' => '客户编号', 'rtrim(a.Gd_客户名称)' => '客户名称', 'rtrim(a.客户料号)' => '客户料号', 'rtrim(a.Uniqid)' => 'GDUID', ]) ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh') ->where([ 'a.gd_statu' => '2-生产中', 'a.行号' => '1', 'b.PD_WG' => '1900-01-01 00:00:00', ]) ->where($where) ->whereNotExists(function ($query) { $query->table('工单_工艺资料')->alias('b2') ->where('b2.Gy0_gdbh = a.Gd_gdbh') ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"'); }) ->group('a.Gd_gdbh') ->select(); }else{ $list = db('工单_基本资料')->alias('a') ->field([ 'rtrim(a.Gd_gdbh)' => '工单编号', 'rtrim(a.Gd_cpdh)' => '产品代号', 'rtrim(a.Gd_cpmc)' => '产品名称', 'rtrim(a.接单日期)' => '接单日期', 'rtrim(a.交货日期)' => '交货日期', 'rtrim(a.订单数量)' => '订单数量', 'rtrim(a.计量单位)' => '计量单位', 'rtrim(a.销售订单号)' => '销售订单号', 'rtrim(a.Gd_客户代号)' => '客户编号', 'rtrim(a.Gd_客户名称)' => '客户名称', 'rtrim(a.客户料号)' => '客户料号', 'rtrim(a.Uniqid)' => 'GDUID', ]) ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh') ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号') ->where([ 'a.gd_statu' => '2-生产中', 'a.行号' => '1', 'b.PD_WG' => '1900-01-01 00:00:00', 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'], 'c.状态' => '', ]) ->where($where) ->group('a.Gd_gdbh') ->select(); } if (empty($list)){ $this->success('未找到工单信息'); } $this->success('成功',$list); } /** * 排程中/制程中工单->工序列表 * @ApiMethod (GET) * @param string $Gd_gdbh 工单编号 * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function ScheduleProcess() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $Gd_gdbh = input('Gd_gdbh'); if (empty($Gd_gdbh)){ $this->error('参数错误'); } $sql = "SELECT rtrim(a.Gy0_gdbh) as 工单编号,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_gxmc,a.Add_gxmc,rtrim(a.Gy0_sbbh) as 设备编号,rtrim(a.Gy0_小时产能) as 小时产能, rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间, rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注, rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量 FROM `工单_工艺资料` AS a JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号 JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh LEFT JOIN ( SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl FROM `设备_产量计酬` GROUP BY sczl_gdbh, sczl_gxh ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL) WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != '' GROUP BY a.Gy0_gxh"; $list = Db::query($sql); if (empty($list)){ $this->success('未找到工序'); } foreach ($list as $key=>$value){ if ((int)$value['Gy0_yjno'] <10){ $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']); } if ((int)$value['Gy0_gxh'] <10){ $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']); } if (rtrim($value['Add_gxmc']) == ''){ $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']); }else{ $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】'; } unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']); $list[$key]['机组'] = $value['设备编号']; $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量']; } $this->success('成功',$list); } /** * 排单页面左侧车间和机台菜单 * @ApiMethod (GET) * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function workbench() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $data = []; $department = \db('设备_基本资料') ->distinct(true) ->where('使用部门','<>','研发中心') ->where('设备编组','<>','') ->order('设备编组') ->column('使用部门'); if (empty($department)){ $this->success('为获取到机台数据'); } foreach ($department as $value){ $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->cache(true)->column('设备编组'); foreach ($benchClass as $v){ if (rtrim($v) !== ''){ $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select(); foreach ($machine as $kk=>$vv){ $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称']; } } } } $this->success('成功',$data); } /** * 工单状态设置 * @ApiMethod (GET) * @param string $workOrder 工单编号 * @param string $status 工单状态 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function StatusEdit() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $workOrder = input('workOrder'); $status = input('status'); if (empty($workOrder) || empty($status)){ $this->error('参数错误'); } $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]); $res = Db::query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 更改工序状态 * @ApiMethod (GET) * @param void * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function complete() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $data = $this->request->param(); if (empty($data)){ $this->error('参数错误'); } $where = [ 'Gy0_gdbh' => $data['workOrder'], 'Gy0_gxh' => $data['processCode'] ]; $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]); $res = Db::query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 加入排产 * @ApiMethod (POST) * @param void $data * @return void * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function ProductionSchedulingAdd() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $data = Request::instance()->post(); if (empty($data)){ $this->error('参数错误'); } $where = [ 'Gy0_gdbh' => $data['workOrder'], 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'], 'Gy0_yjno' => $data['printCode'], 'Gy0_gxh' => $data['processCode'] ]; $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find(); if ($result['sj1'] != '1900-01-01 00:00:00'){ $this->error('该工单已经是制程中'); } $lastTime = \db('工单_工艺资料') ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']]) ->field('rtrim(Gy0_sj2) as sj2') ->order('Gy0_sj2 desc') ->find(); $date = date('Y-m-d H:i:s',time()); if ($lastTime['sj2'] < $date){ $newTime = $date; }else{ $newTime = $lastTime['sj2']; } $row = \db('工单_工艺资料') ->where($where) ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时') ->find(); if (empty($row)){ $this->success('未找到该工单工艺资料'); } $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600); $sql = \db('工单_工艺资料') ->where($where) ->fetchSql(true) ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]); $res = Db::query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 暂停排产 * @ApiMethod (POST) * @param void $data * @return void * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function ProductionSchedulingPause() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $data = Request::instance()->post(); if (empty($data)){ $this->error('参数错误'); } $where = [ 'Gy0_gdbh' => $data['workOrder'], 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'], 'Gy0_yjno' => $data['printCode'], 'Gy0_gxh' => $data['processCode'] ]; $machine = $data['machine']; $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find(); if (empty($endTime)){ $this->success('未找到该工序'); } $time = $endTime['sj2']; if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){ $this->error('该工单不是制程中工单'); } $sql = \db('工单_工艺资料') ->where($where) ->fetchSql(true) ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]); $row = \db('工单_工艺资料') ->where($where) ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时') ->find(); if (empty($row)){ $this->success('未找到该工序'); } $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时']; $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh LIKE '%{$machine}%' AND Gy0_sj1 >= '{$time}' AND Gy0_sj1 < '2099-01-01 00:00:00'"; $rechres = Db::query($rechSql); $res = Db::query($sql); if ($res !== false && $rechres !== false){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 工序状态更正 * @ApiMethod (GET) * @param void $param * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function ProcessStatusCorrection() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $where = [ 'Gy0_gdbh' => $param['workOrder'], 'Gy0_sbbh' => ['<>',''] ]; $workOrder = $where['Gy0_gdbh']; $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间,rtrim(UniqId) as UniqId'; $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select(); if (empty($list)){ $this->success('未找到该工单工艺资料'); } $yieldSql = "SELECT a.Gy0_gxh as gxh,SUM(b.sczl_cl) as cl FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` as b ON a.Gy0_gxh = b.sczl_gxh WHERE a.Gy0_gdbh = '{$workOrder}' AND b.sczl_gdbh = '{$workOrder}' GROUP BY a.Gy0_gxh"; $yield = Db::query($yieldSql); foreach ($list as $key=>$value){ if ($value['yjno']<10){ $value['yjno'] = '0'.$value['yjno']; } if ($value['gxh']<10){ $value['gxh'] = '0'.$value['gxh']; } $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc']; foreach ($yield as $k=>$v){ if ($v['gxh'] === $list[$key]['gxh']){ $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl']; $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%'; }else{ $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0'; $list[$key]['完成率'] = ''; } } if ($value['完工时间'] == '1900-01-01 00:00:00') { $list[$key]['完工时间'] = ''; } unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']); } $this->success('成功',$list); } /** * 工序状态更正->工序状态编辑 * @ApiMethod (POST) * @param void * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function ProcessStatusCorrectionEdit() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $i = 0; foreach ($param as $key=>$value){ if ($value['PD_WG'] === null || $value['PD_WG'] === ''){ $endTime = '1900-01-01 00:00:00'; }else{ $endTime = $value['PD_WG']; } $sql = \db('工单_工艺资料') ->where('UniqId',$value['UniqId']) ->fetchSql(true) ->update(['PD_WG'=>$endTime]); $res = Db::query($sql); if ($res !== false){ $i++; } } if ($i !== 0){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 班次选择 * @ApiMethod (GET) * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function ScheduleSelection() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select(); if (empty($list)){ $this->success('未找到班次数据'); } foreach ($list as $key=>$value){ $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime']; unset($list[$key]['desc_'],$list[$key]['stdtime']); } $this->success('成功',$list); } /** * 车间设备制程展示 * @ApiMethod (GET) * @param void $param * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function EquipmentScheduling() { if ($this->request->isGet() === false){ $this->error('参数错误'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $machine = $param['machine']; $list = \db('工单_基本资料') ->alias('a') ->field([ 'rtrim(b.Gy0_gdbh)' => '工单编号', 'rtrim(b.Gy0_计划接货数)' => '计划接货数', 'rtrim(b.Gy0_小时产能)' => '小时产能', 'rtrim(b.Gy0_生产工时)' => '生产工时', 'rtrim(b.Gy0_辅助工时)' => '辅助工时', 'rtrim(b.Gy0_班次安排)' => '班次安排', 'rtrim(b.工序备注)' => '排单备注', 'rtrim(b.Gy0_最早开工时间)' => '最早开工时间', 'rtrim(b.Gy0_sj1)' => '计划开工时间', 'rtrim(b.Gy0_sj2)' => '计划完工时间', 'rtrim(b.Gy0_yjno)' => 'yjno', 'rtrim(b.Gy0_gxh)' => 'gxh', 'rtrim(b.Gy0_gxmc)' => 'gxmc', 'rtrim(b.Gy0_ls)' => 'ls', 'rtrim(b.UniqId)' => 'UniqId', 'SUM(c.sczl_cl)' => '已完成' ]) ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh') ->join('设备_产量计酬 c','a.Gd_gdbh = c.sczl_gdbh AND b.Gy0_gxh = c.sczl_gxh','LEFT') ->where([ 'b.Gy0_sbbh' => $machine, 'b.Gy0_sj1' => ['>','1900-01-01 00:00:00'], 'b.PD_WG' => '1900-01-01 00:00:00', 'a.gd_statu' => '2-生产中' ]) ->where('b.Gy0_sj1','<','2099-01-01 00:00:00') ->group('a.Gd_gdbh') ->select(); foreach ($list as $key=>$value){ $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']); if ($value['yjno']<10){ $value['yjno'] = '0'.$value['yjno']; } if ($value['gxh']<10){ $value['gxh'] = '0'.$value['gxh']; } $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc']; unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']); } $this->success('成功',$list); } /** * 车间设备排程编辑 * @ApiMethod (POST) * @param void $param * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function EquipmentSchedulingEdit() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $i = 0; foreach ($param as $key=>$value){ $data = [ 'Gy0_小时产能' => $value['capacity'], 'Gy0_生产工时' => $value['ProductionHours'], 'Gy0_辅助工时' => $value['AuxiliaryHours'], 'Gy0_班次安排' => $value['shift'], '工序备注' => $value['remark'], 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])), 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])), // 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600), 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['endTime'])), ]; $sql = \db('工单_工艺资料') ->where('UniqId',$value['UniqId']) ->fetchSql(true) ->update($data); $res = Db::query($sql); if ($res !== false){ $i++; } } if ($i !== 0){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 机台工单展示 * @ApiMethod () * @return void * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function MachineWorkOrderList() { if ($this->request->isGet() === false){ $this->error('请求失败'); } $param = $this->request->param(); if (empty($param)){ $this->error('参数错误'); } $where = ''; if (isset($param['search'])){ $where = " a.Gd_gdbh LIKE '%{$param['search']}%' OR a.`成品名称` LIKE '%{$param['search']}%' "; } $list = \db('工单_基本资料') ->alias('a') ->field([ 'RTRIM( a.Gd_gdbh )' => '工单编号', 'RTRIM( a.`销售订单号` )' => '销售订单号', 'RTRIM( c.yj_yjmc )' => '印件名称', 'RTRIM( b.Gy0_yjno )' =>'yjno', 'RTRIM( b.Gy0_gxh )' => 'gxh', 'RTRIM( b.Gy0_gxmc )' => 'gxmc', 'RTRIM( b.Add_gxmc )' => 'Add_gxmc', 'RTRIM( b.`Gy0_计划接货数` )' => '计划接货数', 'RTRIM( b.`Gy0_小时产能` )' => '小时产能', 'RTRIM( b.`工价系数` )' => '产能系数', 'RTRIM( b.`Gy0_生产工时` )' => '生产工时', 'RTRIM( b.Gy0_ls )' => 'ls', 'RTRIM( b.`Gy0_辅助工时` )' => '辅助工时', 'RTRIM( b.`Gy0_最早开工时间` )' => '最早开工时间', 'RTRIM( b.Gy0_sj1 )' => '计划开工时间', 'RTRIM( b.Gy0_sj2 )' => '计划完工时间', 'RTRIM( b.`Gy0_班次安排` )' => '班次安排', 'RTRIM( b.`工序备注` )' => '排单备注', 'RTRIM( a.Gd_cpmc )' => '产品名称', 'RTRIM( a.`成品名称` )' => '成品名称', 'RTRIM( a.`订单数量` )' => '订单数量', 'RTRIM( a.`计量单位` )' => '计量单位', 'RTRIM( a.`交货日期` )' => '交货日期', 'RTRIM( a.Gd_cpdh )' => '产品代号', 'RTRIM( a.`成品代号` )' => '成品代号', 'RTRIM( b.Gy0_sbbh )' => '设备编号', 'RTRIM( b.Gy0_SITE )' => '车间名称', 'RTRIM( b.UniqId )' => 'GYUID', 'RTRIM( a.Uniqid )' => 'UNIQID', 'SUM( d.sczl_cl )' => '已完成产量' ]) ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh') ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gd_gdbh') ->join('设备_产量计酬 d','a.Gd_gdbh = d.sczl_gdbh AND b.Gy0_sbbh = d.sczl_jtbh','LEFT') ->where([ 'a.gd_statu' => '2-生产中', 'a.行号'=> '1', 'b.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'], 'b.PD_WG' => '1900-01-01 00:00:00', ]) ->where($where) ->group('a.Gd_gdbh,b.Gy0_gxh') ->order('Gy0_sj1') ->select(); if (empty($list)){ $this->success('',[]); } $data['制程'] = $data['排程'] = []; foreach ($list as $key=>$value){ $list[$key]['设备编号'] = $param['machine']; if ((int)$value['yjno'] <10){ $value['yjno'] = '0'.rtrim($value['yjno']); } if ((int)$value['gxh'] <10){ $value['gxh'] = '0'.rtrim($value['gxh']); } if (rtrim($value['Add_gxmc']) == ''){ $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']); }else{ $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】'; } unset($list[$key]['Add_gxmc']); if ($value['产品名称'] == ''){ $list[$key]['产品名称'] = $value['成品名称']; } if ($value['产品代号'] == ''){ $list[$key]['产品代号'] = $value['成品代号']; } unset($list[$key]['成品代号'],$list[$key]['成品名称']); if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){ array_push($data['制程'],$list[$key]); }else{ array_push($data['排程'],$list[$key]); } } $this->success('成功',$data); } /** * 机组调整 * @return void * @throws \think\Exception * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function MachineTeamEdit() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param) || isset($param['UniqId']) === false){ $this->error('参数错误'); } $sql = \db('工单_工艺资料') ->where('UniqId',$param['UniqId']) ->fetchSql(true) ->update(['Gy0_sbbh'=>$param['machine']]); $res = \db()->query($sql); if ($res !== false){ $this->success('修改成功'); }else{ $this->error('修改失败'); } } }