response->format = Response::FORMAT_JSON; return parent::beforeAction($action); } /** * Возвращает массив данных о пользователях указанной смены * @param int shiftId * * @return array */ public function actionWorker_list_current_shift() { $shiftId = (int)Yii::$app->request->get('shiftId'); $employees = Accounts::findAll(['shift_id' => $shiftId]); $response = []; foreach ($employees as $employee) { $task = Tasks::findOne([ 'assignees_arr' => $employee->id, 'parent_id' => 0, 'status' => 3//Активные задачи ]); $response[] = [ 'id' => $employee->id, 'fio' => $employee->name, 'status' => $employee->isOnline(), 'job_list' => $employee->getPositionsNames(), 'task' => $task->tasktypes->name, ]; } return $response; } /** * Возвращает список задач поставленных сотруднику за последние 12 часов * @param int userId * * @return array * @throws \Exception */ public function actionList_task_worker_12() { $userId = (int)Yii::$app->request->get('userId'); $date = new \DateTime(); $twelveHours = new \DateInterval('PT12H'); $date->sub($twelveHours); $tasks = Tasks::find() ->where(['assignees_arr' => $userId]) ->andWhere(['>=', 'assigned', $date->format('Y-m-d H:i:s')]) ->all() ; $statuses = TaskStatusNames::find()->indexBy('id')->all(); $response = []; $date = $date->format('Y-m-d H:i:s'); foreach ($tasks as $task) { if (($task->assigned && $task->assigned > $date) || $task->created > $date) { $response[] = [ 'id' => $task->id, 'name' => $task->tasktypes->name, 'status' => $statuses[$task->status]->name, 'desc' => $task->tasktypes->description, 'start' => $task->accepted_time, 'finish' => $task->finished_time, 'norm' => $task->tasktypes->time_to_complete_minutes, 'command' => (bool)$task->parent_id ]; } } //Сортируем по accepted_time // usort($response, function($a, $b) { // return ($a['start'] < $b['start']); // }); return $response; } /** * Возвращает данны о локомотивах за последние hours часов (что бы это не значило) * @param int hours * * @return array * @throws \Exception */ public function actionLocomotive_list() { $hours = (int)Yii::$app->request->get('hours'); $hoursInterval = new \DateInterval('PT' . $hours . 'H'); $date = new \DateTime(); $date->sub($hoursInterval); $projects = ProjectsLocotech::find() ->where(['>=', 'created', $date->format('Y-m-d H:i:s')]) ->all() ; $response = []; foreach ($projects as $project) { $locomotive = LocomotiveSeries::findOne(['name' => $project->loco_type]); $statuses = TaskStatusNames::find()->indexBy('id')->all(); $response[] = [ 'id' => $locomotive->id, 'status' => $statuses[$project->status]->name, 'series' => $project->loco_type, 'number' => $project->loco_number, 'production_date' => $project->created, 'start' => $project->getAcceptedTime(), 'finish' => $project->getFinishedTime() ]; } return $response; } /** * Возвращает все задачи и команды конкретного локомотива, отсортированных по рабочим * @param string locoSeries * @param int locoNumber * @param int hours * * @return array * @throws \Exception */ public function actionList_task_worker_locomotive() { $locoSeries = (string)Yii::$app->request->get('locoSeries'); $locoNumber = (int)Yii::$app->request->get('locoNumber'); $hours = (int)Yii::$app->request->get('hours'); $projects = ProjectsLocotech::findAll([ 'loco_type' => $locoSeries, 'loco_number' => $locoNumber ]); //Все задачи для локомотива $tasks = []; foreach ($projects as $project) { $tasks = array_merge($tasks, $project->getTask()->all()); } $statuses = TaskStatusNames::find()->indexBy('id')->all(); $date = new \DateTime(); $interval = new \DateInterval('PT' . $hours . 'H'); $date->sub($interval); $dateString = $date->format('Y-m-d H:i:s'); $response = []; /** @var Tasks $task */ foreach ($tasks as $task) { if ($hours) { if ($task->created < $dateString) continue; } $user = Accounts::findOne($task->assignees_arr); $response[] = [ 'id' => $task->id, 'fio' => $user->name, 'name' => $task->tasktypes->name, 'command' => (bool)$task->parent_id, 'status' => $statuses[$task->status]->name, 'start' => $task->accepted_time, 'finish' => $task->finished_time, 'norm' => $task->tasktypes->time_to_complete_minutes, 'assigned' => $task->assigned, 'project_id' => $task->input_id, 'parent_id' => $task->parent_id ]; } return $response; } /** * Возвращает все должности с пользователями связанными с ними * @param int shiftId * * @return array * @throws \Exception */ public function actionPositions() { $shiftId = (int)Yii::$app->request->get('shiftId'); $allUsers = Accounts::findAll(['shift_id' => $shiftId]); $response = []; foreach ($allUsers as $user) { /** @var Accounts $user */ foreach ($user->getPositionsList() as $positionInfo) { $response[] = [ 'id' => $positionInfo['id'], 'fio' => $user->name, 'position' => $positionInfo['name'], 'main' => (bool)$positionInfo['main'], 'online' => $user->isOnline(), ]; } } return $response; } }