cqp 9 months ago
parent
commit
2f7c225ef1

+ 67 - 34
app/Service/ApplyOrderService.php

@@ -7,10 +7,12 @@ use App\Model\ApplyOrderDetail;
 use App\Model\Box;
 use App\Model\DispatchSub;
 use App\Model\Employee;
+use App\Model\EmployeeTeamPermission;
 use App\Model\InOutRecord;
 use App\Model\Process;
 use App\Model\ReportWorking;
 use App\Model\ReportWorkingDetail;
+use App\Model\Team;
 use Illuminate\Support\Facades\DB;
 
 class ApplyOrderService extends Service
@@ -480,7 +482,7 @@ class ApplyOrderService extends Service
 
     //报工
     public function reportWorkingEdit($data, $user){
-        list($status,$msg) = $this->MaterialRule($data,false);
+        list($status,$msg) = $this->reportWorkingRule($data,false);
         if(!$status) return [$status,$msg];
 
         DB::beginTransaction();
@@ -497,17 +499,30 @@ class ApplyOrderService extends Service
                 'del_time' => $time
             ]);
 
+            //班组下的人
+            $team_man = [];
+            $model_t = new EmployeeTeamPermission();
+            $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
+            foreach ($team_array as $v){
+                $team_man[$v['team_id']][] = $v['employee_id'];
+            }
+
             $detail_insert = [];
             foreach ($data['order_data'] as $v){
-                $detail_insert[] = [
-                    'report_working_id' => $id,
-                    'data_id' => $v['id'],
-                    'quantity' => $v['quantity'] ?? 0,
-                    'process_id' => $v['process_id'] ?? 0,
-                    'finished_id' => $v['finished_id'] ?? 0,
-                    'crt_time' => $time,
-                ];
+                $t = $team_man[$v['team_id']] ?? [];
+                foreach ($t as $t_v){
+                    $detail_insert[] = [
+                        'report_working_id' => $id,
+                        'data_id' => $v['id'],
+                        'quantity' => $v['quantity'] ?? 0,
+                        'process_id' => $v['process_id'] ?? 0,
+                        'finished_id' => $t_v,
+                        'team_id' => $v['team_id'],
+                        'crt_time' => $time,
+                    ];
+                }
             }
+
             ReportWorkingDetail::insert($detail_insert);
 
             DB::commit();
@@ -533,17 +548,30 @@ class ApplyOrderService extends Service
             $model->save();
             $id = $model->id;
 
+            //班组下的人
+            $team_man = [];
+            $model_t = new EmployeeTeamPermission();
+            $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
+            foreach ($team_array as $v){
+                $team_man[$v['team_id']][] = $v['employee_id'];
+            }
+
             $detail_insert = [];
             foreach ($data['order_data'] as $v){
-                $detail_insert[] = [
-                    'report_working_id' => $id,
-                    'data_id' => $v['id'],
-                    'quantity' => $v['quantity'] ?? 0,
-                    'process_id' => $v['process_id'] ?? 0,
-                    'finished_id' => $v['finished_id'] ?? 0,
-                    'crt_time' => $time,
-                ];
+                $t = $team_man[$v['team_id']] ?? [];
+                foreach ($t as $t_v){
+                    $detail_insert[] = [
+                        'report_working_id' => $id,
+                        'data_id' => $v['id'],
+                        'quantity' => $v['quantity'] ?? 0,
+                        'process_id' => $v['process_id'] ?? 0,
+                        'finished_id' => $t_v,
+                        'team_id' => $v['team_id'],
+                        'crt_time' => $time,
+                    ];
+                }
             }
+
             ReportWorkingDetail::insert($detail_insert);
 
             DB::commit();
@@ -632,32 +660,37 @@ class ApplyOrderService extends Service
         //派工单
         $d = DispatchSub::where('del_time',0)
             ->whereIn('id', $apply_id)
-            ->select('id', 'dispatch_no as order_no', 'product_title','technology_material','wood_name','product_no','process_id','product_unit','price')
+            ->select('id', 'dispatch_no as order_no', 'product_title','technology_material','wood_name','product_no','process_id','product_unit','price','product_size')
             ->get()->toArray();
         $d_tmp = array_column($d,null,'id');
 
         $process_map = Process::whereIn('id',array_unique(array_column($d,'process_id')))
             ->pluck('title','id')
             ->toArray();
+        $team_map = Team::pluck('title','id')->toArray();
+
         $return = [];
         foreach ($apply_d as $t){
             $tmp = $d_tmp[$t['data_id']] ?? [];
 
-            $return[] = [
-                'id' => $t['data_id'] ?? 0,
-                'quantity' => $t['quantity'] ?? 0,
-                'product_no' => $tmp['product_no'] ?? "",
-                'product_title' => $tmp['product_title'] ?? "",
-                'product_size' => $tmp['product_size'] ?? "",
-                'product_unit' => $tmp['product_unit'] ?? "",
-                'technology_material' => $tmp['technology_material'] ?? "",
-                'wood_name' => $tmp['wood_name'] ?? "",
-                'order_no' => $tmp['order_no'] ?? "",
-                'process_id' => $tmp['process_id'] ?? 0,
-                'process_title' => $process_map[$tmp['process_id']] ?? "",
-                'price' => $tmp['price'] ?? 0,
-                'total' => bcmul(($tmp['price'] ?? 0),$t['quantity'],2)
-            ];
+            $str = $t['data_id'] . $t['process_id'];
+            if(! isset($return[$str])){
+                $return[$str] = [
+                    'id' => $t['data_id'] ?? 0,
+                    'quantity' => $t['quantity'] ?? 0,
+                    'product_no' => $tmp['product_no'] ?? "",
+                    'product_title' => $tmp['product_title'] ?? "",
+                    'product_size' => $tmp['product_size'] ?? "",
+                    'product_unit' => $tmp['product_unit'] ?? "",
+                    'technology_material' => $tmp['technology_material'] ?? "",
+                    'wood_name' => $tmp['wood_name'] ?? "",
+                    'order_no' => $tmp['order_no'] ?? "",
+                    'process_id' => $tmp['process_id'] ?? 0,
+                    'process_name' => $process_map[$tmp['process_id']] ?? "",
+                    'team_id' => $t['team_id'] ?? 0,
+                    'team_title' => $team_map[$t['team_id']] ?? '',
+                ];
+            }
         }
 
         $detail['order_data'] = $return;
