logger = $logger; } public function setLog($text) { $this->logger->log($text,$this->className()); } public function curlRequest2($params){ $urlWithParam = $params['url'].'?user_id='. $params['param'] ; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlWithParam); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json")); curl_setopt($curl, CURLOPT_TIMEOUT, 20); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); return $result; } public function Getisabsentworks($listWorks = null, $GWparams ){ if ( null == $listWorks) { return false; } $arrayIdWorks = []; foreach( $listWorks->data as $work ) { $arrayIdWorks[] = $work->id_work; } //$arrayIdWorks[] = 'c7cfdeb5-9293-4314-9958-15d15a297532'; //$asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['not in','asusg_job_uuid_',$arrayIdWorks])->all(); $asusgJob2LaunchEntity = (new \yii\db\Query()) ->select(['t.assignees_arr','ai.id','t.status','t.id','jl.asusg_job_uuid']) //->select(['t.assignees_arr']) ->from('`asusg_job2launch` as `jl`') ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id') ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)') //->where(['jl.asusg_job_uuid' => $job_uuid]) ->andWhere(['in','asusg_job_uuid',$arrayIdWorks]) ->andWhere(['ai.uuid' => $GWparams['param']]) ->andWhere(['<>','t.parent_id', 0]) ->groupBy(['jl.asusg_job_uuid']) ->all(); $resultArrWork = []; foreach( $asusgJob2LaunchEntity as $work ) { $resultArrWork[] = $work["asusg_job_uuid"]; } array_diff ($arrayIdWorks, $resultArrWork); foreach( $listWorks->data as $works ) { if ( in_array($works->id_work, array_diff ($arrayIdWorks, $resultArrWork))) { $result[] = $works; } //$resultArrWork[] = $work["asusg_job_uuid"]; } return $result; /* echo "
";
        var_dump($resultArrWork);
        echo "
"; */ } public function getOnlineMobileUser(){ $result = []; $accountsEntity = \app\models\entity\Accounts::find()->all(); foreach ($accountsEntity as $account) { $last_seen_mobile = ( null != $account->last_seen_mobile )? new \DateTime($account->last_seen_mobile): $account->last_seen_mobile ; $online_mobile = $this->OnlineAccountCheck($this->TimeString($last_seen_mobile)); if ( !$online_mobile ){ continue; } $result[] = ['id' => $account->id, 'uuid' => $account->uuid]; } return $result; } //public function startProject($params,$userInfo,$projecttypeId){ public function startProject(){ $arrayResultTemp = []; $projectsModel = new ProjectsModel(); foreach($this->arResult['listW'] as &$item){ $arrayResult = []; $arrayResult['loco_type'] = $item['info']['locomotive_series']; $arrayResult['loco_number'] = $item['info']["section_subnumber"]; $arrayResult['action'] = $projecttypeId->id; $arrayResult['company'] = $this->arResult['userInfo']->company;//'//$userInfo->company; //$arrayResult['section_id'] = $item['info']["section_number"]; $arrayResult['depo'] = ''; $arrayResult['depo_service'] = ''; $arrayResult['kind'] = ''; $item['project'] = 'sdfsdfsd';//$projectsModel->ProjectsModel($arrayResult,$item['info']["section_number"]); $item['userInfo'] = $this->arResult['userInfo'];//$userInfo; $item['projecttypeId'] = $this->arResult['projecttypeId']->id;//$projecttypeId->id; } //return $params; } public function getUserInfo($user) { if (!$user){ return ''; } $accountsEntity = Accounts::find()->where(['uuid' => $user['param'] ])->one(); return $accountsEntity; } public function getTypeProject($user) { $projettypesEntity = Projecttypes::find()->select('id')->where(['company' => $user->company, 'name' => 'Проект из мэппинга'])->one(); return $projettypesEntity; } public function OnlineAccountCheck($last_seen) { $last_seen = date($last_seen); $time = (time()-strtotime($last_seen)); if ($time <= Yii::$app->params['onlineMobileTimeoutSeconds']) return true; return false; } public function TimeString($timeobj) { if ($timeobj != null) return $timeobj->format('d.m.Y H:i'); //return date('d.m.Y H:i', $timeobj); } public function GetworksOnLoco($listWorks) { $result = []; if (empty($listWorks)){ return $result; } $arrayResult = []; foreach ($listWorks as $work){ $arrayResult[] = $work->section_id; } $sectionsEntity = Sections::find()->where(['in','uuid',$arrayResult])->asArray()->all(); $arrayResult = []; $arrayResultTemp = []; $arrayIdSerieTemp = []; foreach($sectionsEntity as $sec){ $arrayResult[] = $sec['uuid']; $arrayResultTemp[$sec['uuid']] = $sec; $LocomotiveSeriesEntity = LocomotiveSeries::findOne(['name' => $sec['locomotive_series']]); $arrayIdSerieTemp[$sec['uuid']] = $LocomotiveSeriesEntity->id; } $tempArray = []; foreach($listWorks as $w) { if ( in_array($w->section_id,$arrayResult)) { $tempArray[] = $w; $result[$w->section_id] = [ 'info_obj' => $tempArray ,'info'=> $arrayResultTemp[$w->section_id],'id_serie' => $arrayIdSerieTemp[$w->section_id]]; } } return $result; /* echo "
";
        var_dump($result);
        //var_dump($sectionsEntity);
         echo "
