123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\TasksModel;
- use \app\models\entity\Accounts;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\JobtypesTasktypes;
- use app\models\entity\Tasktypes;
- /**
- * This is the model class for table "s_regions".
- *
- * The followings are the available columns in table 's_regions':
- * @property integer $rg_id
- * @property string $rg_name
- */
- class ManagementModel extends Model
- {
- public $errors;
- const STATUS_DONE = 5;
- //=====================================================
- //
- // ФОРМИРУЕТ ЕДИНЫЙ МАССИВ ДЛЯ РЕНДЕРА В ПРЕДСТАВЛЕНИЕ
- //
- //=====================================================
-
- public function mainFuncController(){
-
- $arResult = [];
- $arResult['accountList'] = $this->getAccountList();
- $arResult['locomotiveList'] = $this->getLocomotiveList();
-
- return $arResult;
- }
- //=============================================
- //
- // СПИСОК СОТРУДНИКОВ ОНЛАЙН ДЛЯ ЛЕВОЙ ТАБЛИЧКИ
- //
- //=============================================
-
- private function getAccountList(){
- global $companyID;
- $result = [];
- $query = "SELECT ai.id, ai.name, ai.last_seen_mobile, aj.priority, aj.jobtype_id, jt.name as job_name
- FROM accounts_internal ai
- LEFT JOIN accounts_jobtypes aj ON aj.account_id = ai.id
- right join jobtypes jt on jt.id = aj.jobtype_id
- WHERE ai.company=". $companyID;
-
- $res = Yii::$app->db->createCommand($query)->queryAll();
- $tempArray = [];
- foreach($res as $item) {
- $last_seen_mobile = ( null != $item['last_seen_mobile'] )? new \DateTime($item['last_seen_mobile']): $item['last_seen_mobile'] ;
- $online_mobile = OnlineAccountCheck(TimeString($last_seen_mobile));
- if (!$online_mobile) { continue;}
-
- $tempArray[$item['id']][] = $item;
- $tempArray[$item['id']]['name'] = $item['name'];
- }
- $result = $tempArray;
-
- return $result;
- }
- //===========================================
- //
- // ОСНОВНОЙ СПИСОК ЛОКОМОТИВОВ
- //
- //===========================================
- private function getLocomotiveList(){
-
- global $companyID;
-
- $result = [];
- //var_dump($companyID);
- $projectsLocotechEntity = ProjectsLocotech::find()->where(['company' => $companyID] )->orderBy(['id' => SORT_DESC])->all();
- $listArray = [];
- foreach( $projectsLocotechEntity as $item){ //var_dump($item->id);echo "\n";
- //$tempArray = GetTasksForProject($item->id);
- $status = GetProjectStatus($item->id);
- if ($status != 2 && $status != 1) {continue;}
- $countDone = ['done' => 0, 'all' => 0 ];
- foreach( GetTasksForProject($item->id) as $proj) { //var_dump($proj);echo "<br>";
- $countDone['all']++;
- $tempArray = $proj;
- $tempArray['status'] = $this->CheckAcceptedStatus($proj);
- $tempArray['name'] = GetTaskNameAndDesc($proj['type'])[0];
- $tempArray['listAccounts'] = $this->getAccountListForTask($proj['type']);
- if ( self::STATUS_DONE == $tempArray['status'] ) {$countDone['done']++;}
- //$countDone['all'] ." / " . $countDone['done'];
- $listArray[] = $tempArray;
-
- }
- $result[$item->id]['countDone'] = [ 'done' => $countDone['done'], 'all' => $countDone['all'] ];
- //$tempArray['name'] = GetTaskNameAndDesc($tempArray['type'])[0];
-
- $result[$item->id]['arr'] = $listArray;//GetTasksForProject($item->id);
- $result[$item->id]['obj'] = $item;
- $listArray = [];
- }
- //exit;
- return $result;
-
- }
-
- //======================================================
- //
- // В СПИСКЕ ЛОКОМОТИВОВ ВЫПАДАЮЩИЙ СПИСОК С СОТРУДНИКАМИ
- //
- //======================================================
- private function getAccountListForTask($type){
- $query = "select a.id, a.name
- from accounts a
- where a.id in
- (select aj.account_id
- from accounts_jobtypes aj
- where aj.jobtype_id in (select jt.jobtype_id
- from jobtypes_tasktypes jt
- where tasktype_id in (select tt1.id
- from tasktypes tt
- right join tasktypes tt1 on INSTR(tt.subtasks, tt1.id) > 0
- where tt.id in (". $type ."))))
- and timestampdiff(MINUTE, a.last_seen_mobile, NOW()) < 10;";
-
- $result = Yii::$app->db->createCommand($query)->queryAll();
- return $result;
-
- }
- //======================================================
- //
- // ПРОВЕРКА СТАТУСА ЗАДАЧИ (ПРИНЯТА ОНА ИЛИ НЕТ)
- //
- //======================================================
- private function CheckAcceptedStatus($task) {
-
- $result = false;
- /*var_dump($task);
- $tasktypesEntity = Tasktypes::findOne($task);
- // var_dump($tasktypesEntity);
- if ( null == $task['finished_time'] ){
- if ( null == $task['accepted_time'] ) {
- $result = 1;
- } else {
- $result = 2;
- $acceptedTime = strtotime($task['accepted_time']);
- $expectedTime = ($tasktypesEntity->time_to_complete_minutes * 60) + $acceptedTime;
- if ( strtotime("now") > $expectedTime) {
- $result = 6;
- }
-
- }
- } else {
- $result = 5;
- }
-
- */
- $query = "select if(tx.total = tx.finished, 5, if (tx.accepted <> tx.finished, if(tx.attention > 0, 7, 2), if (tx.accepted = 0, 1, 3))) as taskstatus
- from (select count(t.id) as total,
- sum(if(t.accepted_time is not null, 1, 0)) as accepted,
- sum(if(t.finished_time is not null, 1, 0)) as finished,
- sum(if(t.finished_time is null, if(timestampdiff(MINUTE, t.accepted_time, NOW()) > tt.time_to_complete_minutes, 1, 0), 0)) as attention
- from tasks t
- right join tasktypes tt on t.type = tt.id
- where t.parent_id = ".$task['id'].") tx;";
- $result = Yii::$app->db->createCommand($query)->queryAll();
- $result = $result[0]["taskstatus"];
-
- return $result;
- }
- }
|