cqp il y a 6 mois
Parent
commit
410a0ac8a4

+ 31 - 31
app/Http/Controllers/Api/ScreenController.php

@@ -180,37 +180,37 @@ class ScreenController extends BaseController
      * @param Request $request
      * @return array
      */
-    public function output_value_month11(Request $request){
-        $date = date('Ymd',time());
-
-        $startDate = strtotime(date('Y-m-01 00:00:00', time()));
-        $endDate = strtotime(date('Y-m-t 23:59:59', time()));
-        //工序-----------------------------
-        $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
-        $data = $model->where('del_time',0)
-            ->where('status',4)
-            ->select('crt_time')
-            ->where('crt_time','>=',$startDate)
-            ->where('crt_time','<=',$endDate)
-            ->get()->toArray();
-
-        $return = [];
-        if(! empty($data)){
-            foreach ($data as $value){
-                $crt_time = date('Y-m-d',$value['crt_time']);
-                if(isset($return[$crt_time])){
-                    $return[$crt_time]['num'] += 1;
-                }else{
-                    $return[$crt_time] = [
-                        'num' => 1,
-                        'value' => $crt_time
-                    ];
-                }
-            }
-        }
-        $return = array_values($return);
-        return $this->json_return(200,'',$return);
-    }
+//    public function output_value_month11(Request $request){
+//        $date = date('Ymd',time());
+//
+//        $startDate = strtotime(date('Y-m-01 00:00:00', time()));
+//        $endDate = strtotime(date('Y-m-t 23:59:59', time()));
+//        //工序-----------------------------
+//        $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
+//        $data = $model->where('del_time',0)
+//            ->where('status',4)
+//            ->select('crt_time')
+//            ->where('crt_time','>=',$startDate)
+//            ->where('crt_time','<=',$endDate)
+//            ->get()->toArray();
+//
+//        $return = [];
+//        if(! empty($data)){
+//            foreach ($data as $value){
+//                $crt_time = date('Y-m-d',$value['crt_time']);
+//                if(isset($return[$crt_time])){
+//                    $return[$crt_time]['num'] += 1;
+//                }else{
+//                    $return[$crt_time] = [
+//                        'num' => 1,
+//                        'value' => $crt_time
+//                    ];
+//                }
+//            }
+//        }
+//        $return = array_values($return);
+//        return $this->json_return(200,'',$return);
+//    }
 
     /**
      * 产量趋势图

+ 7 - 7
app/Service/DeleteOrderService.php

@@ -302,13 +302,13 @@ class DeleteOrderService extends Service
                         'team_id' => 0,
                         'equipment_id' => 0
                     ]);
-                $process_model->where('order_product_id',$value['order_product_id'])
-                    ->where('process_id',$value['process_id'])
-                    ->where('dispatch_no',$value['dispatch_no'])
-                    ->where('status',4)
-                    ->update([
-                        'del_time' => time()
-                    ]);
+//                $process_model->where('order_product_id',$value['order_product_id'])
+//                    ->where('process_id',$value['process_id'])
+//                    ->where('dispatch_no',$value['dispatch_no'])
+//                    ->where('status',4)
+//                    ->update([
+//                        'del_time' => time()
+//                    ]);
 
                 $result[$key]['quantity'] = $value['finished_num'];
             }

+ 62 - 33
app/Service/FinishedOrderService.php

@@ -119,27 +119,28 @@ class FinishedOrderService extends Service
 
                 $insert_waste = $scrapp = [];
                 if(! empty($value['waste_array'])){
-                    foreach ($value['waste_array'] as $v){
-                        $num = $v['num'] * 1000;
-                        for($i = 0 ;$i < $num; $i++){
-                            $insert_waste[] = [
-                                'order_product_id' => $value['order_product_id'],
-                                'order_no' => $value['order_no'],
-                                'product_no' => $value['product_no'],
-                                'product_title' => $value['product_title'],
-                                'process_id' => $value['process_id'],
-                                'crt_time' => $time,
-                                'dispatch_no' => $value['dispatch_no'],
-                                'status' => 4,//不良品
-                                'team_id' => $value['team_id'],
-                                'finished_id' => $value['finish_id'],
-                                'equipment_id' => $value['device_id'],
-                                'scrapp_id' => $v['scrapp_id']
-                            ];
-                        }
+                    foreach ($value['waste_array'] as $k => $v){
+//                        $num = $v['num'] * 1000;
+//                        for($i = 0 ;$i < $num; $i++){
+//                            $insert_waste[] = [
+//                                'order_product_id' => $value['order_product_id'],
+//                                'order_no' => $value['order_no'],
+//                                'product_no' => $value['product_no'],
+//                                'product_title' => $value['product_title'],
+//                                'process_id' => $value['process_id'],
+//                                'crt_time' => $time,
+//                                'dispatch_no' => $value['dispatch_no'],
+//                                'status' => 4,//不良品
+//                                'team_id' => $value['team_id'],
+//                                'finished_id' => $value['finish_id'],
+//                                'equipment_id' => $value['device_id'],
+//                                'scrapp_id' => $v['scrapp_id']
+//                            ];
+//                        }
                         $scrapp[] = [
                             'sale_orders_product_id' => $value['sale_orders_product_id'],
                             'order_product_id' => $value['order_product_id'],
+                            'dispatch_sub_id' => $value['id'],
                             'out_order_no' => $value['out_order_no'],
                             'order_no' => $value['order_no'],
                             'customer_no' => $value['customer_no'],
@@ -155,9 +156,10 @@ class FinishedOrderService extends Service
                             'process_mark' => $value['process_mark'],
                             'table_body_mark' => $value['table_body_mark'],
                             'table_header_mark' => $value['table_header_mark'],
+                            'crt_id' => 1,
                             'crt_time' => $time,
-                            'scrapp_num' => $v['num'],
-                            'scrapp_id' => $v['scrapp_id'],
+                            'scrapp_num' => $v,
+                            'scrapp_id' => $k,
                             'team_id' => $value['team_id'],
                             'finished_id' => $value['finish_id'],
                             'equipment_id' => $value['device_id'],
@@ -497,15 +499,32 @@ class FinishedOrderService extends Service
         if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
 
         $first = DispatchSub::where('id',$data['id'])->first();
-        $process_model = new OrdersProductProcess(['channel' => date("Ymd",$first->out_order_no_time)]);
-
-        $result = $process_model->where('del_time',0)
-            ->where('dispatch_no',$first->dispatch_no)
-            ->where('order_product_id',$first->order_product_id)
-            ->where('status',4)
-            ->select(DB::raw('count(id) as num'),'scrapp_id')
-            ->groupBy('scrapp_id')
+
+        $result = [];
+        $scrapp = ScrappCount::where('del_time',0)
+            ->whereIn('order_product_id',$first->order_product_id)
+            ->select('order_product_id','scrapp_num as num', 'scrapp_id')
             ->get()->toArray();
+        foreach ($scrapp as $value){
+            if(isset($result[$value['order_product_id']])){
+                $tmp = bcadd($result[$value['scrapp_id']],$value['num'],3);
+                $result[$value['scrapp_id']] = $tmp;
+            }else{
+                $result[$value['scrapp_id']] = $value['num'];
+            }
+        }
+        $result = array_values($result);
+
+//        $first = DispatchSub::where('id',$data['id'])->first();
+//        $process_model = new OrdersProductProcess(['channel' => date("Ymd",$first->out_order_no_time)]);
+//
+//        $result = $process_model->where('del_time',0)
+//            ->where('dispatch_no',$first->dispatch_no)
+//            ->where('order_product_id',$first->order_product_id)
+//            ->where('status',4)
+//            ->select(DB::raw('count(id) as num'),'scrapp_id')
+//            ->groupBy('scrapp_id')
+//            ->get()->toArray();
 
         $map = Scrapp::whereIn('id',array_column($result,'scrapp_id'))
             ->pluck('title','id')
@@ -554,11 +573,11 @@ class FinishedOrderService extends Service
             if(! empty($value['waste'])){
                 foreach ($value['waste'] as $waste){
                     if(empty($waste['scrapp_id'])) return [false,'请选择损耗原因!'];
-                    if(! is_numeric($value['num']) || $value['num'] < 0) return [false,'损耗数量不能小于0!'];
+                    if(! is_numeric($waste['num']) || $waste['num'] < 0) return [false,'损耗数量不能小于0!'];
                     if(isset($waste_map[$value['id']])){
-                        $waste_map[$value['id']] += $value['num'];
+                        $waste_map[$value['id']] += $waste['num'];
                     }else{
-                        $waste_map[$value['id']] = $value['num'];
+                        $waste_map[$value['id']] = $waste['num'];
                     }
                 }
             }
@@ -569,7 +588,6 @@ class FinishedOrderService extends Service
             }else{
                 $detail_map[$value['id']] = $value['quantity'];
             }
-
             if(! isset($detail_map2[$value['id']])){
                 $detail_map2[$value['id']] = $value;
             }
@@ -589,7 +607,18 @@ class FinishedOrderService extends Service
             $result[$key]['team_id'] = $detail2['team_id'] ?? 0;
             $result[$key]['finish_id'] = $detail2['finish_id'] ?? 0;
             $result[$key]['waste_quantity'] = $waste_map[$value['id']] ?? 0;
-            $result[$key]['waste_array'] = $detail2['waste'] ?? [];
+            $tmp = [];
+            if(! empty($detail2['waste'])){
+                foreach ($detail2['waste'] as $v){
+                    if(isset($tmp[$v['id']])){
+                        $n = bcadd($v['num'],$tmp[$v['scrapp_id']],3);
+                        $tmp[$v['scrapp_id']] = $n;
+                    }else{
+                        $tmp[$v['scrapp_id']] = $v['num'];
+                    }
+                }
+            }
+            $result[$key]['waste_array'] = $tmp;
             $q = $detail_map[$value['id']] ?? 0;
             $quantity_tmp = bcadd($q,$value['finished_num'],3);
             if($quantity_tmp > $value['dispatch_quantity']) {

+ 142 - 77
app/Service/ReportFormsService.php

@@ -9,6 +9,7 @@ use App\Model\OrdersProductProcess;
 use App\Model\Process;
 use App\Model\ReportWorkingDetail;
 use App\Model\Scrapp;
+use App\Model\ScrappCount;
 use App\Model\SystemL;
 use App\Model\Team;
 use Illuminate\Support\Facades\DB;
@@ -412,22 +413,34 @@ class ReportFormsService extends Service
         //查询分表数据
         $production_id = array_keys($list);
         $detail = [];
-        foreach ($out_time as $value){
-            //子表搜索
-            $models = new OrdersProductProcess(['channel' => $value]);
-            $tmp = $models->whereIn('order_product_id',$production_id)
-                ->where('del_time',0)
-                ->where('status',4)
-                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
-                ->groupBy('order_product_id')
-                ->get()->toArray();//不良品数据
-
-            foreach ($tmp as $t){
-                if(isset($detail[$t['order_product_id']])){
-                    $detail[$t['order_product_id']]['bad_goods_num'] += $t['bad_goods_num'];
-                }else{
-                    $detail[$t['order_product_id']] = $t['bad_goods_num'];
-                }
+//        foreach ($out_time as $value){
+//            //子表搜索
+//            $models = new OrdersProductProcess(['channel' => $value]);
+//            $tmp = $models->whereIn('order_product_id',$production_id)
+//                ->where('del_time',0)
+//                ->where('status',4)
+//                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
+//                ->groupBy('order_product_id')
+//                ->get()->toArray();//不良品数据
+//
+//            foreach ($tmp as $t){
+//                if(isset($detail[$t['order_product_id']])){
+//                    $detail[$t['order_product_id']]['bad_goods_num'] += $t['bad_goods_num'];
+//                }else{
+//                    $detail[$t['order_product_id']] = $t['bad_goods_num'];
+//                }
+//            }
+//        }
+        $scrapp = ScrappCount::where('del_time',0)
+            ->whereIn('order_product_id',$production_id)
+            ->select('order_product_id','scrapp_num as bad_goods_num')
+            ->get()->toArray();
+        foreach ($scrapp as $value){
+            if(isset($detail[$value['order_product_id']])){
+                $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
+                $detail[$value['order_product_id']] = $tmp;
+            }else{
+                $detail[$value['order_product_id']] = $value['bad_goods_num'];
             }
         }
 
@@ -463,30 +476,47 @@ class ReportFormsService extends Service
 
         $detail = $detail_scrapp = [];
         $order_product_id = array_column($list,'id');
-        foreach ($out_time as $value){
-            //子表搜索
-            $models = new OrdersProductProcess(['channel' => $value]);
-            $tmp = $models->whereIn('order_product_id',$order_product_id)
-                ->where('del_time',0)
-                ->where('status',4)
-                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'), DB::raw("GROUP_CONCAT(DISTINCT scrapp_id ORDER BY scrapp_id SEPARATOR ',') as scrapp_ids"))
-                ->groupBy('order_product_id')
-                ->get()
-                ->toArray();//不良品数据
-
-            foreach ($tmp as $v){
-                if(isset($detail[$v['order_product_id']])){
-                    $detail[$v['order_product_id']] += $v['bad_goods_num'];
-                }else{
-                    $detail[$v['order_product_id']] = $v['bad_goods_num'];
-                }
-                if(isset($detail_scrapp[$v['order_product_id']])){
-                    $detail_scrapp[$v['order_product_id']] .= "," . $v['scrapp_ids'];
-                }else{
-                    $detail_scrapp[$v['order_product_id']] = $v['scrapp_ids'];
-                }
+        $scrapp = ScrappCount::where('del_time',0)
+            ->whereIn('order_product_id',$order_product_id)
+            ->select('order_product_id','scrapp_num as bad_goods_num','scrapp_id')
+            ->get()->toArray();
+        foreach ($scrapp as $value){
+            if(isset($detail[$value['order_product_id']])){
+                $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
+                $detail[$value['order_product_id']] = $tmp;
+            }else{
+                $detail[$value['order_product_id']] = $value['bad_goods_num'];
+            }
+            if(isset($detail_scrapp[$value['order_product_id']])){
+                $detail_scrapp[$value['order_product_id']] .= "," . $value['scrapp_id'];
+            }else{
+                $detail_scrapp[$value['order_product_id']] = $value['scrapp_id'];
             }
         }
+//        foreach ($out_time as $value){
+//            //子表搜索
+//            $models = new OrdersProductProcess(['channel' => $value]);
+//            $tmp = $models->whereIn('order_product_id',$order_product_id)
+//                ->where('del_time',0)
+//                ->where('status',4)
+//                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'), DB::raw("GROUP_CONCAT(DISTINCT scrapp_id ORDER BY scrapp_id SEPARATOR ',') as scrapp_ids"))
+//                ->groupBy('order_product_id')
+//                ->get()
+//                ->toArray();//不良品数据
+//
+//            foreach ($tmp as $v){
+//                if(isset($detail[$v['order_product_id']])){
+//                    $detail[$v['order_product_id']] += $v['bad_goods_num'];
+//                }else{
+//                    $detail[$v['order_product_id']] = $v['bad_goods_num'];
+//                }
+//                if(isset($detail_scrapp[$v['order_product_id']])){
+//                    $detail_scrapp[$v['order_product_id']] .= "," . $v['scrapp_ids'];
+//                }else{
+//                    $detail_scrapp[$v['order_product_id']] = $v['scrapp_ids'];
+//                }
+//            }
+//        }
 
         $scrapp_map = Scrapp::where('del_time',0)->pluck('title','id')->toArray();
         foreach ($list as $key => $value) {
@@ -546,24 +576,36 @@ class ReportFormsService extends Service
         //查询分表数据
         $production_id = array_keys($list);
         $detail = [];
-        foreach ($out_time as $value){
-            //子表搜索
-            $models = new OrdersProductProcess(['channel' => $value]);
-            $tmp = $models->whereIn('order_product_id',$production_id)
-                ->where('del_time',0)
-                ->where('status',4)
-                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
-                ->groupBy('order_product_id')
-                ->get()->toArray();//不良品数据
-
-            foreach ($tmp as $t){
-                if(isset($detail[$t['order_product_id']])){
-                    $detail[$t['order_product_id']]['bad_goods_num'] += $t['bad_goods_num'];
-                }else{
-                    $detail[$t['order_product_id']] = $t['bad_goods_num'];
-                }
+        $scrapp = ScrappCount::where('del_time',0)
+            ->whereIn('order_product_id',$production_id)
+            ->select('order_product_id','scrapp_num as bad_goods_num')
+            ->get()->toArray();
+        foreach ($scrapp as $value){
+            if(isset($detail[$value['order_product_id']])){
+                $tmp = bcadd($detail[$value['order_product_id']],$value['bad_goods_num'],3);
+                $detail[$value['order_product_id']] = $tmp;
+            }else{
+                $detail[$value['order_product_id']] = $value['bad_goods_num'];
             }
         }
+//        foreach ($out_time as $value){
+//            //子表搜索
+//            $models = new OrdersProductProcess(['channel' => $value]);
+//            $tmp = $models->whereIn('order_product_id',$production_id)
+//                ->where('del_time',0)
+//                ->where('status',4)
+//                ->select('order_product_id',DB::raw('COUNT(id) as bad_goods_num'))
+//                ->groupBy('order_product_id')
+//                ->get()->toArray();//不良品数据
+//
+//            foreach ($tmp as $t){
+//                if(isset($detail[$t['order_product_id']])){
+//                    $detail[$t['order_product_id']] += $t['bad_goods_num'];
+//                }else{
+//                    $detail[$t['order_product_id']] = $t['bad_goods_num'];
+//                }
+//            }
+//        }
 
         //返回统计数据
 
@@ -594,33 +636,56 @@ class ReportFormsService extends Service
 
         $detail = $scrapp_id = $team = $man = [];
         $order_product_id = array_column($list,'id');
-        foreach ($out_time as $value){
-            //子表搜索
-            $models = new OrdersProductProcess(['channel' => $value]);
-            $tmp = $models->where('order_product_id',$order_product_id)
-                ->where('del_time',0)
-                ->where('status',4)
-                ->select('order_product_id','scrapp_id','team_id','finished_id',DB::raw('COUNT(id) as bad_goods_num'))
-                ->groupBy('order_product_id','scrapp_id')
-                ->get()->toArray();//不良品数据
-
-            foreach ($tmp as $v){
-                if(! in_array($v['scrapp_id'], $scrapp_id)) $scrapp_id[] = $v['scrapp_id'];
-                if(! in_array($v['team_id'], $team)) $team[] = $v['team_id'];
-                if(! in_array($v['finished_id'], $man)) $man[] = $v['finished_id'];
-                if(isset($detail[$v['order_product_id']])){
-                    foreach ($detail[$v['order_product_id']] as $k => $d){
-                        if($k == $v['scrapp_id']){
-                            $detail[$v['order_product_id']][$k]['bad_goods_num'] += $v['bad_goods_num'];
-                        }else{
-                            $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
-                        }
+
+        $scrapp = ScrappCount::where('del_time',0)
+            ->whereIn('order_product_id',$order_product_id)
+            ->select('order_product_id','scrapp_num as bad_goods_num','scrapp_id','team_id','finished_id')
+            ->get()->toArray();
+        foreach ($scrapp as $value){
+            if(isset($detail[$value['order_product_id']])){
+                foreach ($detail[$value['order_product_id']] as $k => $d){
+                    if($k == $value['scrapp_id']){
+                        $t = bcadd($detail[$value['order_product_id']][$k]['bad_goods_num'], $value['bad_goods_num'],3);
+                        $detail[$value['order_product_id']][$k]['bad_goods_num'] = $t;
+                    }else{
+                        $detail[$value['order_product_id']][$value['scrapp_id']] = $value;
                     }
-                }else{
-                    $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
                 }
+            }else{
+                $detail[$value['order_product_id']][$value['scrapp_id']] = $value;
             }
+
+            if(! in_array($value['scrapp_id'], $scrapp_id)) $scrapp_id[] = $value['scrapp_id'];
+            if(! in_array($value['team_id'], $team)) $team[] = $value['team_id'];
+            if(! in_array($value['finished_id'], $man)) $man[] = $value['finished_id'];
         }
+//        foreach ($out_time as $value){
+//            //子表搜索
+//            $models = new OrdersProductProcess(['channel' => $value]);
+//            $tmp = $models->where('order_product_id',$order_product_id)
+//                ->where('del_time',0)
+//                ->where('status',4)
+//                ->select('order_product_id','scrapp_id','team_id','finished_id',DB::raw('COUNT(id) as bad_goods_num'))
+//                ->groupBy('order_product_id','scrapp_id')
+//                ->get()->toArray();//不良品数据
+//
+//            foreach ($tmp as $v){
+//                if(! in_array($v['scrapp_id'], $scrapp_id)) $scrapp_id[] = $v['scrapp_id'];
+//                if(! in_array($v['team_id'], $team)) $team[] = $v['team_id'];
+//                if(! in_array($v['finished_id'], $man)) $man[] = $v['finished_id'];
+//                if(isset($detail[$v['order_product_id']])){
+//                    foreach ($detail[$v['order_product_id']] as $k => $d){
+//                        if($k == $v['scrapp_id']){
+//                            $detail[$v['order_product_id']][$k]['bad_goods_num'] += $v['bad_goods_num'];
+//                        }else{
+//                            $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
+//                        }
+//                    }
+//                }else{
+//                    $detail[$v['order_product_id']][$v['scrapp_id']] = $v;
+//                }
+//            }
+//        }
 
         //次品原因 班组 人员
         $map = Scrapp::whereIn('id',$scrapp_id)