|
@@ -2,7 +2,13 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use App\Model\DispatchSub;
|
|
|
+use App\Model\Employee;
|
|
|
+use App\Model\Equipment;
|
|
|
+use App\Model\Process;
|
|
|
use App\Model\Scrapp;
|
|
|
+use App\Model\ScrappCount;
|
|
|
+use App\Model\Team;
|
|
|
|
|
|
/**
|
|
|
* 报废原因
|
|
@@ -82,4 +88,174 @@ class ScrappService extends Service
|
|
|
|
|
|
return [true,$data];
|
|
|
}
|
|
|
+
|
|
|
+ //质检单
|
|
|
+ public function zjList($data, $user){
|
|
|
+ $model = ScrappCount::where('del_time',0)
|
|
|
+ ->select('id','dispatch_sub_id','crt_time','team_id','finished_id','equipment_id','order_number','process_id')
|
|
|
+ ->groupBy('order_number');
|
|
|
+
|
|
|
+ if(! empty($data['order_number'])) {
|
|
|
+ $order_number = str_replace("ZJ","",$data['order_number']);
|
|
|
+ if(! empty($order_number)) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillZjList($list);
|
|
|
+
|
|
|
+ return [true,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillZjList($data){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $emp_map = Employee::whereIn('id',array_column($data['data'],'finished_id'))
|
|
|
+ ->pluck('emp_name','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();
|
|
|
+ $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
|
|
|
+ ->pluck('title','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]['finished_title'] = $emp_map[$value['finished_id']] ?? '';
|
|
|
+ $data['data'][$key]['team_title'] = $team_maps[$value['team_id']] ?? '';
|
|
|
+ $data['data'][$key]['equipment_title'] = $equipment_map[$value['equipment_id']] ?? '';
|
|
|
+ $data['data'][$key]['process_title'] = $process_map[$value['process_id']] ?? '';
|
|
|
+ $data['data'][$key]['order_number'] = "ZJ" . $value['order_number'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function zjDetail($data, $user){
|
|
|
+ if(empty($data['order_number'])) return [false, '请选择质检单数据'];
|
|
|
+ $order_number = str_replace("ZJ","",$data['order_number']);
|
|
|
+ $result = ScrappCount::where('del_time',0)
|
|
|
+ ->where('order_number', $order_number)
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($result)) return [false, '质检单不存在或已被删除'];
|
|
|
+
|
|
|
+ $first = $result[0] ?? [];
|
|
|
+ $order['order_number'] = "ZJ" . $first['order_number'];
|
|
|
+ $order['crt_time'] = $first['crt_time'] ? date("Y-m-d H:i:s", $first['crt_time']) : '';
|
|
|
+ $order['process_title'] = Process::where('id',$first['process_id'])->value("title");
|
|
|
+ $order['team_title'] = Team::where('id',$first['team_id'])->value("title");
|
|
|
+ $order['finished_title'] = Employee::where('id',$first['finished_id'])->value("emp_name");
|
|
|
+ $order['equipment_title'] = Equipment::where('id',$first['equipment_id'])->value("title");
|
|
|
+ $dispatch = DispatchSub::where('id',$first['dispatch_sub_id'])->first();
|
|
|
+ $dispatch = empty($dispatch) ? [] : $dispatch->toArray();
|
|
|
+ $order['dispatch_no'] = $dispatch['order_no'] ?? "";
|
|
|
+
|
|
|
+ $scrapp_quantity = array_sum(array_column($result, 'scrapp_num')); // 不良品数量
|
|
|
+ $detail = [
|
|
|
+ 'product_no' => $first['product_no'],
|
|
|
+ 'product_title' => $first['product_title'],
|
|
|
+ 'product_size' => $first['product_size'],
|
|
|
+ 'product_unit' => $first['product_unit'],
|
|
|
+ 'technology_material' => $first['technology_material'],
|
|
|
+ 'wood_name' => $first['wood_name'],
|
|
|
+ 'production_quantity' => $dispatch['production_quantity'] ?? 0, // 生产数量
|
|
|
+ 'dispatch_quantity' => $dispatch['dispatch_quantity'] ?? 0, // 派工数量
|
|
|
+ 'quantity' => $first['quantity'], // 完工数量
|
|
|
+ 'scrapp_quantity' => $scrapp_quantity, // 不良品数量
|
|
|
+ 'zj_quantity' => $first['quantity'] + $scrapp_quantity, // 质检数量
|
|
|
+ 'hg_quantity' => $first['quantity'], // 合格数量
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order['detail'][] = $detail;
|
|
|
+
|
|
|
+ return [true, $order];
|
|
|
+ }
|
|
|
+
|
|
|
+ //不良品
|
|
|
+ public function blpList($data, $user){
|
|
|
+ $model = ScrappCount::where('del_time',0)
|
|
|
+ ->select('id','dispatch_sub_id','crt_time','team_id','finished_id','equipment_id','order_number','process_id')
|
|
|
+ ->groupBy('order_number');
|
|
|
+
|
|
|
+ if(! empty($data['order_number'])) {
|
|
|
+ $order_number = str_replace("BLP","",$data['order_number']);
|
|
|
+ if(! empty($order_number)) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->fillBLPList($list);
|
|
|
+
|
|
|
+ return [true,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillBLPList($data){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $emp_map = Employee::whereIn('id',array_column($data['data'],'finished_id'))
|
|
|
+ ->pluck('emp_name','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();
|
|
|
+ $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
|
|
|
+ ->pluck('title','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]['finished_title'] = $emp_map[$value['finished_id']] ?? '';
|
|
|
+ $data['data'][$key]['team_title'] = $team_maps[$value['team_id']] ?? '';
|
|
|
+ $data['data'][$key]['equipment_title'] = $equipment_map[$value['equipment_id']] ?? '';
|
|
|
+ $data['data'][$key]['process_title'] = $process_map[$value['process_id']] ?? '';
|
|
|
+ $data['data'][$key]['order_number'] = "BLP" . $value['order_number'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function blpDetail($data, $user){
|
|
|
+ if(empty($data['order_number'])) return [false, '请选择质检单数据'];
|
|
|
+ $order_number = str_replace("BLP","",$data['order_number']);
|
|
|
+ $result = ScrappCount::where('del_time',0)
|
|
|
+ ->where('order_number', $order_number)
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($result)) return [false, '不良品单不存在或已被删除'];
|
|
|
+
|
|
|
+ $first = $result[0] ?? [];
|
|
|
+ $order['order_number'] = "BLP" . $first['order_number'];
|
|
|
+ $order['crt_time'] = $first['crt_time'] ? date("Y-m-d H:i:s", $first['crt_time']) : '';
|
|
|
+ $order['process_title'] = Process::where('id',$first['process_id'])->value("title");
|
|
|
+ $order['team_title'] = Team::where('id',$first['team_id'])->value("title");
|
|
|
+ $order['finished_title'] = Employee::where('id',$first['finished_id'])->value("emp_name");
|
|
|
+ $order['equipment_title'] = Equipment::where('id',$first['equipment_id'])->value("title");
|
|
|
+ $dispatch = DispatchSub::where('id',$first['dispatch_sub_id'])->first();
|
|
|
+ $dispatch = empty($dispatch) ? [] : $dispatch->toArray();
|
|
|
+ $order['dispatch_no'] = $dispatch['order_no'] ?? "";
|
|
|
+
|
|
|
+ $scrapp = Scrapp::whereIn('id', array_unique(array_column($result,'scrapp_id')))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $detail = [];
|
|
|
+ foreach ($result as $value){
|
|
|
+ $tmp = [
|
|
|
+ 'product_no' => $first['product_no'],
|
|
|
+ 'product_title' => $first['product_title'],
|
|
|
+ 'product_size' => $first['product_size'],
|
|
|
+ 'product_unit' => $first['product_unit'],
|
|
|
+ 'technology_material' => $first['technology_material'],
|
|
|
+ 'wood_name' => $first['wood_name'],
|
|
|
+ 'scrapp_quantity' => $value['scrapp_num'], // 不良品数量
|
|
|
+ 'scrapp_title' => $scrapp[$value['scrapp_id']], // 不良品原因
|
|
|
+ ];
|
|
|
+ $detail[] = $tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ $order['detail'] = $detail;
|
|
|
+
|
|
|
+ return [true, $order];
|
|
|
+ }
|
|
|
}
|