getSaleOrderMan($data); } return [true, $return]; } public function delete($data,$user){ if(empty($data['id']) || empty($data['type']) || empty($data['man_type']) || empty($data['man'])) return [false, '必填参数不能为空!']; try { DB::beginTransaction(); if($data['type'] == 1){ $this->delSaleOrderMan($data,$user); } DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function getSaleOrderMan($data){ $man_id = SalesOrderInfo::where('del_time',0) ->where('sales_order_id',$data['id']) ->where('type',$data['man_type']) ->get('data_id')->toArray(); $man_id = array_column($man_id,'data_id'); return Employee::whereIn('id',$man_id)->select('id', 'emp_name')->get()->toArray(); } public function delSaleOrderMan($data,$user){ $time = time(); SalesOrderInfo::where('del_time',0) ->where('sales_order_id',$data['id']) ->where('type',$data['man_type']) ->update(['del_time' => $time]); if(! empty($data['man'])){ $insert = []; foreach ($data['man'] as $value){ $insert[] = [ 'sales_order_id' => $data['id'], 'data_id' => $value, 'type' => $data['man_type'], 'crt_time' => $time, ]; } SalesOrderInfo::insert($insert); $type = 0; if($data['man_type'] == SalesOrderInfo::type_two) $type = OrderOperation::sixty; if($data['man_type'] == SalesOrderInfo::type_three) $type = OrderOperation::seventeen; $order = SalesOrder::where('id',$data['id'])->first(); $order = $order->toArray(); if($type){ (new OrderOperationService())->add([ 'order_number' => $order['order_number'], 'msg' => OrderOperation::$type[$type] ?? "", 'type' => $type ],$user); } } } public function fp($data,$user){ if(empty($data['id']) || empty($data['type']) || empty($data['man'])) return [false, '必填参数不能为空!']; // $key = "fpyj".$data['id'].$data['type']; // list($status,$msg) = $this->limitingSendRequestBackgExpire($key); // if(! $status) return [false,$msg]; try { DB::beginTransaction(); if($data['type'] == 1){ $this->fpSaleOrderMan($data,$user); }elseif ($data['type'] == 2){ $this->fpCustomerMan($data,$user); }elseif($data['type'] == 3){ $this->fpConstructionMan($data,$user); } DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function fpSaleOrderMan($data,$user){ $time = time(); if(! empty($data['man'])){ $insert = []; foreach ($data['man'] as $value){ $insert[] = [ 'sales_order_id' => $data['id'], 'data_id' => $value, 'type' => SalesOrderInfo::type_two, 'crt_time' => $time, ]; } SalesOrderInfo::insert($insert); $order = SalesOrder::where('id',$data['id'])->first(); $order = $order->toArray(); (new OrderOperationService())->add([ 'order_number' => $order['order_number'], 'msg' => OrderOperation::$type[OrderOperation::eighteen] ?? "", 'type' => OrderOperation::eighteen ],$user); } } public function fpCustomerMan($data,$user){ $time = time(); if(! empty($data['man'])){ $insert = []; //协同人 $xt = CustomerInfo::where('del_time',0) ->whereIn('customer_id',$data['id']) ->where('type',CustomerInfo::type_three) ->where('data_id',$user['id']) ->select('customer_id')->get()->toArray(); $xt = array_column($xt,'customer_id'); //负责人清除 CustomerInfo::where('del_time',0) ->whereIn('customer_id',$data['id']) ->where('type', CustomerInfo::type_two) ->update(['del_time' => $time]); foreach ($data['man'] as $value){ foreach ($data['id'] as $data_id){ //负责人累加 $insert[] = [ 'customer_id' => $data_id, 'data_id' => $value, 'type' => CustomerInfo::type_two, 'crt_time' => $time, ]; if(! in_array($data_id, $xt)){ //协同人累加 $insert[] = [ 'customer_id' =>$data_id, 'data_id' => $user['id'], 'type' => CustomerInfo::type_three, 'crt_time' => $time, ]; } } } CustomerInfo::insert($insert); $fp_top_depart_id = $data['fp_top_depart_id'] ?? 0; if(! is_array($data['id'])){ $title = Customer::where('id',$data['id'])->value('title') ?? ""; (new OrderOperationService())->add([ 'order_number' => Customer::$order_number . "|" . $data['id'] . "|" . $title, 'msg' => OrderOperation::$type[OrderOperation::twenty_three] ?? "", 'type' => OrderOperation::twenty_three ],$user); Customer::where('id',$data['id'])->update(['fp_time' => $time, 'fp_top_depart_id' => $fp_top_depart_id]); }else{ $title = Customer::whereIn('id',$data['id'])->pluck('title','id')->toArray(); foreach($data['id'] as $value){ $t_title = $title[$value] ?? ""; (new OrderOperationService())->add([ 'order_number' => Customer::$order_number . "|" . $value . "|" . $t_title, 'msg' => OrderOperation::$type[OrderOperation::twenty_three] ?? "", 'type' => OrderOperation::twenty_three ],$user); } Customer::whereIn('id',$data['id'])->update(['fp_time' => $time,'fp_top_depart_id' => $fp_top_depart_id]); } // foreach ($data['man'] as $value){ // $tmp_data = [ // "测试", // '测试', // '审核通过', // '测试', // date('Y-m-d H:i:s'), // ]; // (new OaService())->sendWxMsg($value,2,0,16,$tmp_data); // } } } public function fpConstructionMan($data,$user){ $time = time(); //负责人清除 ConstructionInfo::where('del_time',0) ->where('construction_id',$data['id']) ->where('type', ConstructionInfo::type_three) ->update(['del_time' => $time]); if(! empty($data['man'])){ $insert = []; foreach ($data['man'] as $value){ $insert[] = [ 'construction_id' => $data['id'], 'employee_id' => $value, 'type' => ConstructionInfo::type_three, 'crt_time' => $time, ]; } ConstructionInfo::insert($insert); $order = Construction::where('id',$data['id'])->first(); $order = $order->toArray(); (new OrderOperationService())->add([ 'order_number' => $order['order_number'], 'msg' => OrderOperation::$type[OrderOperation::twenty_six] ?? "", 'type' => OrderOperation::twenty_six ],$user); } } public function yj($data,$user){ if(empty($data['id']) || empty($data['type']) || empty($data['man'])) return [false, '必填参数不能为空!']; // $key = "fpyj".$data['id'].$data['type']; // list($status,$msg) = $this->limitingSendRequestBackgExpire($key); // if(! $status) return [false,$msg]; try { DB::beginTransaction(); if($data['type'] == 1){ $this->yjSaleOrderMan($data,$user); }elseif ($data['type'] == 2){ $this->yjCustomerMan($data,$user); } DB::commit(); }catch (\Exception $exception){ DB::rollBack(); return [false,$exception->getMessage()]; } return [true,'']; } public function yjSaleOrderMan($data,$user){ $time = time(); SalesOrderInfo::where('del_time',0) ->where('sales_order_id',$data['id']) ->where('type', SalesOrderInfo::type_two) ->where('data_id', $user['id']) ->update(['del_time' => $time]); if(! empty($data['man'])){ $insert = []; foreach ($data['man'] as $value){ $insert[] = [ 'sales_order_id' => $data['id'], 'data_id' => $value, 'type' => SalesOrderInfo::type_two, 'crt_time' => $time, ]; } SalesOrderInfo::insert($insert); $order = SalesOrder::where('id',$data['id'])->first(); $order = $order->toArray(); (new OrderOperationService())->add([ 'order_number' => $order['order_number'], 'msg' => OrderOperation::$type[OrderOperation::nineteen] ?? "", 'type' => OrderOperation::nineteen ],$user); } } public function yjCustomerMan($data,$user){ $time = time(); if(! is_array($data['id'])) $data['id'] = [$data['id']]; CustomerInfo::where('del_time',0) ->whereIn('customer_id',$data['id']) ->where('type', CustomerInfo::type_two) ->update(['del_time' => $time]); if(! empty($data['man'])){ $insert = []; foreach ($data['man'] as $value){ if(! is_array($data['id'])){ $insert[] = [ 'customer_id' => $data['id'], 'data_id' => $value, 'type' => CustomerInfo::type_two, 'crt_time' => $time, ]; }else{ foreach ($data['id'] as $data_id){ $insert[] = [ 'customer_id' => $data_id, 'data_id' => $value, 'type' => CustomerInfo::type_two, 'crt_time' => $time, ]; } } } CustomerInfo::insert($insert); $fp_top_depart_id = $data['fp_top_depart_id'] ?? 0; if(! is_array($data['id'])){ $title = Customer::where('id',$data['id'])->value('title') ?? ""; (new OrderOperationService())->add([ 'order_number' => Customer::$order_number . "|" . $data['id'] . "|" . $title, 'msg' => OrderOperation::$type[OrderOperation::twenty_four] ?? "", 'type' => OrderOperation::twenty_four ],$user); Customer::where('id',$data['id'])->update(['fp_time' => $time, 'fp_top_depart_id' => $fp_top_depart_id]); }else{ $title = Customer::whereIn('id',$data['id'])->pluck('title','id')->toArray(); foreach($data['id'] as $value){ $t_title = $title[$value] ?? ""; (new OrderOperationService())->add([ 'order_number' => Customer::$order_number . "|" . $value . "|" . $t_title, 'msg' => OrderOperation::$type[OrderOperation::twenty_four] ?? "", 'type' => OrderOperation::twenty_four ],$user); } Customer::whereIn('id',$data['id'])->update(['fp_time' => $time,'fp_top_depart_id' => $fp_top_depart_id]); } } } public function pq($data,$user){ list($status,$msg) = $this->pqRule($data,$user); if(! $status) return [false,$msg]; try { DB::beginTransaction(); if(! empty($msg['schedule_id']) && ! empty($msg['day_start_stamp']) && ! empty($msg['day_end_stamp'])){ //如果已经设置过排期 将子表占用数据释放 $schedule = ScheduleInfo::where('del_time',0) ->where('schedule_id',$msg['schedule_id']) ->where('start_time',$msg['day_start_stamp']) ->where('end_time',$msg['day_end_stamp']) ->where('is_use','>', ScheduleInfo::not_use) ->first(); if(! empty($schedule)) ScheduleInfo::where('id',$schedule->id)->update(['is_use' => ScheduleInfo::not_use]); } Construction::where('id',$data['id'])->update([ 'schedule_id' => $data['schedule_id'], 'day_stamp' => $data['day_stamp'], 'day_start_stamp' => $data['day_start_stamp'], 'day_end_stamp' => $data['day_end_stamp'], 'pq_state' => Construction::STATE_ONE ]); if(! empty($data['schedule_info_id'])) ScheduleInfo::where('id',$data['schedule_info_id'])->update(['is_use' => 1]); DB::commit(); }catch (\Exception $exception){ $this->dellimitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']); DB::rollBack(); return [false,$exception->getMessage()]; } $this->dellimitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']); return [true,'']; } public function pqRule(&$data,$user){ if(empty($data['id'])) return [false, '施工单不能为空!']; $construction = Construction::where('id',$data['id'])->where('del_time',0)->first(); if(empty($construction)) return [false,'施工单不存在或已被删除']; $construction = $construction->toArray(); if($construction['state'] != Construction::STATE_TWO) return [false,'施工单未确认无法排期!']; if(empty($data['schedule_id']) ||empty($data['day_stamp']) || empty($data['day_start_stamp']) || empty($data['day_end_stamp'])) return [false,'排班时间信息不能为空']; //day_stamp 日期的时间戳(0点的) day_start_stamp 日期加上开始时分的时间戳 day_end_stamp 日期加上结束时分的时间戳 if($construction['day_stamp'] != $data['day_stamp'] || $construction['day_start_stamp'] != $data['day_start_stamp'] && $construction['day_end_stamp'] != $data['day_end_stamp']) { $schedule_info = ScheduleInfo::where('del_time',0) ->where('day',$data['day_stamp']) ->where('start_time',$data['day_start_stamp']) ->where('end_time',$data['day_end_stamp']) ->where('is_use',ScheduleInfo::not_use) ->first(); if(empty($schedule_info)) return [false,'该时间段排班已满或不存在!']; $data['schedule_info_id'] = $schedule_info->id; list($status,$msg) = $this->limitingSendRequestBackg(ScheduleInfo::limit_key . $data['schedule_info_id']); if(! $status) return [false,'操作频繁,请稍等!']; }else{ return [false,'排期未做更新!']; } return [true, $construction]; } }