@@ -666,13 +699,13 @@ class ApplyOrderService extends Service
     }
 
     public function reportWorkingRule(&$data,$is_add = true){
-        if($this->isEmpty($data,'apply_id')) return [false,'申请人不能为空'];
         if($this->isEmpty($data,'report_time')) return [false,'报工时间不能为空'];
         if(empty($data['order_data'])) return [false, '报工单详细信息不能为空'];
         foreach ($data['order_data'] as $value){
             if(empty($value['id'])) return [false, '报工单详细信息ID不能为空'];
             if(empty($value['quantity'])) return [false, '报工单详细信息数量不能为空'];
             if(empty($value['process_id'])) return [false, '报工单详细信息工序不能为空'];
+            if(empty($value['team_id'])) return [false, '报工单详细信息班组不能为空'];
         }
 
         $id = array_unique(array_column($data['order_data'],'id'));

+ 3 - 0
app/Service/Box/BoxService.php

@@ -484,15 +484,18 @@ class BoxService extends Service
                 $team_tmp = $process_map[$value['process_id']] ?? 0; // 班组
                 if(empty($team_tmp)){
                     $tmp['finished_id'] = 0;
+                    $tmp['team_id'] = 0;
                     $last_update2[] = $tmp;
                 }else{
                     $t_m = $team_man[$team_tmp] ?? []; //班组下的人
                     if(empty($t_m)) {
                         $tmp['finished_id'] = 0;
+                        $tmp['team_id'] = $team_tmp;
                         $last_update2[] = $tmp;
                     }else{
                         foreach ($t_m as $m_v){
                             $tmp['finished_id'] = $m_v;
+                            $tmp['team_id'] = $team_tmp;
                             $last_update2[] = $tmp;
                         }
                     }

+ 24 - 12
app/Service/FinishedOrderService.php

@@ -100,19 +100,21 @@ class FinishedOrderService extends Service
                 }
 
                 //班组下的人
-                $man = [];
-                if(! empty($value['team_id'])) $man = $team_man[$value['team_id']] ?? [];
-                if(! in_array($value['finish_id'], $man)) $man[] = $value['finish_id'];
-
+                $man = $team_man[$value['team_id']] ?? [];
+                $f_m = 0;
+                if(! in_array($value['finish_id'], $man) && $value['finish_id'] > 0) {
+                    $man[] = $value['finish_id'];
+                    $f_m = 1;
+                }
                 $tmp['process_id'] = $value['process_id'];
-                if(empty($man)){
-                    $tmp['finished_id'] = 0;
-                    $last_update2[] = $tmp;
-                }else{
-                    foreach ($man as $m_v){
-                        $tmp['finished_id'] = $m_v;
-                        $last_update2[] = $tmp;
+                foreach ($man as $m_v){
+                    if($f_m && $m_v == $value['finish_id']){
+                        $tmp['team_id'] = 0;
+                    }else{
+                        $tmp['team_id'] = $value['team_id'];
                     }
+                    $tmp['finished_id'] = $m_v;
+                    $last_update2[] = $tmp;
                 }
 
                 $insert_waste = $scrapp = [];
@@ -250,6 +252,7 @@ class FinishedOrderService extends Service
                     'quantity' => $v['quantity'] ?? 0,
                     'finished_id' => $v['finished_id'] ?? 0,
                     'process_id' => $v['process_id'] ?? 0,
+                    'team_id' => $v['team_id'] ?? 0,
                     'crt_time' => $time,
                 ];
             }
@@ -533,11 +536,20 @@ class FinishedOrderService extends Service
         if(! isset($data['is_finish_all'])) return [false, '完工类型不能为空!'];
         if(empty($data['detail'])) return [false, '完工明细数据不能为空!'];
         $detail_map = $id = $detail_map2 = $waste_map = [];
+
+        //班组下的人
+        $team_man = [];
+        $team_array = EmployeeTeamPermission::select('employee_id', 'team_id')->get()->toArray();
+        foreach ($team_array as $v){
+            $team_man[$v['team_id']][] = $v['employee_id'];
+        }
         foreach ($data['detail'] as $value){
             if(empty($value['id'])) return [false,'请选择完工数据!'];
             $id[] = $value['id'];
             if(empty($value['device_id'])) return [false, '请选择设备!'];
-            if(empty($value['team_id']) && empty($value['finish_id'])) return [false,'班组和人员必须选择一个!'];
+            if(empty($value['team_id'])) return [false, '班组必须选择'];
+            if(empty($team_man[$value['team_id']])) return [false, '班组下的人不能为空,请设置'];
+//            if(empty($value['team_id']) && empty($value['finish_id'])) return [false,'班组和人员必须选择一个!'];
             if(! is_numeric($value['quantity']) || $value['quantity'] < 0) return [false,'完工数量不能小于0!'];
             if(! empty($value['waste'])){
                 foreach ($value['waste'] as $waste){