| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Request;
- /**
- * 设备运行跟踪
- */
- class Facility extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 左侧菜单栏
- * @ApiMethod (GET)
- * @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);
- $department = \db('设备_基本资料')
- ->distinct(true)
- ->where('使用部门','<>','研发中心')
- ->where('设备编组','<>','')
- ->order('设备编组')
- ->column('rtrim(使用部门) as 使用部门');
- if (empty($department)){
- $this->success('为获取到机台数据');
- }
- $list = \db('设备_产量计酬')
- ->field([
- 'DISTINCT(sczl_rq)' => '时间',
- 'rtrim(sczl_jtbh)' => '机台编号'
- ])
- ->where('sczl_rq','>',$date)
- ->cache(true,86400)
- ->order('sczl_rq desc')
- ->select();
- if (empty($list)){
- $this->success('未找到机台生产记录');
- }
- foreach ($department as $value){
- $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->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);
- }
- /**
- * 机台每日产量
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @param string $date 日期
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function chanLiang()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $machine = input('machine');
- $date = input('date');
- $where = [
- 'sczl_jtbh' => $machine,
- 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
- ];
- $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
- rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
- rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
- rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
- rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
- sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
- sczl_rate8,sczl_rate9,sczl_rate10';
- //机台信息
- $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
- //工单编号
- $Gd_gdbh = \db('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
- //产品名称
- $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->field('rtrim(Gd_gdbh) as gdbh')->find();
- //组员信息
- $list = \db('设备_产量计酬')->where($where)->field($field)->cache(true,86400)->select();
- $totalA = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
- $totalB = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
- if (empty($list)){
- $this->success('',[]);
- }
- foreach ($list as $key=>$value){
- $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['gdbh'];
- if ($value['yjno']<10){
- $list[$key]['yjno'] = '0'.$value['yjno'];
- }
- $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
- $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
- $list[$key]['千件工价'] = $machineDetail['千件工价'];
- $list[$key]['日定额'] = $machineDetail['日定额'];
- for ($i=1;$i<11;$i++){
- if (isset($value['sczl_bh'.$i])){
- $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
- if (isset($name['name'])){
- $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
- }
- }
- unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
- }
- unset($list[$key]['工序编号'],$list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['num'],$list[$key]['sj1'],$list[$key]['sj2'],$list[$key]['bzdh']);
- }
- $list['totalA'] = $totalA[0]['产量'];
- $list['totalB'] = $totalB[0]['产量'];
- $this->success('成功',$list);
- }
- /**
- * 当日制程检验记录
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @param string $date 日期
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function Inspect()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $machine = input('machine');
- $date = input('date');
- if (empty($machine) || empty($date)){
- $this->error('参数错误');
- }
- $where = [
- '设备编号' => $machine,
- '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
- '类别' => ['in',['IPQC检验','机台检验']],
- ];
- $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
- $list = \db('制程检验_记录')
- ->where($where)
- ->field($field)
- ->cache(true,86400)
- ->select();
- if (empty($list)){
- $this->success('未找到检验记录');
- }
- $data = [];
- foreach ($list as $key=>$value)
- {
- $data['item'][$key] = $value['检验项目'];
- $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
- $data['工单编号'][$key] = $value['工单编号'];
- }
- $data['item'] = array_unique($data['item']);
- $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
- $data['工单编号'] = array_values(array_unique($data['工单编号']));
- foreach ($data['工单编号'] as $key => $value){
- foreach ($data['item'] as $k=>$v){
- $time = '';
- foreach ($list as $kk=>$vv){
- if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
- $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
- $data['row'][$key][$k] = [
- '工单编号' => $value,
- '印件号' => $vv['印件号'],
- '工序名称' => $vv['工序名称'],
- '检验项目' => $v,
- 'time' => substr($time,0,-1),
- ];
- }
- }
- }
- $data['row'][$key] = array_values($data['row'][$key]);
- }
- unset($data['item'],$data['工单编号']);
- $this->success('成功',$data);
- }
- /**
- * 设备生产中工单信息
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function Production()
- {
- 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('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
- $endTime = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$data['工单编号'])
- ->where('Gy0_sbbh','like','%'.$machine.'%')
- ->find();
- $list = [];
- if ($endTime['PD_WG'] === '1900-01-01 00:00:00'){
- $list['工单编号'] = $data['工单编号'];
- $list['印件号'] = $data['印件号'];
- $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
- $list['产品名称'] = rtrim($name);
- $where['Gy0_gdbh'] = $data['工单编号'];
- $where['Gy0_yjno'] = $data['印件号'];
- $where['Gy0_gxh'] = $data['工序号'];
- $gxmc = \db('工单_工艺资料')->where($where)->find();
- if ((int)$gxmc['Gy0_gxh']<10){
- $gxmc['Gy0_gxh'] = '0'.rtrim($gxmc['Gy0_gxh']);
- }
- if ($gxmc['Add_gxmc'] !== ''){
- $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']).'【'.rtrim($gxmc['Add_gxmc']).'】';
- }else{
- $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']);
- }
- $list['工序名称'] = $printName;
- }else{
- $list['工单编号'] = '';
- $list['印件号'] = 0;
- $list['产品名称'] = '';
- $list['工序名称'] = '';
- }
- $list['班组编号'] = rtrim($data['班组编号']);
- $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
- rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
- rtrim(sczl_bh10) as bh10")->find();
- $row = [];
- for ($i=1;$i<11;$i++) {
- if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
- $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
- $row[$i] = [
- '编号' => $class['bh' . $i],
- '姓名' => $name['姓名']
- ];
- }
- }
- $list['班组成员'] = $row;
- $this->success('成功',$list);
- }
- /**
- * 设备工作清单
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function EquipmentWorklist()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $machine = input('machine');
- if (empty($machine)){
- $this->error('参数错误');
- }
- $sql = "SELECT
- rtrim( b.Gy0_gdbh ) AS gdbh,
- rtrim(b.质量要求) AS 质量信息,
- rtrim( b.Gy0_yjno ) AS yjno,
- rtrim( b.Gy0_gxh ) AS gxh,
- rtrim( b.Gy0_gxmc ) AS gxmc,
- rtrim( b.Add_gxmc ) AS add_gxmc,
- rtrim( b.Gy0_辅助工时 ) AS 装版时数,
- rtrim( b.Gy0_小时产能 ) AS 工序产能,
- rtrim( b.Gy0_生产工时 ) AS 计划工时,
- rtrim( b.Gy0_sj1 ) AS sj1,
- rtrim( b.Gy0_sj2 ) AS sj2,
- rtrim(b.工序备注) AS 排产备注,
- RTRIM(d.yj_yjmc) AS 印件名称,
- RTRIM(a.Gd_cpmc) AS 产品名称,
- RTRIM(a.成品代号) AS 产品代号,
- SUM(E.sczl_cl) AS 已完成,
- rtrim(b.Gy0_计划接货数) AS 计划接货数,
- RTRIM(b.Gy0_ls) AS ls
- FROM
- `工单_基本资料` AS a
- JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
- JOIN `产品_基本资料` AS c ON a.`成品代号` = c.`产品编号`
- JOIN `工单_印件资料` AS d ON a.Gd_gdbh = d.Yj_Gdbh
- LEFT JOIN `设备_产量计酬` AS e ON e.sczl_gdbh = a.Gd_gdbh AND e.sczl_jtbh = b.Gy0_sbbh
- WHERE
- a.gd_statu = '2-生产中'
- AND a.`行号` = '1'
- AND b.Gy0_sbbh = '{$machine}'
- AND c.`状态` = ''
- AND b.PD_WG = '1900-01-01 00:00:00'
- AND b.Gy0_sj1 <> '1900-01-01 00:00:00'
- GROUP BY a.Gd_gdbh
- ORDER BY b.Gy0_sj1";
- $orderList = Db::query($sql);
- if (empty($orderList)){
- $this->success('未找到排产工单');
- }
- foreach ($orderList as $key=>$value){
- $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
- if ($value['yjno']<10){
- $orderList[$key]['yjno'] = '0'.$value['yjno'];
- }
- if ($value['gxh']<10){
- $orderList[$key]['gxh'] = '0'.$value['gxh'];
- }
- $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
- $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
- $orderList[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$value['已完成']=null?'':(int)$value['已完成'];
- $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
- unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['sj1'],$orderList[$key]['sj2'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
- }
- $this->success('成功',$orderList);
- }
- /**
- * 工序、印件、完成数量
- * @ApiMethod (GET)
- * @param string $workOrder 工单编号
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function Procedure()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $workOrder = input('Gd_gdbh');
- if (empty($workOrder)){
- $this->error('参数错误');
- }
- //右边工艺及完成数量
- $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
- ->distinct(true)->order('sczl_gxh')
- ->column('sczl_gxh');
- $data = [];
- foreach ($Process as $k=>$v){
- $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
- ->where('sczl_gxh',$v)
- ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
- ->find();
- if ($res['sczl_yjno']<10){
- $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
- }
- $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
- $processList['completed'] = \db('设备_产量计酬')
- ->where('sczl_gdbh',$workOrder)
- ->where('sczl_gxh',$v)
- ->count();
- array_push($data,$processList);
- }
- $this->success('成功',$data);
- }
- /**
- * 班组人员及分配比例
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function Team()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $machine = input('machine');
- if (empty($machine)){
- $this->error('参数错误');
- }
- $where = [
- 'sczl_jtbh' => $machine,
- ];
- $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
- rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
- rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
- rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
- rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
- $team = \db('设备_产量计酬')
- ->where('sczl_jtbh',$machine)
- ->field($field)
- ->order('UniqId desc')
- ->find();
- $list = \db('设备_班组资料')->where($where)->field($field)->select();
- $data = [];
- foreach ($list as $k=>$v){
- if ($team == $v){
- $data[$k]['status'] = 1;
- }else{
- $data[$k]['status'] = 0;
- }
- $data[$k]['ID'] = $v['ID'];
- $data[$k]['班组号'] = $v['班组号'];
- for ($i=1;$i<11;$i++){
- if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
- $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
- $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
- }
- }
- }
- $this->success('成功',$data);
- }
- /**
- * 当班产量明细
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @param string $workOrder 工单编号
- * @param string $team 班次
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function OutputDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $machine = input('machine');
- $workOrder = input('Gd_gdbh');
- $team = input('team');
- if (empty($machine) || empty($workOrder) || empty($team)){
- $this->error('参数错误');
- }
- $name = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
- $where = [
- 'sczl_gdbh' => $workOrder,
- 'sczl_jtbh' => $machine,
- 'sczl_cl' => ['<>',0.0],
- 'sczl_bzdh' => $team,
- ];
- $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
- rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
- rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
- rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
- rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
- $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
- if (empty($list)){
- $this->success('未找到生产记录');
- }
- foreach ($list as $k=>$v){
- if ($v['yjno']<10){
- $list[$k]['yjno'] = '0'.$v['yjno'];
- }
- $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
- $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
- $list[$k]['产品名称'] = $name['productName'];
- unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
- }
- $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
- SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
- SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
- SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
- $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
- $total[0]['版数'] = count($list);
- $list['total'] = $total[0];
- $this->success('成功',$list);
- }
- /**
- * 检验记录
- * @ApiMethod (GET)
- * @param string $machine 机台编号
- * @param string $workOrder 工单编号
- * @param string $team 班次
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function InspectionRecord()
- {
- if ($this->request->isGet() === false){
- $this->error('请求失败');
- }
- $machine = input('machine');
- $workOrder = input('Gd_gdbh');
- $team = input('team');
- if (empty($machine) || empty($workOrder) || empty($team)){
- $this->error('参数错误');
- }
- $where = [
- '设备编号' => $machine,
- '工单编号' => $workOrder,
- '班组编号' => $team,
- '类别' => ['in',['IPQC检验','机台检验']],
- ];
- //检验项目筛选
- $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
- //检验时间
- $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
- foreach ($InspectionTime as $k=>$v){
- $InspectionTime[$k] = date('H:i',strtotime($v));
- }
- //检测记录详情
- $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
- $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
- $data = [];
- //检测数据
- foreach ($item as $key=>$value){
- $SubmissionTime = \db('制程检验_记录')->where($where)
- ->where('检验项目',$value)
- ->where('检验结果','合格')
- ->field('rtrim(提交时间) as 提交时间')
- ->select();
- $time = [];
- foreach ($SubmissionTime as $k=>$v){
- $time[$k] = date('H:i',strtotime($v['提交时间']));
- }
- $data[$key] = [
- '工单编号' => $nameDetail['工单编号'],
- '印件号' => $nameDetail['印件号'],
- '工序名称' => $nameDetail['工序名称'],
- '检验项目' => $value,
- 'inspectresult' => implode(',',$time),
- ];
- }
- $data['inspectiontime'] = $InspectionTime;
- $this->success('成功',$data);
- }
- /**
- * 班组维护->班组添加
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function MachineTeamAdd()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $teamDetail = \db('设备_班组资料')
- ->where('UniqId',$param['UniqId'])
- ->find();
- if (empty($teamDetail)){
- $this->error('数据错误');
- }
- $lastId = \db('设备_班组资料')
- ->order('UniqId desc')
- ->value('UniqId');
- if ($lastId<100000){
- $lastId = 1000000;
- }
- $teamDetail['sczl_jtbh'] = $param['machine'].'#';
- $teamDetail['UniqId'] = $lastId + 1;
- $teamDetail['sczl_bzdh'] = $param['team'];
- $res = \db('设备_班组资料')->insert($teamDetail);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 机台编号列表
- * @ApiMethod (GET)
- * @return void
- */
- public function MachineList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
- if (empty($list)){
- $this->success('未找到机台编号');
- }
- $data = [];
- foreach ($list as $key=>$value){
- $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
- }
- $this->success('成功',$data);
- }
- /**
- * 删除班组信息
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function teamDel()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $res = \db('设备_班组资料')
- ->where('UniqId',$param['UniqId'])
- ->delete();
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 管理人员现场巡检记录->展示
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function FieldInspectionRecord()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $date = date('Y-m-d H:i:s',time());
- if (empty($param['start'])){
- $startTime = date('Y-m-d 08:30:00',time());
- }else{
- $startTime = $param['start'];
- }
- if ($date<$startTime){
- $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
- }
- $where = [
- '工单编号' => $param['workOrder'],
- '开工时间' => $startTime,
- '类别' => '现场巡查记录',
- '班组编号' => $param['team']
- ];
- $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
- rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
- rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
- $list = \db('制程检验_记录')->where($where)
- ->field($filed)
- ->select();
- if (empty($list)){
- $this->success('',[]);
- }
- foreach ($list as $key=>$value){
- $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
- $list[$key]['归属时段'] = $value['开工时间'];
- $list[$key]['分钟差数'] = $number;
- if ($number != 0){
- $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
- }
- }
- $this->success('成功',$list);
- }
- /**
- * 管理人员现场巡检记录->添加
- * @ApiMethod (POST)
- * @param void
- * @return void
- */
- public function FieldInspectionRecordAdd()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- if ($param['processCode']<10){
- $param['processCode'] = '0'.$param['processCode'];
- }
- $date = date('Y-m-d H:i:s',time());
- $startTime = date('Y-m-d 08:30:00',time());
- if ($date<$startTime){
- $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
- }
- $data = [
- '类别' => $param['category'],
- '工单编号' => $param['workOrder'],
- '印件号' => $param['printCode'],
- '工序名称' => $param['processCode'].'-'.$param['process'],
- '流程单号' => $param['flowCode'],
- '设备编号' => $param['machine'],
- '班组编号' => $param['team'],
- '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
- '相关标准' => '',
- '量测仪器' => '',
- '检验结果' => '',
- '检验备注' => $param['remark'],
- '提交时间' => date('Y-m-d H:i:s',time()),
- '开工时间' => $startTime,
- 'sys_id' => '',
- 'sys_rq' => date('Y-m-d H:i:s',time()),
- 'mod_rq' => '0000-00-00 00:00:00',
- 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
- ];
- $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 设备点检->左侧菜单栏
- * @ApiMethod (GET)
- * @param void
- * @return void
- */
- public function SpotCheckItem()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('设备_点检项目')
- ->where('适用机型','LIKE','%;'.$param['machine'].';%')
- ->distinct(true)
- ->column('部件名称','部件编号');
- if (empty($list)){
- $this->success('');
- }
- $this->success('成功',$list);
- }
- /**
- * 设备点检->检测项目
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function InspectionItem()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('设备_点检项目')
- ->where('部件名称',$param['unitName'])
- ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
- ->select();
- if (empty($list)){
- $this->success('未找到检测项目');
- }
- $this->success('成功',$list);
- }
- /**
- * 设备点检->检测记录添加
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function InspectionItemAdd()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
- if ((int)$lastNumber>10000000){
- $lastId = $lastNumber;
- }else{
- $lastId = 10000000;
- }
- $row = [];
- foreach ($param as $key=>$value){
- $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
- $row[$key] = [
- '日期' => date('Y-m-d 00:00:00',time()),
- '班组编号' => $value['team'],
- '点检设备' => $value['machine'],
- '部件编号' => $unitCode['部件编号'],
- '部件名称' => $value['unitName'],
- '检验项目' => $value['itemName'],
- '判定标准' => $value['standard'],
- '点检方法' => $value['method'],
- '点检结果' => $value['status'],
- '备注说明' => $value['remark'],
- 'Sys_id' =>'',
- 'Sys_rq' => date('Y-m-d H:i:s',time()),
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- 'Uniqid' => $lastId+$key+1
- ];
- }
- $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
- $res = Db::query($sql);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 机台印版领用->左侧菜单
- * @ApiMethod (GET)
- * @param void
- * @return void
- */
- public function PrintGetTab()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $productCode = $param['productCode'];
- $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
- JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
- WHERE a.YB_Cpdh = '{$productCode}'";
- $res = Db::query($sql);
- if (empty($res)){
- $this->success('');
- }
- $this->success('成功',$res);
- }
- /**
- * 机台印版领用记录->数据详情
- * @ApiMethod (GET)
- * @param void
- * @return void
- */
- public function PrintDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求失败');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $productCode = $param['productCode'];
- $code = $param['code'].'%';
- $workOrder = $param['workOrder'];
- $sql = "SELECT
- RTRIM(a.`存货编码`) as `存货编码`,
- RTRIM(c.`物料名称`) as `存货名称`,
- RTRIM(b.`印版名称`) as `印版名称`,
- RTRIM(b.`供方批号`) as `供方批号`,
- RTRIM(b.`制造日期`) as `制造日期`,
- SUM(d.`Yb_印数`) as `印数`,
- RTRIM(e.`名称`) as `印版类别`,
- SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
- RTRIM(f.`Gd_客户名称`) as `客户名称`,
- RTRIM(a.YB_Cpdh) as `产品编号`,
- RTRIM(f.Gd_cpmc) as `产品名称`
- FROM `产品_印版资料` as a
- LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
- JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
- LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
- JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
- JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
- WHERE a.YB_Cpdh = '{$productCode}'
- AND a.`存货编码` LIKE '{$code}'
- AND f.Gd_gdbh = '{$workOrder}'
- AND b.`报废日期` = '1900-01-01 00:00:00'
- GROUP BY b.`供方批号`
- ORDER BY a.`存货编码`";
- $list = Db::query($sql);
- if (empty($list)){
- $this->success('');
- }
- $this->success('成功',$list);
- }
- /**
- * 换型清场->左侧菜单栏
- * @ApiMethod (GET)
- * @param void
- * @return void
- */
- public function remodelGetTab()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $date = date('Y-m-d 00:00:00',time()-3888000);
- $nowTime = date('Y-m-d H:i:s',time());
- $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
- if (empty($list)){
- $this->error('失败');
- }
- $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId FROM `设备_基本资料` as a
- LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
- WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' ORDER BY b.`UniqId`";
- $res = Db::query($sql);
- $data = $result = [];
- foreach ($list as $key=>$value){
- $data[$value] = $result[$value]= $time = [];
- foreach ($res as $k=>$v){
- if ($value === $v['设备编号']){
- $row = [
- '日期' => $v['日期'],
- 'id' => $v['UniqId']
- ];
- array_push($data[$value],$row);
- }
- }
- foreach ($data[$value] as $m=>$n){
- $time[$m] = $n['日期'];
- }
- $time = array_values(array_unique($time));
- foreach ($time as $kk=>$vv){
- $i=1;
- foreach ($data[$value] as $kkk=>$vvv){
- if ($kkk>=$kk && $vv === $vvv['日期']){
- array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
- $i++;
- }
- }
- }
- }
- $this->success('成功',$result);
- }
- /**
- * 换型清场->详情
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function RemodelDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
- rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
- rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
- rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
- $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
- if (empty($list)){
- $this->success('未找到该条清场记录');
- }
- $list['日期'] = date('Y-m-d',strtotime($list['日期']));
- $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
- $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
- $this->success('成功',$list);
- }
- /**
- * 换型清场->当前设备清场记录
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ModelChangeRecord()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $date = date('Y-m-d 00:00:00',time()-3888000);
- $nowTime = date('Y-m-d H:i:s',time());
- $where = [
- '日期' =>['between',[$date,$nowTime]],
- '机台编号' => $param['machine']
- ];
- $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
- rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
- rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
- rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_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]['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
- $list[$key]['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
- }
- $this->success('成功',$list);
- }
- /**
- * 车间机台状态列表展示
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\exception\PDOException
- */
- public function MachineDetailList()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $workshop = $param['workshop'];
- $sql = "SELECT
- RTRIM( a.`设备编号` ) AS 设备编号,
- RTRIM( a.`设备名称` ) AS 设备名称,
- RTRIM( d.`当前状态` ) AS 状态
- FROM
- `设备_基本资料` AS a
- JOIN (
- SELECT
- b.`设备编号`,
- b.`当前状态`,
- b.`开工时间`
- FROM
- `设备_产量采集` AS b
- JOIN ( SELECT `设备编号`, MAX( `开工时间` ) AS `最新开工时间` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
- AND b.`开工时间` = c.`最新开工时间`
- ) AS d ON a.`设备编号` = d.`设备编号`
- WHERE
- a.`使用部门` = '{$workshop}'
- GROUP BY
- a.`设备编号`";
- $list = \db()->query($sql);
- foreach ($list as $key=>$value){
- if ($value['状态'] == ''){
- $list[$key]['状态'] = '待单';
- }
- }
- $this->success('成功',$list);
- }
- /**
- * 机台当前参数展示
- * @ApiMethod (GET)
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function MachineDetail()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $data = [];
- //机台状态时间
- $startTime = \db('设备_产量采集')
- ->where('设备编号',$param['machine'])
- ->where('开工时间',$param['start'])
- ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
- ->order('UniqId')
- ->group('当前状态')
- ->find();
- if (!empty($startTime)){
- $timeDifference = round((strtotime($startTime['最大时间'])-strtotime($startTime['时间']))/3600,2);
- $data['timeDifference'] = $timeDifference;
- $data['field'] = $startTime['最大产量']-$startTime['当班产量'];
- }else{
- $data['timeDifference'] = 0;
- $data['field'] = 0;
- }
- //机台产能/时间明细
- $row = \db('设备_产量采集')
- ->where('设备编号',$param['machine'])
- ->where('开工时间',$param['start'])
- ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
- ->select();
- if (empty($row)){
- $data['row'] = '';
- }
- foreach ($row as $key=>$value){
- $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
- $data['row'][$key]['状态'] = $value['状态'];
- if ($key<2){
- $data['row'][$key]['产能'] = 0;
- }else{
- $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
- }
- }
- //机台状态
- $status = end($row);
- if (empty($status['状态'])){
- $data['status'] = '待单';
- }else{
- $data['status'] = $status['状态'];
- }
- //检验数据
- $list = \db('制程检验_记录')
- ->where('开工时间',$param['start'])
- ->where('设备编号',$param['machine'])
- ->where('sys_rq','>',$param['start'])
- ->field('rtrim(类别) as 类别,提交时间')
- ->select();
- $data['首件'] = $data['自检'] = $data['IPQC'] = [];
- if (empty($list)){
- $this->success('未找到检验记录');
- }
- foreach ($list as $key=>$value){
- if ($value['类别'] == '现场巡查记录'){
- array_push($data['首件'],$value['提交时间']);
- }
- if ($value['类别'] == '机台自检'){
- array_push($data['自检'],$value['提交时间']);
- }
- if ($value['类别'] == 'IPQC检验'){
- array_push($data['IPQC'],$value['提交时间']);
- }
- }
- $data['首件'] = array_values(array_unique($data['首件']));
- $data['自检'] = array_values(array_unique($data['自检']));
- $data['IPQC'] = array_values(array_unique($data['IPQC']));
- $this->success('成功',$data);
- }
- /**
- * 制程检验记录->检验项目
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ProcessInspectionRecordsItem()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (empty($param)){
- $this->error('参数错误');
- }
- $list = \db('制程检验_项目')
- ->where('工序','like','%'.$param['process'].'%')
- ->select();
- if (empty($list)){
- $this->success('未找到检测项目');
- }
- $data = [];
- foreach ($list as $key=>$value){
- $data['首件']['指标检验'][$key] = [
- '检验项目' => rtrim($value['检测项目']),
- '检测方法' => rtrim($value['检测方法']),
- '检验频率' => rtrim($value['首件签样要求']),
- '相关标准' => rtrim($value['技术要求'])
- ];
- $data['机台检验']['指标检验'][$key] = [
- '检验项目' => rtrim($value['检测项目']),
- '检测方法' => rtrim($value['检测方法']),
- '检验频率' => rtrim($value['机台自检频率']),
- '相关标准' => rtrim($value['技术要求'])
- ];
- $data['IPQC']['指标检验'][$key] = [
- '检验项目' => rtrim($value['检测项目']),
- '检测方法' => rtrim($value['检测方法']),
- '检验频率' => rtrim($value['IPQC检验频率']),
- '相关标准' => rtrim($value['技术要求'])
- ];
- }
- $row = \db('制程检验_项目附加')
- ->where('工序','like','%'.$param['process'].'%')
- ->select();
- foreach ($row as $key=>$value){
- $data['首件']['附加'][$key] = [
- '缺陷备注' => rtrim($value['缺陷备注']),
- '编号' => rtrim($value['编号'])
- ];
- $data['机台检验']['附加'][$key] = [
- '缺陷备注' => rtrim($value['缺陷备注']),
- '编号' => rtrim($value['编号'])
- ];
- $data['IPQC']['附加'][$key] = [
- '缺陷备注' => rtrim($value['缺陷备注']),
- '编号' => rtrim($value['编号'])
- ];
- }
- $this->success('成功',$data);
- }
- /**
- * 制程检验记录->检测记录添加
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ProcessInspectionRecordsItemAdd()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
- if ($startID<100000000){
- $startID = 100000000;
- }
- $process = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$param[0]['workOrder'])
- ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
- ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
- ->find();
- $startTime = \db('设备_产量采集')
- ->where('设备编号','like','%'.$param[0]['machine'].'#%')
- ->where('工单编号',$param[0]['workOrder'])
- ->order('UniqId desc')
- ->find();
- if ((int)$process['gxh']<10){
- $process['gxh'] = '0'.$process['gxh'];
- }
- if ($process['add_gxmc'] !== ''){
- $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
- }else{
- $printName = $process['gxh'].'-'.$process['gxmc'];
- }
- if (empty($process)){
- $this->success('数据错误');
- }
- $data = [];
- foreach ($param as $key=>$value){
- $data[$key] = [
- '类别' => $value['category'],
- '工单编号' => $value['workOrder'],
- '印件号' => $value['yjno'],
- '工序名称' => $printName,
- '流程单号' => $value['flow'],
- '设备编号' => $value['machine'],
- '班组编号' => $startTime['班组编号'],
- '检验项目' => $value['item'],
- '相关标准' => $value['standard'],
- '量测仪器' => $value['instrument'],
- '检验结果' => $value['result'],
- '检验备注' => $value['remark'],
- '提交时间' => date('Y-m-d H:i:s',time()),
- '开工时间' => rtrim($startTime['开工时间']),
- 'sys_id' => '',
- 'sys_rq' => date('Y-m-d H:i:s',time()),
- 'mod_rq' => '0000-00-00 00:00:00',
- 'UniqId' => $startID + $key +1
- ];
- }
- $res = \db('制程检验_记录')->insertAll($data);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 制程检验记录->附加检验记录添加
- * @ApiMethod (POST)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function AdditionalInspectionRecordAdd()
- {
- if (Request::instance()->isPost() === false){
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)){
- $this->error('参数错误');
- }
- $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
- if ($startID<100000000){
- $startID = 100000000;
- }
- $process = \db('工单_工艺资料')
- ->where('Gy0_gdbh',$param[0]['workOrder'])
- ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
- ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
- ->find();
- $startTime = \db('设备_产量采集')
- ->where('设备编号','like','%'.$param[0]['machine'].'#%')
- ->where('工单编号',$param[0]['workOrder'])
- ->order('UniqId desc')
- ->find();
- if ((int)$process['gxh']<10){
- $process['gxh'] = '0'.$process['gxh'];
- }
- if ($process['add_gxmc'] !== ''){
- $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
- }else{
- $printName = $process['gxh'].'-'.$process['gxmc'];
- }
- if (empty($process)){
- $this->success('数据错误');
- }
- $data = [];
- foreach ($param as $key=>$value){
- $data[$key] = [
- '工单编号' => $value['workOrder'],
- '印件号' => $value['yjno'],
- '工序名称' => $printName,
- '流程单号' => $value['flow'],
- '设备编号' => $value['machine'],
- '班组编号' => $startTime['班组编号'],
- '缺陷备注' => $value['remark'],
- '提交时间' => date('Y-m-d H:i:s',time()),
- '开工时间' => rtrim($startTime['开工时间']),
- 'sys_id' => '',
- 'sys_rq' => date('Y-m-d H:i:s',time()),
- 'mod_rq' => '0000-00-00 00:00:00',
- 'UniqId' => $startID + $key +1
- ];
- }
- $res = \db('制程检验_记录附加')->insertAll($data);
- if ($res !== false){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- }
- /**
- * 客诉记录
- * @ApiMethod (GET)
- * @param void
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function ComplaintRecord()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $param = $this->request->param();
- if (isset($param['productCode'])){
- $where['产品编号'] = $param['productCode'];
- }
- $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
- rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
- rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
- rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
- $list = \db('db_客诉记录')
- ->where($where)
- ->field($filed)
- ->select();
- if (empty($list)){
- $this->success('未找到该产品客诉记录');
- }
- $this->success('成功',$list);
- }
- }
|