|
|
@@ -6,15 +6,19 @@ use App\Model\ApplyOrder;
|
|
|
use App\Model\ApplyOrderDetail;
|
|
|
use App\Model\Box;
|
|
|
use App\Model\BoxDetail;
|
|
|
+use App\Model\Dispatch;
|
|
|
use App\Model\DispatchSub;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\EmployeeTeamPermission;
|
|
|
use App\Model\InOutRecord;
|
|
|
+use App\Model\OrdersProduct;
|
|
|
use App\Model\Process;
|
|
|
use App\Model\ReportWorking;
|
|
|
use App\Model\ReportWorkingDetail;
|
|
|
use App\Model\SaleOrdersProduct;
|
|
|
+use App\Model\ScrappCount;
|
|
|
use App\Model\Team;
|
|
|
+use App\Service\Box\BoxService;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class ApplyOrderService extends Service
|
|
|
@@ -196,6 +200,18 @@ class ApplyOrderService extends Service
|
|
|
->select('apply_order_id')
|
|
|
->get()->toArray();
|
|
|
$model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
|
|
|
+ }elseif($data['type'] == ApplyOrder::type_five){
|
|
|
+ $zj_id = ScrappCount::where('del_time',0)
|
|
|
+ ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $zj_id = array_column($zj_id,'id');
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->where('type', $data['type'])
|
|
|
+ ->whereIn('data_id', $zj_id)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
|
|
|
}else{
|
|
|
$no = SaleOrdersProduct::where('del_time',0)
|
|
|
->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
|
|
|
@@ -229,10 +245,12 @@ class ApplyOrderService extends Service
|
|
|
->pluck('emp_name','id')
|
|
|
->toArray();
|
|
|
|
|
|
- $array1 = $array2 = [];
|
|
|
+ $array1 = $array2 = $array3 = [];
|
|
|
foreach ($data['data'] as $value){
|
|
|
if(in_array($value['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
|
|
|
$array1[] = $value['id'];
|
|
|
+ }elseif ($value['type'] == ApplyOrder::type_five){
|
|
|
+ $array3[] = $value['id'];
|
|
|
}else{
|
|
|
$array2[] = $value['id'];
|
|
|
}
|
|
|
@@ -245,7 +263,7 @@ class ApplyOrderService extends Service
|
|
|
foreach ($order1 as $value){
|
|
|
$order1_map[$value['apply_order_id']][] = $value['data_id'];
|
|
|
}
|
|
|
- $order2 = ApplyOrderDetail::whereNotIn('type',[ApplyOrder::type_one,ApplyOrder::type_two])
|
|
|
+ $order2 = ApplyOrderDetail::whereNotIn('type',[ApplyOrder::type_one,ApplyOrder::type_two,ApplyOrder::type_five])
|
|
|
->whereIn('apply_order_id', $array2)
|
|
|
->select('data_id','apply_order_id')
|
|
|
->get()->toArray();
|
|
|
@@ -253,6 +271,14 @@ class ApplyOrderService extends Service
|
|
|
foreach ($order2 as $value){
|
|
|
$order2_map[$value['apply_order_id']][] = $value['data_id'];
|
|
|
}
|
|
|
+ $order3 = ApplyOrderDetail::whereIn('type',[ApplyOrder::type_five])
|
|
|
+ ->whereIn('apply_order_id', $array3)
|
|
|
+ ->select('data_id','apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $order3_map = [];
|
|
|
+ foreach ($order3 as $value){
|
|
|
+ $order3_map[$value['apply_order_id']][] = $value['data_id'];
|
|
|
+ }
|
|
|
$map1 = DispatchSub::whereIn('id', array_unique(array_column($order1,'data_id')))
|
|
|
->pluck('out_order_no','id')
|
|
|
->toArray();
|
|
|
@@ -262,8 +288,12 @@ class ApplyOrderService extends Service
|
|
|
$map2_fin = SaleOrdersProduct::whereIn('order_no',array_unique(array_values($map2)))
|
|
|
->pluck('out_order_no','order_no')
|
|
|
->toArray();
|
|
|
+ $map3 = ScrappCount::whereIn('id', array_unique(array_column($order3,'data_id')))
|
|
|
+ ->pluck('out_order_no','id')
|
|
|
+ ->toArray();
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['apply_time'] = $value['apply_time'] ? date('Y-m-d',$value['apply_time']) : '';
|
|
|
$data['data'][$key]['status_title'] = ApplyOrder::$state_name[$value['status']] ?? "";
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
$data['data'][$key]['apply_name'] = $emp[$value['apply_id']] ?? '';
|
|
|
@@ -279,6 +309,18 @@ class ApplyOrderService extends Service
|
|
|
$sale_order_number = array_unique($sale_order_number);
|
|
|
$sale_order_number = implode(',',$sale_order_number);
|
|
|
$data['data'][$key]['sale_order_number'] = $sale_order_number;
|
|
|
+ }elseif ($value['type'] == ApplyOrder::type_five){
|
|
|
+ $order_tmp = $order3_map[$value['id']] ?? [];
|
|
|
+ $order_tmp = array_unique($order_tmp);
|
|
|
+ $sale_order_number = [];
|
|
|
+ foreach ($order_tmp as $v){
|
|
|
+ $str = $map3[$v] ?? '';
|
|
|
+ if(empty($str)) continue;
|
|
|
+ $sale_order_number[] = $str;
|
|
|
+ }
|
|
|
+ $sale_order_number = array_unique($sale_order_number);
|
|
|
+ $sale_order_number = implode(',',$sale_order_number);
|
|
|
+ $data['data'][$key]['sale_order_number'] = $sale_order_number;
|
|
|
}else{
|
|
|
$order_tmp = $order2_map[$value['id']] ?? [];
|
|
|
$order_tmp = array_unique($order_tmp);
|
|
|
@@ -306,6 +348,7 @@ class ApplyOrderService extends Service
|
|
|
->first();
|
|
|
if(empty($detail)) return [false,'申请单不存在或已被删除'];
|
|
|
$detail = $detail->toArray();
|
|
|
+ $detail['apply_time'] = $detail['apply_time'] ? date('Y-m-d',$detail['apply_time']) : '';
|
|
|
$detail['apply_title'] = Employee::where('id', $detail['apply_id'])->value('emp_name');
|
|
|
$apply_d = ApplyOrderDetail::where('del_time', 0)
|
|
|
->where('apply_order_id', $id)
|
|
|
@@ -369,6 +412,11 @@ class ApplyOrderService extends Service
|
|
|
->whereIn('id', $apply_id)
|
|
|
->select('id', 'order_no')
|
|
|
->get()->toArray();
|
|
|
+ }elseif ($detail['type'] == ApplyOrder::type_five){ //质检入库申请
|
|
|
+ $d = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('id', $apply_id)
|
|
|
+ ->select('id', 'order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
|
|
|
+ ->get()->toArray();
|
|
|
}
|
|
|
$d_tmp = array_column($d,null,'id');
|
|
|
|
|
|
@@ -450,6 +498,12 @@ class ApplyOrderService extends Service
|
|
|
->select('id', 'order_no', 'status')
|
|
|
->get()->toArray();
|
|
|
if(count($box) != count($id)) return [false, '包装单信息错误,请重新选择'];
|
|
|
+ }elseif ($data['type'] == ApplyOrder::type_five){
|
|
|
+ $scrapp = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('id', $id)
|
|
|
+ ->select('id', 'order_no', 'status')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(count($scrapp) != count($id)) return [false, '质检单信息错误,请重新选择'];
|
|
|
}else{
|
|
|
return [false, '申请单类型错误'];
|
|
|
}
|
|
|
@@ -463,14 +517,17 @@ class ApplyOrderService extends Service
|
|
|
$apply = ApplyOrder::where('id', $data['id'])->where('del_time', 0)->first();
|
|
|
if(empty($apply)) return [false, '申请单不存在或已被删除'];
|
|
|
if($apply->status != 0) return [false, '申请单已审核,编辑失败'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
- public function setOrderNO($type = ""){
|
|
|
- $str = date('Ymd',time());
|
|
|
+ public function setOrderNO($type = "",$time = 0){
|
|
|
+ if(empty($time)){
|
|
|
+ $str = date('Ymd',time());
|
|
|
+ }else{
|
|
|
+ $str = date('Ymd',$time);
|
|
|
+ }
|
|
|
|
|
|
$order_number = ApplyOrder::where('order_number','Like','%'. $str . '%')
|
|
|
->where('type', $type)
|
|
|
@@ -493,7 +550,7 @@ class ApplyOrderService extends Service
|
|
|
return $number;
|
|
|
}
|
|
|
|
|
|
- public function createSQ($data, $user, $type = 0, $status = 1){
|
|
|
+ public function createSQ($data, $user, $type = 0, $status = 1,$time = 0){
|
|
|
if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
|
|
|
|
|
|
if($type == ApplyOrder::type_one){
|
|
|
@@ -505,7 +562,7 @@ class ApplyOrderService extends Service
|
|
|
}elseif ($type == ApplyOrder::type_three){
|
|
|
$storehouse_id = "002";
|
|
|
$storehouse_title = "产成品仓";
|
|
|
- }else{
|
|
|
+ }elseif($type == ApplyOrder::type_four){
|
|
|
$storehouse_id = "003";
|
|
|
$storehouse_title = "包材、辅料仓" ;
|
|
|
}
|
|
|
@@ -513,15 +570,16 @@ class ApplyOrderService extends Service
|
|
|
try{
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
- $order_number = $this->setOrderNO($type);
|
|
|
+ $order_number = $this->setOrderNO($type, $time);
|
|
|
// list($status,$msg) = $this->limitingSendRequestBackg("spAdd" . $order_number . $type);
|
|
|
// if(! $status) return [false, $msg];
|
|
|
|
|
|
- $time = time();
|
|
|
+ if(empty($time)) $time = time();
|
|
|
+
|
|
|
$model = new ApplyOrder();
|
|
|
$model->order_number = $order_number;
|
|
|
$model->apply_id = $user['id'];
|
|
|
- $model->apply_time = time();
|
|
|
+ $model->apply_time = $time;
|
|
|
$model->storehouse_id = $storehouse_id;
|
|
|
$model->storehouse_title = $storehouse_title;
|
|
|
$model->type = $type;
|
|
|
@@ -559,8 +617,59 @@ class ApplyOrderService extends Service
|
|
|
return [true, $id];
|
|
|
}
|
|
|
|
|
|
+ public function createSqFive($data, $user, $type = 0, $status = 1, $time = 0){
|
|
|
+ if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
|
|
|
+
|
|
|
+ try{
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ if(empty($time)) $time = time();
|
|
|
+
|
|
|
+ $first = $data[0] ?? [];
|
|
|
+ $order_number = $this->setOrderNO($type, $time);
|
|
|
+ $model = new ApplyOrder();
|
|
|
+ $model->order_number = $order_number;
|
|
|
+ $model->apply_id = $user['id'];
|
|
|
+ $model->apply_time = $time;
|
|
|
+ $model->storehouse_id = $first['storehouse_id'];
|
|
|
+ $model->storehouse_title = $first['storehouse_title'];
|
|
|
+ $model->type = $type;
|
|
|
+ $model->status = $status; //是否审核
|
|
|
+ $model->save();
|
|
|
+ $id = $model->id;
|
|
|
+
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'apply_order_id' => $id,
|
|
|
+ 'data_id' => $value['id'],
|
|
|
+ 'quantity' => $value['quantity'] ?? 0,
|
|
|
+ 'product_no' => $value['product_no'] ?? "",
|
|
|
+ 'product_title' => $value['product_title'] ?? "",
|
|
|
+ 'product_size' => $value['product_size'] ?? "",
|
|
|
+ 'product_unit' => $value['product_unit'] ?? "",
|
|
|
+ 'technology_name' => $value['technology_name'] ?? "",
|
|
|
+ 'wood_name' => $value['wood_name'] ?? "",
|
|
|
+ 'top_product_no' => $value['top_product_no'] ?? "",
|
|
|
+ 'top_product_title' => $value['top_product_title'] ?? "",
|
|
|
+ 'type' => $type,
|
|
|
+ 'storehouse_id' => $value['storehouse_id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ ApplyOrderDetail::insert($insert);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$e->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
//流水
|
|
|
- public function createRecord($id){
|
|
|
+ public function createRecord($id){return [true, ''];
|
|
|
$record = ApplyOrderDetail::where('apply_order_id', $id)
|
|
|
->where('del_time',0)
|
|
|
->get()->toArray();
|
|
|
@@ -601,7 +710,7 @@ class ApplyOrderService extends Service
|
|
|
|
|
|
//报工
|
|
|
public function reportWorkingEdit($data, $user){
|
|
|
- list($status,$msg) = $this->reportWorkingRule($data,false);
|
|
|
+ list($status,$msg) = $this->reportWorkingRule($data,$user,false);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
@@ -611,6 +720,7 @@ class ApplyOrderService extends Service
|
|
|
$model = $model->where('id',$data['id'])->first();
|
|
|
$model->report_time = $data['report_time'];
|
|
|
$model->mark = $data['mark']?? "";
|
|
|
+ $model->status = $data['auto'] ?? 0;
|
|
|
$model->save();
|
|
|
$id = $model->id;
|
|
|
|
|
|
@@ -629,13 +739,25 @@ class ApplyOrderService extends Service
|
|
|
$detail_insert = [];
|
|
|
foreach ($data['order_data'] as $v){
|
|
|
$t = $team_man[$v['team_id']] ?? [];
|
|
|
- foreach ($t as $t_v){
|
|
|
+ if(! empty($t)){
|
|
|
+ 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,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
$detail_insert[] = [
|
|
|
'report_working_id' => $id,
|
|
|
'data_id' => $v['id'],
|
|
|
'quantity' => $v['quantity'] ?? 0,
|
|
|
'process_id' => $v['process_id'] ?? 0,
|
|
|
- 'finished_id' => $t_v,
|
|
|
+ 'finished_id' => 0,
|
|
|
'team_id' => $v['team_id'],
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
@@ -653,7 +775,7 @@ class ApplyOrderService extends Service
|
|
|
}
|
|
|
|
|
|
public function reportWorkingAdd($data,$user){
|
|
|
- list($status,$msg) = $this->reportWorkingRule($data);
|
|
|
+ list($status,$msg) = $this->reportWorkingRule($data,$user);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
@@ -664,6 +786,7 @@ class ApplyOrderService extends Service
|
|
|
$model->report_time = $data['report_time'];
|
|
|
$model->mark = $data['mark']?? "";
|
|
|
$model->crt_id = $user['id'];
|
|
|
+ $model->status = $data['auto'] ?? 0;
|
|
|
$model->save();
|
|
|
$id = $model->id;
|
|
|
|
|
|
@@ -678,13 +801,25 @@ class ApplyOrderService extends Service
|
|
|
$detail_insert = [];
|
|
|
foreach ($data['order_data'] as $v){
|
|
|
$t = $team_man[$v['team_id']] ?? [];
|
|
|
- foreach ($t as $t_v){
|
|
|
+ if(! empty($t)){
|
|
|
+ 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,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
$detail_insert[] = [
|
|
|
'report_working_id' => $id,
|
|
|
'data_id' => $v['id'],
|
|
|
'quantity' => $v['quantity'] ?? 0,
|
|
|
'process_id' => $v['process_id'] ?? 0,
|
|
|
- 'finished_id' => $t_v,
|
|
|
+ 'finished_id' => 0,
|
|
|
'team_id' => $v['team_id'],
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
|
@@ -792,11 +927,31 @@ class ApplyOrderService extends Service
|
|
|
->pluck('emp_name','id')
|
|
|
->toArray();
|
|
|
|
|
|
+ $detail = ReportWorkingDetail::where('del_time',0)
|
|
|
+ ->whereIn('report_working_id', array_column($data['data'],'id'))
|
|
|
+ ->select('data_id','report_working_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map = [];
|
|
|
+ foreach ($detail as $value){
|
|
|
+ $map[$value['data_id']] = $value['report_working_id'];
|
|
|
+ }
|
|
|
+ $dispatch = DispatchSub::whereIn('id',array_column($detail,'data_id'))
|
|
|
+ ->get()->toArray();
|
|
|
+ $map1 = [];
|
|
|
+ $team_map = Team::where("del_time",0)->pluck('title','id')->toArray();
|
|
|
+ $process_map = Process::where("del_time",0)->pluck('title','id')->toArray();
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $report_working_id = $map[$value['id']] ?? 0;
|
|
|
+ $value['team_name'] = $team_map[$value['team_id']] ?? "";
|
|
|
+ $value['process_name'] = $process_map[$value['process_id']] ?? "";
|
|
|
+ $map1[$report_working_id][] = $value;
|
|
|
+ }
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
- $data['data'][$key]['report_time'] = $value['report_time'] ? date('Y-m-d H:i:s',$value['report_time']) : '';
|
|
|
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
+ $data['data'][$key]['report_time'] = $value['report_time'] ? date('Y-m-d',$value['report_time']) : '';
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
|
|
|
$data['data'][$key]['status_title'] = ReportWorking::$state_name[$value['status']] ?? "";
|
|
|
$data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
+ $data['data'][$key]['dispatch'] = $map1[$value['id']] ?? [];
|
|
|
}
|
|
|
|
|
|
return $data;
|
|
|
@@ -810,6 +965,8 @@ class ApplyOrderService extends Service
|
|
|
->first();
|
|
|
if(empty($detail)) return [false,'报工单不存在或已被删除'];
|
|
|
$detail = $detail->toArray();
|
|
|
+ $detail['report_time'] = $detail['report_time'] ? date('Y-m-d',$detail['report_time']) : '';
|
|
|
+
|
|
|
$apply_d = ReportWorkingDetail::where('del_time', 0)
|
|
|
->where('report_working_id', $id)
|
|
|
->get()->toArray();
|
|
|
@@ -856,7 +1013,7 @@ class ApplyOrderService extends Service
|
|
|
return [true, $detail];
|
|
|
}
|
|
|
|
|
|
- public function reportWorkingRule(&$data,$is_add = true){
|
|
|
+ public function reportWorkingRule(&$data,$user, $is_add = true){
|
|
|
if($this->isEmpty($data,'report_time')) return [false,'报工时间不能为空'];
|
|
|
if(empty($data['order_data'])) return [false, '报工单详细信息不能为空'];
|
|
|
foreach ($data['order_data'] as $value){
|
|
|
@@ -869,9 +1026,11 @@ class ApplyOrderService extends Service
|
|
|
$id = array_unique(array_column($data['order_data'],'id'));
|
|
|
$dispatch = DispatchSub::where('del_time',0)
|
|
|
->whereIn('id', $id)
|
|
|
- ->select('id', 'dispatch_no', 'status')
|
|
|
+ ->select('id', 'dispatch_no', 'status', 'dispatch_quantity','order_product_id')
|
|
|
->get()->toArray();
|
|
|
if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
|
|
|
+ $count = array_unique(array_column($dispatch,'order_product_id'));
|
|
|
+ if(count($count) > 1) return [false, '批量报工时请选择同一生产订单下的派工单'];
|
|
|
|
|
|
if($is_add){
|
|
|
$data['order_number'] = $this->setOrderNO2();
|
|
|
@@ -885,11 +1044,55 @@ class ApplyOrderService extends Service
|
|
|
|
|
|
}
|
|
|
|
|
|
+ list($status, $msg) = $this->compareQuantity($dispatch, $data);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ $em = new EmployeeService();
|
|
|
+ $data['auto'] = $em->is_auto($user, "wgbg_auto");
|
|
|
+
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
- public function setOrderNO2(){
|
|
|
- $str = date('Ymd',time());
|
|
|
+ public function compareQuantity($dispatch, $data){
|
|
|
+ $id = $data['id'] ?? 0;
|
|
|
+
|
|
|
+ $result = ReportWorkingDetail::where('del_time',0)
|
|
|
+ ->when(! empty($id), function ($query) use ($id){
|
|
|
+ return $query->where('report_working_id', '<>', $id);
|
|
|
+ })
|
|
|
+ ->where('data_id', array_column($dispatch, 'id'))
|
|
|
+ ->select('data_id as dispatch_id','quantity')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $map1 = [];
|
|
|
+ foreach ($result as $value){
|
|
|
+ if(isset($map1[$value['dispatch_id']])){
|
|
|
+ $tmp = bcadd($map1[$value['dispatch_id']], $value['quantity'], 3);
|
|
|
+ $map1[$value['dispatch_id']] = $tmp;
|
|
|
+ }else{
|
|
|
+ $map1[$value['dispatch_id']] = $value['quantity'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $map2 = array_column($dispatch,null,'id');
|
|
|
+
|
|
|
+ foreach ($data['order_data'] as $value){
|
|
|
+ $tmp = $map2[$value['id']] ?? [];
|
|
|
+ $total = $tmp['dispatch_quantity'] ?? 0;
|
|
|
+ $dispatch_no = $tmp['dispatch_no'] ?? "";
|
|
|
+ $save = $map1[$value['id']] ?? 0;
|
|
|
+ $save_total = bcadd($value['quantity'], $save, 2);
|
|
|
+ if($save_total > $total) return [false, "派工单号:" . $dispatch_no . "的报工总数量不能超过" . $total . "吨,目前累计报工" . $save . "吨"];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setOrderNO2($time = 0){
|
|
|
+ if(empty($time)) {
|
|
|
+ $str = date('Ymd',time());
|
|
|
+ }else{
|
|
|
+ $str = date('Ymd', $time);
|
|
|
+ }
|
|
|
|
|
|
$model = new ReportWorking();
|
|
|
$order_number = $model->where('order_number','Like','%'. $str . '%')
|
|
|
@@ -942,6 +1145,18 @@ class ApplyOrderService extends Service
|
|
|
->select('apply_order_id')
|
|
|
->get()->toArray();
|
|
|
$model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
|
|
|
+ }elseif($data['type'] == ApplyOrder::type_five){
|
|
|
+ $zj_id = ScrappCount::where('del_time',0)
|
|
|
+ ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $zj_id = array_column($zj_id,'id');
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->where('type', $data['type'])
|
|
|
+ ->whereIn('data_id', $zj_id)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
|
|
|
}else{
|
|
|
$no = SaleOrdersProduct::where('del_time',0)
|
|
|
->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
|
|
|
@@ -1096,6 +1311,11 @@ class ApplyOrderService extends Service
|
|
|
->whereIn('id', $apply_id)
|
|
|
->select('id', 'order_no')
|
|
|
->get()->toArray();
|
|
|
+ }elseif($type == ApplyOrder::type_five){
|
|
|
+ $d = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('id', $apply_id)
|
|
|
+ ->select('id', 'order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
|
|
|
+ ->get()->toArray();
|
|
|
}
|
|
|
|
|
|
return [$d, $d_no_map];
|
|
|
@@ -1114,6 +1334,10 @@ class ApplyOrderService extends Service
|
|
|
$map1 = DispatchSub::whereIn('id', array_unique($data_id))
|
|
|
->pluck('out_order_no','id')
|
|
|
->toArray();
|
|
|
+ }elseif($type == ApplyOrder::type_five){
|
|
|
+ $map3 = ScrappCount::whereIn('id', array_unique($data_id))
|
|
|
+ ->pluck('out_order_no','id')
|
|
|
+ ->toArray();
|
|
|
}else{
|
|
|
$map2 = Box::whereIn('id', array_unique($data_id))
|
|
|
->pluck('top_order_no','id')
|
|
|
@@ -1139,6 +1363,15 @@ class ApplyOrderService extends Service
|
|
|
$sale_order_number = array_unique($sale_order_number);
|
|
|
$sale_order_number = implode(',',$sale_order_number);
|
|
|
$data[$key]['sale_order_number'] = $sale_order_number;
|
|
|
+ }elseif ($type == ApplyOrder::type_five){
|
|
|
+ foreach ($order_tmp as $v){
|
|
|
+ $str = $map3[$v] ?? '';
|
|
|
+ if(empty($str)) continue;
|
|
|
+ $sale_order_number[] = $str;
|
|
|
+ }
|
|
|
+ $sale_order_number = array_unique($sale_order_number);
|
|
|
+ $sale_order_number = implode(',',$sale_order_number);
|
|
|
+ $data[$key]['sale_order_number'] = $sale_order_number;
|
|
|
}else{
|
|
|
foreach ($order_tmp as $v){
|
|
|
$m2_t = $map2[$v] ?? '';
|
|
|
@@ -1154,4 +1387,810 @@ class ApplyOrderService extends Service
|
|
|
|
|
|
return array_column($data,null,'id');
|
|
|
}
|
|
|
+
|
|
|
+ public function editZj($data, $user){
|
|
|
+ list($status, $msg) = $this->editZjRule($data);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ $order_map = array_column($msg,null,'data_id');
|
|
|
+ try{
|
|
|
+ DB::beginTransaction();
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $insert = [];
|
|
|
+ $max_id = $this->getDailyId();
|
|
|
+
|
|
|
+ list($status,$msg) = $this->limitingSendRequestBackg("quantity_id_" . $max_id);
|
|
|
+ if(! $status) return [false,$msg];
|
|
|
+
|
|
|
+ $get_order_number = $insert_wg = [];
|
|
|
+ foreach ($data['data'] as $value){
|
|
|
+ $order_t = $order_map[$value['data_id']] ?? [];
|
|
|
+ $order = $order_t['dispatch'] ?? [];
|
|
|
+ if(empty($value['waste'])){
|
|
|
+ $max_id += 1;
|
|
|
+ $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
|
|
|
+ $get_order_number[] = $order_number;
|
|
|
+ $insert[] = [
|
|
|
+ 'sale_orders_product_id' => $order['sale_orders_product_id'],
|
|
|
+ 'order_product_id' => $order['order_product_id'],
|
|
|
+ 'dispatch_sub_id' => $order['id'],
|
|
|
+ 'out_order_no' => $order['out_order_no'],
|
|
|
+ 'order_no' => $order['order_no'],
|
|
|
+ 'customer_no' => $order['customer_no'],
|
|
|
+ 'customer_name' => $order['customer_name'],
|
|
|
+ 'product_no' => $order['product_no'],
|
|
|
+ 'product_title' => $order['product_title'],
|
|
|
+ 'product_size' => $order['product_size'],
|
|
|
+ 'product_unit' => $order['product_unit'],
|
|
|
+ 'technology_material' => $order['technology_material'],
|
|
|
+ 'technology_name' => $order['technology_name'],
|
|
|
+ 'wood_name' => $order['wood_name'],
|
|
|
+ 'price' => $order['price'],
|
|
|
+ 'process_mark' => $order['process_mark'],
|
|
|
+ 'table_body_mark' => $order['table_body_mark'],
|
|
|
+ 'table_header_mark' => $order['table_header_mark'],
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'scrapp_num' => 0,
|
|
|
+ 'scrapp_id' => 0,
|
|
|
+ 'team_id' => $data['team_id'],
|
|
|
+ 'finished_id' => $user['id'],
|
|
|
+ 'equipment_id' => $data['equipment_id'],
|
|
|
+ 'order_number' => $order_number,
|
|
|
+ 'process_id' => $order['process_id'],
|
|
|
+ 'quantity' => $value['num'],
|
|
|
+ 'report_id' => $data['id'],
|
|
|
+ 'result' => 0,
|
|
|
+ 'warehouse_no' => "",
|
|
|
+ 'warehouse_title' => "",
|
|
|
+ 'daily_id' => $max_id,
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ foreach ($value['waste'] as $v){
|
|
|
+ $max_id += 1;
|
|
|
+ $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
|
|
|
+ $get_order_number[] = $order_number;
|
|
|
+ $insert[] = [
|
|
|
+ 'sale_orders_product_id' => $order['sale_orders_product_id'],
|
|
|
+ 'order_product_id' => $order['order_product_id'],
|
|
|
+ 'dispatch_sub_id' => $order['id'],
|
|
|
+ 'out_order_no' => $order['out_order_no'],
|
|
|
+ 'order_no' => $order['order_no'],
|
|
|
+ 'customer_no' => $order['customer_no'],
|
|
|
+ 'customer_name' => $order['customer_name'],
|
|
|
+ 'product_no' => $order['product_no'],
|
|
|
+ 'product_title' => $order['product_title'],
|
|
|
+ 'product_size' => $order['product_size'],
|
|
|
+ 'product_unit' => $order['product_unit'],
|
|
|
+ 'technology_material' => $order['technology_material'],
|
|
|
+ 'technology_name' => $order['technology_name'],
|
|
|
+ 'wood_name' => $order['wood_name'],
|
|
|
+ 'price' => $order['price'],
|
|
|
+ 'process_mark' => $order['process_mark'],
|
|
|
+ 'table_body_mark' => $order['table_body_mark'],
|
|
|
+ 'table_header_mark' => $order['table_header_mark'],
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'scrapp_num' => $v['num'],
|
|
|
+ 'scrapp_id' => $v['scrapp_id'],
|
|
|
+ 'team_id' => $data['team_id'],
|
|
|
+ 'finished_id' => $user['id'],
|
|
|
+ 'equipment_id' => $data['equipment_id'],
|
|
|
+ 'order_number' => $order_number,
|
|
|
+ 'process_id' => $order['process_id'],
|
|
|
+ 'quantity' => $value['num'],
|
|
|
+ 'report_id' => $data['id'],
|
|
|
+ 'result' => $v['result'],
|
|
|
+ 'warehouse_no' => $v['warehouse_no'],
|
|
|
+ 'warehouse_title' => $v['warehouse_title'],
|
|
|
+ 'daily_id' => $max_id,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($value['num'] > 0) $insert_wg[] = [
|
|
|
+ 'dispatch_id' => $value['data_id'],
|
|
|
+ 'num' => $value['num']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ //质检单 不良品单 会记录报工单的id
|
|
|
+ if(! empty($insert)) ScrappCount::insert($insert);
|
|
|
+ //获取新增的单据
|
|
|
+ $result = ScrappCount::whereIn('order_number',$get_order_number)
|
|
|
+ ->select('scrapp_num as num','id','dispatch_sub_id','warehouse_no','warehouse_title')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ //完工入库申请单 半成品
|
|
|
+ list($status, $msg) = $this->insertWg($insert_wg, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ //获取写入的数据 写其它的业务逻辑
|
|
|
+ list($status, $msg) = $this->insertOther($result, $user, $time);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ //反写 根据质检单上的派工单id 反写上游单据
|
|
|
+ $this->writeDispatchQuantity(array_column($result,'dispatch_sub_id'));
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage() . '|' . $exception->getLine()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function editZjRule($data){
|
|
|
+ if(empty($data['id'])) return [false, '报工单ID不能为空'];
|
|
|
+ $order = ReportWorkingDetail::where('del_time',0)
|
|
|
+ ->where('report_working_id', $data['id'])
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($order)) return [false, "报工单信息不存在或已被删除"];
|
|
|
+ $map = [];
|
|
|
+ foreach ($order as $value){
|
|
|
+ if(! isset($map[$value['data_id']])) $map[$value['data_id']] = $value['quantity'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($data['team_id'])) return [false, '质检班组不能为空'];
|
|
|
+ if(empty($data['equipment_id'])) return [false, '设备不能为空'];
|
|
|
+ if(empty($data['data'])) return [false, '质检信息不能为空'];
|
|
|
+
|
|
|
+ $data_id = [];
|
|
|
+ foreach ($data['data'] as $value){
|
|
|
+ if(empty($value['data_id'])) return [false, 'dataID不能为空'];
|
|
|
+ if(! isset($value['num'])) return [false, 'num不能为空'];
|
|
|
+ $num = 0;
|
|
|
+ if(! empty($value['waste'])){
|
|
|
+ foreach ($value['waste'] as $v){
|
|
|
+ if(empty($v['num'])) return [false, "质检数量不能为空"];
|
|
|
+ if(empty($v['scrapp_id'])) return [false, "请选择质检原因"];
|
|
|
+ if(empty($v['result'])) return [false, '请选择质检产品处理结果'];
|
|
|
+ if($v['result'] == ReportWorking::type_two && (empty($v['warehouse_no']) || empty($v['warehouse_title']))) return [false, '请选择产品去向仓库'];
|
|
|
+ $num = bcadd($v['num'], $num, 3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $total = bcadd($num, $value['num'],3);
|
|
|
+ $total2 = $map[$value['data_id']] ?? 0;
|
|
|
+ if($total > $total2) return [false, '总数量不能超过报工数量'];
|
|
|
+
|
|
|
+ $data_id[] = $value['data_id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::whereIn('id',$data_id)->get()->toArray();
|
|
|
+ $dispatch_map = array_column($dispatch,null,'id');
|
|
|
+ foreach ($order as $key => $value){
|
|
|
+ if(! in_array($value['data_id'], $data_id)){
|
|
|
+ unset($order[$key]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $order[$key]['dispatch'] = $dispatch_map[$value['data_id']] ?? [];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, array_values($order)];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getDailyId($time = 0)
|
|
|
+ {
|
|
|
+ if(empty($time)) $time = time();
|
|
|
+
|
|
|
+ $today_start = strtotime(date("Y-m-d 00:00:00",$time));
|
|
|
+ $today_end = strtotime(date("Y-m-d 23:59:59",$time));
|
|
|
+
|
|
|
+ // 获取今天的最大daily_id
|
|
|
+ $maxDailyId = ScrappCount::where('crt_time', '>=', $today_start)
|
|
|
+ ->where('crt_time', '<=', $today_end)
|
|
|
+ ->max(DB::raw('daily_id + 0'));
|
|
|
+
|
|
|
+ return $maxDailyId ?? 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function insertWg($all_data, $user){
|
|
|
+ if(empty($all_data)) return [true, ''];
|
|
|
+ $dispatchList = DispatchSub::whereIn('id', array_column($all_data,'dispatch_id'))->get()->toArray();
|
|
|
+
|
|
|
+ //是否最后一道工序
|
|
|
+ $orders = OrdersProduct::whereIn('id', array_unique(array_column($dispatchList, 'order_product_id')))
|
|
|
+ ->select('id','process_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map = [];
|
|
|
+ foreach ($orders as $value){
|
|
|
+ $p = explode(",", $value['process_id']);
|
|
|
+ $lastElement = end($p);
|
|
|
+ $map[$value['id']] = $lastElement;
|
|
|
+ }
|
|
|
+
|
|
|
+ $all_data_map = array_column($all_data,null,'dispatch_id');
|
|
|
+ $need_insert = [];
|
|
|
+ foreach ($dispatchList as $value){
|
|
|
+ $num = $all_data_map[$value['id']] ?? 0;
|
|
|
+ if(! $num) continue;
|
|
|
+ if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id']){
|
|
|
+ $tmp = [
|
|
|
+ 'id' => $value['id'],
|
|
|
+ 'quantity' => $num,
|
|
|
+ 'product_no' => $value['product_no'] ?? "",
|
|
|
+ 'product_title' => $value['product_title'] ?? "",
|
|
|
+ 'product_size' => $value['product_size'] ?? "",
|
|
|
+ 'product_unit' => $value['product_unit'] ?? "",
|
|
|
+ ];
|
|
|
+ $need_insert[] = $tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成完工入库申请单
|
|
|
+ $service = new BoxService();
|
|
|
+ list($status, $msg) = $service->createWGSQ($need_insert, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function insertOther($all_data, $user, $time){
|
|
|
+ try {
|
|
|
+ $result = [];
|
|
|
+ foreach ($all_data as $value){
|
|
|
+ if($value['result'] > 0) $result[] = $value;
|
|
|
+ }
|
|
|
+ if(empty($result)) return [true, ''];
|
|
|
+ $dispatchList = DispatchSub::whereIn('id', array_column($result,'dispatch_sub_id'))->get()->toArray();
|
|
|
+ $dispatch_map = array_column($dispatchList,null,'id');
|
|
|
+
|
|
|
+ //是否自动审核
|
|
|
+ $em = new EmployeeService();
|
|
|
+ $auto = $em->is_auto($user, "pg_auto");
|
|
|
+
|
|
|
+ $dispatch_no = (new DispatchService())->setOrderNO();
|
|
|
+ if(! $dispatch_no) return [false,'返工派工单号生成失败!'];
|
|
|
+ $prefix = substr($dispatch_no, 0, -3);// "20250611"
|
|
|
+ $startNum = (int)substr($dispatch_no, -3); // 7
|
|
|
+ $is_first = true;
|
|
|
+
|
|
|
+ $dispatch_main = $dispatch = $is_need_ll = $is_need_warehouse = [];
|
|
|
+ foreach ($result as $value){
|
|
|
+ //派工单
|
|
|
+ $t = $dispatch_map[$value['dispatch_sub_id']] ?? [];
|
|
|
+
|
|
|
+ if(! $is_first){
|
|
|
+ $startNum += 1;
|
|
|
+ $number = str_pad($startNum,3,'0',STR_PAD_LEFT);
|
|
|
+ $number = $prefix . $number;
|
|
|
+ $dispatch_no_t = $number;
|
|
|
+ }else{
|
|
|
+ $dispatch_no_t = $dispatch_no;
|
|
|
+ $is_first = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($value['result'] == ReportWorking::type_one){
|
|
|
+ //重新入生产流程 需要生成返工派工单
|
|
|
+ }else{
|
|
|
+ //入仓库 那么需要生成质检入库申请单 生成领料申请单 生成返工派工单
|
|
|
+ //'id','dispatch_quantity as quantity',"product_no","order_product_id","product_no",'technology_name','crt_time'
|
|
|
+ $is_need_ll[] = $dispatch_no_t;
|
|
|
+ $is_need_warehouse[] = [
|
|
|
+ 'warehouse_no' => $value['warehouse_no'],
|
|
|
+ 'warehouse_title' => $value['warehouse_title'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $dispatch_main[] = ['dispatch_no' => $dispatch_no_t,'crt_time' => $time];
|
|
|
+ $dispatch[] = [
|
|
|
+ 'order_product_id' => $t['order_product_id'],
|
|
|
+ 'order_no' => $t['order_no'],
|
|
|
+ 'product_no' => $t['product_no'],
|
|
|
+ 'product_title' => $t['product_title'],
|
|
|
+ 'product_size' => $t['product_size'],
|
|
|
+ 'product_unit' => $t['product_unit'],
|
|
|
+ 'production_quantity' => $t['production_quantity'],
|
|
|
+ 'dispatch_quantity' => $value['num'],
|
|
|
+ 'technology_material' => $t['technology_material'],
|
|
|
+ 'technology_name' => $t['technology_name'],
|
|
|
+ 'wood_name' => $t['wood_name'],
|
|
|
+ 'process_mark' => $t['process_mark'],
|
|
|
+ 'table_body_mark' => $t['table_body_mark'],
|
|
|
+ 'table_header_mark' => $t['table_header_mark'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'status' => $auto,
|
|
|
+ 'dispatch_no' => $dispatch_no_t,
|
|
|
+ 'process_id' => $t['process_id'],
|
|
|
+ 'dispatch_time_start' => $t['dispatch_time_start'],
|
|
|
+ 'dispatch_time_end' => $t['dispatch_time_end'],
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
+ 'sale_orders_product_id' => $t['sale_orders_product_id'],
|
|
|
+ 'out_order_no' => $t['out_order_no'],
|
|
|
+ 'out_order_no_time' => $t['out_order_no_time'],
|
|
|
+ 'price' => $t['price'],
|
|
|
+ 'customer_no' => $t['customer_no'],
|
|
|
+ 'customer_name' => $t['customer_name'],
|
|
|
+ 'pre_shipment_time' => $t['pre_shipment_time'],
|
|
|
+ 'team_id' => $t['team_id'],
|
|
|
+ 'device_id' => $t['device_id'],
|
|
|
+ 'type' => 1,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ Dispatch::insert($dispatch_main);
|
|
|
+ DispatchSub::insert($dispatch);
|
|
|
+
|
|
|
+ if(! empty($is_need_ll)){
|
|
|
+ //获取上一次插入订单的所有数据
|
|
|
+ $insert = DispatchSub::whereIn('dispatch_no', $is_need_ll)
|
|
|
+ ->where('crt_time',$time)
|
|
|
+ ->where('crt_id',$user['id'])
|
|
|
+ ->select('id','dispatch_quantity as quantity',"product_no")
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ //领料申请单
|
|
|
+ list($status, $msg) = (new DispatchService())->createSQ($insert, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ //质检入库申请单 原材料
|
|
|
+ list($status, $msg) = $this->createZJSQ($insert, $user, $is_need_warehouse);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createZJSQ($insert_data, $user, $warehouse, $time = 0){
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ //是否自动审核质检入库申请单
|
|
|
+ $em = new EmployeeService();
|
|
|
+ $auto = $em->is_auto($user, "zjsq_auto");
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ $product_no = array_unique(array_column($insert_data,'product_no'));
|
|
|
+ //获取原料
|
|
|
+ $service = new FyyOrderService();
|
|
|
+ list($status, $msg) = $service->getProductDataFromSqlServer(['product_no' => $product_no], $user);
|
|
|
+ if($status) $return = $msg;
|
|
|
+
|
|
|
+ //组织原材料写入数据
|
|
|
+ $insert = [];
|
|
|
+ foreach ($insert_data as $key => $value){
|
|
|
+ $quantity = 0;
|
|
|
+ if(! empty($value['quantity'])) {
|
|
|
+ $quantity = $value['quantity'];
|
|
|
+ }elseif (! empty($value['dispatch_quantity'])){
|
|
|
+ $quantity = $value['dispatch_quantity'];
|
|
|
+ }
|
|
|
+ $t = $return[$value['product_no']] ?? [];
|
|
|
+ $tmp = [
|
|
|
+ 'id' => $value['id'],
|
|
|
+ 'quantity' => $quantity,
|
|
|
+ 'product_no' => "",
|
|
|
+ 'product_title' => "",
|
|
|
+ 'product_size' => "",
|
|
|
+ 'product_unit' => "",
|
|
|
+ 'storehouse_id' => $warehouse[$key]['warehouse_no'] ?? "",
|
|
|
+ 'storehouse_title' => $warehouse[$key]['warehouse_title'] ?? "",
|
|
|
+ ];
|
|
|
+ if(! empty($t)){
|
|
|
+ foreach ($t as $v){
|
|
|
+ $tmp['product_no'] = $v['product_no'];
|
|
|
+ $tmp['product_title'] = $v['product_title'];
|
|
|
+ $tmp['product_size'] = $v['product_size'];
|
|
|
+ $tmp['product_unit'] = $v['product_unit'];
|
|
|
+ $insert[] = $tmp;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $tmp['quantity'] = 0;
|
|
|
+ $insert[] = $tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成质检入库申请单
|
|
|
+ $service = new ApplyOrderService();
|
|
|
+ list($status, $msg) = $service->createSqFive($insert, $user, ApplyOrder::type_five, $auto, $time);
|
|
|
+ if(! $status) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getFile() . $exception->getMessage() . $exception->getLine()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ //反写
|
|
|
+ public function writeDispatchQuantity($dispatch_id){
|
|
|
+ $result = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('dispatch_sub_id', $dispatch_id)
|
|
|
+ ->select('dispatch_sub_id','quantity','scrapp_num','crt_time','process_id','order_product_id')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ //是否最后一道工序
|
|
|
+ $orders = OrdersProduct::whereIn('id', array_unique(array_column($result, 'order_product_id')))
|
|
|
+ ->select('id','process_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map = [];
|
|
|
+ foreach ($orders as $value){
|
|
|
+ $p = explode(",", $value['process_id']);
|
|
|
+ $lastElement = end($p);
|
|
|
+ $map[$value['id']] = $lastElement;
|
|
|
+ }
|
|
|
+
|
|
|
+ //汇总这个派工单一共质检良品数量 但是同一时间下的 只取一次
|
|
|
+ $update = $flag = $need_update = [];
|
|
|
+ foreach ($result as $value){
|
|
|
+ if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id'] && ! in_array($value['order_product_id'], $need_update)){
|
|
|
+ $need_update[] = [
|
|
|
+ 'order_product_id' => $value['order_product_id'],
|
|
|
+ 'process_id' => $value['process_id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $key = $value['dispatch_sub_id'] . $value['crt_time'];
|
|
|
+ if(isset($flag[$key])) continue;
|
|
|
+
|
|
|
+ if(isset($update[$value['dispatch_sub_id']])){
|
|
|
+ $tmp = bcadd($value['quantity'], $update[$value['dispatch_sub_id']], 3);
|
|
|
+ $update[$value['dispatch_sub_id']] = $tmp;
|
|
|
+ }else{
|
|
|
+ $update[$value['dispatch_sub_id']] = $value['quantity'];
|
|
|
+ }
|
|
|
+ $flag[$key] = 1;
|
|
|
+ }
|
|
|
+ unset($flag);
|
|
|
+
|
|
|
+ //更新派工单完工数量----------------------------------------------------
|
|
|
+ foreach ($update as $id => $num){
|
|
|
+ DispatchSub::where('id', $id)->update([
|
|
|
+ 'finished_num' => $num
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($need_update)){
|
|
|
+ //更新生产订单的完工数量--------------------------------------------------
|
|
|
+ $list = DispatchSub::where("del_time",0)
|
|
|
+ ->when(! empty($need_update), function ($query) use ($need_update) {
|
|
|
+ return $query->where(function ($q) use ($need_update) {
|
|
|
+ foreach ($need_update as $value) {
|
|
|
+ $order_product_id = $value['order_product_id'];
|
|
|
+ $process_id = $value['process_id'];
|
|
|
+ $q->orWhere(function ($subQ) use ($order_product_id, $process_id) {
|
|
|
+ $subQ->where('order_product_id', $order_product_id)
|
|
|
+ ->where('process_id', $process_id);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select('order_product_id', 'finished_num', 'sale_orders_product_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map2 = [];
|
|
|
+ foreach ($list as $value){
|
|
|
+ if(isset($map2[$value['order_product_id']])){
|
|
|
+ $tmp = bcadd($map2[$value['order_product_id']], $value['finished_num'], 3);
|
|
|
+ $map2[$value['order_product_id']] = $tmp;
|
|
|
+ }else{
|
|
|
+ $map2[$value['order_product_id']] = $value['finished_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($map2 as $id => $num){
|
|
|
+ OrdersProduct::where('id', $id)->update([
|
|
|
+ 'finished_num' => $num
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新销售订单完工数量-------------------------------------------------------
|
|
|
+ $list2 = OrdersProduct::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', array_unique(array_column($list, 'sale_orders_product_id')))
|
|
|
+ ->select('finished_num','sale_orders_product_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $map3 = [];
|
|
|
+ foreach ($list2 as $value){
|
|
|
+ if(isset($map3[$value['sale_orders_product_id']])){
|
|
|
+ $tmp = bcadd($map3[$value['sale_orders_product_id']], $value['finished_num'], 3);
|
|
|
+ $map3[$value['sale_orders_product_id']] = $tmp;
|
|
|
+ }else{
|
|
|
+ $map3[$value['sale_orders_product_id']] = $value['finished_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($map3 as $id => $num){
|
|
|
+ SaleOrdersProduct::where('id', $id)->update([
|
|
|
+ 'finished_num' => $num
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function orderSearchList($data){
|
|
|
+ if(empty($data['type'])) return [false, '单据联查类型不能为空'];
|
|
|
+ if(empty($data['data_id'])) return [false, '依据单据ID不能为空'];
|
|
|
+ //不管进来的是什么单据id 转换为销售订单
|
|
|
+ $sales_id = $this->changeIdToOrder($data);
|
|
|
+ list($status, $msg) = $this->forSearch($data, $sales_id);
|
|
|
+
|
|
|
+ return [$status, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function changeIdToOrder($data)
|
|
|
+ {
|
|
|
+ $id = $data['id'];
|
|
|
+ $search_id = $result = [];
|
|
|
+ if ($data['type'] == 1) {
|
|
|
+ $result[] = [
|
|
|
+ 'id' => $id
|
|
|
+ ];
|
|
|
+ } elseif ($data['type'] == 2) {
|
|
|
+ $result = OrdersProduct::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 3) {
|
|
|
+ $result = DispatchSub::where('del_time', 0)
|
|
|
+ ->where('id', $data['data_id'])
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 4) {
|
|
|
+ $detail = ReportWorkingDetail::where('data_id', $id)
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->select('data_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = DispatchSub::where('del_time', 0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail, 'data_id')))
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 5) {
|
|
|
+ $result = DispatchSub::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->where('finished_num', '>', 0)
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 6) {
|
|
|
+ $first = Box::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->select("top_order_no", 'order_no')
|
|
|
+ ->first();
|
|
|
+ if (!empty($first)) {
|
|
|
+ $first = $first->toArray();
|
|
|
+ $box_detail = new BoxDetail(['channel' => $first['top_order_no']]);
|
|
|
+ $result = $box_detail->where('order_no', $first['order_no'])->selct('top_id as id')->get()->toArray();
|
|
|
+ }
|
|
|
+ } elseif ($data['type'] == 7) {
|
|
|
+ $result = ScrappCount::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 8) {
|
|
|
+ $result = ScrappCount::where('del_time', 0)
|
|
|
+ ->where('id', $id)
|
|
|
+ ->where('scrapp_num', '>', 0)
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 9) {
|
|
|
+ $detail = ApplyOrderDetail::where('del_time', 0)
|
|
|
+ ->where('apply_order_id', $id)
|
|
|
+ ->where('type', ApplyOrder::type_one)
|
|
|
+ ->select('data_id as dispatch_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = DispatchSub::where('del_time', 0)
|
|
|
+ ->where('id', array_unique(array_column($detail, 'dispatch_id')))
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 10) {
|
|
|
+ $detail = ApplyOrderDetail::where('del_time', 0)
|
|
|
+ ->where('apply_order_id', $id)
|
|
|
+ ->where('type', ApplyOrder::type_two)
|
|
|
+ ->select('data_id as dispatch_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = DispatchSub::where('del_time', 0)
|
|
|
+ ->where('id', array_unique(array_column($detail, 'dispatch_id')))
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ } elseif ($data['type'] == 11) {
|
|
|
+ $detail = ApplyOrderDetail::where('del_time', 0)
|
|
|
+ ->where('apply_order_id', $id)
|
|
|
+ ->where('type', ApplyOrder::type_four)
|
|
|
+ ->select('data_id as box_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $first = Box::where('del_time', 0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail, 'box_id')))
|
|
|
+ ->select("top_order_no", 'order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ if (!empty($first)) {
|
|
|
+ foreach ($first as $value) {
|
|
|
+ $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
|
|
|
+ $t = $box_detail->where('order_no', $first['order_no'])->selct('top_id as id')->get()->toArray();
|
|
|
+ $result = array_merge($result, $t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } elseif ($data['type'] == 12) {
|
|
|
+ $detail = ApplyOrderDetail::where('del_time', 0)
|
|
|
+ ->where('apply_order_id', $id)
|
|
|
+ ->where('type', ApplyOrder::type_three)
|
|
|
+ ->select('data_id as box_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $first = Box::where('del_time', 0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail, 'box_id')))
|
|
|
+ ->select("top_order_no", 'order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ if (!empty($first)) {
|
|
|
+ foreach ($first as $value) {
|
|
|
+ $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
|
|
|
+ $t = $box_detail->where('order_no', $first['order_no'])->selct('top_id as id')->get()->toArray();
|
|
|
+ $result = array_merge($result, $t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } elseif ($data['type'] == 13) {
|
|
|
+ $detail = ApplyOrderDetail::where('del_time', 0)
|
|
|
+ ->where('apply_order_id', $id)
|
|
|
+ ->where('type', ApplyOrder::type_five)
|
|
|
+ ->select('data_id as zj_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ScrappCount::where('del_time', 0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
|
|
|
+ ->select('sale_orders_product_id as id')
|
|
|
+ ->get()->toArray();
|
|
|
+ }
|
|
|
+ foreach ($result as $value) {
|
|
|
+ if (!in_array($value['id'], $search_id)) {
|
|
|
+ $search_id[] = $value['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $search_id;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private function forSearch($data, $sales_id){
|
|
|
+ $result = [];
|
|
|
+ //通过销售订单查找所有业务单据
|
|
|
+ if($data['for_type'] == 1){
|
|
|
+ $result = SaleOrdersProduct::where('del_time',0)
|
|
|
+ ->whereIn('id', $sales_id)
|
|
|
+ ->select('id', 'out_order_no as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 2){
|
|
|
+ $result = OrdersProduct::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id', 'production_no as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 3){
|
|
|
+ $result = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id', 'dispatch_no as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 4){
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->select('data_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ReportWorking::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'data_id')))
|
|
|
+ ->select('id', 'order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 5){
|
|
|
+ $result = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->where('finished_num','>',0)
|
|
|
+ ->select('id', 'dispatch_no as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 6){
|
|
|
+ $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
|
|
|
+
|
|
|
+ foreach ($sale as $value){
|
|
|
+ $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
|
|
|
+ $box_detail_order = $box_detail->where('top_id',$data['data_id'])->selct('order_no')->get()->toArray();
|
|
|
+ $tmp = Box::where('del_time',0)
|
|
|
+ ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
|
|
|
+ ->select("id","order_no")
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = array_merge($result, $tmp);
|
|
|
+ }
|
|
|
+ }elseif ($data['for_type'] == 7){
|
|
|
+ $result = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id', 'order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif ($data['for_type'] == 8){
|
|
|
+ $result = ScrappCount::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->where('scrapp_num','>', 0)
|
|
|
+ ->select('id', 'order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif ($data['for_type'] == 9){
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->whereIn('data_id', array_column($dispatch,'id'))
|
|
|
+ ->where('type',ApplyOrder::type_one)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ApplyOrder::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
|
|
|
+ ->select('id','order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif ($data['for_type'] == 10){
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->whereIn('data_id', array_column($dispatch,'id'))
|
|
|
+ ->where('type',ApplyOrder::type_two)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ApplyOrder::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
|
|
|
+ ->select('id','order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 11){
|
|
|
+ $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
|
|
|
+ $ids = [];
|
|
|
+ foreach ($sale as $value){
|
|
|
+ $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
|
|
|
+ $box_detail_order = $box_detail->where('top_id',$data['data_id'])->selct('order_no')->get()->toArray();
|
|
|
+ $tmp = Box::where('del_time',0)
|
|
|
+ ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
|
|
|
+ ->select("id")
|
|
|
+ ->get()->toArray();
|
|
|
+ $ids = array_merge($ids, $tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->whereIn('data_id', array_column($ids,'id'))
|
|
|
+ ->where('type',ApplyOrder::type_four)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ApplyOrder::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
|
|
|
+ ->select('id','order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 12){
|
|
|
+ $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
|
|
|
+ $ids = [];
|
|
|
+ foreach ($sale as $value){
|
|
|
+ $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
|
|
|
+ $box_detail_order = $box_detail->where('top_id',$data['data_id'])->selct('order_no')->get()->toArray();
|
|
|
+ $tmp = Box::where('del_time',0)
|
|
|
+ ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
|
|
|
+ ->select("id")
|
|
|
+ ->get()->toArray();
|
|
|
+ $ids = array_merge($ids, $tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->whereIn('data_id', array_column($ids,'id'))
|
|
|
+ ->where('type',ApplyOrder::type_three)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ApplyOrder::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
|
|
|
+ ->select('id','order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }elseif($data['for_type'] == 13){
|
|
|
+ $zj_id = ScrappCount::where('del_time',0)
|
|
|
+ ->where('scrapp_num','>',0)
|
|
|
+ ->whereIn('sale_orders_product_id', $sales_id)
|
|
|
+ ->select('id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $detail = ApplyOrderDetail::where('del_time',0)
|
|
|
+ ->whereIn('data_id', array_column($zj_id,'id'))
|
|
|
+ ->where('type',ApplyOrder::type_five)
|
|
|
+ ->select('apply_order_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $result = ApplyOrder::where('del_time',0)
|
|
|
+ ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
|
|
|
+ ->select('id','order_number as order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $result];
|
|
|
+ }
|
|
|
}
|