Parcourir la source

月份平均值

qiuenguang il y a 1 an
Parent
commit
b24d428ec1

+ 98 - 7
application/api/controller/Decision.php

@@ -292,12 +292,103 @@ class Decision extends Api
         $mouth = \db('工单_质量考核汇总')
             ->where('sys_ny','like',$param['year'].'%')
             ->column('distinct(sys_ny) as mouth');
-        //查询进入超节损一年内所有数据
-//        $list = \db('工单_质量考核汇总')
-//            ->alias('a')
-//            ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
-//            ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
-//            ->field('a.sys_ny,a.工序','b.Gy0_gxmc','b.Gy0_计划接货数*b.Gy0_ls*b.Gy0_ks as 计划产量',
-//            'a.计划损耗','a.')
+        //创建工序数组
+        $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
+        $result = $data = [];
+        foreach ($mouth as $key=>$value){
+            foreach ($processType as $item){
+                //查询进入超节损一年内所有数据
+                $list = \db('工单_质量考核汇总')
+                    ->alias('a')
+                    ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
+                    ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
+                    ->field('a.sys_ny,(a.计划损耗+sum(a.班组质检废品))/a.印件工序产量 as 废品率')
+                    ->where('b.Gy0_gxmc','like',$item.'%')
+                    ->where('a.sys_ny',$value)
+                    ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
+                    ->select();
+                $data[$value][$item] = $list;
+            }
+        }
+        $months = [
+            $param['year'].'01' => '01月',
+            $param['year'].'02' => '02月',
+            $param['year'].'03' => '03月',
+            $param['year'].'04' => '04月',
+            $param['year'].'05' => '05月',
+            $param['year'].'06' => '06月',
+            $param['year'].'07' => '07月',
+            $param['year'].'08' => '08月',
+            $param['year'].'09' => '09月',
+            $param['year'].'10' => '10月',
+            $param['year'].'11' => '11月',
+            $param['year'].'12' => '12月'
+        ];
+        //汇总数据
+        foreach ($processType as $index => $process) {
+            $result[$index] = array(
+                "工序类型" => $process,
+                "01月" => "",
+                "02月" => "",
+                "03月" => "",
+                "04月" => "",
+                "05月" => "",
+                "06月" => "",
+                "07月" => "",
+                "08月" => "",
+                "09月" => "",
+                "10月" => "",
+                "11月" => "",
+                "12月" => ""
+            );
+
+            // 遍历月份
+            foreach ($months as $month => $monthName) {
+                $totalRate = 0;
+
+                // 检查月份是否存在于数据中
+                if (isset($data[$month])) {
+                    // 检查工序是否存在于月份数据中
+                    if (isset($data[$month][$process])) {
+                        // 累加废品率
+                        foreach ($data[$month][$process] as $rate) {
+                            $totalRate += floatval($rate["废品率"]);
+                        }
+                    }
+                }
+
+                // 格式化为百分比字符串,保留两位小数
+                if ($totalRate > 0) {
+                    $result[$index][$monthName] = sprintf("%.2f%%", (1-$totalRate) * 100);
+                } else {
+                    $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
+                }
+            }
+        }
+        foreach ($result as &$item) {
+            $total = 0;
+            $count = 0;
+
+            // 遍历月份,计算总和和数量
+            for ($i = 1; $i <= 12; $i++) {
+                $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
+                if (isset($item[$month]) && $item[$month] !== "") {
+                    // 移除百分号,并将字符串转换为浮点数
+                    $value = floatval(str_replace("%", "", $item[$month]));
+                    $total += $value;
+                    $count++;
+                }
+            }
+
+            // 计算平均值
+            if ($count > 0) {
+                $average = $total / $count;
+                // 格式化为百分比字符串,保留两位小数
+                $item["平均值"] = sprintf("%.2f%%", $average);
+            } else {
+                $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
+            }
+        }
+        $this->success('成功',$result);
     }
 }

+ 12 - 7
application/api/controller/OrderSuperLoss.php

@@ -398,7 +398,7 @@ class OrderSuperLoss extends Api
             $this->error('参数错误');
         }
         $sql = "SELECT a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_ls,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数,a.Gy0_ms,
