123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- <?php
- namespace App\Service;
- 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;
- /**
- * 报废原因
- * @package App\Models
- */
- class ScrappService extends Service
- {
- public function scrappEdit($data){
- list($status,$msg) = $this->scrappRule($data,false);
- if(!$status) return [$status,$msg];
- $update = $msg['data'][0];
- Scrapp::where('id',$data['id'])->update($update);
- return [true,'保存成功!'];
- }
- public function scrappAdd($data){
- list($status,$msg) = $this->scrappRule($data);
- if(!$status) return [$status,$msg];
- Scrapp::insert($msg['data']);
- return [true,'保存成功!'];
- }
- public function scrappDel($data){
- if($this->isEmpty($data,'id')) return [false,'ID必须!'];
- Scrapp::whereIn('id',$data['id'])->update([
- 'del_time' => time()
- ]);
- return [true,'删除成功'];
- }
- public function scrappList($data){
- $model = Scrapp::where('del_time',0)
- ->select('*');
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
- $list = $this->limit($model,'',$data);
- return [200,$list];
- }
- public function zjdaList($data){
- $model = Zj::where('del_time',0)
- ->select('*');
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
- $list = $this->limit($model,'',$data);
- return [200,$list];
- }
- public function zjPlanList($data){
- $model = ZjPlan::where('del_time',0)
- ->select('*');
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
- $list = $this->limit($model,'',$data);
- $map = Zj::where('del_time',0)->pluck('title','id')->toArray();
- foreach ($list['data'] as $key => $value){
- $zj_plan_title = "";
- $tmp = explode(',', $value['zj_id']);
- foreach ($tmp as $v){
- $t = $map[$v];
- if(empty($t)) continue;
- $zj_plan_title .= $t . ",";
- }
- $list['data'][$key]['zj_plan_title'] = rtrim($zj_plan_title,',');
- }
- return [200,$list];
- }
- public function scrappRule($data,$is_add = true){
- if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
- $title = array_column($data['data'],'title');
- $title = array_map(function($val) {
- return $val !== null ? $val : 0;
- }, $title);
- $title_count = array_count_values($title);
- foreach ($title as $value){
- if(empty($value)) return [false,'名称不能为空!'];
- if($title_count[$value] > 1) return [false,'名称不能重复'];
- }
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['upd_time'] = time();
- if($is_add){
- $bool = Scrapp::whereRaw("title = '{$value['title']}'")
- ->where('del_time',0)
- ->exists();
- $data['data'][$key]['crt_time'] = time();
- }else{
- if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
- $bool = Scrapp::whereRaw("title = '{$value['title']}'")
- ->where('id','<>',$data['id'])
- ->where('del_time',0)
- ->exists();
- }
- if($bool) return [false,'名称不能重复'];
- }
- return [true,$data];
- }
- //质检单
- public function zjList($data, $user){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $model = ScrappCount::where('del_time',0)
- ->whereIn('process_id', $process)
- ->select('*')
- ->orderBy('order_number','desc');
- if(! empty($data['sq'])) $model->where('result',ReportWorking::type_two);
- if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
- if(! empty($data['dispatch_no'])) {
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $model->whereIn('dispatch_sub_id', $dispatch_id);
- }
- if(! empty($data['sale_order_number'])) {
- $sales_id = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $sales_id = array_column($sales_id,'id');
- $model->whereIn('sale_orders_product_id', $sales_id);
- }
- if(! empty($data['team_id'])) $model->where('team_id', $data['team_id']);
- if(! empty($data['team_man_id'])) {
- $team_id = EmployeeTeamPermission::where('employee_id',$data['team_man_id'])
- ->select('team_id')
- ->get()->toArray();
- $model->whereIn('team_id', array_unique(array_column($team_id,'team_id')));
- }
- if(! empty($data['finished_id'])) $model->where('finished_id', $data['finished_id']);
- if(! empty($data['equipment_id'])) $model->where('equipment_id', $data['equipment_id']);
- if(! empty($data['process_id'])) $model->where('process_id', $data['process_id']);
- $list = $this->limit($model,'',$data);
- $list = $this->fillZjList($list, $data, $user);
- return [true,$list];
- }
- public function fillZjList($data, $erg, $user){
- if(empty($data['data'])) return $data;
- $team_id = array_unique(array_column($data['data'],'team_id'));
- $team_maps = Team::whereIn('id',$team_id)
- ->pluck('title','id')
- ->toArray();
- $team_man = EmployeeTeamPermission::whereIn('team_id',$team_id)
- ->select('team_id','employee_id')
- ->get()->toArray();
- $emp_map = Employee::whereIn('id',array_merge_recursive(array_column($data['data'],'finished_id'),array_column($team_man,'employee_id')))
- ->pluck('emp_name','id')
- ->toArray();
- $team_man_maps = [];
- foreach ($team_man as $value){
- $t = $emp_map[$value['employee_id']] ?? "";
- if(empty($t)) continue;
- if(isset($team_man_maps[$value['team_id']])){
- $team_man_maps[$value['team_id']] .= ',' . $t;
- }else{
- $team_man_maps[$value['team_id']] = $t;
- }
- }
- $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();
- $sales_number = SaleOrdersProduct::whereIn('id',array_unique(array_column($data['data'],'sale_orders_product_id')))
- ->pluck('out_order_no','id')
- ->toArray();
- $dispatch_no = DispatchSub::whereIn('id',array_column($data['data'], 'dispatch_sub_id'))
- ->pluck('dispatch_no','id')
- ->toArray();
- $return = [];
- if(! empty($erg['material'])){
- $product_no = array_unique(array_column($data['data'],'product_no'));
- $service = new FyyOrderService();
- list($status, $msg) = $service->getProductDataFromSqlServer(['product_no' => $product_no], $user);
- if($status) $return = $msg;
- }
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['material'] = $return[$value['product_no']] ?? [];
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d", $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]['team_man'] = $team_man_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]['sale_order_number'] = $sales_number[$value['sale_orders_product_id']] ?? "";
- $dispatch_t = $dispatch_no[$value['dispatch_sub_id']] ?? "";
- $data['data'][$key]['dispatch_no'] = $dispatch_t;
- // $data['data'][$key]['crt_time'] = date("Y-m-d",strtotime(substr($dispatch_t,0,8)));
- }
- return $data;
- }
- public function zjDetail($data, $user){
- if(empty($data['order_number'])) return [false, '请选择质检单数据'];
- $result = ScrappCount::where('del_time',0)
- ->where('order_number', $data['order_number'])
- ->get()->toArray();
- if(empty($result)) return [false, '质检单不存在或已被删除'];
- $first = $result[0] ?? [];
- $order['order_number'] = $first['order_number'];
- $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['dispatch_no'] ?? "";
- $order['crt_time'] = date("Y-m-d", $first['crt_time']);
- $team_man = EmployeeTeamPermission::where('team_id',$first['team_id'])
- ->select('team_id','employee_id')
- ->get()->toArray();
- $emp_map = Employee::whereIn('id',array_column($team_man,'employee_id'))
- ->pluck('emp_name','id')
- ->toArray();
- $team_man_maps = "";
- foreach ($team_man as $value){
- $t = $emp_map[$value['employee_id']] ?? "";
- if(empty($t)) continue;
- if(! empty($team_man_maps)){
- $team_man_maps .= ',' . $t;
- }else{
- $team_man_maps = $t;
- }
- }
- $order['team_man'] = $team_man_maps;
- $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_name' => $first['technology_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;
- $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];
- }
- //不良品
- public function blpList($data, $user){
- $model = ScrappCount::where('del_time',0)
- ->where('scrapp_num','>',0)
- ->select('id','dispatch_sub_id','crt_time','team_id','finished_id','equipment_id','order_number','process_id','sale_orders_product_id')
- ->orderBy('dispatch_sub_id','desc')
- ->groupBy('order_number');
- if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
- if(! empty($data['dispatch_no'])) {
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $model->whereIn('dispatch_sub_id', $dispatch_id);
- }
- if(! empty($data['sale_order_number'])) {
- $sales_id = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $sales_id = array_column($sales_id,'id');
- $model->whereIn('sale_orders_product_id', $sales_id);
- }
- if(! empty($data['team_id'])) $model->where('team_id', $data['team_id']);
- if(! empty($data['finished_id'])) $model->where('finished_id', $data['finished_id']);
- if(! empty($data['team_man_id'])) {
- $team_id = EmployeeTeamPermission::where('employee_id',$data['team_man_id'])
- ->select('team_id')
- ->get()->toArray();
- $model->whereIn('team_id', array_unique(array_column($team_id,'team_id')));
- }
- if(! empty($data['equipment_id'])) $model->where('equipment_id', $data['equipment_id']);
- if(! empty($data['process_id'])) $model->where('process_id', $data['process_id']);
- $list = $this->limit($model,'',$data);
- $list = $this->fillBLPList($list);
- return [true,$list];
- }
- public function fillBLPList($data){
- if(empty($data['data'])) return $data;
- $team_id = array_unique(array_column($data['data'],'team_id'));
- $team_maps = Team::whereIn('id',$team_id)
- ->pluck('title','id')
- ->toArray();
- $team_man = EmployeeTeamPermission::whereIn('team_id',$team_id)
- ->select('team_id','employee_id')
- ->get()->toArray();
- $emp_map = Employee::whereIn('id',array_merge_recursive(array_column($data['data'],'finished_id'),array_column($team_man,'employee_id')))
- ->pluck('emp_name','id')
- ->toArray();
- $team_man_maps = [];
- foreach ($team_man as $value){
- $t = $emp_map[$value['employee_id']] ?? "";
- if(empty($t)) continue;
- if(isset($team_man_maps[$value['team_id']])){
- $team_man_maps[$value['team_id']] .= ',' . $t;
- }else{
- $team_man_maps[$value['team_id']] = $t;
- }
- }
- $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();
- $sales_number = SaleOrdersProduct::whereIn('id',array_unique(array_column($data['data'],'sale_orders_product_id')))
- ->pluck('out_order_no','id')
- ->toArray();
- $dispatch_no = DispatchSub::whereIn('id',array_column($data['data'], 'dispatch_sub_id'))
- ->pluck('dispatch_no','id')
- ->toArray();
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d", $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]['team_man'] = $team_man_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]['sale_order_number'] = $sales_number[$value['sale_orders_product_id']] ?? "";
- $dispatch_t = $dispatch_no[$value['dispatch_sub_id']] ?? "";
- $data['data'][$key]['dispatch_no'] = $dispatch_t;
- // $data['data'][$key]['crt_time'] = date("Y-m-d",strtotime(substr($dispatch_t,0,8)));
- }
- return $data;
- }
- public function blpDetail($data, $user){
- if(empty($data['order_number'])) return [false, '请选择质检单数据'];
- $result = ScrappCount::where('del_time',0)
- ->where('order_number', $data['order_number'])
- ->get()->toArray();
- if(empty($result)) return [false, '不良品单不存在或已被删除'];
- $first = $result[0] ?? [];
- $order['order_number'] = $first['order_number'];
- $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['dispatch_no'] ?? "";
- $order['crt_time'] = date("Y-m-d",$first['crt_time']);
- $team_man = EmployeeTeamPermission::where('team_id',$first['team_id'])
- ->select('team_id','employee_id')
- ->get()->toArray();
- $emp_map = Employee::whereIn('id',array_column($team_man,'employee_id'))
- ->pluck('emp_name','id')
- ->toArray();
- $team_man_maps = "";
- foreach ($team_man as $value){
- $t = $emp_map[$value['employee_id']] ?? "";
- if(empty($t)) continue;
- if(! empty($team_man_maps)){
- $team_man_maps .= ',' . $t;
- }else{
- $team_man_maps = $t;
- }
- }
- $order['team_man'] = $team_man_maps;
- $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_name' => $first['technology_name'],
- 'scrapp_quantity' => $value['scrapp_num'], // 不良品数量
- 'scrapp_title' => $scrapp[$value['scrapp_id']] ?? "", // 不良品原因
- ];
- $detail[] = $tmp;
- }
- $order['detail'] = $detail;
- 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]];
- }
- }
|