"; var_dump(count($arrayResult),count($sectionsEntity)); */ } public function checkMapping($arrProj) { $tempResult = []; $result = []; foreach ( $arrProj as &$proj) { foreach ( $proj['info_obj'] as $work) { $tempResult[] = $work->work_name; } $res = AsusgJobPlan::find()->where(['in', 'name',$tempResult])->all(); $proj['jobplan'] = $res; } return $arrProj; } public function addJobproject($minRes) { $projectTypes = []; foreach ( $minRes as &$proj) { foreach($proj['info_obj'] as $obj){ $repairtypesEntity = Repairtypes::find()->select('id')->where(['name'=> $obj->repair_name])->one(); $projectTypes[] = $repairtypesEntity->id; } $projectTypes = array_unique($projectTypes); foreach ( $projectTypes as $type) { $field = Yii::$app->params['sections_letter'][$proj['info']["letter"]]; $asusgProjectEntity = new AsusgProject(); $asusgProjectEntity->loco_serie_id = $proj['id_serie']; //locomotive_series $asusgProjectEntity->repair_type = $type; // repairtypes name из асусг $asusgProjectEntity->loco_number = $proj['info']["section_number"]; $asusgProjectEntity->$field = $proj['info']["section_subnumber"]; $asusgProjectTypeEntity = AsusgProjectType::findOne(['loco_serie_id' => $proj['id_serie'], 'repair_type' => $type]); $asusgProjectEntity->asusg_projecttype_id = $asusgProjectTypeEntity->id; $asusgProjectEntity->save(); $proj['asusgProject_id'] = $asusgProjectEntity->id; } } return $minRes; } public function addJob2launch($minRes) { foreach ( $minRes as $proj) { $resultArr = []; $order = 1; foreach ( $proj['jobplan'] as $work) { $sectionTemp = ''; $id_workTemp = ''; foreach($proj['info_obj'] as $obj){ if( $obj->work_name == $work->name){ $sectionTemp = $obj->section_id; $id_workTemp = $obj->id_work; break; } } $asusgJob2LaunchEntity = new AsusgJob2Launch(); $asusgJob2LaunchEntity->asusg_jobplan_id = $work->id; $asusgJob2LaunchEntity->asusg_employee_id1 = $proj['userInfo']->id; $asusgJob2LaunchEntity->asusg_job_uuid = $id_workTemp; $asusgJob2LaunchEntity->section_uuid = $sectionTemp; $asusgJob2LaunchEntity->asusg_project_id = $proj['asusgProject_id']; $asusgJob2LaunchEntity->job_order = $order; $asusgJob2LaunchEntity->save(); echo "
";
                var_dump($asusgJob2LaunchEntity->errors);
                //var_dump($sectionsEntity);
                echo "