-                a.Gy0_计划接货数*a.Gy0_ls as Gy0_计划接货数,a.Gy0_计划损耗,sum(b.sczl_cl) as total_cl,sum(b.sczl_zcfp) as total_fp,sum(c.sczl_cl) as cl,SUM(c.sczl_fp) as fp FROM `工单_工艺资料` a
+                a.Gy0_计划接货数*a.Gy0_ls as Gy0_计划接货数,a.Gy0_计划损耗*a.Gy0_ls as a.Gy0_计划损耗,sum(b.sczl_cl) as total_cl,sum(b.sczl_zcfp) as total_fp,sum(c.sczl_cl) as cl,SUM(c.sczl_fp) as fp FROM `工单_工艺资料` a
                 LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
                 LEFT JOIN `db_sczl` c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
                 WHERE a.Gy0_gdbh = '{$params['order']}' AND a.Gy0_yjno = '{$params['yjno']}' GROUP BY a.Gy0_gxh";
@@ -534,6 +534,7 @@ class OrderSuperLoss extends Api
                         fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13,UniqId
                         FROM db_qczl WHERE qczl_gdbh = '{$order}' AND qczl_yjno = '{$params['yjno']}'";
         $waste_out = Db::query($out_sql);
+        halt($waste_out);
         $list = []; //外发废数组
         $quality = [];//质检废数组
         $material = [];//材料废数组
@@ -1219,10 +1220,12 @@ class OrderSuperLoss extends Api
      */
     public function OneOrderSuperLoss($gdbh,$yjno)
     {
+//        $param = $this->request->param();
         $param = [
             'gdbh' => $gdbh,
             'yjno' => $yjno
         ];
+//        halt($param);
         //查询工单入仓数据
         $workOrderData = \db('成品入仓')
             ->where('jjcp_gdbh', $param['gdbh'])
@@ -1399,12 +1402,11 @@ class OrderSuperLoss extends Api
                 'a.Gy0_gxh' => ['in', $gxh_values],
                 'b.sczl_cl|c.sczl_cl' => ['>', 0],
             ])
-            ->group('b.sczl_gxh,b.sczl_jtbh,b.sczl_bh1, CASE WHEN b.sczl_bh2 = "000000" THEN "" ELSE b.sczl_bh2 END, b.sczl_bh3, 
+            ->group('b.sczl_gxh,b.sczl_jtbh,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')
             ->select();
         foreach ($gy_data as $kk => $vv) {
-//            $gy_data[$kk]['Gy0_yjno'] = $vv['Gy0_yjno'] > 10 ? $vv['Gy0_yjno'] : '0'.$vv['Gy0_yjno'];
             //每道工序的产量(按班组分)
             $gy_data[$kk]['total_cl'] = $vv['total_cl'] * $vv['Gy0_ls'] * $vv['Gy0_ks'];
             if (empty($vv['total_cl'])) {
@@ -1512,7 +1514,6 @@ class OrderSuperLoss extends Api
             $total['waste_intangible'] += $item['无形损分摊'];
             $total['reward'] += floatval(str_replace(',', '', $gy_data[$n]['节损奖']));
         }
-
         //整合数据
         $result = [];
         foreach ($gy_data as $key => $value) {
@@ -1523,11 +1524,11 @@ class OrderSuperLoss extends Api
                 '工序' => $value['Gy0_gxh'],
                 '工序名称' => $value['sczl_gxmc'],
                 '联数' => $value['Gy0_ls'],
-                '基础损耗' => $value['Gy0_Rate0'] * $value['Gy0_ls'],
+                '基础损耗' => $value['Gy0_Rate0'],
                 '损耗率' => $value['Gy0_Rate1'],
                 '损耗系数' => $value['损耗系数'],
                 '计损色数' => $value['Gy0_ms'],
-                '计划产量' => $value['计划产量'] * $value['Gy0_ls'],
+                '计划产量' => $value['计划产量'],
                 '计划损耗' => $value['Gy0_计划损耗'],
                 '班组分摊计划损耗' => $value['计划损耗'],
                 '印件工序产量' => $value['工序产量'],
@@ -1591,8 +1592,12 @@ class OrderSuperLoss extends Api
                 'sys_rq' => date('Y-m-d H:i:s', time()),
                 '车间名称' => $value['Gy0_SITE']
             ];
-            return $result;
         }
+        return $result;
+//        $sql = \db('工单_质量考核汇总')
+//            ->fetchSql(true)
+//            ->insertAll($result);
+//        \db()->query($sql);
     }