123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Accounts;
- use app\models\entity\Sections;
- use app\models\entity\Positions;
- use app\models\LocomotiveModel;
- use app\models\EmployeesModel;
- use app\models\UserModel;
- use app\models\TasksModel;
- use app\models\AccountModel;
- use app\models\ProjectsModel;
- use app\models\ServiceModel;
- class ServiceModel extends MainModel
- {
- const PROJECT_TYPE_TO_START = 129;
- public $errors = [];
- public function requestUser(){
-
- //$url = 'http://62.141.88.61:8085/Thingworx/Things/2050RepairsLibrary/Services/users'; //!!!!!!!!!!!!
- $url = '62.141.88.61:8085/Thingworx/Things/connSmoppLibrary/Services/get_workers';
- return $this->curlRequest($url);
- }
-
- public function getNewUsers( $usersArray = [] ) {
-
- if( empty($usersArray) ){
- return [];
- }
- $arResult = [];
- $accountsEntity = Accounts::find()->all();
- $idAccountArray = [];
- foreach ( $accountsEntity as $account){
- $idAccountArray[] = $account->id;
- }
-
- foreach ( $usersArray as $user ){
- if ( !in_array($user["user_id"], $idAccountArray) ) {
- $arResult[] = ['id' => $user["user_id"], 'jobtypes' => $user["jobtypes_id"],'name'=> $user["fio"]];
- }
- }
- return $arResult;
- }
-
- public function getSuitUser() {
-
-
- $url = 'http://62.141.88.61:8085/Thingworx/Things/2050RepairsLibrary/Services/users'; //!!!!!!!!!!!!
- return $this->curlRequest($url);
- }
-
- public function addSections($params = []) {
-
- if(empty($params)) {
- return false;
- }
- $sectionsEntity = new Sections();
- $sectionsEntity->locomotive_series = $params['series'];
- $sectionsEntity->section_number = $params['number'];
- $sectionsEntity->section_subnumber = $params['subnumber'];
- // $sectionsEntity->date_start_repair = $params['dateTime'];
- $sectionsEntity->rfid = $params['rfid'];
- $sectionsEntity->uuid = $params['sectionId'];
- //$sectionsEntity->
- if ($sectionsEntity->save()){
- return $sectionsEntity;
- //return true;
- }
- $this->errors['addSections'] = $sectionsEntity->errors;
- return false;
- }
-
- public function addSectionRemarks($param) {
-
- $locomotiveModel = new LocomotiveModel();
- $resultLocomotiveModel = $locomotiveModel->getSectionRemarks($param);
-
- }
-
- public function checkPost($post = []){
-
- $result = [];
- if( empty($post)){
- $this->errors['checkPost'] = 'Пустой пост';
- return false;
- }
- foreach (Yii::$app->params['api']['addworkRequestParams'] as $item) {
- if ( null == $post[$item] or '' == $post[$item] ) {
- $result[$item] = $post[$item];
- }
- }
- if ( !empty( $result ) ) {
- $this->errors['checkPost'] = $result;
- return false;
- }
- return true;
- }
-
- public function addWokrWeb($params) {
- $params = ['action' => self::PROJECT_TYPE_TO_START, 'company' => 3, 'loco_type'=> '','loco_number' => '','depo' => '', 'depo_service'=> 'Братское'];
- $locomotiveModel = new LocomotiveModel();
- $locomotiveModel = new LocomotiveModel();
- $projectsModel = new ProjectsModel();
- $serviceModel = new ServiceModel();
- $employeesModel = new EmployeesModel;
- $taskModel = new TasksModel();
- $userModel = new UserModel();
-
- $this->status(self::PROJECT_TYPE_TO_START);
- /*
- $param['place'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';//2';
- //$params['place'] = '5fb47130-580c-11e7-aefa-00155d6cab05';
- $param['date'] = '1562077752';
- //$result = $locomotiveModel->getSectionList($param);
- $pr['placeOfRepair'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';
- $result = $employeesModel->getWorkers($pr);
- return $result;
- $result = json_decode($result);
- $result = $result->array[0];
- *
- */
-
- $arrayParams['series'] = $result->PlaceOfRepair;
- $arrayParams['number'] = $result->SectionNumber;
- $arrayParams['subnumber'] = $result->SectionSubnumber;
- $arrayParams['dateTime'] = $result->RepairStartDateFact;
- $params['diagnosticCard'] = $result->DiagnosticMapsLocomotive;
- $params['loco_number'] = $result->LocomotiveNumber;
- $params['kind'] = $result->TypeOfRepair;
-
- //$res = $serviceModel->addSections($arrayParams); // +
-
- $activeid = $projectsModel->addProject($params); // Добавление новой записи в ProjectLocotech +
- $locomotiveModel->project_id = $activeid;
- $res = $locomotiveModel->getSectionRemarks($arrayParams, true); // +
- if ($activeid > 0) {
- if (StartProject($params['action'],$activeid) ) {
- TasksAssign('', true, $activeid);
- }
- //if ($projectsModel->StartProject($params['action'],$activeid)) { // +
- // $taskModel->TasksAssign('', true, $activeid);
- //}
- $proj = \Project::Find($activeid, $entityManager);
- $workers = $proj->GetWorkers();
- var_dump($workers);
- }
-
- $resultArray = ['workers' => $workers,
- 'inspectionId' => $activeid,
- 'inspectionData' => '2019-06-13 12:34:16',
- 'error_code' => 200,
- 'error_message' => 'Success',
- 'executeData' => $projectsModel->message,
- ];
-
- return $resultArray;
-
- }
-
- public function createPositions(){
-
- $employeesModel = new EmployeesModel;
-
- $result = $employeesModel->getPositionList();
- $result = json_decode($result);
- $result = $result->array;
- //"array":[{"Kod":"000000929","ID":"f5916bb5-08c8-11e4-803b-ac162db0b20c","Name":"Юрисконсульт 2 категории"}
- foreach( $result as $pos){
-
- //echo $pos->ID;
- //echo '<br>';
- //echo $pos->Name;
- $positionsEntity = new Positions();
- $positionsEntity->uuid = $pos->ID;
- $positionsEntity->name = $pos->Name;
- $positionsEntity->save();
-
- }
- //return json_decode($res);
- }
-
- }
|