Bladeren bron

工艺资料计划产量分配

qiuenguang 1 jaar geleden
bovenliggende
commit
d5a5a45880
1 gewijzigde bestanden met toevoegingen van 122 en 35 verwijderingen
  1. 122 35
      application/api/controller/WorkOrder.php

+ 122 - 35
application/api/controller/WorkOrder.php

@@ -416,8 +416,22 @@ class WorkOrder extends Api
             '排产时库存' => isset($param['kc'])?$param['kc']:'',
             '平均合格率' => isset($param['avg'])?$param['avg']:'',
         ];
+        //获取印件资料
+        $printCode = \db('工单_印件资料')
+            ->where('Uniqid',$param['printID'])
+            ->value('yj_Yjno');
+        if (empty($printCode)){
+            $this->success('未找到该工单印件资料');
+        }
+        //修改工单工艺计划产量
+        $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
+        if ($result === false){
+            $this->success('分配工序计划产量失败');
+        }
+        //修改工单信息
         $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
         $res = Db::query($sql);
+        //修改印件信息
         $printSql = \db('工单_印件资料')
             ->where('Uniqid',$param['printID'])
             ->fetchSql(true)
@@ -991,37 +1005,13 @@ class WorkOrder extends Api
         ];
         //获取工单编号
         $workOrder = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->field('Yj_Gdbh,yj_Yjno')->find();
-        //获取工艺资料
-        $processList = \db('工单_工艺资料')
-            ->where('Gy0_gdbh',$workOrder['Yj_Gdbh'])
-            ->where('Gy0_yjno',$workOrder['yj_Yjno'])
-            ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
-            ->select();
-        //计算损耗定额和计划产量
-        $production = [];
-        foreach ($processList as $key=>$value){
-            if ($key === 0){
-                array_push($production,$param['pztl']);
-            }
-            $wastage = 0;
-            if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
-                $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
-            }
-
-            if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
-                $wastage = round($wastage * $value['Gy0_ms']);
-            }
-            if ((int)$value['Gy0_ls'] === 1 && $key>=1){
-                $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
-            }else{
-                $number = $production[$key];
-            }
-            array_push($production,ceil($number-$wastage));
-            $processSql = \db('工单_工艺资料')
-                ->where('UniqId',$value['UniqId'])
-                ->fetchSql(true)
-                ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
-            \db()->query($processSql);
+        if (empty($workOrder)){
+            $this->success('未找到该工单印件资料');
+        }
+        //重新分配工序计划产量
+        $result = $this->PlannedProcessYield($workOrder['Yj_Gdbh'],$workOrder['yj_Yjno'],0,$param['pztl']);
+        if ($result === false){
+            $this->success('修改工序产量失败');
         }
         $sql = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
         $res = Db::query($sql);
@@ -1071,8 +1061,10 @@ class WorkOrder extends Api
             'Gy0_小时产能' => $param['xscn'],
             'Mod_rq' => date('Y-m-d H:i:s',time()),
         ];
+        //修改工艺资料
         $sql = \db('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
         $res = Db::query($sql);
+        //修改工单状态
         $status = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
         if ($status['status'] !== '2-生产中'){
             $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
@@ -1589,8 +1581,8 @@ class WorkOrder extends Api
             $this->error('参数错误');
         }
         $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
-        if ($lastId<1000000){
-            $lastId = 1000000;
+        if (empty($lastId)){
+            $lastId = 0;
         }else{
             $lastId = $lastId + 1;
         }
@@ -1622,8 +1614,8 @@ class WorkOrder extends Api
             $this->error('参数错误');
         }
         $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
-        if ($lastId<100000000){
-            $lastId = 100000000;
+        if (empty($lastId)){
+            $lastId = 0;
         }else{
             $lastId = $lastId + 1;
         }
@@ -1645,6 +1637,13 @@ class WorkOrder extends Api
             ->fetchSql(true)
             ->insert($param);
         $res = \db()->query($sql);
+        //获取平张投料
+        $number = \db('工单_印件资料')
+            ->where('Yj_Gdbh',$param['Gy0_gdbh'])
+            ->where('yj_Yjno',$param['Gy0_yjno'])
+            ->value('rtrim(yj_平张投料)');
+        //分配工艺计划产量
+        $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
         if ($res !== false){
             $this->success('成功');
         }else{
@@ -1734,6 +1733,19 @@ class WorkOrder extends Api
         }
         $printId = explode(',',$param['UniqId']);
         $i = 0;
+        //获取工单编号、印件号
+        $codeList = \db('工单_工艺资料')
+            ->where('UniqId',$printId[0])
+            ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
+            ->find();
+        //获取平张投料数量
+        $number = \db('工单_印件资料')
+            ->where([
+                'Yj_Gdbh' => $codeList['工单编号'],
+                'yj_Yjno' => $codeList['印件号']
+            ])
+            ->value('rtrim(yj_平张投料)');
+        //循环删除工艺资料
         foreach ($printId as $value){
             $res = \db('工单_工艺资料')
                 ->where('UniqId',$value)
@@ -1742,6 +1754,8 @@ class WorkOrder extends Api
                 $i++;
             }
         }
+        //重新分配工艺计划产量
+        $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
         if ($i === 0){
             $this->success('删除成功');
         }else{
@@ -2153,4 +2167,77 @@ class WorkOrder extends Api
         $this->success('成功',$list);
     }
 
+
+    /**
+     * 工艺资料计划产量重新分配
+     * @param string $workOrder 工单
+     * @param int $yjno 印件号
+     * @param int $gxh 工序号
+     * @param int $feed 平张投料
+     * @return bool
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
+    {
+        if ($gxh === 0){
+            $where = [
+                'Gy0_gdbh'=>$workOrder,
+                'Gy0_yjno'=>$yjno,
+            ];
+        }else{
+            $where = [
+                'Gy0_gdbh'=>$workOrder,
+                'Gy0_yjno'=>$yjno,
+                'Gy0_gxh'=>['>=',$gxh]
+            ];
+        }
+        //获取工艺资料
+        $processList = \db('工单_工艺资料')
+            ->where($where)
+            ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
+            ->select();
+        if (empty($processList)){
+            $this->success('未找到该工单工序资料');
+        }
+        //计算损耗定额和计划产量
+        $production = [];
+        $i = 0;
+        foreach ($processList as $key=>$value){
+            if ($key === 0){
+                array_push($production,$feed);
+            }
+            $wastage = 0;
+            if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
+                $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
+            }
+
+            if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
+                $wastage = round($wastage * $value['Gy0_ms']);
+            }
+            if ((int)$value['Gy0_ls'] === 1 && $key>=1){
+                $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
+            }else{
+                $number = $production[$key];
+            }
+            array_push($production,ceil($number-$wastage));
+            $processSql = \db('工单_工艺资料')
+                ->where('UniqId',$value['UniqId'])
+                ->fetchSql(true)
+                ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
+            $res = \db()->query($processSql);
+            if ($res === false){
+                $i++;
+            }
+        }
+        if ($i===0){
+            return true;
+        }else{
+            return false;
+        }
+    }
 }