Jelajahi Sumber

Merge branch 'master' of https://git.7in6.com/Minong/mes-server-api

曹鹤洋 1 tahun lalu
induk
melakukan
ed0f2d1b33

+ 147 - 2
application/api/controller/Facility.php

@@ -595,7 +595,8 @@ class Facility extends Api
         $param['sys_rq'] = date('Y-m-d H:i:s',time());
         $param['UniqId'] = $lastId + 1;
         $param['mod_rq'] = date('Y-m-d H:i:s',time());
-        $res = \db('设备_班组资料')->insert($param);
+        $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
+        $res = \db()->query($sql);
         if ($res !== false){
             $this->success('成功');
         }else{
@@ -924,7 +925,8 @@ class Facility extends Api
                 SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
                 RTRIM(f.`Gd_客户名称`) as `客户名称`,
                 RTRIM(a.YB_Cpdh) as `产品编号`,
-                RTRIM(f.Gd_cpmc) as `产品名称`
+                RTRIM(f.Gd_cpmc) as `产品名称`,
+                RTRIM(d.UniqID) as UniqId
                 FROM `产品_印版资料` as a 
                 LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
                 JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
@@ -1657,4 +1659,147 @@ class Facility extends Api
         }
         $this->success('成功',$res);
     }
+
+    /**
+     * 换型清场添加
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function remodelDataAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
+        $param['sys_id'] = '['.$param['机台编号'].']';
+        $param['sys_rq'] = date('Y-m-d H:i:s',time());
+        $param['mod_rq'] = date('Y-m-d H:i:s',time());
+        $param['UniqId'] = $lastId + 1;
+        $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 换型清场记录修改
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function remodelDataEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $param['mod_rq'] = date('Y-m-d H:i:s',time());
+        $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 换型清场记录删除
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function remodelDataDel()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
+        if ($res !== false){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 印版领用记录添加
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function PrintDetailAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
+        foreach ($param as $key=>$value){
+            $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
+            $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
+            $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
+            $param[$key]['UniqID'] = $lastId + $key +1;
+        }
+        $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('添加成功');
+        }else{
+            $this->error('添加失败');
+        }
+    }
+
+    /**
+     * 印版领用记录退还
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function PrintDetailEdit()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $idList = explode(',',$param['id']);
+        $i = 0;
+        foreach ($idList as $key=>$value){
+            $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
+            $data['Mod_rq'] = date('Y-m-d H:i:s',time());
+            $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
+            $res = \db()->query($sql);
+            if ($res === false){
+                $i++;
+            }
+        }
+        if ($i !== 0){
+            $this->error('退还失败');
+        }else{
+            $this->success('退还成功');
+        }
+    }
 }

+ 18 - 8
application/api/controller/OrderSuperLoss.php

@@ -33,7 +33,7 @@ class OrderSuperLoss extends Api
         }
         $sql = "SELECT LEFT(a.jjcp_sj, 7) AS date,RTRIM(b.`编号`) AS 编号,RTRIM(b.`名称`) as 客户名称,COUNT(DISTINCT a.jjcp_gdbh) AS count
                     FROM `成品入仓` a LEFT JOIN `物料_存货结构` b ON LEFT(a.`成品编码`, 4) = RTRIM(b.`编号`)
-                    WHERE LEFT(a.jjcp_sj, 7) >= LEFT(DATE_SUB(CURDATE(), INTERVAL 12 MONTH), 7) AND a.jjcp_smb = '末 板' AND a.`成品编码` != ''
+                    WHERE LEFT(a.jjcp_sj, 7) >= LEFT(DATE_SUB(CURDATE(), INTERVAL 12 MONTH), 7) AND (a.jjcp_smb = '末 板' OR a.jjcp_smb = '末板') AND a.`成品编码` != ''
                     GROUP BY LEFT(a.jjcp_sj, 7), RTRIM(b.`编号`) ORDER BY date DESC, 编号 ASC";
         $data = Db::query($sql);
         // 创建一个新数组来存储整理后的数据
@@ -435,6 +435,7 @@ class OrderSuperLoss extends Api
                 $gy_data[$k]['waste_quality'] = 0;
                 $gy_data[$k]['total_fp'] = $item['total_fp'] * $item['Gy0_ls'];
                 $gy_data[$k]['total_cl'] = $item['total_cl'] * $item['Gy0_ls'];
+                //无形损
                 $gy_data[$k]['intangible_loss'] = round($item['Gy0_计划损耗'] / $plan_total * $data['intangible_loss']);
                 foreach ($waste_out as $entry) {
                     for ($i = 1; $i <= 13; $i++) {
@@ -446,10 +447,23 @@ class OrderSuperLoss extends Api
                         }
                     }
                 }
-                $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] +  $gy_data[$k]['total_fp'];
+                //报废合计
+                if ($gy_data[$k]['intangible_loss'] < 0){
+                    $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality']  +  $gy_data[$k]['total_fp'];
+                }else{
+                    $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] +  $gy_data[$k]['total_fp'];
+                }
+                //工序节损数
                 $gy_data[$k]['loss'] = $item['Gy0_计划损耗'] - $gy_data[$k]['total_waste'];
+                //占投料报废率
                 $gy_data[$k]['loss_rate'] = number_format($gy_data[$k]['loss'] / $item['Gy0_计划接货数'],4) * 100 .'%';
-                $gy_data[$k]['target_loss_rate'] = number_format($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'],4) * 100 .'%';
+                //工序目标报废率
+                $target_loss_rate = floor($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'] * 10000) / 10000;
+                if ($target_loss_rate == 0){
+                    $target_loss_rate = round($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'] * 10000) / 10000;
+                }
+                $gy_data[$k]['target_loss_rate'] = $target_loss_rate * 100 . '%';
+                //工序实际报废率
                 $gy_data[$k]['actual_loss_rate'] = number_format($gy_data[$k]['total_waste'] / $item['Gy0_计划接货数'],4) * 100 .'%';
                 $gy_data[$k]['超节损承担比例'] = number_format($item['超节损承担比例'],4) * 100 .'%';
 
@@ -492,13 +506,10 @@ class OrderSuperLoss extends Api
                     'a.Gy0_gdbh' => $order,
                     'a.Gy0_gxh' => ['in', $gxh_values]
                 ])
-//                ->group('b.sczl_gxh,b.sczl_bh1, b.sczl_bh2, b.sczl_bh3, b.sczl_bh4,b.sczl_bh5,b.sczl_bh6,b.sczl_bh7,b.sczl_bh8,b.sczl_bh9,b.sczl_bh10, c.sczl_bh')
                 ->group('b.sczl_gxh, b.sczl_bh1, CASE WHEN b.sczl_bh2 = "000000" THEN "" ELSE b.sczl_bh2 END, b.sczl_bh3, 
                          b.sczl_bh4, b.sczl_bh5, b.sczl_bh6, b.sczl_bh7, b.sczl_bh8, b.sczl_bh9, c.sczl_bh1')
                 ->order('a.Gy0_gxh asc, b.开工时间 asc, c.sczl_rq desc')
-//                ->fetchSql(true)
                 ->select();
-//            halt($gy_data);
             foreach ($gy_data as $key=>$value){
                 $gy_data[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
                 //每道工序的产量(按班组分)
@@ -543,10 +554,8 @@ class OrderSuperLoss extends Api
                         }
                     }
                 }
-
                 //无形损分摊
                 $gy_data[$key]['无形损分摊'] = round($gy_data[$key]['计划损耗'] / $plan_total * $data['intangible_loss']);
-
                 $gy_data[$key]['超节损承担比例'] = number_format($value['超节损承担比例'],4) * 100 .'%';
                 //班组成员
                 $nameArr = [];
@@ -563,6 +572,7 @@ class OrderSuperLoss extends Api
                 unset($gy_data[$key]['cl']);
                 unset($gy_data[$key]['fp']);
                 unset($gy_data[$key]['sczl_bh']);
+
             }
             //重新计算多班组同组长的质检废,质检废 = 班组产量 / 总产量 * 质检废
             $totals = [];