ServiceModel.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use app\models\entity\Accounts;
  6. use app\models\entity\Sections;
  7. use app\models\entity\Positions;
  8. use app\models\LocomotiveModel;
  9. use app\models\EmployeesModel;
  10. use app\models\UserModel;
  11. use app\models\TasksModel;
  12. use app\models\AccountModel;
  13. use app\models\ProjectsModel;
  14. use app\models\ServiceModel;
  15. class ServiceModel extends MainModel
  16. {
  17. const PROJECT_TYPE_TO_START = 129;
  18. public $errors = [];
  19. public function requestUser(){
  20. //$url = 'http://62.141.88.61:8085/Thingworx/Things/2050RepairsLibrary/Services/users'; //!!!!!!!!!!!!
  21. $url = '62.141.88.61:8085/Thingworx/Things/connSmoppLibrary/Services/get_workers';
  22. return $this->curlRequest($url);
  23. }
  24. public function getNewUsers( $usersArray = [] ) {
  25. if( empty($usersArray) ){
  26. return [];
  27. }
  28. $arResult = [];
  29. $accountsEntity = Accounts::find()->all();
  30. $idAccountArray = [];
  31. foreach ( $accountsEntity as $account){
  32. $idAccountArray[] = $account->id;
  33. }
  34. foreach ( $usersArray as $user ){
  35. if ( !in_array($user["user_id"], $idAccountArray) ) {
  36. $arResult[] = ['id' => $user["user_id"], 'jobtypes' => $user["jobtypes_id"],'name'=> $user["fio"]];
  37. }
  38. }
  39. return $arResult;
  40. }
  41. public function getSuitUser() {
  42. $url = 'http://62.141.88.61:8085/Thingworx/Things/2050RepairsLibrary/Services/users'; //!!!!!!!!!!!!
  43. return $this->curlRequest($url);
  44. }
  45. public function addSections($params = []) {
  46. if(empty($params)) {
  47. return false;
  48. }
  49. $sectionsEntity = new Sections();
  50. $sectionsEntity->locomotive_series = $params['series'];
  51. $sectionsEntity->section_number = $params['number'];
  52. $sectionsEntity->section_subnumber = $params['subnumber'];
  53. // $sectionsEntity->date_start_repair = $params['dateTime'];
  54. $sectionsEntity->rfid = $params['rfid'];
  55. $sectionsEntity->uuid = $params['sectionId'];
  56. //$sectionsEntity->
  57. if ($sectionsEntity->save()){
  58. return $sectionsEntity;
  59. //return true;
  60. }
  61. $this->errors['addSections'] = $sectionsEntity->errors;
  62. return false;
  63. }
  64. public function addSectionRemarks($param) {
  65. $locomotiveModel = new LocomotiveModel();
  66. $resultLocomotiveModel = $locomotiveModel->getSectionRemarks($param);
  67. }
  68. public function checkPost($post = []){
  69. $result = [];
  70. if( empty($post)){
  71. $this->errors['checkPost'] = 'Пустой пост';
  72. return false;
  73. }
  74. foreach (Yii::$app->params['api']['addworkRequestParams'] as $item) {
  75. if ( null == $post[$item] or '' == $post[$item] ) {
  76. $result[$item] = $post[$item];
  77. }
  78. }
  79. if ( !empty( $result ) ) {
  80. $this->errors['checkPost'] = $result;
  81. return false;
  82. }
  83. return true;
  84. }
  85. public function addWokrWeb($params) {
  86. $params = ['action' => self::PROJECT_TYPE_TO_START, 'company' => 3, 'loco_type'=> '','loco_number' => '','depo' => '', 'depo_service'=> 'Братское'];
  87. $locomotiveModel = new LocomotiveModel();
  88. $locomotiveModel = new LocomotiveModel();
  89. $projectsModel = new ProjectsModel();
  90. $serviceModel = new ServiceModel();
  91. $employeesModel = new EmployeesModel;
  92. $taskModel = new TasksModel();
  93. $userModel = new UserModel();
  94. $this->status(self::PROJECT_TYPE_TO_START);
  95. /*
  96. $param['place'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';//2';
  97. //$params['place'] = '5fb47130-580c-11e7-aefa-00155d6cab05';
  98. $param['date'] = '1562077752';
  99. //$result = $locomotiveModel->getSectionList($param);
  100. $pr['placeOfRepair'] = 'a84d0a15-08ec-11e5-829d-00155d6cab05';
  101. $result = $employeesModel->getWorkers($pr);
  102. return $result;
  103. $result = json_decode($result);
  104. $result = $result->array[0];
  105. *
  106. */
  107. $arrayParams['series'] = $result->PlaceOfRepair;
  108. $arrayParams['number'] = $result->SectionNumber;
  109. $arrayParams['subnumber'] = $result->SectionSubnumber;
  110. $arrayParams['dateTime'] = $result->RepairStartDateFact;
  111. $params['diagnosticCard'] = $result->DiagnosticMapsLocomotive;
  112. $params['loco_number'] = $result->LocomotiveNumber;
  113. $params['kind'] = $result->TypeOfRepair;
  114. //$res = $serviceModel->addSections($arrayParams); // +
  115. $activeid = $projectsModel->addProject($params); // Добавление новой записи в ProjectLocotech +
  116. $locomotiveModel->project_id = $activeid;
  117. $res = $locomotiveModel->getSectionRemarks($arrayParams, true); // +
  118. if ($activeid > 0) {
  119. if (StartProject($params['action'],$activeid) ) {
  120. TasksAssign('', true, $activeid);
  121. }
  122. //if ($projectsModel->StartProject($params['action'],$activeid)) { // +
  123. // $taskModel->TasksAssign('', true, $activeid);
  124. //}
  125. $proj = \Project::Find($activeid, $entityManager);
  126. $workers = $proj->GetWorkers();
  127. var_dump($workers);
  128. }
  129. $resultArray = ['workers' => $workers,
  130. 'inspectionId' => $activeid,
  131. 'inspectionData' => '2019-06-13 12:34:16',
  132. 'error_code' => 200,
  133. 'error_message' => 'Success',
  134. 'executeData' => $projectsModel->message,
  135. ];
  136. return $resultArray;
  137. }
  138. public function createPositions(){
  139. $employeesModel = new EmployeesModel;
  140. $result = $employeesModel->getPositionList();
  141. $result = json_decode($result);
  142. $result = $result->array;
  143. //"array":[{"Kod":"000000929","ID":"f5916bb5-08c8-11e4-803b-ac162db0b20c","Name":"Юрисконсульт 2 категории"}
  144. foreach( $result as $pos){
  145. //echo $pos->ID;
  146. //echo '<br>';
  147. //echo $pos->Name;
  148. $positionsEntity = new Positions();
  149. $positionsEntity->uuid = $pos->ID;
  150. $positionsEntity->name = $pos->Name;
  151. $positionsEntity->save();
  152. }
  153. //return json_decode($res);
  154. }
  155. }