Răsfoiți Sursa

超节损计算和排产优化

qiuenguang 11 luni în urmă
părinte
comite
acf44c1e52

+ 86 - 69
application/api/controller/Manufacture.php

@@ -427,45 +427,51 @@ class Manufacture extends Api
         if (Request::instance()->isPost() === false){
         if (Request::instance()->isPost() === false){
             $this->error('请求错误');
             $this->error('请求错误');
         }
         }
-        $data = Request::instance()->post();
-        if (empty($data)){
+        $datas = Request::instance()->post();
+        if (empty($datas)){
             $this->error('参数错误');
             $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('未找到该工单工艺资料');
+        $i = 0;
+        foreach ($datas as $data){
+            $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){
+                $i++;
+            }
         }
         }
-        $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){
+        if ($i === 0){
             $this->success('成功');
             $this->success('成功');
         }else{
         }else{
             $this->error('失败');
             $this->error('失败');
@@ -489,41 +495,51 @@ class Manufacture extends Api
         if (Request::instance()->isPost() === false){
         if (Request::instance()->isPost() === false){
             $this->error('请求错误');
             $this->error('请求错误');
         }
         }
-        $data = Request::instance()->post();
-        if (empty($data)){
+        $datas = Request::instance()->post();
+        if (empty($datas)){
             $this->error('参数错误');
             $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('该工单不是制程中工单');
+        $i = $j = 0;
+        foreach ($datas as $data){
+            $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 ($rechres === false){
+                $i++;
+            }
+            if ($res === false){
+                $j++;
+            }
         }
         }
-        $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){
+
+        if ($i === 0 && $j === 0){
             $this->success('成功');
             $this->success('成功');
         }else{
         }else{
             $this->error('失败');
             $this->error('失败');
@@ -912,8 +928,9 @@ class Manufacture extends Api
         if (empty($param) || isset($param['UniqId']) === false){
         if (empty($param) || isset($param['UniqId']) === false){
             $this->error('参数错误');
             $this->error('参数错误');
         }
         }
+        $uid = explode(',',$param['UniqId']);
         $sql = \db('工单_工艺资料')
         $sql = \db('工单_工艺资料')
-            ->where('UniqId',$param['UniqId'])
+            ->where('UniqId','in',$uid)
             ->fetchSql(true)
             ->fetchSql(true)
             ->update(['Gy0_sbbh'=>$param['machine']]);
             ->update(['Gy0_sbbh'=>$param['machine']]);
         $res = \db()->query($sql);
         $res = \db()->query($sql);

+ 46 - 26
application/api/controller/OrderSuperLoss.php

@@ -1245,7 +1245,6 @@ class OrderSuperLoss extends Api
             'gdbh' => $gdbh,
             'gdbh' => $gdbh,
             'yjno' => $yjno
             'yjno' => $yjno
         ];
         ];
-
         //查询工单入仓数据
         //查询工单入仓数据
         $workOrderData = \db('成品入仓')
         $workOrderData = \db('成品入仓')
             ->where('jjcp_gdbh', $param['gdbh'])
             ->where('jjcp_gdbh', $param['gdbh'])
@@ -1660,6 +1659,7 @@ class OrderSuperLoss extends Api
                 '车间名称' => $value['Gy0_SITE']
                 '车间名称' => $value['Gy0_SITE']
             ];
             ];
         }
         }
+
         return $result;
         return $result;
 //        halt($result);
 //        halt($result);
 //        \db('工单_质量考核汇总')
 //        \db('工单_质量考核汇总')
@@ -2050,31 +2050,51 @@ class OrderSuperLoss extends Api
 
 
 
 
     //循环插入超节损数据
     //循环插入超节损数据
-//    public function orderLossData()
-//    {
-//        $param = $this->request->param();
-//        $list = \db('成品入仓')
-//            ->alias('a')
-//            ->join('设备_产量计酬 b','a.jjcp_gdbh = b.sczl_gdbh AND a.jjcp_yjno = b.sczl_yjno')
-//            ->join('物料_收发记录 c','a.jjcp_gdbh = c.st_gdbh AND a.jjcp_cpdh = c.cpdh')
-//            ->where('a.jjcp_sj','like',$param['mouth'].'%')
-//            ->where('a.jjcp_smb','like','末%')
-//            ->field('a.jjcp_gdbh,a.jjcp_yjno')
-//            ->group('a.jjcp_gdbh,a.jjcp_yjno')
-//            ->select();
-//
-//        foreach ($list as $item){
-//            $result = $this->OneOrderSuperLoss($item['jjcp_gdbh'],$item['jjcp_yjno']);
-//            \db('工单_质量考核汇总')
-//            ->where('Gy0_gdbh', $item['jjcp_gdbh'])
-//            ->where('印件及工序', $item['jjcp_yjno'])
-//            ->delete();
-//            $sql = \db('工单_质量考核汇总')
-//                ->fetchSql(true)
-//                ->insertAll($result);
-//            $res = \db()->query($sql);
-//        }
-//    }
+    public function orderLossData()
+    {
+        $param = $this->request->param();
+        $where = [];
+        if (isset($param['gdbh']) && isset($param['yjno']) && !empty($param['gdbh']) && !empty($param['yjno'])){
+            $where['a.jjcp_gdbh'] = $param['gdbh'];
+            $where['a.jjcp_yjno'] = $param['yjno'];
+        }
+        if (isset($param['mouth'])){
+            $where['a.jjcp_sj'] = ['like',$param['mouth'].'%'];
+        }
+        $where['a.jjcp_smb'] = ['like','末%'];
+        $list = \db('成品入仓')
+            ->alias('a')
+            ->join('设备_产量计酬 b','a.jjcp_gdbh = b.sczl_gdbh AND a.jjcp_yjno = b.sczl_yjno')
+            ->join('物料_收发记录 c','a.jjcp_gdbh = c.st_gdbh AND a.jjcp_cpdh = c.cpdh')
+            ->where($where)
+            ->where(function ($query) {
+                $query->where('c.仓库编号', '101')
+                    ->whereOr('c.仓库编号', 'Y101');
+            })
+            ->field('a.jjcp_gdbh,a.jjcp_yjno')
+            ->group('a.jjcp_gdbh,a.jjcp_yjno')
+            ->select();
+        $i = 0;
+        foreach ($list as $item){
+            $result = $this->OneOrderSuperLoss($item['jjcp_gdbh'],$item['jjcp_yjno']);
+            \db('工单_质量考核汇总')
+            ->where('Gy0_gdbh', $item['jjcp_gdbh'])
+            ->where('印件及工序', $item['jjcp_yjno'])
+            ->delete();
+            $sql = \db('工单_质量考核汇总')
+                ->fetchSql(true)
+                ->insertAll($result);
+            $res = \db()->query($sql);
+            if ($res === false){
+                $i++;
+            }
+        }
+        if ($i === 0){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
 }
 }