qiuenguang 1 год назад
Родитель
Сommit
5b2e0b7d32
1 измененных файлов с 14 добавлено и 11 удалено
  1. 14 11
      application/api/controller/OrderSuperLoss.php

+ 14 - 11
application/api/controller/OrderSuperLoss.php

@@ -1227,8 +1227,7 @@ class OrderSuperLoss extends Api
             'gdbh' => $gdbh,
             'yjno' => $yjno
         ];
-//        echo $param['gdbh'];
-//        echo $param['yjno'];
+//
         //查询工单入仓数据
         $workOrderData = \db('成品入仓')
             ->where('jjcp_gdbh', $param['gdbh'])
@@ -1241,7 +1240,9 @@ class OrderSuperLoss extends Api
             ->where('jjcp_yjno', $param['yjno'])
             ->column('SUM(jjcp_sl)');
         //查询工单资料、投料数据
-        $field = 'a.Gd_gdbh,rtrim(a.成品代号) as 成品代号,rtrim(a.成品名称) as 成品名称,rtrim(a.销售订单号) as 销售订单号,a.订单数量,c.yj_ls as ls,c.yj_ks as ks,SUM(b.st_sl) as 投料';
+        $field = 'a.Gd_gdbh,rtrim(a.成品代号) as 成品代号,rtrim(a.成品名称) as 成品名称,
+                  rtrim(a.销售订单号) as 销售订单号,a.订单数量,c.yj_ls as ls,c.yj_ks as ks,SUM(b.st_sl) as 投料,
+                  b.st_dw,c.yj_zzmc';
         $data = db('工单_基本资料')
             ->alias('a')
             ->join('物料_收发记录 b', 'a.Gd_gdbh = b.st_gdbh AND a.Gd_cpdh = b.cpdh')
@@ -1257,6 +1258,10 @@ class OrderSuperLoss extends Api
         if ($data['投料'] == null){
             return false;
         }
+        preg_match('/(\d+)g/',$data['yj_zzmc'], $matches);
+        if ($data['st_dw'] === '吨'){
+            $data['投料'] = round(($data['投料']*1000*1000)/$matches[1]);
+        }
         //将开数、联数为0重新赋值
         if ($data['ls'] == 0) {
             $data['ls'] === 1;
@@ -1312,7 +1317,7 @@ class OrderSuperLoss extends Api
         //工单无形损 = 实际投料-入仓数量-废品合计
         $data['intangible_loss'] = (int)($data['实际投料'] * 10000 - $total_number[0] - $waste_total);
         //查询核检单废品上报数据
-        $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
+        $out_sql = "SELECT qczl_num,fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
                         fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13, 
                         fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
                         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
@@ -1398,7 +1403,7 @@ class OrderSuperLoss extends Api
                 'a.Gy0_gdbh', 'a.Gy0_yjno', 'a.Gy0_gxh', 'a.Gy0_ls', 'a.Gy0_ks', 'a.Gy0_计划损耗', 'a.超节损承担比例',
                 'b.sczl_gxmc', 'SUM(b.sczl_zcfp) as sczl_zcfp', 'SUM(b.sczl_cl) as total_cl',
                 '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',
+                'b.sczl_bh7', 'b.sczl_bh8', 'b.sczl_bh9', 'b.sczl_bh10', 'GROUP_CONCAT(DISTINCT b.sczl_num SEPARATOR ",") AS 流程单',
                 'b.sczl_bzdh', 'b.sczl_rate1', 'b.sczl_rate2', 'b.sczl_rate3', 'b.sczl_rate4', 'b.sczl_rate5',
                 'b.sczl_rate6', 'b.sczl_rate7', 'b.sczl_rate8', 'b.sczl_rate9', 'b.sczl_rate10',
                 'rtrim(c.sczl_gxmc) as gxmc', 'SUM(c.sczl_cl) as cl', 'SUM(c.sczl_fp) as fp', 'c.sczl_bh1 as sczl_bh',
@@ -1421,6 +1426,7 @@ class OrderSuperLoss extends Api
             ->order('a.Gy0_gxh asc, b.开工时间 asc, c.sczl_rq desc')
             ->select();
         foreach ($gy_data as $kk => $vv) {
+            $num_data = explode(',',$vv['流程单']);
             //每道工序的产量(按班组分)
             $gy_data[$kk]['total_cl'] = $vv['total_cl'] * $vv['Gy0_ls'] * $vv['Gy0_ks'];
             if (empty($vv['total_cl'])) {
@@ -1460,13 +1466,9 @@ class OrderSuperLoss extends Api
                     $gxlbKey = "fp_lb" . $i;
                     $slKey = "fp_sl" . $i;
                     $bhKey = "fp_bh" . $i;
-                    if ((int)substr($entry[$gxmcKey], 0, 2) == $vv['Gy0_gxh'] && $entry[$bhKey] == $vv['sczl_bh1']) {
+                    if ((int)substr($entry[$gxmcKey], 0, 2) == $vv['Gy0_gxh'] && $entry[$bhKey] == $vv['sczl_bh1'] && in_array($entry['qczl_num'],$num_data)) {
                         $gy_data[$kk]['质检废'] += $entry[$slKey];
                     }
-//                    if (substr($entry[$gxlbKey], 0, 1) == 'K'){
-//                        $gy_data[$kk]['质检废'] = $data['机检废'];
-//                        echo $entry[$slKey];
-//                    }
                 }
             }
             //无形损分摊
@@ -1537,7 +1539,6 @@ class OrderSuperLoss extends Api
         }
         //整合数据
         $result = [];
-//        halt($gy_data);
         foreach ($gy_data as $key => $value) {
             $result[$key] = [
                 'sys_ny' => $value['sys_ny'],
@@ -1616,6 +1617,7 @@ class OrderSuperLoss extends Api
             ];
         }
         return $result;
+//        halt($result);
 //        \db('工单_质量考核汇总')
 //            ->where('Gy0_gdbh', $param['gdbh'])
 //            ->where('印件及工序', $param['yjno'])
@@ -1821,6 +1823,7 @@ class OrderSuperLoss extends Api
             ->where($where)
             ->field($total_field)
             ->find();
+        $list['机检废'] = $total['total_waste'] - $total['材料废'] - $total['total_zjfp'];
         $list['total'] = $total;
         $this->success('成功',$list);
     }