|
@@ -47,64 +47,25 @@ class DispatchService extends Service
|
|
list($status,$msg) = $this->orderRule($data);
|
|
list($status,$msg) = $this->orderRule($data);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
- $dispatch_no = $this->setOrderNO();
|
|
|
|
try{
|
|
try{
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
|
|
|
- //主表
|
|
|
|
- Dispatch::insert(['dispatch_no' => $dispatch_no,'crt_time' => time()]);
|
|
|
|
-
|
|
|
|
- //生产数据的源数据
|
|
|
|
- $result = $msg;
|
|
|
|
-
|
|
|
|
- date_default_timezone_set("PRC");
|
|
|
|
- $time_tmp = date("Ymd", $data['out_order_no_time'][0]);
|
|
|
|
- $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]['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','')
|
|
|
|
- ->take($quantity_tmp)
|
|
|
|
- ->update([
|
|
|
|
- 'dispatch_no' => $dispatch_no,
|
|
|
|
- 'status' => 1
|
|
|
|
- ]);
|
|
|
|
|
|
+ if($data['is_split']){
|
|
|
|
+ foreach ($msg as $value){
|
|
|
|
+ $this->insertDispatch([$value],$data,$user);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $this->insertDispatch($msg,$data,$user);
|
|
}
|
|
}
|
|
|
|
|
|
- DispatchSub::insert($result);
|
|
|
|
-
|
|
|
|
- if(! empty($insert_emp_sub)) DispatchEmpSub::insert($insert_emp_sub);
|
|
|
|
-
|
|
|
|
//反写已派工数量
|
|
//反写已派工数量
|
|
- $this->writeDispatchQuantity(array_column($result,'order_product_id'));
|
|
|
|
|
|
+ $this->writeDispatchQuantity(array_column($msg,'order_product_id'));
|
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
return [false,$e->getLine().':'.$e->getMessage()];
|
|
return [false,$e->getLine().':'.$e->getMessage()];
|
|
}
|
|
}
|
|
-
|
|
|
|
- return [true,'保存成功!'];
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function makeData($equipment_id, $team_id,$employee_id,$message){
|
|
public function makeData($equipment_id, $team_id,$employee_id,$message){
|
|
@@ -181,6 +142,52 @@ class DispatchService extends Service
|
|
return $arr;
|
|
return $arr;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function insertDispatch($msg, $data, $user){
|
|
|
|
+ //生产数据的源数据
|
|
|
|
+ $result = $msg;
|
|
|
|
+ $time = time();
|
|
|
|
+
|
|
|
|
+ $dispatch_no = $this->setOrderNO();
|
|
|
|
+ //主表
|
|
|
|
+ Dispatch::insert(['dispatch_no' => $dispatch_no,'crt_time' => $time]);
|
|
|
|
+
|
|
|
|
+ date_default_timezone_set("PRC");
|
|
|
|
+ $time_tmp = date("Ymd", $data['out_order_no_time'][0]);
|
|
|
|
+ $process_model = new OrdersProductProcess(['channel' => $time_tmp]);
|
|
|
|
+
|
|
|
|
+ $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){
|
|
|
|
+ $result[$key]['dispatch_no'] = $dispatch_no;
|
|
|
|
+ $result[$key]['process_id'] = $data['process_id'];
|
|
|
|
+ $result[$key]['dispatch_time_start'] = $data['dispatch_time'][0];
|
|
|
|
+ $result[$key]['dispatch_time_end'] = $data['dispatch_time'][1];
|
|
|
|
+ $result[$key]['dispatch_quantity'] = $value['quantity'];
|
|
|
|
+ $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','')
|
|
|
|
+ ->take($value['quantity'])
|
|
|
|
+ ->update([
|
|
|
|
+ 'dispatch_no' => $dispatch_no,
|
|
|
|
+ 'status' => 1
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DispatchSub::insert($result);
|
|
|
|
+
|
|
|
|
+ if(! empty($insert_emp_sub)) DispatchEmpSub::insert($insert_emp_sub);
|
|
|
|
+ }
|
|
|
|
+
|
|
public function del($data){
|
|
public function del($data){
|
|
if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
|
|
|
@@ -275,19 +282,37 @@ class DispatchService extends Service
|
|
->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','price','customer_name')
|
|
->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','price','customer_name')
|
|
->orderBy('id','desc')
|
|
->orderBy('id','desc')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
+ $result_map = array_column($result,null,'order_product_id');
|
|
|
|
|
|
//已派工数据
|
|
//已派工数据
|
|
$map = $this->getDispatchQuantity($data['id']);
|
|
$map = $this->getDispatchQuantity($data['id']);
|
|
|
|
|
|
|
|
+ $total_map = $return = [];
|
|
|
|
+ if($data['is_split']){
|
|
|
|
+ foreach ($data['id'] as $key => $value){
|
|
|
|
+ if(isset($total_map[$value])){
|
|
|
|
+ $total_map[$value] += $data['quantity'][$key];
|
|
|
|
+ }else{
|
|
|
|
+ $total_map[$value] = $data['quantity'][$key];
|
|
|
|
+ }
|
|
|
|
+ $tmp = $result_map[$value];
|
|
|
|
+ $tmp['quantity'] = $data['quantity'][$key];
|
|
|
|
+ $return[] = $tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
foreach ($result as $key => $value){
|
|
foreach ($result as $key => $value){
|
|
|
|
+ //数据校验
|
|
|
|
+ $quantity_tmp = $total_map[$value['order_product_id']] ?? $data['quantity'][$key];
|
|
if(isset($map[$value['order_product_id']])){
|
|
if(isset($map[$value['order_product_id']])){
|
|
- if($map[$value['order_product_id']] + $data['quantity'][$key] > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
|
|
|
|
+ if($map[$value['order_product_id']] + $quantity_tmp > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
}else{
|
|
}else{
|
|
- if($data['quantity'][$key] > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
|
|
|
|
+ if($quantity_tmp > $value['production_quantity']) return [false,'派单数量不能大于生产订单数量'];
|
|
}
|
|
}
|
|
|
|
+ if(! empty($return)) $result[$key]['quantity'] = $data['quantity'][$key];
|
|
}
|
|
}
|
|
|
|
|
|
- return [true, $result];
|
|
|
|
|
|
+ $array = ! empty($return) ? $return : $result;
|
|
|
|
+ return [true, $array];
|
|
}
|
|
}
|
|
|
|
|
|
public function fillData($data){
|
|
public function fillData($data){
|