Ver Fonte

换型清场、当前生产订单

qiuenguang há 1 ano atrás
pai
commit
de824fd9a6
1 ficheiros alterados com 104 adições e 108 exclusões
  1. 104 108
      application/api/controller/Facility.php

+ 104 - 108
application/api/controller/Facility.php

@@ -31,66 +31,66 @@ class Facility extends Api
             $this->error('请求错误');
         }
         $data = [];
-        $department = \db('设备_基本资料')->distinct(true)->column('使用部门');
-        $date = date('Y-m-d 00:00:00',time()-3888000);
-        if (empty($department)){
-            $this->success('未获取到机台数据');
-        }
-        foreach ($department as $value){
-            if (rtrim($value) !== '研发中心'){
-                $machine = \db('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
-                foreach ($machine as $kk=>$vv){
-                    if ($vv['设备编号'] !== 'ZH01#'){
-                        $date = \db('设备_产量计酬')
-                            ->where('sczl_jtbh',$vv['设备编号'])
-//                            ->where('sczl_rq','> time',$date)
-                            ->distinct(true)
-                            ->cache(true)
-                            ->limit(40)
-                            ->order('UniqId desc')
-                            ->column('sczl_rq');
-                        $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
-                    }
-                }
-            }
-        }
-        $this->success('成功',$data);
+//        $department = \db('设备_基本资料')->distinct(true)->column('使用部门');
 //        $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('未找到机台生产记录');
+//            $this->success('未获取到机台数据');
 //        }
 //        foreach ($department as $value){
-//            $machine = \db('设备_基本资料')->where('使用部门',$value)->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
-//            foreach ($machine as $k=>$v){
-////                $data[rtrim($value)][$k] = $v['设备编号'].'-->'.$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['时间'])));
-//                        array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],$vv['时间']);
+//            if (rtrim($value) !== '研发中心'){
+//                $machine = \db('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
+//                foreach ($machine as $kk=>$vv){
+//                    if ($vv['设备编号'] !== 'ZH01#'){
+//                        $date = \db('设备_产量计酬')
+//                            ->where('sczl_jtbh',$vv['设备编号'])
+////                            ->where('sczl_rq','> time',$date)
+//                            ->distinct(true)
+//                            ->cache(true)
+//                            ->limit(40)
+//                            ->order('UniqId desc')
+//                            ->column('sczl_rq');
+//                        $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
 //                    }
 //                }
 //            }
 //        }
 //        $this->success('成功',$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('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
+            foreach ($machine as $k=>$v){
+//                $data[rtrim($value)][$k] = $v['设备编号'].'-->'.$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['时间'])));
+//                        array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],$vv['时间']);
+                    }
+                }
+            }
+        }
+        $this->success('成功',$data);
     }
 
 
@@ -250,6 +250,7 @@ class Facility extends Api
         $list = [];
         $list['工单编号'] = $data['工单编号'];
         $list['印件号'] = $data['印件号'];
+        $list['班组编号'] = $data['班组编号'];
         $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
         $list['产品名称'] = rtrim($name);
         $where['Gy0_gdbh'] = $data['工单编号'];
@@ -266,49 +267,12 @@ class Facility extends Api
                 $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
                 $row[$i] = [
                     '编号' => $class['bh' . $i],
-                    '名' => $name['姓名']
+                    '名' => $name['姓名']
                 ];
             }
         }
         $list['班组成员'] = $row;
         $this->success('成功',$list);
-//        $this->success('请求成功',$list);
-//        $sql = "SELECT
-//                rtrim(b.Gy0_gdbh) AS 工单编号,
-//                rtrim(b.Gy0_yjno) AS 印件号,
-//                rtrim(b.Gy0_gxh) AS gxh,
-//                rtrim(b.Gy0_gxmc) AS gxmc,
-//                rtrim(b.Add_gxmc) AS add_gxmc,
-//                RTRIM(a.Gd_cpmc) AS 产品名称
-//            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
-//            LIMIT 1";
-//        $list = Db::query($sql);
-//        if (empty($list)){
-//            $this->success('未找到排产工单',[]);
-//        }
-//        foreach ($list as $key=>$value){
-//            if ($value['gxh']<10){
-//                $list[$key]['gxh'] = '0'.$value['gxh'];
-//            }
-//            $list[$key]['工序名称'] = $list[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
-//            unset($list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
-//        }
-//        $this->success('成功',$list);
     }
 
     /**
@@ -422,7 +386,6 @@ class Facility extends Api
             $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
             $processList['completed'] = \db('设备_产量计酬')
                 ->where('sczl_gdbh',$workOrder)
-//                ->where('UniqId','>',$startUniqid)
                 ->where('sczl_gxh',$v)
                 ->count();
             array_push($data,$processList);
@@ -563,14 +526,11 @@ class Facility extends Api
         if (empty($machine) || empty($workOrder) || empty($team)){
             $this->error('参数错误');
         }
-//        $last_id = \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
-//        $startId = $last_id['UniqId']-100000;
         $where = [
             '设备编号' => $machine,
             '工单编号' => $workOrder,
             '班组编号' => $team,
             '类别' => ['in',['IPQC检验','机台检验']],
-//            'UniqId' => ['>',$startId],
         ];
         //检验项目筛选
         $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
@@ -981,8 +941,12 @@ class Facility extends Api
         $this->success('成功',$list);
     }
 
-    //换型清场记录->左侧菜单栏
-
+    /**
+     * 换型清场->左侧菜单栏
+     * @ApiMethod  (GET)
+     * @param  void
+     * @return void
+     */
     public function remodelGetTab()
     {
         if ($this->request->isGet() === false){
@@ -996,28 +960,36 @@ class Facility extends Api
         }
         $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.`日期`";
+                WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' ORDER BY b.`UniqId`";
         $res = Db::query($sql);
-        $data = [];
+        $data = $result = [];
         foreach ($list as $key=>$value){
-            $i=0;
-            $data[$value] = [];
+            $data[$value] = $result[$value]= $time = [];
             foreach ($res as $k=>$v){
-                $row = [];
                 if ($value === $v['设备编号']){
-                    $row[$i] = [
+                    $row = [
                         '日期' => $v['日期'],
                         'id' => $v['UniqId']
                     ];
-                    $i++;
-                    foreach ($row as $vv){
+                    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++;
                     }
-                    array_push($data[$value],$row);
                 }
             }
         }
-        $this->success('成功',$data);
+        $this->success('成功',$result);
     }
 
     /**
@@ -1050,7 +1022,15 @@ class Facility extends Api
         $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){
@@ -1063,9 +1043,25 @@ class Facility extends Api
         $date = date('Y-m-d 00:00:00',time()-3888000);
         $nowTime = date('Y-m-d H:i:s',time());
         $where = [
-            '日期' =>['between',[$nowTime,$date]],
-
+            '日期' =>['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);
     }
 
     /**