|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Service;
|
|
|
|
|
|
use App\Model\Dispatch;
|
|
|
+use App\Model\DispatchEmpSub;
|
|
|
use App\Model\DispatchSub;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\EmployeeTeamPermission;
|
|
@@ -51,7 +52,7 @@ class DispatchService extends Service
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
//主表
|
|
|
- Dispatch::insert(['dispatch_no' => $dispatch_no,'process_id' => $data['process_id'],'equipment_id' => $data['equipment_id'], 'team_id' => $data['team_id'],'dispatch_time_start' => $data['dispatch_time'][0],'dispatch_time_end' => $data['dispatch_time'][1], 'crt_time' => time()]);
|
|
|
+ Dispatch::insert(['dispatch_no' => $dispatch_no,'crt_time' => time()]);
|
|
|
|
|
|
//生产数据的源数据
|
|
|
$result = $msg;
|
|
@@ -61,18 +62,25 @@ class DispatchService extends Service
|
|
|
$process_model = new OrdersProductProcess(['channel' => $time_tmp]);
|
|
|
|
|
|
$time = time();
|
|
|
+ $equipment_id = is_array($data['equipment_id']) ? $data['equipment_id'] : [$data['equipment_id']];
|
|
|
+ $equipment_id = array_filter($equipment_id);
|
|
|
+ $team_id = is_array($data['team_id']) ? $data['team_id'] : [$data['team_id']];
|
|
|
+ $team_id = array_filter($team_id);
|
|
|
+
|
|
|
+ $insert_emp_sub = [];
|
|
|
foreach ($result as $key => $value){
|
|
|
$quantity_tmp = $data['quantity'][$key];
|
|
|
$result[$key]['dispatch_no'] = $dispatch_no;
|
|
|
$result[$key]['process_id'] = $data['process_id'];
|
|
|
- $result[$key]['equipment_id'] = $data['equipment_id'];
|
|
|
- $result[$key]['team_id'] = $data['team_id'];
|
|
|
$result[$key]['dispatch_time_start'] = $data['dispatch_time'][0];
|
|
|
$result[$key]['dispatch_time_end'] = $data['dispatch_time'][1];
|
|
|
$result[$key]['dispatch_quantity'] = $quantity_tmp;
|
|
|
$result[$key]['crt_time'] = $time;
|
|
|
$result[$key]['crt_id'] = $user['id'];
|
|
|
|
|
|
+ $tmp = $this->makeData($equipment_id,$team_id,$data['employee_id'],$result[$key]);
|
|
|
+ $insert_emp_sub = array_merge_recursive($insert_emp_sub,$tmp);
|
|
|
+
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
|
->where('process_id',$data['process_id'])
|
|
|
->where('dispatch_no','')
|
|
@@ -85,6 +93,8 @@ class DispatchService extends Service
|
|
|
|
|
|
DispatchSub::insert($result);
|
|
|
|
|
|
+ if(! empty($insert_emp_sub)) DispatchEmpSub::insert($insert_emp_sub);
|
|
|
+
|
|
|
//反写已派工数量
|
|
|
$this->writeDispatchQuantity(array_column($result,'order_product_id'));
|
|
|
|
|
@@ -97,6 +107,80 @@ class DispatchService extends Service
|
|
|
return [true,'保存成功!'];
|
|
|
}
|
|
|
|
|
|
+ public function makeData($equipment_id, $team_id,$employee_id,$message){
|
|
|
+ $arr = [];
|
|
|
+ if(! empty($equipment_id)){
|
|
|
+ foreach ($equipment_id as $v_e){
|
|
|
+ if(! empty($team_id)){
|
|
|
+ foreach ($team_id as $t){
|
|
|
+ if(! empty($employee_id)){
|
|
|
+ foreach ($employee_id as $e){
|
|
|
+ $arr[] = [
|
|
|
+ 'equipment_id' => $v_e,
|
|
|
+ 'team_id' => $t,
|
|
|
+ 'employee_id' => $e,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $arr[] = [
|
|
|
+ 'equipment_id' => $v_e,
|
|
|
+ 'team_id' => $t,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif(! empty($employee_id)){
|
|
|
+ foreach ($employee_id as $e){
|
|
|
+ $arr[] = [
|
|
|
+ 'equipment_id' => $v_e,
|
|
|
+ 'employee_id' => $e,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $arr[] = [
|
|
|
+ 'equipment_id' => $v_e,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif (! empty($team_id)){
|
|
|
+ foreach ($team_id as $t){
|
|
|
+ if(! empty($employee_id)){
|
|
|
+ foreach ($employee_id as $e){
|
|
|
+ $arr[] = [
|
|
|
+ 'team_id' => $t,
|
|
|
+ 'employee_id' => $e,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $arr[] = [
|
|
|
+ 'team_id' => $t,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }elseif(! empty($employee_id)){
|
|
|
+ foreach ($employee_id as $e){
|
|
|
+ $arr[] = [
|
|
|
+ 'employee_id' => $e,
|
|
|
+ 'order_product_id' => $message['order_product_id'],
|
|
|
+ 'dispatch_no' => $message['dispatch_no'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+
|
|
|
public function del($data){
|
|
|
if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
|
|
@@ -186,8 +270,6 @@ class DispatchService extends Service
|
|
|
if(empty($data['dispatch_time'][0]) || empty($data['dispatch_time'][1])) return [false,'计划生产时间不能为空!'];
|
|
|
if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单时间不能为空!'];
|
|
|
if($this->isEmpty($data,'process_id')) return [false,'工序不能为空!'];
|
|
|
- if($this->isEmpty($data,'equipment_id')) return [false,'设备不能为空!'];
|
|
|
- if($this->isEmpty($data,'team_id')) return [false,'班组不能为空!'];
|
|
|
|
|
|
$result = OrdersProduct::whereIn('id',$data['id'])
|
|
|
->select('id as order_product_id','sale_orders_product_id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','production_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','sale_orders_product_id','out_order_no_time')
|
|
@@ -247,28 +329,43 @@ class DispatchService extends Service
|
|
|
|
|
|
public function dispatchOrderList($data){
|
|
|
$model = DispatchSub::where('del_time',0)
|
|
|
- ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','dispatch_no','status','crt_id','process_id','equipment_id','team_id','dispatch_time_start','dispatch_time_end','crt_time')
|
|
|
+ ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','dispatch_no','status','crt_id','process_id','dispatch_time_start','dispatch_time_end','crt_time','finished_num','waste_num')
|
|
|
->orderBy('id','desc');
|
|
|
|
|
|
+ if(isset($data['finished_num'])) $model->where('finished_num', '>',0);
|
|
|
+
|
|
|
if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
|
|
|
if(! empty($data['dispatch_no'])) $model->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%');
|
|
|
if(! empty($data['process_id'])) $model->where('process_id',$data['process_id']);
|
|
|
- if(! empty($data['team_id'])) $model->where('team_id',$data['team_id']);
|
|
|
- if(! empty($data['equipment_id'])) $model->where('equipment_id',$data['equipment_id'].'%');
|
|
|
if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');
|
|
|
if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
|
|
|
if(! empty($data['dispatch_time'][0]) && ! empty($data['dispatch_time'][1])){
|
|
|
$model->where('dispatch_time_start','<=',$data['dispatch_time'][0]);
|
|
|
$model->where('dispatch_time_end','>=',$data['dispatch_time'][1]);
|
|
|
}
|
|
|
+ if(! empty($data['team_id'])) {
|
|
|
+ $res = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->where('team_id',$data['team_id'])
|
|
|
+ ->distinct()
|
|
|
+ ->select('dispatch_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
+ }
|
|
|
+ if(! empty($data['equipment_id'])) {
|
|
|
+ $res = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->where('equipment_id',$data['equipment_id'])
|
|
|
+ ->distinct()
|
|
|
+ ->select('dispatch_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
+ }
|
|
|
if(! empty($data['employee_id'])) {
|
|
|
- $team_id = Employee::from('employee as a')
|
|
|
- ->leftJoin('employee_team_permission as b','b.employee_id','a.id')
|
|
|
- ->where('a.id', $data['employee_id'])
|
|
|
- ->select('b.team_id')
|
|
|
+ $res = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->where('employee_id',$data['employee_id'])
|
|
|
+ ->distinct()
|
|
|
+ ->select('dispatch_no')
|
|
|
->get()->toArray();
|
|
|
- $team_id = array_column($team_id,'team_id');
|
|
|
- $model->where('team_id',$team_id ?? []);
|
|
|
+ $model->whereIn('dispatch_no',array_column($res,'dispatch_no'));
|
|
|
}
|
|
|
|
|
|
$list = $this->limit($model,'',$data);
|
|
@@ -280,34 +377,40 @@ class DispatchService extends Service
|
|
|
public function fillDispatchOrderListData($data){
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
- $team = EmployeeTeamPermission::from('employee_team_permission as a')
|
|
|
- ->leftJoin('employee as b','b.id','a.employee_id')
|
|
|
- ->whereIn('a.team_id',array_column($data['data'],'team_id'))
|
|
|
- ->select('b.emp_name','a.team_id')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- $team_map = [];
|
|
|
- if(! empty($team)){
|
|
|
- foreach ($team as $value){
|
|
|
- if(isset($team_map[$value['team_id']])){
|
|
|
- $team_map[$value['team_id']] .= ','. $value['emp_name'];
|
|
|
- }else{
|
|
|
- $team_map[$value['team_id']] = $value['emp_name'];
|
|
|
- }
|
|
|
+ $emp_sub = DispatchEmpSub::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_no',array_column($data['data'],'dispatch_no'))
|
|
|
+ ->select('dispatch_no','equipment_id','team_id','employee_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($emp_sub)){
|
|
|
+ $team_map = Team::whereIn('id',array_unique(array_column($emp_sub,'team_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $equipment_map = Equipment::whereIn('id',array_unique(array_column($emp_sub,'equipment_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $emp_map = Employee::whereIn('id',array_unique(array_column($emp_sub,'employee_id')))
|
|
|
+ ->pluck('emp_name','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $equipment_map1 = $team_map1 = $employee_map1 = $employee_map2 = $equipment_map2 = $team_map2 = [];
|
|
|
+ foreach ($emp_sub as $value){
|
|
|
+ $equipment_name = $equipment_map[$value['equipment_id']] ?? '';
|
|
|
+ $team_name = $team_map[$value['team_id']] ?? '';
|
|
|
+ $employee_name = $emp_map[$value['employee_id']] ?? '';
|
|
|
+
|
|
|
+ $equipment_map1[$value['dispatch_no']][] = $equipment_name;
|
|
|
+ $equipment_map2[$value['dispatch_no']][] = $value['equipment_id'];
|
|
|
+ $team_map1[$value['dispatch_no']][] = $team_name;
|
|
|
+ $team_map2[$value['dispatch_no']][] = $value['team_id'];
|
|
|
+ $employee_map1[$value['dispatch_no']][] = $employee_name;
|
|
|
+ $employee_map2[$value['dispatch_no']][] = $value['employee_id'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
- $team_maps = Team::whereIn('id',array_column($data['data'],'team_id'))
|
|
|
- ->pluck('title','id')
|
|
|
- ->toArray();
|
|
|
- $equipment_map = Equipment::whereIn('id',array_column($data['data'],'equipment_id'))
|
|
|
- ->pluck('title','id')
|
|
|
- ->toArray();
|
|
|
|
|
|
- $finished_map = $this->getFinishedQuantity(array_column($data['data'],'id'));
|
|
|
date_default_timezone_set("PRC");
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
$data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
|
|
@@ -315,18 +418,21 @@ class DispatchService extends Service
|
|
|
$time1 = $value['dispatch_time_start'] ? date('Y-m-d',$value['dispatch_time_start']) : '';
|
|
|
$time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
|
|
|
$data['data'][$key]['dispatch_time'] = $time1 . ' ' . $time2;
|
|
|
- $data['data'][$key]['team_man'] = $team_map[$value['team_id']] ?? '';
|
|
|
$data['data'][$key]['process_name'] = $process_map[$value['process_id']] ?? '';
|
|
|
- $data['data'][$key]['team_name'] = $team_maps[$value['team_id']] ?? '';
|
|
|
- $data['data'][$key]['equipment_name'] = $equipment_map[$value['equipment_id']] ?? '';
|
|
|
- $data['data'][$key]['un_finished_quantity'] = $value['dispatch_quantity'] - ($finished_map[$value['id']] ?? 0);
|
|
|
+ $data['data'][$key]['team_man'] = implode(',',array_unique($employee_map1[$value['dispatch_no']]));
|
|
|
+ $data['data'][$key]['team_man_id'] = array_unique($employee_map2[$value['dispatch_no']]);
|
|
|
+ $data['data'][$key]['team_name'] = implode(',',array_unique($team_map1[$value['dispatch_no']]));
|
|
|
+ $data['data'][$key]['team_id'] = implode(',',array_unique($team_map2[$value['dispatch_no']]));
|
|
|
+ $data['data'][$key]['equipment_name'] = implode(',',array_unique($equipment_map1[$value['dispatch_no']]));
|
|
|
+ $data['data'][$key]['equipment_id'] = implode(',',array_unique($equipment_map2[$value['dispatch_no']]));
|
|
|
+ $data['data'][$key]['un_finished_quantity'] = $value['dispatch_quantity'] - $value['finished_num'];
|
|
|
}
|
|
|
$data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- //反写写完工数量
|
|
|
+ //反写写派工数量
|
|
|
public function writeDispatchQuantity($order_product_id){
|
|
|
if(empty($order_product_id)) return;
|
|
|
|
|
@@ -345,18 +451,4 @@ class DispatchService extends Service
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //返回已完工数量
|
|
|
- public function getFinishedQuantity($dispatch_id = []){
|
|
|
- if(empty($dispatch_id)) return [];
|
|
|
-
|
|
|
- $result = FinishedOrderSub::where('del_time',0)
|
|
|
- ->whereIn("dispatch_id",$dispatch_id)
|
|
|
- ->select(DB::raw("sum(finished_num) as finished_num"),'dispatch_id')
|
|
|
- ->groupby('dispatch_id')
|
|
|
- ->pluck('finished_num','dispatch_id')
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
}
|