"; $order++; } } } // Добавление новой ЗАДАЧИ public function addNewMainTask() { $work = Yii::$app->params['api']['mesrmntParam']['work']; /*echo "
 Main Task";
        var_dump(Yii::$app->params['api']['mesrmntParam']);
        echo "
"; return true;*/ $tasksEntity = new Tasks(); $tasksEntity->parent_id = 0; $tasksEntity->status = 2; $tasksEntity->type = Yii::$app->params['api']['mesrmntParam']['type'];//$tasktypesEntity->id; $tasksEntity->assignees_arr = Yii::$app->params['api']['mesrmntParam']['assignees_arr'];//Yii::$app->params['assignees_arr'];//$user->id; $tasksEntity->created = date("Y-m-d H:i;s"); $tasksEntity->asusg_job_mapped_id = Yii::$app->params['api']['mesrmntParam']['asusg_job_mapped_id'];//$asusgJob2LaunchEntity->id; $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; $tasksEntity->text = $work["outfit"] . ': ' . $work['work_name']; if($tasksEntity->save()) { Yii::$app->params['api']['mesrmntParam']['parent_id'] = $tasksEntity->id; //$this->testIdpl3 = $tasksEntity->id; //$this->setLog('в Tasks была добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { //$this->setLog('в Tasks была НЕ добавлена ЗАДАЧА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } return $tasksEntity; } // Добавление новой КОМАНДЫ // param // $chp => boolean ( добавлять чекпоинты или нет ) public function addNewTask($chp = false) { // $tasksEntity->id; родительская задача // $countPriority приоритет // $user->id сотрудник // $job->jobplantie->id launch Yii::$app->params['countPriority']++; $work = Yii::$app->params['api']['mesrmntParam']['work']; /*echo "
 Task";
        var_dump(Yii::$app->params['api']['mesrmntParam']);
        echo "
"; return true;*/ $result = []; $arrJ = []; $tasksEntity = new Tasks(); $tasksEntity->input_id = Yii::$app->params['api']['mesrmntParam']['input_id'];//$tasksEntity->id; $tasksEntity->parent_id = Yii::$app->params['api']['mesrmntParam']['parent_id'];//$tasksEntity->id; $tasksEntity->status = 2; $tasksEntity->priority = Yii::$app->params['countPriority'];//$countPriority; $tasksEntity->created = date("Y-m-d H:i:s"); $tasksEntity->type = Yii::$app->params['api']['mesrmntParam']['type'];//$job->smopp_cmd_id;//Yii::$app->params['supercycletype']; $tasksEntity->assignees_arr = Yii::$app->params['api']['mesrmntParam']['assignees_arr'];//$user->id; $tasksEntity->asusg_job_mapped_id = Yii::$app->params['api']['mesrmntParam']['asusg_job_mapped_id'];//$job->jobplantie->id; $tasksEntity->name = Yii::$app->params['api']['mesrmntParam']['measurement_name']; $tasksEntity->text = $work["eq_serie"] . " ".$work["section_lit"] . ", ". $work["outfit"] . ": " . $work['work_name']; $tasksEntity->mapping_comment = $work["outfit"] . ': ' . $work['work_name']; if ( $tasksEntity->save()) { $arrJ[] = $tasksEntity->id; if( $chp ) { //$query = "call asusg_add_checkpoints_to_task(" . Yii::$app->params['api']['mesrmntParam']['assignees_arr'] . ",'" . $tasksEntity->id . "')"; //$resProc = Yii::$app->db->createCommand($query)->execute(); //var_dump($resProc, 'запись checkpoints',$query); echo "\n"; } //$this->setLog('в Tasks была добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } else { //$this->setLog('в Tasks была НЕ добавлена КОМАНДА => "'. $work['work_name'] . '" id => '.$tasksEntity->id); } Yii::$app->params['countPriority']++; $result['arrJ'] = $arrJ; $result['tasksEntity'] = $tasksEntity; return $result; } }