|
@@ -6,14 +6,17 @@ use App\Model\DispatchSub;
|
|
|
use App\Model\Employee;
|
|
|
use App\Model\EmployeeTeamPermission;
|
|
|
use App\Model\Equipment;
|
|
|
+use App\Model\OrdersProduct;
|
|
|
use App\Model\Process;
|
|
|
use App\Model\ReportWorking;
|
|
|
+use App\Model\ReportWorkingDetail;
|
|
|
use App\Model\SaleOrdersProduct;
|
|
|
use App\Model\Scrapp;
|
|
|
use App\Model\ScrappCount;
|
|
|
use App\Model\Team;
|
|
|
use App\Model\Zj;
|
|
|
use App\Model\ZjPlan;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 报废原因
|
|
@@ -287,6 +290,35 @@ class ScrappService extends Service
|
|
|
];
|
|
|
|
|
|
$order['detail'][] = $detail;
|
|
|
+ $table1 = $table2 = [];
|
|
|
+ if(! empty($dispatch['zj_plan_id'])){
|
|
|
+ $plan = ZjPlan::where('id',$dispatch['zj_plan_id'])->first();
|
|
|
+ if(! empty($plan)){
|
|
|
+ $plan = $plan->toArray();
|
|
|
+ $map = Zj::where('del_time',0)->pluck('title','id')->toArray();
|
|
|
+ $tmp = explode(',', $plan['zj_id']);
|
|
|
+ foreach ($tmp as $value){
|
|
|
+ $table1[] = [
|
|
|
+ 'zj_title' => $map[$value] ?? "",
|
|
|
+ 'number' => $first['quantity'],
|
|
|
+ 'mark' => ''
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($first['scrapp_id'])){
|
|
|
+ $scrapp = Scrapp::where('id', $first['scrapp_id'])
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $table2[] = [
|
|
|
+ 'zj_title' => $scrapp[$first['scrapp_id']] ?? "", // 不良品原因
|
|
|
+ 'number' => $scrapp_quantity,
|
|
|
+ 'mark' => ''
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $order['table1'] = $table1;
|
|
|
+ $order['table2'] = $table2;
|
|
|
|
|
|
return [true, $order];
|
|
|
}
|
|
@@ -441,4 +473,185 @@ class ScrappService extends Service
|
|
|
|
|
|
return [true, $order];
|
|
|
}
|
|
|
+
|
|
|
+ public function processFlowList($data, $user){
|
|
|
+ $model = OrdersProduct::where('del_time',0)
|
|
|
+ ->select('id as order_number','production_no','out_order_no','production_time','customer_name','product_title','technology_name','product_size','product_unit','dispatch_complete_quantity as quantity')
|
|
|
+ ->orderBy('id','desc');
|
|
|
+
|
|
|
+ if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
|
|
|
+ if(! empty($data['production_no'])) $model->where('production_no', 'LIKE', '%'.$data['production_no'].'%');
|
|
|
+ if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
|
|
|
+ if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
|
|
|
+ if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
|
|
|
+ if(! empty($data['order_number'])) {
|
|
|
+ $order_number = str_replace('FC','',$data['order_number']);
|
|
|
+ $model->where('id', 'LIKE', '%'.$order_number.'%');
|
|
|
+ }
|
|
|
+ if(! empty($data['technology_name'])) $model->where('technology_name', 'LIKE', '%'.$data['technology_name'].'%');
|
|
|
+ if(! empty($data['wood_name'])) $model->where('wood_name', 'LIKE', '%'.$data['wood_name'].'%');
|
|
|
+ if(! empty($data['process_mark'])) $model->where('process_mark', 'LIKE', '%'.$data['process_mark'].'%');
|
|
|
+ if(! empty($data['table_header_mark'])) $model->where('table_header_mark', 'LIKE', '%'.$data['table_header_mark'].'%');
|
|
|
+ if(! empty($data['table_body_mark'])) $model->where('table_body_mark', 'LIKE', '%'.$data['table_body_mark'].'%');
|
|
|
+ if(! empty($data['out_checker_man'])) $model->where('out_checker_man', 'LIKE', '%'.$data['out_checker_man'].'%');
|
|
|
+ if(! empty($data['out_crt_man'])) $model->where('out_crt_man', 'LIKE', '%'.$data['out_crt_man'].'%');
|
|
|
+ if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) $model->whereBetween('out_checker_time',[$data['out_checker_time'][0],$data['out_checker_time'][1]]);
|
|
|
+ if(! empty($data['out_order_no_time'][0]) && ! empty($data['out_order_no_time'][1])) $model->whereBetween('out_order_no_time',[$data['out_order_no_time'][0],$data['out_order_no_time'][1]]);
|
|
|
+ if(! empty($data['production_time'][0]) && ! empty($data['production_time'][1])) $model->whereBetween('production_time',[$data['production_time'][0],$data['production_time'][1]]);
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillData($list, $user);
|
|
|
+
|
|
|
+ return [200,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillData($data, $user){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['order_number'] = "FC". $value['order_number'];
|
|
|
+ $data['data'][$key]['title'] = "工艺路线(默认)";
|
|
|
+ $data['data'][$key]['production_time'] = $value['production_time'] ? date('Y-m-d',$value['production_time']) : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function processFlowDetail($data, $user){
|
|
|
+ if(empty($data['order_number'])) return [false, '工艺流程卡单号不能为空'];
|
|
|
+ $order_number = str_replace('FC','',$data['order_number']);
|
|
|
+ $order = OrdersProduct::where('del_time',0)
|
|
|
+ ->where('id',$order_number)
|
|
|
+ ->select('id as order_number','production_no','out_order_no','production_time','customer_name','product_title','technology_name','product_size','product_unit','dispatch_complete_quantity as quantity', 'production_quantity')
|
|
|
+ ->first();
|
|
|
+ if(empty($order)) return [false, '工艺流程卡不存在或已被删除'];
|
|
|
+ $order = $order->toArray();
|
|
|
+ $id = $order['order_number'];
|
|
|
+ $order['order_number'] = "FC". $order['order_number'];
|
|
|
+ $order['not_quantity'] = bcsub($order['production_quantity'], $order['quantity'],3);
|
|
|
+ $order['title'] = "工艺路线(默认)";
|
|
|
+ $order['production_time'] = $order['production_time'] ? date('Y-m-d', $order['production_time']) : '';
|
|
|
+
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->where('order_product_id', $id)
|
|
|
+ ->select('process_id','dispatch_quantity','finished_num','finished_num as bg_num','finished_num as hg_num','waste_num','team_id','device_id','dispatch_time_start','dispatch_time_end')
|
|
|
+ ->get()->toArray();
|
|
|
+
|
|
|
+ $team_map = Team::whereIn('id',array_unique(array_column($dispatch,'team_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $equipment_map = Equipment::whereIn('id',array_unique(array_column($dispatch,'device_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $process_map = Process::whereIn('id',array_column($dispatch,'process_id'))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ foreach ($dispatch as $key => $value){
|
|
|
+ $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']) : '';
|
|
|
+ $dispatch[$key]['dispatch_time'] = $time1 . ' ' . $time2;
|
|
|
+ $dispatch[$key]['process_name'] = $process_map[$value['process_id']] ?? '';
|
|
|
+ $dispatch[$key]['team_name'] = $team_map[$value['team_id']] ?? "";
|
|
|
+ $dispatch[$key]['device_name'] = $equipment_map[$value['device_id']] ?? "";
|
|
|
+ }
|
|
|
+
|
|
|
+ $order['table'] = $dispatch;
|
|
|
+
|
|
|
+ return [true, $order];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function bgOrZj($data, $user){
|
|
|
+// $order_number = (new ApplyOrderService())->setOrderNO2(0);dd($order_number);
|
|
|
+// // 1. 获取所有需要更新的记录(按 id 升序)
|
|
|
+// $records = ReportWorking::where('del_time', 0)
|
|
|
+// ->where('id', '>=', 10151)
|
|
|
+// ->orderBy('id') // 关键:按 id 排序
|
|
|
+// ->get();
|
|
|
+// // 2. 设置起始 order_number(你可以根据需要修改)
|
|
|
+// $startNumber = 202510101000;
|
|
|
+//
|
|
|
+// $updateData = [];
|
|
|
+//
|
|
|
+// foreach ($records as $index => $record) {
|
|
|
+// $newOrderNumber = $startNumber + $index;
|
|
|
+//
|
|
|
+// // 收集要更新的数据
|
|
|
+// $updateData[] = [
|
|
|
+// 'id' => $record->id,
|
|
|
+// 'order_number' => (string)$newOrderNumber, // 转为字符串保持类型一致
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// foreach ($updateData as $value){
|
|
|
+// ReportWorking::where('id', $value['id'])->update(['order_number' => $value['order_number']]);
|
|
|
+// }
|
|
|
+// dd(1);
|
|
|
+ if(empty($user['role'])) return [false, '当前账号暂未配置角色,无法确认操作报工或质检'];
|
|
|
+ $role = $user['role'][0];
|
|
|
+ if(! in_array($role,[9,12,13,14,15,16,17])) return [false, '当前账号角色信息错误'];
|
|
|
+ if(empty($data['order_number'])) return [false, '工艺流程卡号不能为空'];
|
|
|
+ $order_number = str_replace('FC','',$data['order_number']);
|
|
|
+ $order = OrdersProduct::where('del_time',0)
|
|
|
+ ->where('id',$order_number)
|
|
|
+ ->select('id')
|
|
|
+ ->first();
|
|
|
+ if(empty($order)) return [false, '工艺流程卡不存在或已被删除'];
|
|
|
+ $order = $order->toArray();
|
|
|
+
|
|
|
+ $map = [
|
|
|
+ 9 => 12, //清洗脱水
|
|
|
+ 12 => 14, //注塑成型
|
|
|
+ 15 => 11, //破碎分离
|
|
|
+ 16 => 13, //挤出造粒
|
|
|
+ 17 => 15, //混合搅拌
|
|
|
+ 13 => 12,
|
|
|
+ 14 => 14,
|
|
|
+ ];
|
|
|
+ $role = 13;
|
|
|
+ $process_id = $map[$role];
|
|
|
+
|
|
|
+ if(in_array($role, [9,12,15,16,17])){
|
|
|
+ $dispatch_no = DispatchSub::where('del_time',0)
|
|
|
+ ->where('order_product_id',$order['id'])
|
|
|
+ ->where('process_id', $process_id)
|
|
|
+ ->value('dispatch_no');
|
|
|
+ list($status, $msg) = (new DispatchService())->dispatchOrderList(['dispatch_no' => $dispatch_no]);
|
|
|
+ $type = 1;
|
|
|
+ }else{
|
|
|
+ $crt_time = DispatchSub::where('del_time',0)
|
|
|
+ ->where('order_product_id',$order['id'])
|
|
|
+ ->where('process_id', $process_id)
|
|
|
+ ->value('crt_time');
|
|
|
+ $crt_time = $crt_time ? $crt_time->timestamp : 0;
|
|
|
+ $dispatch_id = DispatchSub::where('del_time',0)
|
|
|
+ ->where('order_product_id',$order['id'])
|
|
|
+ ->where('crt_time',$crt_time)
|
|
|
+ ->pluck('id')->toArray();
|
|
|
+
|
|
|
+ $report = ReportWorkingDetail::from('report_working_detail as a')
|
|
|
+ ->join('scrapp_count as b','b.report_id','a.report_working_id')
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->whereIn('a.data_id',$dispatch_id)
|
|
|
+ ->where('a.process_id',$process_id)
|
|
|
+ ->whereRaw('a.quantity > (b.quantity + b.scrapp_num)')
|
|
|
+ ->select('a.report_working_id')
|
|
|
+ ->first();
|
|
|
+ if(empty($report)){
|
|
|
+ $report = ReportWorkingDetail::from('report_working_detail as a')
|
|
|
+ ->join('scrapp_count as b','b.report_id','a.report_working_id')
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->whereIn('a.data_id',$dispatch_id)
|
|
|
+ ->where('a.process_id',$process_id)
|
|
|
+ ->select('a.report_working_id')
|
|
|
+ ->first();
|
|
|
+ }
|
|
|
+ $report = $report->toArray();
|
|
|
+ list($status, $msg) = (new ApplyOrderService())->reportWorkingDetail(['id' => $report['report_working_id']]);
|
|
|
+ $type = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$status, ['type' => $type, 'order' => $msg]];
|
|
|
+ }
|
|
|
}
|