cqp 10 months ago
parent
commit
8ed6b0b554
1 changed files with 86 additions and 2 deletions
  1. 86 2
      app/Service/ReportFormsService.php

+ 86 - 2
app/Service/ReportFormsService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Model\DispatchSub;
 use App\Model\Employee;
 use App\Model\OrdersProduct;
 use App\Model\OrdersProductProcess;
@@ -119,12 +120,95 @@ class ReportFormsService extends Service
         return $out_time;
     }
 
+    public function teamReport($data){
+        if(empty($data['finish_time'][0]) || empty($data['finish_time'][1])) return [false, '完工时间必须选择!'];
+
+        //班组
+        $team_id = $data['team_id'] ?? [];
+
+        $result = DispatchSub::where('del_time',0)
+            ->where('finished_num','>',0)
+            ->whereBetween('upd_time', [$data['finish_time'][0], $data['finish_time'][1]])
+            ->when(!empty($team_id), function ($query) use ($team_id) {
+                return $query->whereIn('team_id', $team_id);
+            })
+            ->select('team_id','upd_time as finished_time','finished_num','order_product_id')
+            ->get()->toArray();
+        if(empty($result)) return [true , []];
+
+        //组织数据
+        $team_map = Team::whereIn('id',array_unique(array_column($result,'team_id')))
+            ->pluck('title','id')
+            ->toArray();
+        $return_team = $return_team_time_tmp = $return_team_time= [];
+
+        foreach ($result as $value){
+            if(isset($return_team[$value['team_id']])){
+                $num = bcadd($value['finished_num'], $return_team[$value['team_id']]['num'],3);
+                $return_team[$value['team_id']]['num'] = $num;
+                if(! in_array($value['order_product_id'], $return_team[$value['team_id']]['production_no'])) {
+                    $return_team[$value['team_id']]['production_no'] = array_merge_recursive($return_team[$value['team_id']]['production_no'],[$value['order_product_id']]);
+                }
+            }else{
+                $return_team[$value['team_id']] = [
+                    'num' => $value['finished_num'],
+                    'team_name' => $team_map[$value['team_id']] ?? '',
+                    'production_no' => [$value['order_product_id']]
+                ];
+            }
+
+            $tmp = date("Y-m-d",$value['finished_time']);
+            if(isset($return_team_time_tmp[$tmp][$value['team_id']])){
+                $num = bcadd($value['finished_num'],$return_team_time_tmp[$tmp][$value['team_id']]['num'],3);
+                $return_team_time_tmp[$tmp][$value['team_id']]['num'] = $num;
+            }else{
+                $return_team_time_tmp[$tmp][$value['team_id']] = [
+                    'time' => $tmp,
+                    'num' => $value['finished_num'],
+                    'team_name' => $team_map[$value['team_id']] ?? '',
+                ];
+            }
+        }ksort($return_team_time_tmp);unset($result);
+
+        $all_team_map = Team::where('del_time',0)
+            ->pluck('title','id')
+            ->toArray();
+        foreach ($return_team_time_tmp as $key => $value){
+            $t_k = array_keys($value);
+            foreach ($all_team_map as $k => $v){
+                if(! in_array($k,$t_k)){
+                    $return_team_time_tmp[$key][$k] = [
+                        'time' => $key,
+                        'num' => 0,
+                        'team_name' => $v,
+                    ];
+                }
+            }
+            ksort($return_team_time_tmp[$key]);
+            $tmp = [];
+            $tmp['time'] = $key;
+            $tmp['sub'] = array_values($return_team_time_tmp[$key]);
+            $return_team_time[] = $tmp;
+        }unset($return_team_time_tmp);
+        foreach ($return_team as $key => $value){
+            $return_team[$key]['num'] = $value['num'];
+        }
+        foreach ($return_team_time as $key => $value){
+            foreach ($value['sub'] as $k => $v){
+                $return_team_time[$key]['sub'][$k]['num'] = $v['num'];
+            }
+        }
+
+        //列表数据 图表数据
+        return [true,['list'=>array_values($return_team),'chart'=>$return_team_time]];
+    }
+
     /**
      * 班组
      * @param $data
      * @return array
      */
-    public function teamReport($data){
+    public function teamReport1($data){
         if(empty($data['finish_time'][0]) || empty($data['finish_time'][1])) return [false, '完工时间必须选择!'];
 
         //班组
@@ -291,7 +375,7 @@ class ReportFormsService extends Service
     public function teamReportDetail($data){
         if(empty($data['production_no'])) return [false,'生产订单号不能为空!'];
 
-        $list = OrdersProduct::whereIn('production_no',$data['production_no'])
+        $list = OrdersProduct::whereIn('id',$data['production_no'])
             ->select('production_time','production_no','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_complete_quantity','finished_num','technology_material','technology_name','wood_name','process_mark','table_body_mark')
             ->get()->toArray();