qiuenguang 1 سال پیش
والد
کامیت
51b96a4763
2فایلهای تغییر یافته به همراه123 افزوده شده و 27 حذف شده
  1. 112 16
      application/api/controller/Facility.php
  2. 11 11
      application/api/controller/Manufacture.php

+ 112 - 16
application/api/controller/Facility.php

@@ -34,7 +34,7 @@ class Facility extends Api
         $department = \db('设备_基本资料')->distinct(true)->column('使用部门');
         $date = date('Y-m-d H:i:s',time()-3888000);
         if (empty($department)){
-            $this->error('未获取到机台数据');
+            $this->success('未获取到机台数据');
         }
         foreach ($department as $value){
             if (rtrim($value) !== '研发中心'){
@@ -97,7 +97,7 @@ class Facility extends Api
         $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->error('未找到机台数据');
+            $this->success('',[]);
         }
         foreach ($list as $key=>$value){
             $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName[$value['工单编号']];
@@ -148,14 +148,10 @@ class Facility extends Api
             '设备编号' => $machine,
             '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
             '类别' => ['in',['IPQC检验','机台检验']],
-//            'UniqId' => ['>',$startId],
         ];
-        $begin = \db('制程检验_记录')->where($where)->field('UniqId')->find();
-        $end = \db('制程检验_记录')->where($where)->order('UniqId desc')->field('UniqId')->find();
-        $where['UniqId'] = ['between',[$begin['UniqId'],$end['UniqId']+1]];
         //检验项目筛选
-        $itemA = \db('制程检验_记录')->where($where)->distinct(true)->where('班组编号','A班')->column('rtrim(检验项目)');
-        $itemB = \db('制程检验_记录')->where($where)->distinct(true)->where('班组编号','B班')->column('rtrim(检验项目)');
+        $itemA = \db('制程检验_记录')->where($where)->distinct(true)->cache(true,3600)->where('班组编号','A班')->column('rtrim(检验项目)');
+        $itemB = \db('制程检验_记录')->where($where)->distinct(true)->cache(true,3600)->where('班组编号','B班')->column('rtrim(检验项目)');
         //检验时间
         $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
         foreach ($InspectionTime as $k=>$v){
@@ -163,8 +159,8 @@ class Facility extends Api
         }
         //检测记录详情
         $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
-        $nameDetailA = \db('制程检验_记录')->where($where)->field($field)->where('班组编号','A班')->find();
-        $nameDetailB = \db('制程检验_记录')->where($where)->field($field)->where('班组编号','B班')->find();
+        $nameDetailA = \db('制程检验_记录')->cache(true,3600)->where($where)->field($field)->where('班组编号','A班')->find();
+        $nameDetailB = \db('制程检验_记录')->cache(true,3600)->where($where)->field($field)->where('班组编号','B班')->find();
         $list = $data1 = $data2 = [];
         //A班检测数据
         foreach ($itemA as $key=>$value){
@@ -258,7 +254,7 @@ class Facility extends Api
             LIMIT 1";
         $list = Db::query($sql);
         if (empty($list)){
-            $this->error('未找到排产工单');
+            $this->success('未找到排产工单',[]);
         }
         foreach ($list as $key=>$value){
             if ($value['gxh']<10){
@@ -325,7 +321,7 @@ class Facility extends Api
             ORDER BY b.Gy0_sj1";
         $orderList = Db::query($sql);
         if (empty($orderList)){
-            $this->error('未找到排产工单');
+            $this->success('未找到排产工单');
         }
         foreach ($orderList as $key=>$value){
             $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
@@ -486,7 +482,7 @@ class Facility extends Api
         rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
         $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
         if (empty($list)){
-            $this->error('未找到生产记录');
+            $this->success('未找到生产记录');
         }
         foreach ($list as $k=>$v){
             if ($v['yjno']<10){
@@ -605,7 +601,7 @@ class Facility extends Api
         }
         $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
         if (empty($list)){
-            $this->error('未找到机台编号');
+            $this->success('未找到机台编号');
         }
         $data = [];
         foreach ($list as $key=>$value){
@@ -1008,7 +1004,7 @@ class Facility extends Api
         rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
         $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
         if (empty($list)){
-            $this->error('未找到该条清场记录');
+            $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'];
@@ -1034,5 +1030,105 @@ class Facility extends Api
         ];
     }
 
-    //
+    /**
+     * 车间机台状态列表展示
+     * @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);
+    }
+
+    //机台当前参数展示
+
+    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()')
+            ->order('UniqId')
+            ->find();
+        if (!empty($startTime) && !empty($endTime)){
+            $timeDifference = ($startTime($endTime['时间'])-strtotime($startTime['时间']))/3600;
+            $data['timeDifference'] = $timeDifference;
+            $data['field'] = $endTime['当班产量']-$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['状态'];
+        }
+    }
 }

+ 11 - 11
application/api/controller/Manufacture.php

@@ -51,7 +51,7 @@ class Manufacture extends Api
         rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
         $list = \db('工单_基本资料')->where($where)->field($field)->limit(500)->order('Uniqid desc')->select();
         if (empty($list)){
-            $this->error('失败');
+            $this->success('',[]);
         }
         foreach ($list as $key=>$value){
             $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
@@ -140,7 +140,7 @@ class Manufacture extends Api
         rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
         $list = \db('工单_印件资料')->where($where)->field($field)->select();
         if (empty($list)){
-            $this->error('失败');
+            $this->success('');
         }
         foreach ($list as $key=>$value){
             $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
@@ -237,7 +237,7 @@ class Manufacture extends Api
         }
         $list = Db::query($sql);
         if (empty($list)){
-            $this->error('未找到工单信息');
+            $this->success('未找到工单信息');
         }
         $this->success('成功',$list);
     }
@@ -277,7 +277,7 @@ class Manufacture extends Api
                 GROUP BY a.Gy0_gxh";
         $list = Db::query($sql);
         if (empty($list)){
-            $this->error('未找到工序');
+            $this->success('未找到工序');
         }
         foreach ($list as $key=>$value){
             if ((int)$value['Gy0_yjno'] <10){
@@ -318,7 +318,7 @@ class Manufacture extends Api
             ->order('设备编组')
             ->column('使用部门');
         if (empty($department)){
-            $this->error('为获取到机台数据');
+            $this->success('为获取到机台数据');
         }
         foreach ($department as $value){
             $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->cache(true)->column('设备编组');
@@ -431,7 +431,7 @@ class Manufacture extends Api
             ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
             ->find();
         if (empty($row)){
-            $this->error('未找到该工单工艺资料');
+            $this->success('未找到该工单工艺资料');
         }
         $endTime = date('Y-m-d H:i:s',strtotime($lastTime['sj2']) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
         $sql = \db('工单_工艺资料')
@@ -476,7 +476,7 @@ class Manufacture extends Api
         $machine = $where['Gy0_sbbh'];
         $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2')->find()['sj2'];
         if (empty($endTime)){
-            $this->error('未找到该工序');
+            $this->success('未找到该工序');
         }
         if ($endTime <= '1900-01-01 00:00:00' || $endTime >= '2099-01-01 00:00:00'){
             $this->error('该工单不是制程中工单');
@@ -490,7 +490,7 @@ class Manufacture extends Api
             ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
             ->find();
         if (empty($row)){
-            $this->error('未找到该工序');
+            $this->success('未找到该工序');
         }
         $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
         $res = Db::query($sql);
@@ -529,7 +529,7 @@ class Manufacture extends Api
         $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->error('未找到该工单工艺资料');
+            $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);
@@ -615,7 +615,7 @@ class Manufacture extends Api
         }
         $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
         if (empty($list)){
-            $this->error('未找到班次数据');
+            $this->success('未找到班次数据');
         }
         foreach ($list as $key=>$value){
             $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
@@ -658,7 +658,7 @@ class Manufacture extends Api
         rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_ls) as ls,rtrim(UniqId) as UniqId';
         $list = \db('工单_工艺资料')->where($where)->field($filed)->cache(true)->select();
         if (empty($list)){
-            $this->error('未找到该机台制程中产品');
+            $this->success('未找到该机台制程中产品');
         }
         $Sql = "SELECT SUM(c.sczl_cl) as 已完成,rtrim(c.sczl_gdbh) as gdbh
                 FROM `工单_工艺资料` AS a  JOIN `设备_产量计酬` AS c ON a.Gy0_gdbh = c.sczl_gdbh